summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-10 11:07:44 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-10 11:07:44 -0300
commit2052e44ba19b4bc9689792bbff2170fc3426d42a (patch)
tree136c99ed015e89874184ece2fbe9b6fe3396c3f7
parent93d3af768b86602b3b13062705cb2d12db82b5a2 (diff)
downloadsubsurface-2052e44ba19b4bc9689792bbff2170fc3426d42a.tar.gz
Fix Tooltip Positions, code cleanup
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--qt-ui/profilegraphics.cpp32
-rw-r--r--qt-ui/profilegraphics.h1
2 files changed, 22 insertions, 11 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 4d900aa73..9441f3ae3 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -142,6 +142,7 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
// Scale the view / do the zoom
+ QPoint toolTipPos = mapFromScene(toolTip->pos());
double scaleFactor = 1.15;
if(event->delta() > 0) {
// Zoom in
@@ -150,23 +151,16 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
// Zooming out
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
}
+ toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
}
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
{
- toolTip->clear();
- int time = (mapToScene(event->pos()).x() * gc.maxtime) / scene()->sceneRect().width();
- char buffer[500];
- get_plot_details(&gc, time, buffer, 500);
- toolTip->addToolTip(QString(buffer));
- QList<QGraphicsItem*> items = scene()->items(mapToScene(event->pos()), Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
- Q_FOREACH(QGraphicsItem *item, items) {
- if (!item->toolTip().isEmpty())
- toolTip->addToolTip(item->toolTip());
- }
+ toolTip->refresh(&gc, mapToScene(event->pos()));
- // Pan on mouseMove code.
+ QPoint toolTipPos = mapFromScene(toolTip->pos());
ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100);
+ toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
QGraphicsView::mouseMoveEvent(event);
}
@@ -1172,6 +1166,22 @@ void ToolTipItem::removeToolTip(const QString& toolTip)
expand();
}
+void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
+{
+ clear();
+ int time = (pos.x() * gc->maxtime) / scene()->sceneRect().width();
+ char buffer[500];
+ get_plot_details(gc, time, buffer, 500);
+ addToolTip(QString(buffer));
+
+ QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
+ Q_FOREACH(QGraphicsItem *item, items) {
+ if (!item->toolTip().isEmpty())
+ addToolTip(item->toolTip());
+ }
+
+}
+
void ToolTipItem::clear()
{
Q_FOREACH(ToolTip t, toolTips) {
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 76179b956..b9b57db08 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -31,6 +31,7 @@ public:
void clear();
void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
void removeToolTip(const QString& toolTip);
+ void refresh(struct graphics_context* gc, QPointF pos);
public Q_SLOTS:
void setRect(const QRectF& rect);