@@ -10,7 +10,7 SOURCES += \ | |||||
10 | $$PWD/qbarlegendmarker.cpp \ |
|
10 | $$PWD/qbarlegendmarker.cpp \ | |
11 | $$PWD/qxylegendmarker.cpp \ |
|
11 | $$PWD/qxylegendmarker.cpp \ | |
12 | $$PWD/qarealegendmarker.cpp \ |
|
12 | $$PWD/qarealegendmarker.cpp \ | |
13 |
$$PWD/ |
|
13 | $$PWD/legendscroller.cpp | |
14 |
|
14 | |||
15 | PRIVATE_HEADERS += \ |
|
15 | PRIVATE_HEADERS += \ | |
16 | $$PWD/legendscroller_p.h \ |
|
16 | $$PWD/legendscroller_p.h \ | |
@@ -21,8 +21,7 PRIVATE_HEADERS += \ | |||||
21 | $$PWD/qpielegendmarker_p.h \ |
|
21 | $$PWD/qpielegendmarker_p.h \ | |
22 | $$PWD/qbarlegendmarker_p.h \ |
|
22 | $$PWD/qbarlegendmarker_p.h \ | |
23 | $$PWD/qxylegendmarker_p.h \ |
|
23 | $$PWD/qxylegendmarker_p.h \ | |
24 |
$$PWD/qarealegendmarker_p.h |
|
24 | $$PWD/qarealegendmarker_p.h | |
25 | $$PWD/mouseeventhandler_p.h |
|
|||
26 |
|
25 | |||
27 |
|
26 | |||
28 | PUBLIC_HEADERS += \ |
|
27 | PUBLIC_HEADERS += \ |
@@ -160,37 +160,6 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) | |||||
160 | return sh; |
|
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 | #include "moc_legendmarkeritem_p.cpp" |
|
163 | #include "moc_legendmarkeritem_p.cpp" | |
195 |
|
164 | |||
196 | QTCOMMERCIALCHART_END_NAMESPACE |
|
165 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -37,13 +37,12 | |||||
37 | #include <QPen> |
|
37 | #include <QPen> | |
38 | #include <QGraphicsSimpleTextItem> |
|
38 | #include <QGraphicsSimpleTextItem> | |
39 | #include <QGraphicsLayoutItem> |
|
39 | #include <QGraphicsLayoutItem> | |
40 | #include "mouseeventhandler_p.h" |
|
|||
41 |
|
40 | |||
42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
43 |
|
42 | |||
44 | class QLegendMarkerPrivate; |
|
43 | class QLegendMarkerPrivate; | |
45 |
|
44 | |||
46 |
class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem |
|
45 | class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem | |
47 | { |
|
46 | { | |
48 | Q_OBJECT |
|
47 | Q_OBJECT | |
49 | Q_INTERFACES(QGraphicsLayoutItem) |
|
48 | Q_INTERFACES(QGraphicsLayoutItem) | |
@@ -66,23 +65,11 public: | |||||
66 | QBrush labelBrush() const; |
|
65 | QBrush labelBrush() const; | |
67 |
|
66 | |||
68 | void setGeometry(const QRectF &rect); |
|
67 | void setGeometry(const QRectF &rect); | |
69 |
|
||||
70 | QRectF boundingRect() const; |
|
68 | QRectF boundingRect() const; | |
71 |
|
69 | |||
72 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
70 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
73 |
|
||||
74 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const; |
|
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 | protected: |
|
73 | protected: | |
87 | QLegendMarkerPrivate *m_marker; // Knows |
|
74 | QLegendMarkerPrivate *m_marker; // Knows | |
88 | QRectF m_markerRect; |
|
75 | QRectF m_markerRect; |
@@ -18,35 +18,47 | |||||
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mouseeventhandler_p.h" |
|
21 | #include <QDebug> | |
22 | #include <QGraphicsSceneMouseEvent> |
|
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 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
30 | |||
26 | MouseEventHandler::MouseEventHandler() : |
|
31 | LegendScroller::LegendScroller(QChart *chart) : QLegend(chart), | |
27 | m_lastPos(0, 0), |
|
32 | m_lastPos(0, 0), | |
28 | m_state(Idle), |
|
33 | m_state(Idle), | |
29 | m_treshold(10) |
|
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 | m_treshold = treshold; |
|
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 | m_state = Pressed; |
|
57 | m_state = Pressed; | |
46 | event->accept(); |
|
58 | event->accept(); | |
47 | } |
|
59 | } | |
48 |
|
60 | |||
49 |
void |
|
61 | void LegendScroller::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
50 | { |
|
62 | { | |
51 | QPointF delta = event->screenPos() - m_lastPos; |
|
63 | QPointF delta = event->screenPos() - m_lastPos; | |
52 |
|
64 | |||
@@ -56,14 +68,14 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) | |||||
56 | if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) { |
|
68 | if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) { | |
57 | m_state = Moved; |
|
69 | m_state = Moved; | |
58 | m_lastPos = event->screenPos(); |
|
70 | m_lastPos = event->screenPos(); | |
59 |
mo |
|
71 | move(delta); | |
60 | } |
|
72 | } | |
61 | event->accept(); |
|
73 | event->accept(); | |
62 | break; |
|
74 | break; | |
63 | } |
|
75 | } | |
64 | case Moved: { |
|
76 | case Moved: { | |
65 | m_lastPos = event->screenPos(); |
|
77 | m_lastPos = event->screenPos(); | |
66 |
mo |
|
78 | move(delta); | |
67 | event->accept(); |
|
79 | event->accept(); | |
68 | break; |
|
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 | m_lastPos = event->screenPos(); |
|
92 | m_lastPos = event->screenPos(); | |
81 |
|
93 | |||
@@ -83,14 +95,21 void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |||||
83 | case Pressed: |
|
95 | case Pressed: | |
84 | { |
|
96 | { | |
85 | m_state = Idle; |
|
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 | event->accept(); |
|
107 | event->accept(); | |
88 | break; |
|
108 | break; | |
89 | } |
|
109 | } | |
90 | case Moved: |
|
110 | case Moved: | |
91 | { |
|
111 | { | |
92 | m_state = Idle; |
|
112 | scrollTo(m_lastPos - m_pressPos); | |
93 | mouseReleased(m_lastPos); |
|
|||
94 | event->accept(); |
|
113 | event->accept(); | |
95 | break; |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -33,18 +33,39 | |||||
33 |
|
33 | |||
34 | #include "qlegend.h" |
|
34 | #include "qlegend.h" | |
35 | #include "qlegend_p.h" |
|
35 | #include "qlegend_p.h" | |
|
36 | #include "scroller_p.h" | |||
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
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 | public: |
|
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 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -584,6 +584,7 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |||||
584 | foreach (QLegendMarker *marker, markers) { |
|
584 | foreach (QLegendMarker *marker, markers) { | |
585 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
585 | m_items->addToGroup(marker->d_ptr.data()->item()); | |
586 | m_markers << marker; |
|
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 | foreach (QLegendMarker *marker, markers) { |
|
593 | foreach (QLegendMarker *marker, markers) { | |
593 | marker->d_ptr->item()->setVisible(false); |
|
594 | marker->d_ptr->item()->setVisible(false); | |
594 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
595 | m_items->removeFromGroup(marker->d_ptr->item()); | |
595 | delete marker; |
|
|||
596 | m_markers.removeOne(marker); |
|
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 | #define QLEGEND_P_H |
|
31 | #define QLEGEND_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 | #include "scroller_p.h" |
|
|||
35 |
|
34 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
36 | |||
@@ -42,7 +41,7 class LegendLayout; | |||||
42 | class Domain; |
|
41 | class Domain; | |
43 | class QLegendMarker; |
|
42 | class QLegendMarker; | |
44 |
|
43 | |||
45 |
class QLegendPrivate : public QObject |
|
44 | class QLegendPrivate : public QObject | |
46 | { |
|
45 | { | |
47 | Q_OBJECT |
|
46 | Q_OBJECT | |
48 | public: |
|
47 | public: | |
@@ -90,10 +89,13 private: | |||||
90 | QList<QLegendMarker *> m_markers; |
|
89 | QList<QLegendMarker *> m_markers; | |
91 | QList<QAbstractSeries *> m_series; |
|
90 | QList<QAbstractSeries *> m_series; | |
92 |
|
91 | |||
|
92 | QHash<QGraphicsItem *, QLegendMarker *> m_markerHash; | |||
|
93 | ||||
93 | friend class QLegend; |
|
94 | friend class QLegend; | |
94 | friend class LegendMarkerItem; |
|
95 | friend class LegendMarkerItem; | |
95 | friend class LegendLayout; |
|
96 | friend class LegendLayout; | |
96 | friend class QLegendMarkerPrivate; |
|
97 | friend class QLegendMarkerPrivate; | |
|
98 | friend class LegendScroller; | |||
97 | }; |
|
99 | }; | |
98 |
|
100 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -56,7 +56,7 void Scroller::move(const QPointF &delta) | |||||
56 | setOffset(offset() - delta); |
|
56 | setOffset(offset() - delta); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 |
void Scroller:: |
|
59 | void Scroller::scrollTo(const QPointF &delta) | |
60 | { |
|
60 | { | |
61 | // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp |
|
61 | // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp | |
62 | // current time is no more than m_timeTresholdMax from timestamp |
|
62 | // current time is no more than m_timeTresholdMax from timestamp |
@@ -73,7 +73,7 public: | |||||
73 | virtual QPointF offset() const = 0; |
|
73 | virtual QPointF offset() const = 0; | |
74 |
|
74 | |||
75 | void move(const QPointF &delta); |
|
75 | void move(const QPointF &delta); | |
76 |
void |
|
76 | void scrollTo(const QPointF &delta); | |
77 |
|
77 | |||
78 | void scrollTick(); |
|
78 | void scrollTick(); | |
79 |
|
79 | |||
@@ -81,7 +81,6 private: | |||||
81 | void startTicker(int interval); |
|
81 | void startTicker(int interval); | |
82 | void stopTicker(); |
|
82 | void stopTicker(); | |
83 |
|
83 | |||
84 |
|
||||
85 | private: |
|
84 | private: | |
86 | void calculateSpeed(const QPointF &position); |
|
85 | void calculateSpeed(const QPointF &position); | |
87 | void lowerSpeed(QPointF &speed, qreal maxSpeed = 100); |
|
86 | void lowerSpeed(QPointF &speed, qreal maxSpeed = 100); |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now