Permalink
Browse files

Show tree node info popup slightly above cursor

  • Loading branch information...
1 parent 987a298 commit 9c96a7f5fe2a058929a4f16c02bdba0afc090107 @jelmervdl jelmervdl committed May 24, 2012
Showing with 14 additions and 2 deletions.
  1. +1 −0 include/TreeNode.hh
  2. +13 −2 src/TreeNode.cpp
View
@@ -41,6 +41,7 @@ private:
void paintLabels(QPainter *painter, QRectF const &leaf);
void paintEdges(QPainter *painter, QRectF const &leaf);
QFont font() const;
+ qreal viewScale() const;
bool d_active;
QHash<QString,QString> d_attributes;
TreeNode *d_parentNode;
View
@@ -1,11 +1,14 @@
#include <QGraphicsScene>
#include <QGraphicsSceneHoverEvent>
+#include <QGraphicsView>
#include <QPainter>
#include <QSettings>
#include "TreeNode.hh"
#include "PopupItem.hh"
+static const QPointF popupCursorOffset(0, -16);
+
TreeNode::TreeNode(QGraphicsItem *parent) :
QGraphicsItem(parent),
d_active(false),
@@ -97,10 +100,10 @@ void TreeNode::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
// the region of the popup when we hover as a result of mouse scrolling.
d_popupItem->scene()->invalidate(d_popupItem->sceneBoundingRect());
#endif
- d_popupItem->setPos(event->scenePos());
+ d_popupItem->setPos(event->scenePos() + popupCursorOffset / viewScale());
}
else
- d_popupItem->setPos(event->scenePos());
+ d_popupItem->setPos(event->scenePos() + popupCursorOffset / viewScale());
event->accept();
}
}
@@ -302,3 +305,11 @@ void TreeNode::paintEdges(QPainter *painter, QRectF const &leaf)
painter->drawLine(origin, target);
}
}
+
+qreal TreeNode::viewScale() const
+{
+ if (!scene() || scene()->views().isEmpty())
+ return 1.0;
+
+ return scene()->views().first()->transform().m11();
+}

0 comments on commit 9c96a7f

Please sign in to comment.