##// END OF EJS Templates
Callout example: removed unnecessary variable
Marek Rosa -
r2379:9645dba0fec9
parent child
Show More
@@ -70,18 +70,13 void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
70
70
71 void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event)
71 void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event)
72 {
72 {
73 if (m_rect.contains(event->pos())) {
73 event->setAccepted(true);
74 m_clickOffset = event->pos();
75 event->setAccepted(true);
76 } else {
77 event->setAccepted(false);
78 }
79 }
74 }
80
75
81 void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
76 void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
82 {
77 {
83 if (event->buttons() & Qt::LeftButton){
78 if (event->buttons() & Qt::LeftButton){
84 setPos(mapToParent(event->pos() - m_clickOffset));
79 setPos(mapToParent(event->pos() - event->buttonDownPos(Qt::LeftButton)));
85 event->setAccepted(true);
80 event->setAccepted(true);
86 } else {
81 } else {
87 event->setAccepted(false);
82 event->setAccepted(false);
@@ -94,7 +89,7 void Callout::setText(const QString &text)
94 QFontMetrics metrics(m_font);
89 QFontMetrics metrics(m_font);
95 m_textRect = metrics.boundingRect(QRect(0, 0, 150, 150), Qt::AlignLeft, m_text);
90 m_textRect = metrics.boundingRect(QRect(0, 0, 150, 150), Qt::AlignLeft, m_text);
96 m_textRect.translate(5, 5);
91 m_textRect.translate(5, 5);
97 prepareGeometryChange();
92 prepareGeometryChange();
98 m_rect = m_textRect.adjusted(-5, -5, 5, 5);
93 m_rect = m_textRect.adjusted(-5, -5, 5, 5);
99 }
94 }
100
95
@@ -27,7 +27,6 private:
27 QRectF m_rect;
27 QRectF m_rect;
28 QPointF m_anchor;
28 QPointF m_anchor;
29 QFont m_font;
29 QFont m_font;
30 QPointF m_clickOffset;
31 };
30 };
32
31
33 #endif // CALLOUT_H
32 #endif // CALLOUT_H
General Comments 0
You need to be logged in to leave comments. Login now