##// END OF EJS Templates
legend theme fix
sauimone -
r1527:14e346f15b06
parent child
Show More
@@ -117,12 +117,20 void ChartTheme::decorate(QLegend *legend)
117 {
117 {
118 QPen pen;
118 QPen pen;
119 QBrush brush;
119 QBrush brush;
120 QFont font;
120
121
121 if (pen == legend->pen() || m_force)
122 if (pen == legend->pen() || m_force)
122 legend->setPen(m_axisLinePen);
123 legend->setPen(m_axisLinePen);
123
124
124 if (brush == legend->brush() || m_force)
125 if (brush == legend->brush() || m_force)
125 legend->setBrush(m_chartBackgroundGradient);
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 void ChartTheme::decorate(QAreaSeries *series, int index)
136 void ChartTheme::decorate(QAreaSeries *series, int index)
@@ -98,6 +98,28 QString LegendMarker::label() const
98 return m_textItem->text();
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 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
123 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
102 {
124 {
103 Q_UNUSED(option)
125 Q_UNUSED(option)
@@ -66,6 +66,10 public:
66
66
67 void setLabel(const QString label);
67 void setLabel(const QString label);
68 QString label() const;
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 QAbstractSeries *series() const { return m_series;}
74 QAbstractSeries *series() const { return m_series;}
71
75
@@ -286,6 +286,50 QFont QLegend::font() const
286 return d_ptr->m_font;
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 void QLegend::setAlignment(Qt::Alignment alignment)
333 void QLegend::setAlignment(Qt::Alignment alignment)
290 {
334 {
291 if(d_ptr->m_alignment!=alignment) {
335 if(d_ptr->m_alignment!=alignment) {
@@ -396,6 +440,8 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend
396 m_alignment(Qt::AlignTop),
440 m_alignment(Qt::AlignTop),
397 m_brush(QBrush()),
441 m_brush(QBrush()),
398 m_pen(QPen()),
442 m_pen(QPen()),
443 m_labelPen(QPen(Qt::NoPen)),
444 m_labelBrush(QBrush()),
399 m_offsetX(0),
445 m_offsetX(0),
400 m_offsetY(0),
446 m_offsetY(0),
401 m_minWidth(0),
447 m_minWidth(0),
@@ -719,6 +765,30 void QLegendPrivate::setFont(const QFont &font)
719 updateLayout();
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 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
792 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
723 {
793 {
724 Q_UNUSED(domain)
794 Q_UNUSED(domain)
@@ -726,6 +796,8 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
726 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
796 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
727 foreach(LegendMarker* marker, markers) {
797 foreach(LegendMarker* marker, markers) {
728 marker->setFont(m_font);
798 marker->setFont(m_font);
799 marker->setLabelPen(m_labelPen);
800 marker->setLabelBrush(m_labelBrush);
729 m_markers->addToGroup(marker);
801 m_markers->addToGroup(marker);
730 }
802 }
731
803
@@ -48,6 +48,9 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
48 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
48 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
49 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
49 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
50 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
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 private:
55 private:
53 explicit QLegend(QChart *chart);
56 explicit QLegend(QChart *chart);
@@ -70,6 +73,13 public:
70
73
71 void setFont(const QFont &font);
74 void setFont(const QFont &font);
72 QFont font() const;
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 void setAlignment(Qt::Alignment alignment);
84 void setAlignment(Qt::Alignment alignment);
75 Qt::Alignment alignment() const;
85 Qt::Alignment alignment() const;
@@ -94,6 +104,11 Q_SIGNALS:
94 void colorChanged(QColor color);
104 void colorChanged(QColor color);
95 void borderColorChanged(QColor color);
105 void borderColorChanged(QColor color);
96 void fontChanged(QFont font);
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 private:
113 private:
99 QScopedPointer<QLegendPrivate> d_ptr;
114 QScopedPointer<QLegendPrivate> d_ptr;
@@ -52,6 +52,8 public:
52 void attachToChart();
52 void attachToChart();
53 int roundness(qreal size);
53 int roundness(qreal size);
54 void setFont(const QFont &font);
54 void setFont(const QFont &font);
55 void setLabelPen(const QPen &pen);
56 void setLabelBrush(const QBrush &brush);
55
57
56 public Q_SLOTS:
58 public Q_SLOTS:
57 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
59 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
@@ -69,6 +71,8 private:
69 QBrush m_brush;
71 QBrush m_brush;
70 QPen m_pen;
72 QPen m_pen;
71 QFont m_font;
73 QFont m_font;
74 QPen m_labelPen;
75 QBrush m_labelBrush;
72 QRectF m_rect;
76 QRectF m_rect;
73 qreal m_offsetX;
77 qreal m_offsetX;
74 qreal m_offsetY;
78 qreal m_offsetY;
General Comments 0
You need to be logged in to leave comments. Login now