@@ -10,7 +10,7 SOURCES += \ | |||
|
10 | 10 | $$PWD/qbarlegendmarker.cpp \ |
|
11 | 11 | $$PWD/qxylegendmarker.cpp \ |
|
12 | 12 | $$PWD/qarealegendmarker.cpp \ |
|
13 |
$$PWD/ |
|
|
13 | $$PWD/legendscroller.cpp | |
|
14 | 14 | |
|
15 | 15 | PRIVATE_HEADERS += \ |
|
16 | 16 | $$PWD/legendscroller_p.h \ |
@@ -21,8 +21,7 PRIVATE_HEADERS += \ | |||
|
21 | 21 | $$PWD/qpielegendmarker_p.h \ |
|
22 | 22 | $$PWD/qbarlegendmarker_p.h \ |
|
23 | 23 | $$PWD/qxylegendmarker_p.h \ |
|
24 |
$$PWD/qarealegendmarker_p.h |
|
|
25 | $$PWD/mouseeventhandler_p.h | |
|
24 | $$PWD/qarealegendmarker_p.h | |
|
26 | 25 | |
|
27 | 26 | |
|
28 | 27 | PUBLIC_HEADERS += \ |
@@ -160,37 +160,6 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) | |||
|
160 | 160 | return sh; |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
164 | { | |
|
165 | MouseEventHandler::handleMousePressEvent(event); | |
|
166 | m_pressPos = event->screenPos(); | |
|
167 | } | |
|
168 | ||
|
169 | void LegendMarkerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
|
170 | { | |
|
171 | MouseEventHandler::handleMouseMoveEvent(event); | |
|
172 | } | |
|
173 | ||
|
174 | void LegendMarkerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
|
175 | { | |
|
176 | MouseEventHandler::handleMouseReleaseEvent(event); | |
|
177 | } | |
|
178 | ||
|
179 | void LegendMarkerItem::mouseClicked() | |
|
180 | { | |
|
181 | emit m_marker->q_func()->clicked(); | |
|
182 | } | |
|
183 | ||
|
184 | void LegendMarkerItem::mouseMoved(const QPointF &delta) | |
|
185 | { | |
|
186 | m_marker->m_legend->d_ptr->move(delta); | |
|
187 | } | |
|
188 | ||
|
189 | void LegendMarkerItem::mouseReleased(const QPointF &pos) | |
|
190 | { | |
|
191 | m_marker->m_legend->d_ptr->release(pos - m_pressPos); | |
|
192 | } | |
|
193 | ||
|
194 | 163 | #include "moc_legendmarkeritem_p.cpp" |
|
195 | 164 | |
|
196 | 165 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -37,13 +37,12 | |||
|
37 | 37 | #include <QPen> |
|
38 | 38 | #include <QGraphicsSimpleTextItem> |
|
39 | 39 | #include <QGraphicsLayoutItem> |
|
40 | #include "mouseeventhandler_p.h" | |
|
41 | 40 | |
|
42 | 41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | 42 | |
|
44 | 43 | class QLegendMarkerPrivate; |
|
45 | 44 | |
|
46 |
class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem |
|
|
45 | class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem | |
|
47 | 46 | { |
|
48 | 47 | Q_OBJECT |
|
49 | 48 | Q_INTERFACES(QGraphicsLayoutItem) |
@@ -66,23 +65,11 public: | |||
|
66 | 65 | QBrush labelBrush() const; |
|
67 | 66 | |
|
68 | 67 | void setGeometry(const QRectF &rect); |
|
69 | ||
|
70 | 68 | QRectF boundingRect() const; |
|
71 | 69 | |
|
72 | 70 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
73 | ||
|
74 | 71 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const; |
|
75 | 72 | |
|
76 | // Event handlers, logic delegated to MouseEventHandler | |
|
77 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
78 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | |
|
79 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
|
80 | ||
|
81 | // Filtered callbacks from MouseEventHandler | |
|
82 | void mouseClicked(); | |
|
83 | void mouseMoved(const QPointF &delta); | |
|
84 | void mouseReleased(const QPointF &pos); | |
|
85 | ||
|
86 | 73 | protected: |
|
87 | 74 | QLegendMarkerPrivate *m_marker; // Knows |
|
88 | 75 | QRectF m_markerRect; |
@@ -18,35 +18,47 | |||
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | #include "mouseeventhandler_p.h" | |
|
21 | #include <QDebug> | |
|
22 | 22 | #include <QGraphicsSceneMouseEvent> |
|
23 | #include <QGraphicsScene> | |
|
24 | #include <QLegendMarker> | |
|
25 | #include "qlegendmarker_p.h" | |
|
26 | #include "legendmarkeritem_p.h" | |
|
27 | #include "legendscroller_p.h" | |
|
23 | 28 | |
|
24 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 30 | |
|
26 | MouseEventHandler::MouseEventHandler() : | |
|
31 | LegendScroller::LegendScroller(QChart *chart) : QLegend(chart), | |
|
27 | 32 | m_lastPos(0, 0), |
|
28 | 33 | m_state(Idle), |
|
29 | 34 | m_treshold(10) |
|
30 | 35 | { |
|
31 | 36 | } |
|
32 | 37 | |
|
33 | MouseEventHandler::~MouseEventHandler() | |
|
38 | void LegendScroller::setOffset(const QPointF &point) | |
|
34 | 39 | { |
|
40 | d_ptr->setOffset(point); | |
|
35 | 41 | } |
|
36 | 42 | |
|
37 | void MouseEventHandler::setMoveTreshold(qreal treshold) | |
|
43 | QPointF LegendScroller::offset() const | |
|
44 | { | |
|
45 | return d_ptr->offset(); | |
|
46 | } | |
|
47 | ||
|
48 | void LegendScroller::setMoveTreshold(qreal treshold) | |
|
38 | 49 | { |
|
39 | 50 | m_treshold = treshold; |
|
40 | 51 | } |
|
41 | 52 | |
|
42 |
void |
|
|
53 | void LegendScroller::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
43 | 54 | { |
|
44 |
m_ |
|
|
55 | m_pressPos = event->screenPos(); | |
|
56 | m_lastPos = m_pressPos; | |
|
45 | 57 | m_state = Pressed; |
|
46 | 58 | event->accept(); |
|
47 | 59 | } |
|
48 | 60 | |
|
49 |
void |
|
|
61 | void LegendScroller::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
|
50 | 62 | { |
|
51 | 63 | QPointF delta = event->screenPos() - m_lastPos; |
|
52 | 64 | |
@@ -56,14 +68,14 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) | |||
|
56 | 68 | if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) { |
|
57 | 69 | m_state = Moved; |
|
58 | 70 | m_lastPos = event->screenPos(); |
|
59 |
mo |
|
|
71 | move(delta); | |
|
60 | 72 | } |
|
61 | 73 | event->accept(); |
|
62 | 74 | break; |
|
63 | 75 | } |
|
64 | 76 | case Moved: { |
|
65 | 77 | m_lastPos = event->screenPos(); |
|
66 |
mo |
|
|
78 | move(delta); | |
|
67 | 79 | event->accept(); |
|
68 | 80 | break; |
|
69 | 81 | } |
@@ -75,7 +87,7 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) | |||
|
75 | 87 | } |
|
76 | 88 | } |
|
77 | 89 | |
|
78 |
void |
|
|
90 | void LegendScroller::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
|
79 | 91 | { |
|
80 | 92 | m_lastPos = event->screenPos(); |
|
81 | 93 | |
@@ -83,14 +95,21 void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |||
|
83 | 95 | case Pressed: |
|
84 | 96 | { |
|
85 | 97 | m_state = Idle; |
|
86 | mouseClicked(); | |
|
98 | QList<QGraphicsItem *> items = scene()->items(event->scenePos()); | |
|
99 | ||
|
100 | foreach (QGraphicsItem *i, items) { | |
|
101 | if (d_ptr->m_markerHash.contains(i)) { | |
|
102 | QLegendMarker *marker = d_ptr->m_markerHash.value(i); | |
|
103 | emit marker->clicked(); | |
|
104 | } | |
|
105 | } | |
|
106 | ||
|
87 | 107 | event->accept(); |
|
88 | 108 | break; |
|
89 | 109 | } |
|
90 | 110 | case Moved: |
|
91 | 111 | { |
|
92 | m_state = Idle; | |
|
93 | mouseReleased(m_lastPos); | |
|
112 | scrollTo(m_lastPos - m_pressPos); | |
|
94 | 113 | event->accept(); |
|
95 | 114 | break; |
|
96 | 115 | } |
@@ -103,4 +122,6 void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |||
|
103 | 122 | } |
|
104 | 123 | } |
|
105 | 124 | |
|
125 | ||
|
126 | #include "moc_legendscroller_p.cpp" | |
|
106 | 127 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -33,18 +33,39 | |||
|
33 | 33 | |
|
34 | 34 | #include "qlegend.h" |
|
35 | 35 | #include "qlegend_p.h" |
|
36 | #include "scroller_p.h" | |
|
36 | 37 | |
|
37 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 39 | |
|
39 | class LegendScroller: public QLegend | |
|
40 | class LegendScroller: public QLegend, public Scroller | |
|
40 | 41 | { |
|
42 | Q_OBJECT | |
|
41 | 43 | |
|
42 | 44 | public: |
|
43 |
LegendScroller(QChart *chart) |
|
|
45 | LegendScroller(QChart *chart); | |
|
44 | 46 | |
|
45 |
void setOffset(const QPointF &point) |
|
|
47 | void setOffset(const QPointF &point); | |
|
48 | QPointF offset() const; | |
|
46 | 49 | |
|
47 | QPointF offset() const { return d_ptr->offset(); } | |
|
50 | void setMoveTreshold(qreal treshold); | |
|
51 | ||
|
52 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
53 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | |
|
54 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
|
55 | ||
|
56 | private: | |
|
57 | ||
|
58 | enum State { | |
|
59 | Idle, | |
|
60 | Pressed, | |
|
61 | Moved, | |
|
62 | Released | |
|
63 | }; | |
|
64 | ||
|
65 | QPointF m_pressPos; | |
|
66 | QPointF m_lastPos; | |
|
67 | State m_state; | |
|
68 | qreal m_treshold; | |
|
48 | 69 | }; |
|
49 | 70 | |
|
50 | 71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -584,6 +584,7 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |||
|
584 | 584 | foreach (QLegendMarker *marker, markers) { |
|
585 | 585 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
586 | 586 | m_markers << marker; |
|
587 | m_markerHash.insert(marker->d_ptr->item(), marker); | |
|
587 | 588 | } |
|
588 | 589 | } |
|
589 | 590 | |
@@ -592,8 +593,9 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | |||
|
592 | 593 | foreach (QLegendMarker *marker, markers) { |
|
593 | 594 | marker->d_ptr->item()->setVisible(false); |
|
594 | 595 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
595 | delete marker; | |
|
596 | 596 | m_markers.removeOne(marker); |
|
597 | m_markerHash.remove(marker->d_ptr->item()); | |
|
598 | delete marker; | |
|
597 | 599 | } |
|
598 | 600 | } |
|
599 | 601 |
@@ -31,7 +31,6 | |||
|
31 | 31 | #define QLEGEND_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qlegend.h" |
|
34 | #include "scroller_p.h" | |
|
35 | 34 | |
|
36 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 36 | |
@@ -42,7 +41,7 class LegendLayout; | |||
|
42 | 41 | class Domain; |
|
43 | 42 | class QLegendMarker; |
|
44 | 43 | |
|
45 |
class QLegendPrivate : public QObject |
|
|
44 | class QLegendPrivate : public QObject | |
|
46 | 45 | { |
|
47 | 46 | Q_OBJECT |
|
48 | 47 | public: |
@@ -90,10 +89,13 private: | |||
|
90 | 89 | QList<QLegendMarker *> m_markers; |
|
91 | 90 | QList<QAbstractSeries *> m_series; |
|
92 | 91 | |
|
92 | QHash<QGraphicsItem *, QLegendMarker *> m_markerHash; | |
|
93 | ||
|
93 | 94 | friend class QLegend; |
|
94 | 95 | friend class LegendMarkerItem; |
|
95 | 96 | friend class LegendLayout; |
|
96 | 97 | friend class QLegendMarkerPrivate; |
|
98 | friend class LegendScroller; | |
|
97 | 99 | }; |
|
98 | 100 | |
|
99 | 101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -56,7 +56,7 void Scroller::move(const QPointF &delta) | |||
|
56 | 56 | setOffset(offset() - delta); |
|
57 | 57 | } |
|
58 | 58 | |
|
59 |
void Scroller:: |
|
|
59 | void Scroller::scrollTo(const QPointF &delta) | |
|
60 | 60 | { |
|
61 | 61 | // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp |
|
62 | 62 | // current time is no more than m_timeTresholdMax from timestamp |
@@ -73,7 +73,7 public: | |||
|
73 | 73 | virtual QPointF offset() const = 0; |
|
74 | 74 | |
|
75 | 75 | void move(const QPointF &delta); |
|
76 |
void |
|
|
76 | void scrollTo(const QPointF &delta); | |
|
77 | 77 | |
|
78 | 78 | void scrollTick(); |
|
79 | 79 | |
@@ -81,7 +81,6 private: | |||
|
81 | 81 | void startTicker(int interval); |
|
82 | 82 | void stopTicker(); |
|
83 | 83 | |
|
84 | ||
|
85 | 84 | private: |
|
86 | 85 | void calculateSpeed(const QPointF &position); |
|
87 | 86 | void lowerSpeed(QPointF &speed, qreal maxSpeed = 100); |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now