##// END OF EJS Templates
Get pie slice label font and pen from theme
Jani Honkonen -
r714:6705438d7ae7
parent child
Show More
@@ -296,6 +296,7 public:
296 *m_series << new CustomSlice(30.0, "Slice 3");
296 *m_series << new CustomSlice(30.0, "Slice 3");
297 *m_series << new CustomSlice(40.0, "Slice 4");
297 *m_series << new CustomSlice(40.0, "Slice 4");
298 *m_series << new CustomSlice(50.0, "Slice 5");
298 *m_series << new CustomSlice(50.0, "Slice 5");
299 m_series->setLabelsVisible();
299 m_chartView->addSeries(m_series);
300 m_chartView->addSeries(m_series);
300
301
301 connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons)));
302 connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons)));
@@ -394,8 +395,8 public:
394 m_brush = new QPushButton();
395 m_brush = new QPushButton();
395 m_brushTool = new BrushTool("Slice brush", this);
396 m_brushTool = new BrushTool("Slice brush", this);
396 m_font = new QPushButton();
397 m_font = new QPushButton();
397 m_labelArmPen = new QPushButton();
398 m_labelPen = new QPushButton();
398 m_labelArmPenTool = new PenTool("Label arm pen", this);
399 m_labelPenTool = new PenTool("Label pen", this);
399 QPushButton *removeSlice = new QPushButton("Remove slice");
400 QPushButton *removeSlice = new QPushButton("Remove slice");
400
401
401 QFormLayout* sliceSettingsLayout = new QFormLayout();
402 QFormLayout* sliceSettingsLayout = new QFormLayout();
@@ -405,7 +406,7 public:
405 sliceSettingsLayout->addRow("Brush", m_brush);
406 sliceSettingsLayout->addRow("Brush", m_brush);
406 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
407 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
407 sliceSettingsLayout->addRow("Label font", m_font);
408 sliceSettingsLayout->addRow("Label font", m_font);
408 sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen);
409 sliceSettingsLayout->addRow("Label pen", m_labelPen);
409 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
410 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
410 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
411 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
411 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
412 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
@@ -419,8 +420,8 public:
419 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
420 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
420 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
421 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
421 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
422 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
422 connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show()));
423 connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show()));
423 connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
424 connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
424 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
425 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
425 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
426 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
426 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
427 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
@@ -475,7 +476,7 public Q_SLOTS:
475 m_slice->setSlicePen(m_penTool->pen());
476 m_slice->setSlicePen(m_penTool->pen());
476 m_slice->setSliceBrush(m_brushTool->brush());
477 m_slice->setSliceBrush(m_brushTool->brush());
477
478
478 m_slice->setLabelArmPen(m_labelArmPenTool->pen());
479 m_slice->setLabelPen(m_labelPenTool->pen());
479 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
480 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
480 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
481 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
481
482
@@ -506,8 +507,8 public Q_SLOTS:
506 m_brushTool->setBrush(m_slice->originalBrush());
507 m_brushTool->setBrush(m_slice->originalBrush());
507
508
508 // label
509 // label
509 m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen()));
510 m_labelPen->setText(PenTool::name(m_slice->labelPen()));
510 m_labelArmPenTool->setPen(m_slice->labelArmPen());
511 m_labelPenTool->setPen(m_slice->labelPen());
511 m_font->setText(slice->labelFont().toString());
512 m_font->setText(slice->labelFont().toString());
512 m_sliceLabelVisible->blockSignals(true);
513 m_sliceLabelVisible->blockSignals(true);
513 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
514 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
@@ -588,8 +589,8 private:
588 QPushButton *m_pen;
589 QPushButton *m_pen;
589 PenTool *m_penTool;
590 PenTool *m_penTool;
590 QPushButton *m_font;
591 QPushButton *m_font;
591 QPushButton *m_labelArmPen;
592 QPushButton *m_labelPen;
592 PenTool *m_labelArmPenTool;
593 PenTool *m_labelPenTool;
593 };
594 };
594
595
595 int main(int argc, char *argv[])
596 int main(int argc, char *argv[])
@@ -221,6 +221,16 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
221 data.m_sliceBrush.setThemed(true);
221 data.m_sliceBrush.setThemed(true);
222 }
222 }
223
223
224 if (data.m_labelPen.isThemed() || force) {
225 data.m_labelPen = QPen(m_titleBrush.color());
226 data.m_labelPen.setThemed(true);
227 }
228
229 if (data.m_labelFont.isThemed() || force) {
230 data.m_labelFont = m_masterFont;
231 data.m_labelFont.setThemed(true);
232 }
233
224 if (s->m_data != data) {
234 if (s->m_data != data) {
225 s->m_data = data;
235 s->m_data = data;
226 emit s->changed();
236 emit s->changed();
@@ -71,7 +71,7 public:
71 m_labelText != other.m_labelText ||
71 m_labelText != other.m_labelText ||
72 m_labelFont != other.m_labelFont ||
72 m_labelFont != other.m_labelFont ||
73 m_labelArmLengthFactor != other.m_labelArmLengthFactor ||
73 m_labelArmLengthFactor != other.m_labelArmLengthFactor ||
74 m_labelArmPen != other.m_labelArmPen)
74 m_labelPen != other.m_labelPen)
75 return true;
75 return true;
76
76
77 if (m_percentage != other.m_percentage ||
77 if (m_percentage != other.m_percentage ||
@@ -96,7 +96,7 public:
96 QString m_labelText;
96 QString m_labelText;
97 Themed<QFont> m_labelFont;
97 Themed<QFont> m_labelFont;
98 qreal m_labelArmLengthFactor;
98 qreal m_labelArmLengthFactor;
99 Themed<QPen> m_labelArmPen;
99 Themed<QPen> m_labelPen;
100
100
101 qreal m_percentage;
101 qreal m_percentage;
102 QPointF m_center;
102 QPointF m_center;
@@ -56,11 +56,9 void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op
56 painter->restore();
56 painter->restore();
57
57
58 if (m_data.m_isLabelVisible) {
58 if (m_data.m_isLabelVisible) {
59 painter->save();
59 painter->setPen(m_data.m_labelPen);
60 painter->setPen(m_data.m_labelArmPen);
61 painter->drawPath(m_labelArmPath);
60 painter->drawPath(m_labelArmPath);
62 painter->restore();
61 // the pen color will affect the font color as well
63
64 painter->setFont(m_data.m_labelFont);
62 painter->setFont(m_data.m_labelFont);
65 painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText);
63 painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText);
66 }
64 }
@@ -182,13 +182,13 QBrush QPieSlice::sliceBrush() const
182 }
182 }
183
183
184 /*!
184 /*!
185 Returns the pen used to draw label arm in this slice.
185 Returns the pen used to draw the label in this slice.
186 \sa setLabelArmPen()
186 \sa setLabelArmPen()
187 */
187 */
188 QPen QPieSlice::labelArmPen() const
188 QPen QPieSlice::labelPen() const
189 {
189 {
190 Q_D(const QPieSlice);
190 Q_D(const QPieSlice);
191 return d->m_data.m_labelArmPen;
191 return d->m_data.m_labelPen;
192 }
192 }
193
193
194 /*!
194 /*!
@@ -358,16 +358,16 void QPieSlice::setSliceBrush(const QBrush &brush)
358 }
358 }
359
359
360 /*!
360 /*!
361 Sets the \a pen used to draw the label arm in this slice.
361 Sets the \a pen used to draw the label in this slice.
362 Note that applying a theme will override this.
362 Note that applying a theme will override this.
363 \sa labelArmPen()
363 \sa labelArmPen()
364 */
364 */
365 void QPieSlice::setLabelArmPen(const QPen &pen)
365 void QPieSlice::setLabelPen(const QPen &pen)
366 {
366 {
367 Q_D(QPieSlice);
367 Q_D(QPieSlice);
368 if (d->m_data.m_labelArmPen != pen) {
368 if (d->m_data.m_labelPen != pen) {
369 d->m_data.m_labelArmPen = pen;
369 d->m_data.m_labelPen = pen;
370 d->m_data.m_labelArmPen.setThemed(false);
370 d->m_data.m_labelPen.setThemed(false);
371 emit changed();
371 emit changed();
372 }
372 }
373 }
373 }
@@ -41,8 +41,8 public:
41 QPen slicePen() const;
41 QPen slicePen() const;
42 void setSliceBrush(const QBrush &brush);
42 void setSliceBrush(const QBrush &brush);
43 QBrush sliceBrush() const;
43 QBrush sliceBrush() const;
44 void setLabelArmPen(const QPen &pen);
44 void setLabelPen(const QPen &pen);
45 QPen labelArmPen() const;
45 QPen labelPen() const;
46 void setLabelFont(const QFont &font);
46 void setLabelFont(const QFont &font);
47 QFont labelFont() const;
47 QFont labelFont() const;
48 void setLabelArmLengthFactor(qreal factor);
48 void setLabelArmLengthFactor(qreal factor);
General Comments 0
You need to be logged in to leave comments. Login now