diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index 21a5f76..d43e221 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -56,6 +56,7 @@ int main(int argc, char *argv[]) QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); + QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); //! [4] //! [5] diff --git a/src/barchart/barpresenter.cpp b/src/barchart/barpresenter.cpp index d6d61fb..7b59970 100644 --- a/src/barchart/barpresenter.cpp +++ b/src/barchart/barpresenter.cpp @@ -61,6 +61,7 @@ void BarPresenter::layoutChanged() Separator* sep = mSeparators.at(s); sep->setPos(xPos,0); sep->setSize(QSizeF(1,mHeight)); + sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme xPos += categoryWidth; } @@ -73,10 +74,10 @@ void BarPresenter::layoutChanged() qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); - // TODO: remove hard coding, apply layout - value->resize(100,50); + QBarSet* barSet = mSeries->barsetAt(set); + value->resize(100,50); // TODO: proper layout for this. value->setPos(xPos, yPos-barHeight/2); - value->setPen(QPen(QColor(255,255,255,255))); + value->setPen(barSet->floatingValuePen()); if (mSeries->valueAt(set,category) != 0) { value->setValueString(QString::number(mSeries->valueAt(set,category))); diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index fc41f1c..225c5d2 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -78,7 +78,6 @@ void BarPresenterBase::dataChanged() int count = mSeries->categoryCount() - 1; // There is one less separator than columns for (int i=0; isetColor(QColor(255,0,0,255)); // TODO: color for separations from theme sep->setVisible(mSeries->separatorsVisible()); childItems().append(sep); mSeparators.append(sep); diff --git a/src/barchart/percentbarpresenter.cpp b/src/barchart/percentbarpresenter.cpp index c44ce77..c8dce2a 100644 --- a/src/barchart/percentbarpresenter.cpp +++ b/src/barchart/percentbarpresenter.cpp @@ -76,10 +76,10 @@ void PercentBarPresenter::layoutChanged() qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); - // TODO: remove hard coding, apply layout - value->resize(100,50); + QBarSet* barSet = mSeries->barsetAt(set); + value->resize(100,50); // TODO: proper layout for this. value->setPos(xPos, yPos-barHeight/2); - value->setPen(QPen(QColor(255,255,255,255))); + value->setPen(barSet->floatingValuePen()); if (mSeries->valueAt(set,category) != 0) { int p = mSeries->percentageAt(set,category) * 100; diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index ec7da1d..a105cd4 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -154,6 +154,22 @@ QBrush QBarSet::brush() const } /*! + Sets the pen for floating values that are drawn on top of this set +*/ +void QBarSet::setFloatingValuePen(const QPen pen) +{ + mFloatingValuePen = pen; +} + +/*! + Returns the pen for floating values that are drawn on top of this set +*/ +QPen QBarSet::floatingValuePen() const +{ + return mFloatingValuePen; +} + +/*! \internal \a pos */ void QBarSet::barHoverEnterEvent(QPoint pos) diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 4b656c8..c4246e5 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -33,6 +33,9 @@ public: void setBrush(const QBrush brush); QBrush brush() const; + void setFloatingValuePen(const QPen pen); + QPen floatingValuePen() const; + Q_SIGNALS: void clicked(QString category); // Clicked and hover signals exposed to user void rightClicked(QString category); @@ -59,7 +62,7 @@ private: QMap mMappedValues; QPen mPen; QBrush mBrush; - + QPen mFloatingValuePen; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/stackedbarpresenter.cpp b/src/barchart/stackedbarpresenter.cpp index 98fa654..1870f43 100644 --- a/src/barchart/stackedbarpresenter.cpp +++ b/src/barchart/stackedbarpresenter.cpp @@ -83,10 +83,10 @@ void StackedBarPresenter::layoutChanged() qreal barHeight = mSeries->valueAt(set,category) * scale; BarValue* value = mFloatingValues.at(itemIndex); - // TODO: remove hard coding, apply layout - value->resize(100,50); + QBarSet* barSet = mSeries->barsetAt(set); + value->resize(100,50); // TODO: proper layout for this. value->setPos(xPos, yPos-barHeight/2); - value->setPen(QPen(QColor(255,255,255,255))); + value->setPen(barSet->floatingValuePen()); if (mSeries->valueAt(set,category) != 0) { value->setValueString(QString::number(mSeries->valueAt(set,category))); diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 8e6e06f..611e473 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -160,6 +160,16 @@ void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count) qreal pos = (qreal) i / (qreal) sets.count(); QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); + + // Pick label color as far as possible from bar color (within gradient). + // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) + // TODO: better picking of label color? + if (pos < 0.3) { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1); + } else { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0); + } + sets.at(i)->setFloatingValuePen(QPen(c)); } } @@ -170,6 +180,13 @@ void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,i qreal pos = (qreal) i / (qreal) sets.count(); QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); + + if (pos < 0.3) { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1); + } else { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0); + } + sets.at(i)->setFloatingValuePen(QPen(c)); } } @@ -180,6 +197,13 @@ void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,i qreal pos = (qreal) i / (qreal) sets.count(); QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos); sets.at(i)->setBrush(QBrush(c)); + + if (pos < 0.3) { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1); + } else { + c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0); + } + sets.at(i)->setFloatingValuePen(QPen(c)); } }