##// END OF EJS Templates
Use light outline color instead of dark for bar, area and scatter
Tero Ahola -
r653:f4e416c6727f
parent child
Show More
@@ -11,6 +11,8 Bar::Bar(QString category, QGraphicsItem *parent)
11 mYpos(0),
11 mYpos(0),
12 mWidth(0),
12 mWidth(0),
13 mHeight(0),
13 mHeight(0),
14 mBrush(QBrush()),
15 mPen(QPen()),
14 mCategory(category)
16 mCategory(category)
15 {
17 {
16 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
18 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
@@ -54,6 +56,7 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg
54 if (0 == mHeight) {
56 if (0 == mHeight) {
55 return;
57 return;
56 }
58 }
59 painter->setPen(mPen);
57 painter->setBrush(mBrush);
60 painter->setBrush(mBrush);
58
61
59 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
62 // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1.
@@ -48,6 +48,7 void PercentBarPresenter::layoutChanged()
48
48
49 // TODO: width settable per bar?
49 // TODO: width settable per bar?
50 bar->resize(mBarWidth, barHeight);
50 bar->resize(mBarWidth, barHeight);
51 bar->setPen(mSeries->barsetAt(set)->pen());
51 bar->setBrush(mSeries->barsetAt(set)->brush());
52 bar->setBrush(mSeries->barsetAt(set)->brush());
52 bar->setPos(xPos, yPos-barHeight);
53 bar->setPos(xPos, yPos-barHeight);
53 itemIndex++;
54 itemIndex++;
@@ -122,7 +122,7 void ChartTheme::decorate(QAreaSeries* series, int index,bool force)
122 QBrush brush;
122 QBrush brush;
123
123
124 if (pen == series->pen() || force){
124 if (pen == series->pen() || force){
125 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
125 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
126 pen.setWidthF(2);
126 pen.setWidthF(2);
127 series->setPen(pen);
127 series->setPen(pen);
128 }
128 }
@@ -144,90 +144,43 void ChartTheme::decorate(QLineSeries* series,int index,bool force)
144 }
144 }
145 }
145 }
146
146
147 void ChartTheme::decorate(QBarSeries* series,int index,bool force)
147 void ChartTheme::decorate(QBarSeries* series, int index, bool force)
148 {
148 {
149 QBrush brush;
149 QBrush brush;
150 QPen pen;
150 QList<QBarSet*> sets = series->barSets();
151 QList<QBarSet*> sets = series->barSets();
151
152
152 for (int i=0; i<sets.count(); i++) {
153 for (int i(0); i < sets.count(); i++) {
153 qreal pos = 0.5;
154 qreal pos = 0.5;
154 if (sets.count() > 1)
155 if (sets.count() > 1)
155 pos = (qreal) i / (qreal) (sets.count() - 1);
156 pos = (qreal) i / (qreal) (sets.count() - 1);
156
157
157 if(brush == sets.at(i)->brush() || force ){
158 if (brush == sets.at(i)->brush() || force ) {
158 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
159 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
159 sets.at(i)->setBrush(QBrush(c));
160 sets.at(i)->setBrush(QBrush(c));
160 }
161 // Pick label color as far as possible from bar color (within gradient).
162 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
163 // TODO: better picking of label color?
164 QColor c;
165
166 if (pos < 0.3) {
167 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
168 } else {
169 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0);
170 }
171 sets.at(i)->setFloatingValuePen(QPen(c));
172
173 }
174 }
175
176 void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force)
177 {
178 QBrush brush;
179 QList<QBarSet*> sets = series->barSets();
180
181 for (int i=0; i<sets.count(); i++) {
182 qreal pos = 0.5;
183 if (sets.count() > 1)
184 pos = (qreal) i / (qreal) (sets.count() - 1);
185 if(brush == sets.at(i)->brush() || force){
186 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
187 sets.at(i)->setBrush(QBrush(c));
188 }
189 QColor c;
190 if (pos < 0.3) {
191 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
192 } else {
193 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0);
194 }
161 }
195 sets.at(i)->setFloatingValuePen(QPen(c));
196 }
197 }
198
162
199 void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force)
163 // Pick label color from the opposite end of the gradient.
200 {
164 // 0.3 as a boundary seems to work well.
201 QBrush brush;
165 if (pos < 0.3)
202 QList<QBarSet*> sets = series->barSets();
166 sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
167 else
168 sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
203
169
204 for (int i=0; i<sets.count(); i++) {
170 if (pen == sets.at(i)->pen() || force) {
205 qreal pos = 0.5;
171 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
206 if (sets.count() > 1)
172 sets.at(i)->setPen(c);
207 pos = (qreal) i / (qreal) (sets.count() - 1);
208
209 if(brush == sets.at(i)->brush() || force){
210 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
211 sets.at(i)->setBrush(QBrush(c));
212 }
213 QColor c;
214 if (pos < 0.3) {
215 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
216 } else {
217 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0);
218 }
173 }
219 sets.at(i)->setFloatingValuePen(QPen(c));
220 }
174 }
221 }
175 }
222
176
223 void ChartTheme::decorate(QScatterSeries* series, int index,bool force)
177 void ChartTheme::decorate(QScatterSeries* series, int index,bool force)
224 {
178 {
225
226 QPen pen;
179 QPen pen;
227 QBrush brush;
180 QBrush brush;
228
181
229 if (pen == series->pen() || force) {
182 if (pen == series->pen() || force) {
230 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
183 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
231 pen.setWidthF(2);
184 pen.setWidthF(2);
232 series->setPen(pen);
185 series->setPen(pen);
233 }
186 }
@@ -240,20 +193,20 void ChartTheme::decorate(QScatterSeries* series, int index,bool force)
240
193
241 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
194 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
242 {
195 {
243 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
244
245 QPen pen;
196 QPen pen;
246 QBrush brush;
197 QBrush brush;
247
198
248 for (int i(0); i < series->slices().count(); i++) {
199 for (int i(0); i < series->slices().count(); i++) {
249 qreal pos = (qreal) i / (qreal) series->count();
200 if (pen == series->slices().at(i)->slicePen() || force) {
250 if( pen == series->slices().at(i)->slicePen() || force){
201 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
251 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1);
202 series->slices().at(i)->setSlicePen(penColor);
252 series->slices().at(i)->setSlicePen(penColor);
253 }
203 }
254 if( brush == series->slices().at(i)->sliceBrush() || force){
204
255 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
205 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
256 series->slices().at(i)->setSliceBrush(brushColor);
206 qreal pos = (qreal) i / (qreal) series->count();
207 if (brush == series->slices().at(i)->sliceBrush() || force) {
208 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
209 series->slices().at(i)->setSliceBrush(brushColor);
257 }
210 }
258 }
211 }
259 }
212 }
@@ -44,10 +44,7 public:
44 QChart::ChartTheme id() const {return m_id;}
44 QChart::ChartTheme id() const {return m_id;}
45 void decorate(QChart* chart,bool force = true);
45 void decorate(QChart* chart,bool force = true);
46 void decorate(QLegend* legend,bool force = true);
46 void decorate(QLegend* legend,bool force = true);
47 //void decorate(ChartItem* item, QSeries* series,int index);
48 void decorate(QBarSeries* series, int index,bool force = true);
47 void decorate(QBarSeries* series, int index,bool force = true);
49 void decorate(QStackedBarSeries* series, int index,bool force = true);
50 void decorate(QPercentBarSeries* series, int index,bool force = true);
51 void decorate(QLineSeries* series, int index,bool force = true);
48 void decorate(QLineSeries* series, int index,bool force = true);
52 void decorate(QAreaSeries* series, int index,bool force = true);
49 void decorate(QAreaSeries* series, int index,bool force = true);
53 void decorate(QScatterSeries* series, int index,bool force = true);
50 void decorate(QScatterSeries* series, int index,bool force = true);
@@ -6,18 +6,12
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9
10
11
12
13
14
15 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) :
9 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) :
16 XYChartItem(series,parent),
10 XYChartItem(series,parent),
17 m_series(series),
11 m_series(series),
18 m_items(this),
12 m_items(this),
19 m_shape(QScatterSeries::MarkerShapeRectangle),
13 m_shape(QScatterSeries::MarkerShapeRectangle),
20 m_size(10)
14 m_size(15)
21
15
22 {
16 {
23 Q_ASSERT(parent);
17 Q_ASSERT(parent);
General Comments 0
You need to be logged in to leave comments. Login now