@@ -117,12 +117,20 void ChartTheme::decorate(QLegend *legend) | |||
|
117 | 117 | { |
|
118 | 118 | QPen pen; |
|
119 | 119 | QBrush brush; |
|
120 | QFont font; | |
|
120 | 121 | |
|
121 | 122 | if (pen == legend->pen() || m_force) |
|
122 | 123 | legend->setPen(m_axisLinePen); |
|
123 | 124 | |
|
124 | 125 | if (brush == legend->brush() || m_force) |
|
125 | 126 | legend->setBrush(m_chartBackgroundGradient); |
|
127 | ||
|
128 | // TODO: should legend have own brush & font defined by theme? | |
|
129 | if (font == legend->font() || m_force) | |
|
130 | legend->setFont(m_labelFont); | |
|
131 | ||
|
132 | if (brush == legend->labelBrush() || m_force) | |
|
133 | legend->setLabelBrush(m_axisLabelBrush); | |
|
126 | 134 | } |
|
127 | 135 | |
|
128 | 136 | void ChartTheme::decorate(QAreaSeries *series, int index) |
@@ -98,6 +98,28 QString LegendMarker::label() const | |||
|
98 | 98 | return m_textItem->text(); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | void LegendMarker::setLabelBrush(const QBrush &brush) | |
|
102 | { | |
|
103 | m_textItem->setBrush(brush); | |
|
104 | updateLayout(); | |
|
105 | } | |
|
106 | ||
|
107 | QBrush LegendMarker::labelBrush() const | |
|
108 | { | |
|
109 | return m_textItem->brush(); | |
|
110 | } | |
|
111 | ||
|
112 | void LegendMarker::setLabelPen(const QPen &pen) | |
|
113 | { | |
|
114 | m_textItem->setPen(pen); | |
|
115 | updateLayout(); | |
|
116 | } | |
|
117 | ||
|
118 | QPen LegendMarker::labelPen() const | |
|
119 | { | |
|
120 | return m_textItem->pen(); | |
|
121 | } | |
|
122 | ||
|
101 | 123 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
102 | 124 | { |
|
103 | 125 | Q_UNUSED(option) |
@@ -66,6 +66,10 public: | |||
|
66 | 66 | |
|
67 | 67 | void setLabel(const QString label); |
|
68 | 68 | QString label() const; |
|
69 | void setLabelBrush(const QBrush &brush); | |
|
70 | QBrush labelBrush() const; | |
|
71 | void setLabelPen(const QPen &pen); | |
|
72 | QPen labelPen() const; | |
|
69 | 73 | |
|
70 | 74 | QAbstractSeries *series() const { return m_series;} |
|
71 | 75 |
@@ -286,6 +286,50 QFont QLegend::font() const | |||
|
286 | 286 | return d_ptr->m_font; |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | void QLegend::setLabelPen(const QPen &pen) | |
|
290 | { | |
|
291 | if (d_ptr->m_labelPen != pen) { | |
|
292 | d_ptr->setLabelPen(pen); | |
|
293 | emit labelPenChanged(pen); | |
|
294 | } | |
|
295 | } | |
|
296 | ||
|
297 | QPen QLegend::labelPen() const | |
|
298 | { | |
|
299 | return d_ptr->m_labelPen; | |
|
300 | } | |
|
301 | ||
|
302 | void QLegend::setLabelBrush(const QBrush &brush) | |
|
303 | { | |
|
304 | qDebug() << "setting legend brush 1"; | |
|
305 | if (d_ptr->m_labelBrush != brush) { | |
|
306 | d_ptr->setLabelBrush(brush); | |
|
307 | emit labelBrushChanged(brush); | |
|
308 | qDebug() << "setting legend brush 2"; | |
|
309 | } | |
|
310 | } | |
|
311 | ||
|
312 | QBrush QLegend::labelBrush() const | |
|
313 | { | |
|
314 | return d_ptr->m_labelBrush; | |
|
315 | } | |
|
316 | ||
|
317 | void QLegend::setLabelColor(QColor color) | |
|
318 | { | |
|
319 | QBrush b = d_ptr->m_labelBrush; | |
|
320 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
|
321 | b.setStyle(Qt::SolidPattern); | |
|
322 | b.setColor(color); | |
|
323 | setLabelBrush(b); | |
|
324 | emit labelColorChanged(color); | |
|
325 | } | |
|
326 | } | |
|
327 | ||
|
328 | QColor QLegend::labelColor() const | |
|
329 | { | |
|
330 | return d_ptr->m_labelBrush.color(); | |
|
331 | } | |
|
332 | ||
|
289 | 333 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
290 | 334 | { |
|
291 | 335 | if(d_ptr->m_alignment!=alignment) { |
@@ -396,6 +440,8 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend | |||
|
396 | 440 | m_alignment(Qt::AlignTop), |
|
397 | 441 | m_brush(QBrush()), |
|
398 | 442 | m_pen(QPen()), |
|
443 | m_labelPen(QPen(Qt::NoPen)), | |
|
444 | m_labelBrush(QBrush()), | |
|
399 | 445 | m_offsetX(0), |
|
400 | 446 | m_offsetY(0), |
|
401 | 447 | m_minWidth(0), |
@@ -719,6 +765,30 void QLegendPrivate::setFont(const QFont &font) | |||
|
719 | 765 | updateLayout(); |
|
720 | 766 | } |
|
721 | 767 | |
|
768 | void QLegendPrivate::setLabelPen(const QPen &pen) | |
|
769 | { | |
|
770 | m_labelPen = pen; | |
|
771 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
|
772 | ||
|
773 | foreach (QGraphicsItem *markers, items) { | |
|
774 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
|
775 | marker->setPen(m_labelPen); | |
|
776 | } | |
|
777 | updateLayout(); | |
|
778 | } | |
|
779 | ||
|
780 | void QLegendPrivate::setLabelBrush(const QBrush &brush) | |
|
781 | { | |
|
782 | m_labelBrush = brush; | |
|
783 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
|
784 | ||
|
785 | foreach (QGraphicsItem *markers, items) { | |
|
786 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
|
787 | marker->setLabelBrush(m_labelBrush); | |
|
788 | } | |
|
789 | updateLayout(); | |
|
790 | } | |
|
791 | ||
|
722 | 792 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
723 | 793 | { |
|
724 | 794 | Q_UNUSED(domain) |
@@ -726,6 +796,8 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |||
|
726 | 796 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
727 | 797 | foreach(LegendMarker* marker, markers) { |
|
728 | 798 | marker->setFont(m_font); |
|
799 | marker->setLabelPen(m_labelPen); | |
|
800 | marker->setLabelBrush(m_labelBrush); | |
|
729 | 801 | m_markers->addToGroup(marker); |
|
730 | 802 | } |
|
731 | 803 |
@@ -48,6 +48,9 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |||
|
48 | 48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
49 | 49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
50 | 50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
|
52 | // TODO? | |
|
53 | // Q_PROPERTY(QColor labelBorderColor READ labelBorderColor WRITE setLabelBorderColor NOTIFY labelBorderColorChanged) | |
|
51 | 54 | |
|
52 | 55 | private: |
|
53 | 56 | explicit QLegend(QChart *chart); |
@@ -70,6 +73,13 public: | |||
|
70 | 73 | |
|
71 | 74 | void setFont(const QFont &font); |
|
72 | 75 | QFont font() const; |
|
76 | void setLabelPen(const QPen &pen); | |
|
77 | QPen labelPen() const; | |
|
78 | void setLabelBrush(const QBrush &brush); | |
|
79 | QBrush labelBrush() const; | |
|
80 | ||
|
81 | void setLabelColor(QColor color); | |
|
82 | QColor labelColor() const; | |
|
73 | 83 | |
|
74 | 84 | void setAlignment(Qt::Alignment alignment); |
|
75 | 85 | Qt::Alignment alignment() const; |
@@ -94,6 +104,11 Q_SIGNALS: | |||
|
94 | 104 | void colorChanged(QColor color); |
|
95 | 105 | void borderColorChanged(QColor color); |
|
96 | 106 | void fontChanged(QFont font); |
|
107 | void labelPenChanged(QPen pen); | |
|
108 | void labelBrushChanged(QBrush brush); | |
|
109 | void labelColorChanged(QColor color); | |
|
110 | // TODO? | |
|
111 | // void labelBorderColorChanged(QColor color); | |
|
97 | 112 | |
|
98 | 113 | private: |
|
99 | 114 | QScopedPointer<QLegendPrivate> d_ptr; |
@@ -52,6 +52,8 public: | |||
|
52 | 52 | void attachToChart(); |
|
53 | 53 | int roundness(qreal size); |
|
54 | 54 | void setFont(const QFont &font); |
|
55 | void setLabelPen(const QPen &pen); | |
|
56 | void setLabelBrush(const QBrush &brush); | |
|
55 | 57 | |
|
56 | 58 | public Q_SLOTS: |
|
57 | 59 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); |
@@ -69,6 +71,8 private: | |||
|
69 | 71 | QBrush m_brush; |
|
70 | 72 | QPen m_pen; |
|
71 | 73 | QFont m_font; |
|
74 | QPen m_labelPen; | |
|
75 | QBrush m_labelBrush; | |
|
72 | 76 | QRectF m_rect; |
|
73 | 77 | qreal m_offsetX; |
|
74 | 78 | qreal m_offsetY; |
General Comments 0
You need to be logged in to leave comments.
Login now