##// END OF EJS Templates
legend marker pointer fix
sauimone -
r778:5dd3677a0f14
parent child
Show More
@@ -1,173 +1,173
1 #include "qchartglobal.h"
1 #include "qchartglobal.h"
2 #include "legendmarker_p.h"
2 #include "legendmarker_p.h"
3 #include <qpieslice.h>
3 #include <qpieslice.h>
4 #include <qbarset.h>
4 #include <qbarset.h>
5 #include <qxyseries.h>
5 #include <qxyseries.h>
6 #include <QPainter>
6 #include <QPainter>
7 #include <QGraphicsSceneEvent>
7 #include <QGraphicsSceneEvent>
8 #include <QGraphicsSimpleTextItem>
8 #include <QGraphicsSimpleTextItem>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 LegendMarker::LegendMarker(QSeries *series, QGraphicsItem *parent) : QGraphicsObject(parent),
12 LegendMarker::LegendMarker(QSeries *series, QGraphicsItem *parent) : QGraphicsObject(parent),
13 mPos(0,0),
13 m_pos(0,0),
14 mSize(0,0),
14 m_size(0,0),
15 mBoundingRect(0,0,0,0),
15 m_boundingRect(0,0,0,0),
16 mMarkerBoundingRect(0,0,0,0),
16 m_markerBoundingRect(0,0,0,0),
17 mSeries(series),
17 m_series(series),
18 mBarset(0),
18 m_barset(0),
19 mPieslice(0),
19 m_pieslice(0),
20 mType(LegendMarkerTypeSeries),
20 m_type(LegendMarkerTypeSeries),
21 mTextItem(new QGraphicsSimpleTextItem(this))
21 m_textItem(new QGraphicsSimpleTextItem(this))
22 {
22 {
23 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
23 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
24 }
24 }
25
25
26 LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) : QGraphicsObject(parent),
26 LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) : QGraphicsObject(parent),
27 mPos(0,0),
27 m_pos(0,0),
28 mSize(0,0),
28 m_size(0,0),
29 mBoundingRect(0,0,0,0),
29 m_boundingRect(0,0,0,0),
30 mMarkerBoundingRect(0,0,0,0),
30 m_markerBoundingRect(0,0,0,0),
31 mSeries(series),
31 m_series(series),
32 mBarset(barset),
32 m_barset(barset),
33 mPieslice(0),
33 m_pieslice(0),
34 mType(LegendMarkerTypeBarset),
34 m_type(LegendMarkerTypeBarset),
35 mTextItem(new QGraphicsSimpleTextItem(this))
35 m_textItem(new QGraphicsSimpleTextItem(this))
36 {
36 {
37 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
37 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
38 }
38 }
39
39
40 LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) : QGraphicsObject(parent),
40 LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) : QGraphicsObject(parent),
41 mPos(0,0),
41 m_pos(0,0),
42 mSize(0,0),
42 m_size(0,0),
43 mBoundingRect(0,0,0,0),
43 m_boundingRect(0,0,0,0),
44 mMarkerBoundingRect(0,0,0,0),
44 m_markerBoundingRect(0,0,0,0),
45 mSeries(series),
45 m_series(series),
46 mBarset(0),
46 m_barset(0),
47 mPieslice(pieslice),
47 m_pieslice(pieslice),
48 mType(LegendMarkerTypePieslice),
48 m_type(LegendMarkerTypePieslice),
49 mTextItem(new QGraphicsSimpleTextItem(this))
49 m_textItem(new QGraphicsSimpleTextItem(this))
50 {
50 {
51 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
51 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
52 }
52 }
53
53
54 void LegendMarker::setPos(qreal x, qreal y)
54 void LegendMarker::setPos(qreal x, qreal y)
55 {
55 {
56 mPos = QPointF(x,y);
56 m_pos = QPointF(x,y);
57 layoutChanged();
57 layoutChanged();
58 }
58 }
59
59
60 void LegendMarker::setPen(const QPen &pen)
60 void LegendMarker::setPen(const QPen &pen)
61 {
61 {
62 mPen = pen;
62 m_pen = pen;
63 }
63 }
64
64
65 QPen LegendMarker::pen() const
65 QPen LegendMarker::pen() const
66 {
66 {
67 return mPen;
67 return m_pen;
68 }
68 }
69
69
70 void LegendMarker::setBrush(const QBrush &brush)
70 void LegendMarker::setBrush(const QBrush &brush)
71 {
71 {
72 mBrush = brush;
72 m_brush = brush;
73 }
73 }
74
74
75 QBrush LegendMarker::brush() const
75 QBrush LegendMarker::brush() const
76 {
76 {
77 return mBrush;
77 return m_brush;
78 }
78 }
79
79
80 void LegendMarker::setName(const QString name)
80 void LegendMarker::setName(const QString name)
81 {
81 {
82 mTextItem.setText(name);
82 m_textItem->setText(name);
83 layoutChanged();
83 layoutChanged();
84 }
84 }
85
85
86 QString LegendMarker::name() const
86 QString LegendMarker::name() const
87 {
87 {
88 return mTextItem.text();
88 return m_textItem->text();
89 }
89 }
90
90
91 QSeries* LegendMarker::series() const
91 QSeries* LegendMarker::series() const
92 {
92 {
93 return mSeries;
93 return m_series;
94 }
94 }
95
95
96 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
96 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
97 {
97 {
98 Q_UNUSED(option)
98 Q_UNUSED(option)
99 Q_UNUSED(widget)
99 Q_UNUSED(widget)
100
100
101 painter->setPen(mPen);
101 painter->setPen(m_pen);
102 painter->setBrush(mBrush);
102 painter->setBrush(m_brush);
103 painter->drawRect(mMarkerBoundingRect);
103 painter->drawRect(m_markerBoundingRect);
104 }
104 }
105
105
106 QRectF LegendMarker::boundingRect() const
106 QRectF LegendMarker::boundingRect() const
107 {
107 {
108 return mBoundingRect;
108 return m_boundingRect;
109 }
109 }
110
110
111 void LegendMarker::layoutChanged()
111 void LegendMarker::layoutChanged()
112 {
112 {
113 QSizeF markerSize(10,10);
113 QSizeF markerSize(10,10);
114 qreal margin = 2;
114 qreal margin = 2;
115
115
116 mSize.setHeight(markerSize.height() + 2 * margin);
116 m_size.setHeight(markerSize.height() + 2 * margin);
117 mSize.setWidth(mTextItem.boundingRect().width() + markerSize.width() + 3 * margin);
117 m_size.setWidth(m_textItem->boundingRect().width() + markerSize.width() + 3 * margin);
118
118
119 mBoundingRect = QRectF(mPos.x(),mPos.y(),mSize.width(),mSize.height());
119 m_boundingRect = QRectF(m_pos.x(),m_pos.y(),m_size.width(),m_size.height());
120
120
121 mMarkerBoundingRect = QRectF(mPos.x() + margin, mPos.y() + margin, markerSize.width(),markerSize.height());
121 m_markerBoundingRect = QRectF(m_pos.x() + margin, m_pos.y() + margin, markerSize.width(),markerSize.height());
122
122
123 mTextItem.setPos(mPos.x() + markerSize.width() + 2 * margin, mPos.y() + margin);
123 m_textItem->setPos(m_pos.x() + markerSize.width() + 2 * margin, m_pos.y() + margin);
124 }
124 }
125
125
126 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
126 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
127 {
127 {
128 switch (mType)
128 switch (m_type)
129 {
129 {
130 case LegendMarkerTypeSeries: {
130 case LegendMarkerTypeSeries: {
131 emit clicked(mSeries,event->button());
131 emit clicked(m_series,event->button());
132 break;
132 break;
133 }
133 }
134 case LegendMarkerTypeBarset: {
134 case LegendMarkerTypeBarset: {
135 emit clicked(mBarset,event->button());
135 emit clicked(m_barset,event->button());
136 break;
136 break;
137 }
137 }
138 case LegendMarkerTypePieslice: {
138 case LegendMarkerTypePieslice: {
139 emit clicked(mPieslice,event->button());
139 emit clicked(m_pieslice,event->button());
140 break;
140 break;
141 }
141 }
142 default: {
142 default: {
143 break;
143 break;
144 }
144 }
145 }
145 }
146 }
146 }
147
147
148 void LegendMarker::changed()
148 void LegendMarker::changed()
149 {
149 {
150 switch (mType)
150 switch (m_type)
151 {
151 {
152 case LegendMarkerTypeSeries: {
152 case LegendMarkerTypeSeries: {
153 QXYSeries* s = static_cast<QXYSeries*> (mSeries);
153 QXYSeries* s = static_cast<QXYSeries*> (m_series);
154 setBrush(s->brush());
154 setBrush(s->brush());
155 setName(s->name());
155 setName(s->name());
156 break;
156 break;
157 }
157 }
158 case LegendMarkerTypeBarset: {
158 case LegendMarkerTypeBarset: {
159 setBrush(mBarset->brush());
159 setBrush(m_barset->brush());
160 setName(mBarset->name());
160 setName(m_barset->name());
161 break;
161 break;
162 }
162 }
163 case LegendMarkerTypePieslice: {
163 case LegendMarkerTypePieslice: {
164 setBrush(mPieslice->brush());
164 setBrush(m_pieslice->brush());
165 setName(mPieslice->label());
165 setName(m_pieslice->label());
166 break;
166 break;
167 }
167 }
168 }
168 }
169 }
169 }
170
170
171 #include "moc_legendmarker_p.cpp"
171 #include "moc_legendmarker_p.cpp"
172
172
173 QTCOMMERCIALCHART_END_NAMESPACE
173 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,81 +1,81
1 #ifndef LEGENDMARKER_P_H
1 #ifndef LEGENDMARKER_P_H
2 #define LEGENDMARKER_P_H
2 #define LEGENDMARKER_P_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QGraphicsObject>
5 #include <QGraphicsObject>
6 #include <QBrush>
6 #include <QBrush>
7 #include <QPen>
7 #include <QPen>
8 #include <QGraphicsSimpleTextItem>
8 #include <QGraphicsSimpleTextItem>
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QSeries;
12 class QSeries;
13 class QBarSet;
13 class QBarSet;
14 class QPieSlice;
14 class QPieSlice;
15
15
16 // TODO: split this to 3 different markers for series, barset and pieslice. Current implementation is easier to misuse...
16 // TODO: split this to 3 different markers for series, barset and pieslice. Current implementation is easier to misuse...
17 class LegendMarker : public QGraphicsObject
17 class LegendMarker : public QGraphicsObject
18 {
18 {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 enum LegendMarkerType {
21 enum LegendMarkerType {
22 LegendMarkerTypeSeries,
22 LegendMarkerTypeSeries,
23 LegendMarkerTypeBarset,
23 LegendMarkerTypeBarset,
24 LegendMarkerTypePieslice
24 LegendMarkerTypePieslice
25 };
25 };
26
26
27 public:
27 public:
28 LegendMarker(QSeries *series, QGraphicsItem *parent = 0);
28 LegendMarker(QSeries *series, QGraphicsItem *parent = 0);
29 LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent = 0);
29 LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent = 0);
30 LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent = 0);
30 LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent = 0);
31
31
32 void setPos(qreal x, qreal y);
32 void setPos(qreal x, qreal y);
33
33
34 void setPen(const QPen &pen);
34 void setPen(const QPen &pen);
35 QPen pen() const;
35 QPen pen() const;
36
36
37 void setBrush(const QBrush &brush);
37 void setBrush(const QBrush &brush);
38 QBrush brush() const;
38 QBrush brush() const;
39
39
40 void setName(const QString name);
40 void setName(const QString name);
41 QString name() const;
41 QString name() const;
42
42
43 QSeries* series() const;
43 QSeries* series() const;
44
44
45 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
45 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
46
46
47 QRectF boundingRect() const;
47 QRectF boundingRect() const;
48
48
49 void layoutChanged();
49 void layoutChanged();
50
50
51 public:
51 public:
52 // From QGraphicsObject
52 // From QGraphicsObject
53 void mousePressEvent(QGraphicsSceneMouseEvent *event);
53 void mousePressEvent(QGraphicsSceneMouseEvent *event);
54
54
55 Q_SIGNALS:
55 Q_SIGNALS:
56 void clicked(QSeries *series, Qt::MouseButton button);
56 void clicked(QSeries *series, Qt::MouseButton button);
57 void clicked(QBarSet *barset, Qt::MouseButton button);
57 void clicked(QBarSet *barset, Qt::MouseButton button);
58 void clicked(QPieSlice *pieslice, Qt::MouseButton button);
58 void clicked(QPieSlice *pieslice, Qt::MouseButton button);
59
59
60 public Q_SLOTS:
60 public Q_SLOTS:
61 void changed();
61 void changed();
62
62
63 private:
63 private:
64 QPointF mPos;
64 QPointF m_pos;
65 QSize mSize;
65 QSize m_size;
66 QRectF mBoundingRect;
66 QRectF m_boundingRect;
67 QRectF mMarkerBoundingRect;
67 QRectF m_markerBoundingRect;
68 QBrush mBrush;
68 QBrush m_brush;
69 QPen mPen;
69 QPen m_pen;
70
70
71 QSeries *mSeries;
71 QSeries *m_series;
72 QBarSet *mBarset;
72 QBarSet *m_barset;
73 QPieSlice *mPieslice;
73 QPieSlice *m_pieslice;
74
74
75 LegendMarkerType mType;
75 LegendMarkerType m_type;
76 QGraphicsSimpleTextItem mTextItem;
76 QGraphicsSimpleTextItem *m_textItem;
77
77
78 };
78 };
79
79
80 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
81 #endif // LEGENDMARKER_P_H
81 #endif // LEGENDMARKER_P_H
@@ -1,26 +1,26
1 #include "legendscrollbutton_p.h"
1 #include "legendscrollbutton_p.h"
2 #include <QGraphicsSceneEvent>
2 #include <QGraphicsSceneEvent>
3
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
5
6 LegendScrollButton::LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent)
6 LegendScrollButton::LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent)
7 : QGraphicsPolygonItem(parent)
7 : QGraphicsPolygonItem(parent)
8 ,mId(id)
8 ,m_id(id)
9 {
9 {
10 setAcceptedMouseButtons(Qt::LeftButton);
10 setAcceptedMouseButtons(Qt::LeftButton);
11 }
11 }
12
12
13 LegendScrollButton::ScrollButtonId LegendScrollButton::id()
13 LegendScrollButton::ScrollButtonId LegendScrollButton::id()
14 {
14 {
15 return mId;
15 return m_id;
16 }
16 }
17
17
18 void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
18 void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
19 {
19 {
20 emit clicked(event);
20 emit clicked(event);
21 }
21 }
22
22
23 #include "moc_legendscrollbutton_p.cpp"
23 #include "moc_legendscrollbutton_p.cpp"
24
24
25 QTCOMMERCIALCHART_END_NAMESPACE
25 QTCOMMERCIALCHART_END_NAMESPACE
26
26
@@ -1,38 +1,38
1 #ifndef LEGENDSCROLLBUTTON_P_H
1 #ifndef LEGENDSCROLLBUTTON_P_H
2 #define LEGENDSCROLLBUTTON_P_H
2 #define LEGENDSCROLLBUTTON_P_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <qchartglobal.h>
5 #include <qchartglobal.h>
6 #include <QGraphicsPolygonItem>
6 #include <QGraphicsPolygonItem>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class LegendScrollButton : public QObject, public QGraphicsPolygonItem
10 class LegendScrollButton : public QObject, public QGraphicsPolygonItem
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 enum ScrollButtonId {
14 enum ScrollButtonId {
15 ScrollButtonIdLeft,
15 ScrollButtonIdLeft,
16 ScrollButtonIdRight,
16 ScrollButtonIdRight,
17 ScrollButtonIdUp,
17 ScrollButtonIdUp,
18 ScrollButtonIdDown
18 ScrollButtonIdDown
19 };
19 };
20
20
21 explicit LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent = 0);
21 explicit LegendScrollButton(ScrollButtonId id, QGraphicsItem *parent = 0);
22 ScrollButtonId id();
22 ScrollButtonId id();
23
23
24 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
24 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
25
25
26 Q_SIGNALS:
26 Q_SIGNALS:
27 void clicked(QGraphicsSceneMouseEvent* event);
27 void clicked(QGraphicsSceneMouseEvent* event);
28
28
29 public Q_SLOTS:
29 public Q_SLOTS:
30
30
31 private:
31 private:
32
32
33 ScrollButtonId mId;
33 ScrollButtonId m_id;
34 };
34 };
35
35
36 QTCOMMERCIALCHART_END_NAMESPACE
36 QTCOMMERCIALCHART_END_NAMESPACE
37
37
38 #endif // LEGENDSCROLLBUTTON_P_H
38 #endif // LEGENDSCROLLBUTTON_P_H
General Comments 0
You need to be logged in to leave comments. Login now