@@ -68,7 +68,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
68 | 68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
69 | 69 | d_ptr(new QChartPrivate()) |
|
70 | 70 | { |
|
71 | d_ptr->m_legend = new QLegend(this); | |
|
71 | d_ptr->m_legend = new ScrolledQLegend(this); | |
|
72 | 72 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | 73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | 74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
@@ -102,8 +102,7 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |||
|
102 | 102 | m_width(0), |
|
103 | 103 | m_height(0), |
|
104 | 104 | m_visible(false), |
|
105 |
m_dirty(false) |
|
|
106 | m_scroller(new Scroller(this)) | |
|
105 | m_dirty(false) | |
|
107 | 106 | { |
|
108 | 107 | setZValue(ChartPresenter::LegendZValue); |
|
109 | 108 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
@@ -542,22 +541,6 void QLegend::showEvent(QShowEvent *event) | |||
|
542 | 541 | updateLayout(); |
|
543 | 542 | } |
|
544 | 543 | |
|
545 | void QLegend::mousePressEvent(QGraphicsSceneMouseEvent* event) | |
|
546 | { | |
|
547 | //Q_UNUSED(event); | |
|
548 | m_scroller->mousePressEvent(event); | |
|
549 | } | |
|
550 | void QLegend::mouseMoveEvent(QGraphicsSceneMouseEvent* event) | |
|
551 | { | |
|
552 | //Q_UNUSED(event); | |
|
553 | m_scroller->mouseMoveEvent(event); | |
|
554 | } | |
|
555 | void QLegend::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | |
|
556 | { | |
|
557 | //Q_UNUSED(event); | |
|
558 | m_scroller->mouseReleaseEvent(event); | |
|
559 | } | |
|
560 | ||
|
561 | 544 | #include "moc_qlegend.cpp" |
|
562 | 545 | |
|
563 | 546 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -25,6 +25,7 | |||
|
25 | 25 | #include <QGraphicsWidget> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QBrush> |
|
28 | #include "scroller_p.h" | |
|
28 | 29 | |
|
29 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 31 | |
@@ -39,7 +40,6 class QAreaSeries; | |||
|
39 | 40 | class LegendScrollButton; |
|
40 | 41 | class QSeries; |
|
41 | 42 | class QChart; |
|
42 | class Scroller; | |
|
43 | 43 | |
|
44 | 44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
45 | 45 | { |
@@ -90,9 +90,6 protected: | |||
|
90 | 90 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
91 | 91 | void hideEvent(QHideEvent *event); |
|
92 | 92 | void showEvent(QShowEvent *event); |
|
93 | void mousePressEvent(QGraphicsSceneMouseEvent* event); | |
|
94 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event); | |
|
95 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); | |
|
96 | 93 | |
|
97 | 94 | public Q_SLOTS: |
|
98 | 95 | // PIMPL ---> |
@@ -142,11 +139,41 private: | |||
|
142 | 139 | qreal m_height; |
|
143 | 140 | bool m_visible; |
|
144 | 141 | bool m_dirty; |
|
145 | Scroller* m_scroller; | |
|
146 | friend class QChart; | |
|
142 | friend class ScrolledQLegend; | |
|
147 | 143 | // <--- PIMPL |
|
148 | 144 | }; |
|
149 | 145 | |
|
146 | class ScrolledQLegend: public QLegend, public Scroller | |
|
147 | { | |
|
148 | ||
|
149 | public: | |
|
150 | ScrolledQLegend(QChart *chart):QLegend(chart) | |
|
151 | { | |
|
152 | } | |
|
153 | ||
|
154 | void setOffset(const QPointF& point) | |
|
155 | { | |
|
156 | QLegend::setOffset(point); | |
|
157 | } | |
|
158 | QPointF offset() const | |
|
159 | { | |
|
160 | return QLegend::offset(); | |
|
161 | } | |
|
162 | ||
|
163 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ | |
|
164 | Scroller::mousePressEvent(event); | |
|
165 | //QLegend::mousePressEvent(event); | |
|
166 | } | |
|
167 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | |
|
168 | Scroller::mouseMoveEvent(event); | |
|
169 | //QLegend::mouseMoveEvent(event); | |
|
170 | } | |
|
171 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | |
|
172 | Scroller::mouseReleaseEvent(event); | |
|
173 | //QLegend::mouseReleaseEvent(event); | |
|
174 | } | |
|
175 | }; | |
|
176 | ||
|
150 | 177 | QTCOMMERCIALCHART_END_NAMESPACE |
|
151 | 178 | |
|
152 | 179 | #endif // QLEGEND_H |
@@ -24,12 +24,11 | |||
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 |
Scroller::Scroller( |
|
|
27 | Scroller::Scroller(): | |
|
28 | 28 | m_ticker(this), |
|
29 | 29 | m_state(Idle), |
|
30 | 30 | m_moveThreshold(10), |
|
31 |
m_timeTreshold(50) |
|
|
32 | m_legend(legend) | |
|
31 | m_timeTreshold(50) | |
|
33 | 32 | { |
|
34 | 33 | |
|
35 | 34 | } |
@@ -220,16 +219,6 void Scroller::calculateSpeed(const QPointF& position) | |||
|
220 | 219 | } |
|
221 | 220 | } |
|
222 | 221 | |
|
223 | void Scroller::setOffset(const QPointF& point) | |
|
224 | { | |
|
225 | m_legend->setOffset(point); | |
|
226 | } | |
|
227 | ||
|
228 | QPointF Scroller::offset() const | |
|
229 | { | |
|
230 | return m_legend->offset(); | |
|
231 | } | |
|
232 | ||
|
233 | 222 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
234 | 223 | |
|
235 | 224 | ScrollTicker::ScrollTicker(Scroller *scroller,QObject* parent):QObject(parent), |
@@ -67,11 +67,11 public: | |||
|
67 | 67 | Stop |
|
68 | 68 | }; |
|
69 | 69 | |
|
70 | explicit Scroller(QLegend* legend); | |
|
70 | Scroller(); | |
|
71 | 71 | virtual ~Scroller(); |
|
72 | 72 | |
|
73 | virtual void setOffset(const QPointF& point); | |
|
74 | virtual QPointF offset() const; | |
|
73 | virtual void setOffset(const QPointF& point) = 0; | |
|
74 | virtual QPointF offset() const = 0; | |
|
75 | 75 | |
|
76 | 76 | public: |
|
77 | 77 | void scrollTick(); |
@@ -97,7 +97,6 private: | |||
|
97 | 97 | QPointF m_fraction; |
|
98 | 98 | int m_moveThreshold; |
|
99 | 99 | int m_timeTreshold; |
|
100 | QLegend* m_legend; | |
|
101 | 100 | |
|
102 | 101 | |
|
103 | 102 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now