From 6705438d7ae768485c24f1b38484f34941465344 2012-03-23 13:51:02 From: Jani Honkonen Date: 2012-03-23 13:51:02 Subject: [PATCH] Get pie slice label font and pen from theme --- diff --git a/demos/piechartcustomization/main.cpp b/demos/piechartcustomization/main.cpp index 6bc3ad7..cf30083 100644 --- a/demos/piechartcustomization/main.cpp +++ b/demos/piechartcustomization/main.cpp @@ -296,6 +296,7 @@ public: *m_series << new CustomSlice(30.0, "Slice 3"); *m_series << new CustomSlice(40.0, "Slice 4"); *m_series << new CustomSlice(50.0, "Slice 5"); + m_series->setLabelsVisible(); m_chartView->addSeries(m_series); connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons))); @@ -394,8 +395,8 @@ public: m_brush = new QPushButton(); m_brushTool = new BrushTool("Slice brush", this); m_font = new QPushButton(); - m_labelArmPen = new QPushButton(); - m_labelArmPenTool = new PenTool("Label arm pen", this); + m_labelPen = new QPushButton(); + m_labelPenTool = new PenTool("Label pen", this); QPushButton *removeSlice = new QPushButton("Remove slice"); QFormLayout* sliceSettingsLayout = new QFormLayout(); @@ -405,7 +406,7 @@ public: sliceSettingsLayout->addRow("Brush", m_brush); sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); sliceSettingsLayout->addRow("Label font", m_font); - sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen); + sliceSettingsLayout->addRow("Label pen", m_labelPen); sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); sliceSettingsLayout->addRow("Exploded", m_sliceExploded); sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); @@ -419,8 +420,8 @@ public: connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); - connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show())); - connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); + connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); + connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); @@ -475,7 +476,7 @@ public Q_SLOTS: m_slice->setSlicePen(m_penTool->pen()); m_slice->setSliceBrush(m_brushTool->brush()); - m_slice->setLabelArmPen(m_labelArmPenTool->pen()); + m_slice->setLabelPen(m_labelPenTool->pen()); m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); @@ -506,8 +507,8 @@ public Q_SLOTS: m_brushTool->setBrush(m_slice->originalBrush()); // label - m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen())); - m_labelArmPenTool->setPen(m_slice->labelArmPen()); + m_labelPen->setText(PenTool::name(m_slice->labelPen())); + m_labelPenTool->setPen(m_slice->labelPen()); m_font->setText(slice->labelFont().toString()); m_sliceLabelVisible->blockSignals(true); m_sliceLabelVisible->setChecked(slice->isLabelVisible()); @@ -588,8 +589,8 @@ private: QPushButton *m_pen; PenTool *m_penTool; QPushButton *m_font; - QPushButton *m_labelArmPen; - PenTool *m_labelArmPenTool; + QPushButton *m_labelPen; + PenTool *m_labelPenTool; }; int main(int argc, char *argv[]) diff --git a/src/charttheme.cpp b/src/charttheme.cpp index a17e04b..98761c2 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -221,6 +221,16 @@ void ChartTheme::decorate(QPieSeries* series, int index, bool force) data.m_sliceBrush.setThemed(true); } + if (data.m_labelPen.isThemed() || force) { + data.m_labelPen = QPen(m_titleBrush.color()); + data.m_labelPen.setThemed(true); + } + + if (data.m_labelFont.isThemed() || force) { + data.m_labelFont = m_masterFont; + data.m_labelFont.setThemed(true); + } + if (s->m_data != data) { s->m_data = data; emit s->changed(); diff --git a/src/piechart/pieslicedata_p.h b/src/piechart/pieslicedata_p.h index ab60b41..f1585e2 100644 --- a/src/piechart/pieslicedata_p.h +++ b/src/piechart/pieslicedata_p.h @@ -71,7 +71,7 @@ public: m_labelText != other.m_labelText || m_labelFont != other.m_labelFont || m_labelArmLengthFactor != other.m_labelArmLengthFactor || - m_labelArmPen != other.m_labelArmPen) + m_labelPen != other.m_labelPen) return true; if (m_percentage != other.m_percentage || @@ -96,7 +96,7 @@ public: QString m_labelText; Themed m_labelFont; qreal m_labelArmLengthFactor; - Themed m_labelArmPen; + Themed m_labelPen; qreal m_percentage; QPointF m_center; diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index 3caca36..d49eaeb 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -56,11 +56,9 @@ void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op painter->restore(); if (m_data.m_isLabelVisible) { - painter->save(); - painter->setPen(m_data.m_labelArmPen); + painter->setPen(m_data.m_labelPen); painter->drawPath(m_labelArmPath); - painter->restore(); - + // the pen color will affect the font color as well painter->setFont(m_data.m_labelFont); painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText); } diff --git a/src/piechart/qpieslice.cpp b/src/piechart/qpieslice.cpp index 331f1bd..3775acc 100644 --- a/src/piechart/qpieslice.cpp +++ b/src/piechart/qpieslice.cpp @@ -182,13 +182,13 @@ QBrush QPieSlice::sliceBrush() const } /*! - Returns the pen used to draw label arm in this slice. + Returns the pen used to draw the label in this slice. \sa setLabelArmPen() */ -QPen QPieSlice::labelArmPen() const +QPen QPieSlice::labelPen() const { Q_D(const QPieSlice); - return d->m_data.m_labelArmPen; + return d->m_data.m_labelPen; } /*! @@ -358,16 +358,16 @@ void QPieSlice::setSliceBrush(const QBrush &brush) } /*! - Sets the \a pen used to draw the label arm in this slice. + Sets the \a pen used to draw the label in this slice. Note that applying a theme will override this. \sa labelArmPen() */ -void QPieSlice::setLabelArmPen(const QPen &pen) +void QPieSlice::setLabelPen(const QPen &pen) { Q_D(QPieSlice); - if (d->m_data.m_labelArmPen != pen) { - d->m_data.m_labelArmPen = pen; - d->m_data.m_labelArmPen.setThemed(false); + if (d->m_data.m_labelPen != pen) { + d->m_data.m_labelPen = pen; + d->m_data.m_labelPen.setThemed(false); emit changed(); } } diff --git a/src/piechart/qpieslice.h b/src/piechart/qpieslice.h index a6bc0cb..8875a98 100644 --- a/src/piechart/qpieslice.h +++ b/src/piechart/qpieslice.h @@ -41,8 +41,8 @@ public: QPen slicePen() const; void setSliceBrush(const QBrush &brush); QBrush sliceBrush() const; - void setLabelArmPen(const QPen &pen); - QPen labelArmPen() const; + void setLabelPen(const QPen &pen); + QPen labelPen() const; void setLabelFont(const QFont &font); QFont labelFont() const; void setLabelArmLengthFactor(qreal factor);