@@ -8,11 +8,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | 8 | LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent) |
|
9 | 9 | : QGraphicsObject(parent) |
|
10 | 10 | ,mBoundingRect(0,0,1,1) |
|
11 | ,mName("") | |
|
11 | ,mMarkerBoundingRect(0,0,1,1) | |
|
12 | 12 | ,mSeries(series) |
|
13 | 13 | ,mBarset(0) |
|
14 | 14 | ,mPieslice(0) |
|
15 | 15 | ,mType(LegendMarkerTypeSeries) |
|
16 | ,mTextItem(new QGraphicsSimpleTextItem(this)) | |
|
16 | 17 | { |
|
17 | 18 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
18 | 19 | } |
@@ -20,11 +21,12 LegendMarker::LegendMarker(QSeries* series, QGraphicsItem *parent) | |||
|
20 | 21 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) |
|
21 | 22 | : QGraphicsObject(parent) |
|
22 | 23 | ,mBoundingRect(0,0,1,1) |
|
23 | ,mName("") | |
|
24 | ,mMarkerBoundingRect(0,0,1,1) | |
|
24 | 25 | ,mSeries(series) |
|
25 | 26 | ,mBarset(barset) |
|
26 | 27 | ,mPieslice(0) |
|
27 | 28 | ,mType(LegendMarkerTypeBarset) |
|
29 | ,mTextItem(new QGraphicsSimpleTextItem(this)) | |
|
28 | 30 | { |
|
29 | 31 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
30 | 32 | } |
@@ -32,11 +34,12 LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *pare | |||
|
32 | 34 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) |
|
33 | 35 | : QGraphicsObject(parent) |
|
34 | 36 | ,mBoundingRect(0,0,1,1) |
|
35 | ,mName("") | |
|
37 | ,mMarkerBoundingRect(0,0,1,1) | |
|
36 | 38 | ,mSeries(series) |
|
37 | 39 | ,mBarset(0) |
|
38 | 40 | ,mPieslice(pieslice) |
|
39 | 41 | ,mType(LegendMarkerTypePieslice) |
|
42 | ,mTextItem(new QGraphicsSimpleTextItem(this)) | |
|
40 | 43 | { |
|
41 | 44 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
42 | 45 | } |
@@ -44,6 +47,15 LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem * | |||
|
44 | 47 | void LegendMarker::setBoundingRect(const QRectF rect) |
|
45 | 48 | { |
|
46 | 49 | mBoundingRect = rect; |
|
50 | // Calculate Marker pos | |
|
51 | ||
|
52 | // TODO: remove hard coding. 5 is marigin around marker | |
|
53 | QSizeF markerSize(10,10); | |
|
54 | qreal x = mBoundingRect.x() + 5; | |
|
55 | qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2; | |
|
56 | mMarkerBoundingRect = QRectF(x,y,markerSize.width(),markerSize.height()); | |
|
57 | ||
|
58 | mTextItem.setPos(mBoundingRect.x() + markerSize.width() + 10, y ); | |
|
47 | 59 | } |
|
48 | 60 | |
|
49 | 61 | void LegendMarker::setBrush(const QBrush brush) |
@@ -58,12 +70,12 QBrush LegendMarker::brush() const | |||
|
58 | 70 | |
|
59 | 71 | void LegendMarker::setName(const QString name) |
|
60 | 72 | { |
|
61 | mName = name; | |
|
73 | mTextItem.setText(name); | |
|
62 | 74 | } |
|
63 | 75 | |
|
64 | 76 | QString LegendMarker::name() const |
|
65 | 77 | { |
|
66 |
return m |
|
|
78 | return mTextItem.text(); | |
|
67 | 79 | } |
|
68 | 80 | |
|
69 | 81 | QSeries* LegendMarker::series() const |
@@ -74,7 +86,7 QSeries* LegendMarker::series() const | |||
|
74 | 86 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
75 | 87 | { |
|
76 | 88 | painter->setBrush(mBrush); |
|
77 | painter->drawRect(mBoundingRect); | |
|
89 | painter->drawRect(mMarkerBoundingRect); | |
|
78 | 90 | } |
|
79 | 91 | |
|
80 | 92 | QRectF LegendMarker::boundingRect() const |
@@ -51,13 +51,15 Q_SIGNALS: | |||
|
51 | 51 | |
|
52 | 52 | private: |
|
53 | 53 | QRectF mBoundingRect; |
|
54 | QRectF mMarkerBoundingRect; | |
|
54 | 55 | QBrush mBrush; |
|
55 | QString mName; | |
|
56 | 56 | QSeries* mSeries; |
|
57 | 57 | QBarSet* mBarset; |
|
58 | 58 | QPieSlice* mPieslice; |
|
59 | 59 | |
|
60 | 60 | LegendMarkerType mType; |
|
61 | QGraphicsSimpleTextItem mTextItem; | |
|
62 | ||
|
61 | 63 | }; |
|
62 | 64 | |
|
63 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -344,11 +344,10 void QChart::updateLayout() | |||
|
344 | 344 | // TODO: better layout |
|
345 | 345 | if (m_legend) { |
|
346 | 346 | QRectF boundingRect(m_rect.adjusted(margin(), |
|
347 |
rect.height() + margin() + margin()/2 |
|
|
347 | rect.height() + margin() + margin()/2, | |
|
348 | 348 | -margin(), |
|
349 |
-margin()/2 + m_legend->minimumSize().height() |
|
|
349 | -margin()/2 + m_legend->minimumSize().height())); | |
|
350 | 350 | m_legend->handleGeometryChanged(boundingRect); |
|
351 | qDebug() << "legend rect:" << m_legend->boundingRect(); | |
|
352 | 351 | } |
|
353 | 352 | } |
|
354 | 353 | #include "moc_qchart.cpp" |
@@ -32,12 +32,6 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q | |||
|
32 | 32 | { |
|
33 | 33 | painter->setBrush(mBackgroundBrush); |
|
34 | 34 | painter->drawRect(mBoundingRect); |
|
35 | ||
|
36 | foreach(LegendMarker* m, mMarkers) { | |
|
37 | QRectF r = m->boundingRect(); | |
|
38 | painter->setBrush(m->brush()); | |
|
39 | painter->drawText(r.x() + r.width()*2, r.y() + r.height(), m->name()); | |
|
40 | } | |
|
41 | 35 | } |
|
42 | 36 | |
|
43 | 37 | QRectF QLegend::boundingRect() const |
@@ -211,19 +205,12 void QLegend::layoutChanged() | |||
|
211 | 205 | return; |
|
212 | 206 | } |
|
213 | 207 | |
|
214 | // TODO: marker defined by series. | |
|
215 | QSizeF markerSize(10,10); | |
|
216 | ||
|
217 | // TODO: better layout, this is just concept. | |
|
218 | // Leave some space around markers like this: | x x x x | | |
|
219 | 208 | qreal steps = mMarkers.count(); |
|
220 | ||
|
221 | 209 | qreal xStep = mBoundingRect.width() / steps; |
|
222 |
qreal |
|
|
223 |
qreal |
|
|
224 | qreal y = mBoundingRect.y() + (mBoundingRect.height() - markerSize.height())/2; | |
|
210 | qreal x=mBoundingRect.x(); | |
|
211 | qreal y = mBoundingRect.y() + (mBoundingRect.height()/4); | |
|
225 | 212 | foreach (LegendMarker* m, mMarkers) { |
|
226 |
m->setBoundingRect(QRectF(x,y, |
|
|
213 | m->setBoundingRect(QRectF(x,y,xStep,mBoundingRect.height()/2)); | |
|
227 | 214 | x += xStep; |
|
228 | 215 | } |
|
229 | 216 | } |
General Comments 0
You need to be logged in to leave comments.
Login now