##// END OF EJS Templates
legend marker pointer fix
sauimone -
r778:5dd3677a0f14
parent child
Show More
@@ -10,87 +10,87
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)
@@ -98,14 +98,14 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
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()
@@ -113,30 +113,30 void LegendMarker::layoutChanged()
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: {
@@ -147,22 +147,22 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
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 }
@@ -61,19 +61,19 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
@@ -5,14 +5,14 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)
@@ -30,7 +30,7 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
General Comments 0
You need to be logged in to leave comments. Login now