@@ -1,11 +1,13 | |||
|
1 | 1 | #include "legendscrollbutton_p.h" |
|
2 | #include "qlegend.h" | |
|
2 | 3 | #include <QGraphicsSceneEvent> |
|
3 | 4 | |
|
4 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | 6 | |
|
6 |
LegendScrollButton::LegendScrollButton(ScrollButtonId id, Q |
|
|
7 |
: QGraphicsPolygonItem( |
|
|
8 |
|
|
|
7 | LegendScrollButton::LegendScrollButton(ScrollButtonId id, QLegend *legend) | |
|
8 | : QGraphicsPolygonItem(legend), | |
|
9 | m_id(id), | |
|
10 | m_ledgend(legend) | |
|
9 | 11 | { |
|
10 | 12 | setAcceptedMouseButtons(Qt::LeftButton); |
|
11 | 13 | } |
@@ -17,7 +19,8 LegendScrollButton::ScrollButtonId LegendScrollButton::id() | |||
|
17 | 19 | |
|
18 | 20 | void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
19 | 21 | { |
|
20 | emit clicked(event); | |
|
22 | Q_UNUSED(event); | |
|
23 | m_ledgend->scrollButtonClicked(this); | |
|
21 | 24 | } |
|
22 | 25 | |
|
23 | 26 | #include "moc_legendscrollbutton_p.cpp" |
@@ -7,9 +7,10 | |||
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | class LegendScrollButton : public QObject, public QGraphicsPolygonItem | |
|
10 | class QLegend; | |
|
11 | ||
|
12 | class LegendScrollButton : public QGraphicsPolygonItem | |
|
11 | 13 | { |
|
12 | Q_OBJECT | |
|
13 | 14 | public: |
|
14 | 15 | enum ScrollButtonId { |
|
15 | 16 | ScrollButtonIdLeft, |
@@ -18,19 +19,14 public: | |||
|
18 | 19 | ScrollButtonIdDown |
|
19 | 20 | }; |
|
20 | 21 | |
|
21 |
explicit LegendScrollButton(ScrollButtonId id, Q |
|
|
22 | explicit LegendScrollButton(ScrollButtonId id, QLegend *legend); | |
|
22 | 23 | ScrollButtonId id(); |
|
23 | 24 | |
|
24 | 25 | virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
25 | 26 | |
|
26 | Q_SIGNALS: | |
|
27 | void clicked(QGraphicsSceneMouseEvent* event); | |
|
28 | ||
|
29 | public Q_SLOTS: | |
|
30 | ||
|
31 | 27 | private: |
|
32 | ||
|
33 | 28 | ScrollButtonId m_id; |
|
29 | QLegend *m_ledgend; | |
|
34 | 30 | }; |
|
35 | 31 | |
|
36 | 32 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -105,6 +105,7 protected: | |||
|
105 | 105 | protected: |
|
106 | 106 | QScopedPointer<QChartPrivate> d_ptr; |
|
107 | 107 | friend class QChartView; |
|
108 | friend class QLegend; | |
|
108 | 109 | Q_DISABLE_COPY(QChart) |
|
109 | 110 | }; |
|
110 | 111 |
@@ -1,5 +1,5 | |||
|
1 | #include "qchartglobal.h" | |
|
2 | 1 |
|
|
2 | #include "qchart_p.h" | |
|
3 | 3 | #include "qseries.h" |
|
4 | 4 | #include "legendmarker_p.h" |
|
5 | 5 | #include "legendscrollbutton_p.h" |
@@ -66,7 +66,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
66 | 66 | /*! |
|
67 | 67 | Constructs the legend object and sets the parent to \a parent |
|
68 | 68 | */ |
|
69 |
QLegend::QLegend(Q |
|
|
69 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart->d_ptr->m_presenter->rootItem()), | |
|
70 | 70 | m_margin(5), |
|
71 | 71 | m_pos(0,0), |
|
72 | 72 | m_minimumSize(50,20), // TODO: magic numbers |
@@ -80,16 +80,6 QLegend::QLegend(QGraphicsItem *parent) : QGraphicsObject(parent), | |||
|
80 | 80 | m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); |
|
81 | 81 | m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); |
|
82 | 82 | m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); |
|
83 | ||
|
84 | connect(m_scrollButtonLeft, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
|
85 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
|
86 | connect(m_scrollButtonRight, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
|
87 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
|
88 | connect(m_scrollButtonUp, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
|
89 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
|
90 | connect(m_scrollButtonDown, SIGNAL(clicked(QGraphicsSceneMouseEvent*)), | |
|
91 | this, SLOT(handleScrollButtonClicked(QGraphicsSceneMouseEvent*))); | |
|
92 | ||
|
93 | 83 | setZValue(ChartPresenter::LegendZValue); |
|
94 | 84 | } |
|
95 | 85 | |
@@ -297,12 +287,9 void QLegend::handleMarkerDestroyed() | |||
|
297 | 287 | /*! |
|
298 | 288 | \internal \a event Handles clicked signals from scroll buttons |
|
299 | 289 | */ |
|
300 | void QLegend::handleScrollButtonClicked(QGraphicsSceneMouseEvent *event) | |
|
290 | void QLegend::scrollButtonClicked(LegendScrollButton *scrollButton) | |
|
301 | 291 | { |
|
302 | Q_UNUSED(event); // Maybe later something happens with right click... | |
|
303 | ||
|
304 | LegendScrollButton* scrollButton = static_cast<LegendScrollButton *> (sender()); | |
|
305 | Q_ASSERT(scrollButton); | |
|
292 | Q_ASSERT(scrollButton); | |
|
306 | 293 | |
|
307 | 294 | switch (scrollButton->id()) { |
|
308 | 295 | case LegendScrollButton::ScrollButtonIdLeft: |
@@ -1,8 +1,8 | |||
|
1 | 1 | #ifndef QLEGEND_H |
|
2 | 2 | #define QLEGEND_H |
|
3 | 3 | |
|
4 |
#include < |
|
|
5 |
#include <QGraphics |
|
|
4 | #include <QChartGlobal> | |
|
5 | #include <QGraphicsWidget> | |
|
6 | 6 | #include <QPen> |
|
7 | 7 | #include <QBrush> |
|
8 | 8 | |
@@ -17,9 +17,10 class QBarSeries; | |||
|
17 | 17 | class QPieSeries; |
|
18 | 18 | class LegendScrollButton; |
|
19 | 19 | class QSeries; |
|
20 | class QChart; | |
|
20 | 21 | |
|
21 | 22 | // TODO: This as widget |
|
22 |
class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphics |
|
|
23 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
|
23 | 24 | { |
|
24 | 25 | Q_OBJECT |
|
25 | 26 | public: |
@@ -31,9 +32,10 public: | |||
|
31 | 32 | LayoutLeft = Qt::AlignLeft, |
|
32 | 33 | LayoutRight = Qt::AlignRight |
|
33 | 34 | }; |
|
35 | private: | |
|
36 | explicit QLegend(QChart *chart); | |
|
34 | 37 | |
|
35 | explicit QLegend(QGraphicsItem *parent = 0); | |
|
36 | ||
|
38 | public: | |
|
37 | 39 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
38 | 40 | QRectF boundingRect() const; |
|
39 | 41 | |
@@ -53,6 +55,8 public: | |||
|
53 | 55 | void setSize(const QSizeF size); |
|
54 | 56 | void setPos(const QPointF &pos); |
|
55 | 57 | |
|
58 | void scrollButtonClicked(LegendScrollButton *scrollButton); | |
|
59 | ||
|
56 | 60 | Q_SIGNALS: |
|
57 | 61 | // for interactions. |
|
58 | 62 | void clicked(QSeries *series, Qt::MouseButton button); |
@@ -66,7 +70,7 public Q_SLOTS: | |||
|
66 | 70 | void handleAdded(QList<QPieSlice *> slices); |
|
67 | 71 | void handleRemoved(QList<QPieSlice *> slices); |
|
68 | 72 | void handleMarkerDestroyed(); |
|
69 | void handleScrollButtonClicked(QGraphicsSceneMouseEvent *event); | |
|
73 | ||
|
70 | 74 | // PIMPL <--- |
|
71 | 75 | |
|
72 | 76 | private: |
@@ -103,6 +107,7 private: | |||
|
103 | 107 | LegendScrollButton *m_scrollButtonUp; |
|
104 | 108 | LegendScrollButton *m_scrollButtonDown; |
|
105 | 109 | |
|
110 | friend class QChart; | |
|
106 | 111 | // <--- PIMPL |
|
107 | 112 | }; |
|
108 | 113 |
General Comments 0
You need to be logged in to leave comments.
Login now