##// END OF EJS Templates
tooltip for barcharts
sauimone -
r283:b72248832d09
parent child
Show More
@@ -1,6 +1,7
1 #include "bar_p.h"
1 #include "bar_p.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <QPainter>
3 #include <QPainter>
4 #include <QGraphicsSceneEvent>
4
5
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
7
@@ -70,12 +71,12 void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/)
70
71
71 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
72 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
72 {
73 {
73 emit hoverEntered(event);
74 emit hoverEntered(event->lastScreenPos());
74 }
75 }
75
76
76 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
77 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/)
77 {
78 {
78 emit hoverLeaved(event);
79 emit hoverLeaved();
79 }
80 }
80
81
81 #include "moc_bar_p.cpp"
82 #include "moc_bar_p.cpp"
@@ -34,8 +34,8 public:
34
34
35 Q_SIGNALS:
35 Q_SIGNALS:
36 void clicked();
36 void clicked();
37 void hoverEntered(QGraphicsSceneHoverEvent *event);
37 void hoverEntered(QPoint pos);
38 void hoverLeaved(QGraphicsSceneHoverEvent *event);
38 void hoverLeaved();
39
39
40 private:
40 private:
41
41
@@ -71,8 +71,8 void BarPresenterBase::dataChanged()
71 mBars.append(bar);
71 mBars.append(bar);
72 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
72 connect(bar,SIGNAL(clicked()),set,SLOT(barClicked()));
73 // TODO: should the event be passed to set or not?
73 // TODO: should the event be passed to set or not?
74 //connect(bar,SIGNAL(hoverEntered(QGraphicsSceneHoverEvent* event)),set,SLOT(barHoverEntered(QGraphicsSceneHoverEvent* event)));
74 connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEntered(QPoint)));
75 //connect(bar,SIGNAL(hoverLeaved(QGraphicsSceneHoverEvent* event)),set,SLOT(barHoverLeaved(QGraphicsSceneHoverEvent *event)));
75 connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaved()));
76 }
76 }
77 }
77 }
78
78
@@ -1,5 +1,6
1 #include "qbarset.h"
1 #include "qbarset.h"
2 #include <QDebug>
2 #include <QDebug>
3 #include <QToolTip>
3
4
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
6
@@ -67,7 +68,7 void QBarSet::enableFloatingValues(bool enabled)
67 mFloatingValuesEnabled = enabled;
68 mFloatingValuesEnabled = enabled;
68 }
69 }
69
70
70 void QBarSet::enableHoverNames(bool enabled)
71 void QBarSet::enableToolTip(bool enabled)
71 {
72 {
72 qDebug() << "QBarSet::enableHoverNames" << enabled;
73 qDebug() << "QBarSet::enableHoverNames" << enabled;
73 mHoverNamesEnabled = enabled;
74 mHoverNamesEnabled = enabled;
@@ -81,11 +82,12 void QBarSet::barClicked()
81 emit clicked(); // Notify that set has been clicked
82 emit clicked(); // Notify that set has been clicked
82 }
83 }
83
84
84 void QBarSet::barHoverEntered()
85 void QBarSet::barHoverEntered(QPoint pos)
85 {
86 {
86 qDebug() << "QBarset::barHoverEntered" << this;
87 qDebug() << "QBarset::barHoverEntered" << this << pos;
87 if (mHoverNamesEnabled) {
88 if (mHoverNamesEnabled) {
88 emit hoverEnter();
89 QToolTip::showText(pos, mName);
90 // emit hoverEnter();
89 }
91 }
90 }
92 }
91
93
@@ -93,7 +95,7 void QBarSet::barHoverLeaved()
93 {
95 {
94 qDebug() << "QBarset::barHoverLeaved" << this;
96 qDebug() << "QBarset::barHoverLeaved" << this;
95 if (mHoverNamesEnabled) {
97 if (mHoverNamesEnabled) {
96 emit hoverLeave();
98 // emit hoverLeave();
97 }
99 }
98 }
100 }
99
101
@@ -34,13 +34,14 Q_SIGNALS:
34 void toggleFloatingValues(); // Private signal, TODO: move to private impl
34 void toggleFloatingValues(); // Private signal, TODO: move to private impl
35
35
36 public Q_SLOTS:
36 public Q_SLOTS:
37 // TODO: should these be in series instead?
37 void enableFloatingValues(bool enabled); // enables floating values on top of bars
38 void enableFloatingValues(bool enabled); // enables floating values on top of bars
38 void enableHoverNames(bool enabled); // enableHoverEvents would be better name?
39 void enableToolTip(bool enabled); // enables tooltips
39
40
40 // TODO: these slots belong to private implementation.
41 // TODO: these slots belong to private implementation.
41 // These are for single bars to notify set about internal events
42 // These are for single bars to notify set about internal events
42 void barClicked();
43 void barClicked();
43 void barHoverEntered();
44 void barHoverEntered(QPoint pos);
44 void barHoverLeaved();
45 void barHoverLeaved();
45
46
46 private:
47 private:
General Comments 0
You need to be logged in to leave comments. Login now