From f4e416c6727fe2414478ebc0cf57ed591a6cbe17 2012-03-19 14:35:17 From: Tero Ahola Date: 2012-03-19 14:35:17 Subject: [PATCH] Use light outline color instead of dark for bar, area and scatter --- diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 02d1590..bed5d7c 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -11,6 +11,8 @@ Bar::Bar(QString category, QGraphicsItem *parent) mYpos(0), mWidth(0), mHeight(0), + mBrush(QBrush()), + mPen(QPen()), mCategory(category) { setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); @@ -54,6 +56,7 @@ void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg if (0 == mHeight) { return; } + painter->setPen(mPen); painter->setBrush(mBrush); // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. diff --git a/src/barchart/percentbarpresenter.cpp b/src/barchart/percentbarpresenter.cpp index ca4c921..1abb9d1 100644 --- a/src/barchart/percentbarpresenter.cpp +++ b/src/barchart/percentbarpresenter.cpp @@ -48,6 +48,7 @@ void PercentBarPresenter::layoutChanged() // TODO: width settable per bar? bar->resize(mBarWidth, barHeight); + bar->setPen(mSeries->barsetAt(set)->pen()); bar->setBrush(mSeries->barsetAt(set)->brush()); bar->setPos(xPos, yPos-barHeight); itemIndex++; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index d61fd04..dcfe137 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -122,7 +122,7 @@ void ChartTheme::decorate(QAreaSeries* series, int index,bool force) QBrush brush; if (pen == series->pen() || force){ - pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); + pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); pen.setWidthF(2); series->setPen(pen); } @@ -144,90 +144,43 @@ void ChartTheme::decorate(QLineSeries* series,int index,bool force) } } -void ChartTheme::decorate(QBarSeries* series,int index,bool force) +void ChartTheme::decorate(QBarSeries* series, int index, bool force) { QBrush brush; + QPen pen; QList sets = series->barSets(); - for (int i=0; i 1) pos = (qreal) i / (qreal) (sets.count() - 1); - if(brush == sets.at(i)->brush() || force ){ - QColor c = colorAt(m_seriesGradients.at(index % 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? - QColor c; - - if (pos < 0.3) { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); - } else { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); - } - sets.at(i)->setFloatingValuePen(QPen(c)); - - } -} - -void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force) -{ - QBrush brush; - QList sets = series->barSets(); - - for (int i=0; i 1) - pos = (qreal) i / (qreal) (sets.count() - 1); - if(brush == sets.at(i)->brush() || force){ - QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); - sets.at(i)->setBrush(QBrush(c)); - } - QColor c; - if (pos < 0.3) { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); - } else { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); + if (brush == sets.at(i)->brush() || force ) { + QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); + sets.at(i)->setBrush(QBrush(c)); } - sets.at(i)->setFloatingValuePen(QPen(c)); - } -} -void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force) -{ - QBrush brush; - QList sets = series->barSets(); + // Pick label color from the opposite end of the gradient. + // 0.3 as a boundary seems to work well. + if (pos < 0.3) + sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); + else + sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); - for (int i=0; i 1) - pos = (qreal) i / (qreal) (sets.count() - 1); - - if(brush == sets.at(i)->brush() || force){ - QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); - sets.at(i)->setBrush(QBrush(c)); - } - QColor c; - if (pos < 0.3) { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); - } else { - c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); + if (pen == sets.at(i)->pen() || force) { + QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); + sets.at(i)->setPen(c); } - sets.at(i)->setFloatingValuePen(QPen(c)); } } void ChartTheme::decorate(QScatterSeries* series, int index,bool force) { - QPen pen; QBrush brush; if (pen == series->pen() || force) { - pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); + pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); pen.setWidthF(2); series->setPen(pen); } @@ -240,20 +193,20 @@ void ChartTheme::decorate(QScatterSeries* series, int index,bool force) void ChartTheme::decorate(QPieSeries* series, int index, bool force) { - // Get color for a slice from a gradient linearly, beginning from the start of the gradient - QPen pen; QBrush brush; for (int i(0); i < series->slices().count(); i++) { - qreal pos = (qreal) i / (qreal) series->count(); - if( pen == series->slices().at(i)->slicePen() || force){ - QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); - series->slices().at(i)->setSlicePen(penColor); + if (pen == series->slices().at(i)->slicePen() || force) { + QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); + series->slices().at(i)->setSlicePen(penColor); } - if( brush == series->slices().at(i)->sliceBrush() || force){ - QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); - series->slices().at(i)->setSliceBrush(brushColor); + + // Get color for a slice from a gradient linearly, beginning from the start of the gradient + qreal pos = (qreal) i / (qreal) series->count(); + if (brush == series->slices().at(i)->sliceBrush() || force) { + QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); + series->slices().at(i)->setSliceBrush(brushColor); } } } diff --git a/src/charttheme_p.h b/src/charttheme_p.h index ec5ac47..ee77ed4 100644 --- a/src/charttheme_p.h +++ b/src/charttheme_p.h @@ -44,10 +44,7 @@ public: QChart::ChartTheme id() const {return m_id;} void decorate(QChart* chart,bool force = true); void decorate(QLegend* legend,bool force = true); - //void decorate(ChartItem* item, QSeries* series,int index); void decorate(QBarSeries* series, int index,bool force = true); - void decorate(QStackedBarSeries* series, int index,bool force = true); - void decorate(QPercentBarSeries* series, int index,bool force = true); void decorate(QLineSeries* series, int index,bool force = true); void decorate(QAreaSeries* series, int index,bool force = true); void decorate(QScatterSeries* series, int index,bool force = true); diff --git a/src/scatterseries/scatterchartitem.cpp b/src/scatterseries/scatterchartitem.cpp index d9248da..e3c9fd5 100644 --- a/src/scatterseries/scatterchartitem.cpp +++ b/src/scatterseries/scatterchartitem.cpp @@ -6,18 +6,12 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE - - - - - - ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) : XYChartItem(series,parent), m_series(series), m_items(this), m_shape(QScatterSeries::MarkerShapeRectangle), - m_size(10) + m_size(15) { Q_ASSERT(parent);