aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-02-27 22:52:03 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-27 18:57:48 -0800
commit006265d7a088cff4fea665159dbb454956c2cd76 (patch)
tree0b12c541de10ca46045f2b014b2abbfa05f43c41 /qt-ui/profile
parent63f7f37e4617b15af9bbd1894d529da2c22a34f1 (diff)
downloadsubsurface-006265d7a088cff4fea665159dbb454956c2cd76.tar.gz
Try to fix the font issue on the ruler.
This changes the ruler a bit, I hope nobody gets offended by it. :) The main issue is that the scene is now 100x100 pixels wide, so the font was *really* huge. and setting itemIgnoresTransformations on the ruler broke a lot of stuff. I removed the code that painted the text and created a QGraphics TextItem for that - that will hold the text for the ruler. Then I played with the view to get the correct angle of the line, that was in scene coordinates and thus, could not be used directly on the item that had ignore transformation changes. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/ruleritem.cpp54
-rw-r--r--qt-ui/profile/ruleritem.h1
2 files changed, 22 insertions, 33 deletions
diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
index d2b06f72d..04b7fd996 100644
--- a/qt-ui/profile/ruleritem.cpp
+++ b/qt-ui/profile/ruleritem.cpp
@@ -1,8 +1,11 @@
#include "ruleritem.h"
+#include "divetextitem.h"
+
#include <QFont>
#include <QFontMetrics>
#include <QPainter>
#include <QGraphicsScene>
+#include <QGraphicsView>
#include <QDebug>
#include <stdint.h>
@@ -62,11 +65,13 @@ RulerItem2::RulerItem2():
timeAxis(NULL),
depthAxis(NULL),
source(new RulerNodeItem2(pInfo)),
- dest(new RulerNodeItem2(pInfo))
+ dest(new RulerNodeItem2(pInfo)),
+ textItem(new QGraphicsSimpleTextItem(this))
{
memset(&pInfo, 0, sizeof(pInfo));
source->setRuler(this);
dest->setRuler(this);
+ textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
}
void RulerItem2::recalculate()
@@ -82,6 +87,7 @@ void RulerItem2::recalculate()
prepareGeometryChange();
startPoint = mapFromItem(source, 0, 0);
endPoint = mapFromItem(dest, 0, 0);
+
if (startPoint.x() > endPoint.x()) {
tmp = endPoint;
endPoint = startPoint;
@@ -92,22 +98,21 @@ void RulerItem2::recalculate()
compare_samples(source->entry, dest->entry, buffer, 500, 1);
text = QString(buffer);
- QRect r = fm.boundingRect(QRect(QPoint(10,-1*INT_MAX), QPoint(line.length()-10, 0)), Qt::TextWordWrap, text);
- if (r.height() < 10)
- height = 10;
- else
- height = r.height();
+ //Draw Text
+ // This text item ignores transformations, so we cant use
+ // the line.angle(), we need to calculate the angle based
+ // on the view.
+
+ QGraphicsView *view = scene()->views().first();
+ QPoint begin = view->mapFromScene(mapToScene(startPoint));
+ QPoint end = view->mapFromScene(mapToScene(endPoint));
+ QLineF globalLine(begin, end);
+ textItem->setText(text);
+ textItem->resetMatrix();
+ textItem->resetTransform();
+ textItem->setPos(startPoint);
+ textItem->rotate(globalLine.angle() * -1);
- QLineF line_n = line.normalVector();
- line_n.setLength(height);
- if (scene()) {
- /* Determine whether we draw down or upwards */
- if (scene()->sceneRect().contains(line_n.p2()) &&
- scene()->sceneRect().contains(endPoint+QPointF(line_n.dx(),line_n.dy())))
- paint_direction = -1;
- else
- paint_direction = 1;
- }
}
RulerNodeItem2 *RulerItem2::sourceNode() const
@@ -125,26 +130,9 @@ void RulerItem2::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
Q_UNUSED(option);
Q_UNUSED(widget);
QLineF line(startPoint, endPoint);
- QLineF line_n = line.normalVector();
painter->setPen(QColor(Qt::black));
painter->setBrush(Qt::NoBrush);
- line_n.setLength(height);
-
- if (paint_direction == 1)
- line_n.setAngle(line_n.angle()+180);
painter->drawLine(line);
- painter->drawLine(line_n);
- painter->drawLine(line_n.p1() + QPointF(line.dx(), line.dy()), line_n.p2() + QPointF(line.dx(), line.dy()));
-
- //Draw Text
- painter->save();
- painter->translate(startPoint.x(), startPoint.y());
- painter->rotate(line.angle()*-1);
- if (paint_direction == 1)
- painter->translate(0, height);
- painter->setPen(Qt::black);
- painter->drawText(QRectF(QPointF(10,-1*height), QPointF(line.length()-10, 0)), Qt::TextWordWrap, text);
- painter->restore();
}
QRectF RulerItem2::boundingRect() const
diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h
index 714bf09f9..f9cc98577 100644
--- a/qt-ui/profile/ruleritem.h
+++ b/qt-ui/profile/ruleritem.h
@@ -54,5 +54,6 @@ private:
int paint_direction;
DiveCartesianAxis *timeAxis;
DiveCartesianAxis *depthAxis;
+ QGraphicsSimpleTextItem *textItem;
};
#endif \ No newline at end of file