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