##// END OF EJS Templates
Adds ScrolledQLegend...
Michal Klocek -
r859:e87be6f0a1e1
parent child
Show More
@@ -68,7 +68,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
68 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
69 d_ptr(new QChartPrivate())
69 d_ptr(new QChartPrivate())
70 {
70 {
71 d_ptr->m_legend = new QLegend(this);
71 d_ptr->m_legend = new ScrolledQLegend(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
72 d_ptr->m_dataset = new ChartDataSet(this);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
73 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
74 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
@@ -102,8 +102,7 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
102 m_width(0),
102 m_width(0),
103 m_height(0),
103 m_height(0),
104 m_visible(false),
104 m_visible(false),
105 m_dirty(false),
105 m_dirty(false)
106 m_scroller(new Scroller(this))
107 {
106 {
108 setZValue(ChartPresenter::LegendZValue);
107 setZValue(ChartPresenter::LegendZValue);
109 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
108 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
@@ -542,22 +541,6 void QLegend::showEvent(QShowEvent *event)
542 updateLayout();
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 #include "moc_qlegend.cpp"
544 #include "moc_qlegend.cpp"
562
545
563 QTCOMMERCIALCHART_END_NAMESPACE
546 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,6 +25,7
25 #include <QGraphicsWidget>
25 #include <QGraphicsWidget>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include "scroller_p.h"
28
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
@@ -39,7 +40,6 class QAreaSeries;
39 class LegendScrollButton;
40 class LegendScrollButton;
40 class QSeries;
41 class QSeries;
41 class QChart;
42 class QChart;
42 class Scroller;
43
43
44 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
44 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
45 {
45 {
@@ -90,9 +90,6 protected:
90 void resizeEvent(QGraphicsSceneResizeEvent *event);
90 void resizeEvent(QGraphicsSceneResizeEvent *event);
91 void hideEvent(QHideEvent *event);
91 void hideEvent(QHideEvent *event);
92 void showEvent(QShowEvent *event);
92 void showEvent(QShowEvent *event);
93 void mousePressEvent(QGraphicsSceneMouseEvent* event);
94 void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
95 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
96
93
97 public Q_SLOTS:
94 public Q_SLOTS:
98 // PIMPL --->
95 // PIMPL --->
@@ -142,11 +139,41 private:
142 qreal m_height;
139 qreal m_height;
143 bool m_visible;
140 bool m_visible;
144 bool m_dirty;
141 bool m_dirty;
145 Scroller* m_scroller;
142 friend class ScrolledQLegend;
146 friend class QChart;
147 // <--- PIMPL
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 QTCOMMERCIALCHART_END_NAMESPACE
177 QTCOMMERCIALCHART_END_NAMESPACE
151
178
152 #endif // QLEGEND_H
179 #endif // QLEGEND_H
@@ -24,12 +24,11
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 Scroller::Scroller(QLegend* legend):
27 Scroller::Scroller():
28 m_ticker(this),
28 m_ticker(this),
29 m_state(Idle),
29 m_state(Idle),
30 m_moveThreshold(10),
30 m_moveThreshold(10),
31 m_timeTreshold(50),
31 m_timeTreshold(50)
32 m_legend(legend)
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 ScrollTicker::ScrollTicker(Scroller *scroller,QObject* parent):QObject(parent),
224 ScrollTicker::ScrollTicker(Scroller *scroller,QObject* parent):QObject(parent),
@@ -67,11 +67,11 public:
67 Stop
67 Stop
68 };
68 };
69
69
70 explicit Scroller(QLegend* legend);
70 Scroller();
71 virtual ~Scroller();
71 virtual ~Scroller();
72
72
73 virtual void setOffset(const QPointF& point);
73 virtual void setOffset(const QPointF& point) = 0;
74 virtual QPointF offset() const;
74 virtual QPointF offset() const = 0;
75
75
76 public:
76 public:
77 void scrollTick();
77 void scrollTick();
@@ -97,7 +97,6 private:
97 QPointF m_fraction;
97 QPointF m_fraction;
98 int m_moveThreshold;
98 int m_moveThreshold;
99 int m_timeTreshold;
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