##// END OF EJS Templates
Theme gradients now generated from a single base color
Tero Ahola -
r507:cd18b203dd88
parent child
Show More
@@ -196,31 +196,12 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int co
196
196
197 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
197 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
198 {
198 {
199 // create a list of slice colors based on current theme
199 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
200 int i = 0;
200 for (int i(0); i < series->slices().count(); i++) {
201 QList<QColor> colors;
201 qreal pos = (qreal) i / (qreal) series->count();
202 bool toggle = false;
203 while (colors.count() < series->count()) {
204
205 qreal pos = (qreal) colors.count() / (qreal) series->count();
206 if (toggle)
207 pos += 0.5;
208 toggle = !toggle;
209 if (pos > 1.0)
210 pos = pos - 1.0;
211
212 //qreal pos = (qreal) (qrand() % series->count()) / (qreal) series->count();
213
214 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
202 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
215
203 series->slices().at(i)->setSlicePen(c);
216 colors << c;
204 series->slices().at(i)->setSliceBrush(c);
217 }
218
219 // finally update colors
220 foreach (QPieSlice* s, series->slices()) {
221 QColor c = colors.takeFirst();
222 s->setSlicePen(c);
223 s->setSliceBrush(c);
224 }
205 }
225 }
206 }
226
207
@@ -261,6 +242,32 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int coun
261 // presenter->m_markerPen = pen;
242 // presenter->m_markerPen = pen;
262 }
243 }
263
244
245 void ChartTheme::generateSeriesGradients()
246 {
247 // Generate gradients in HSV color space
248 foreach (QColor color, m_seriesColors) {
249 QLinearGradient g;
250 qreal h = color.hsvHueF();
251 qreal s = color.hsvSaturationF();
252
253 // TODO: tune the algorithm to give nice results with most base colors defined in
254 // most themes. The rest of the gradients we can define manually in theme specific
255 // implementation.
256 QColor start = color;
257 start.setHsvF(h, 0.05, 0.95);
258 g.setColorAt(0.0, start);
259
260 g.setColorAt(0.5, color);
261
262 QColor end = color;
263 end.setHsvF(h, s, 0.25);
264 g.setColorAt(1.0, end);
265
266 m_seriesGradients << g;
267 }
268 }
269
270
264 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
271 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
265 {
272 {
266 Q_ASSERT(pos >=0.0 && pos <= 1.0);
273 Q_ASSERT(pos >=0.0 && pos <= 1.0);
@@ -47,6 +47,7 public:
47 void decorate(SplineChartItem* presenter, QSplineSeries* series, int count);
47 void decorate(SplineChartItem* presenter, QSplineSeries* series, int count);
48
48
49 public: // utils
49 public: // utils
50 void generateSeriesGradients();
50 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
51 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
51 static QColor colorAt(const QGradient &gradient, qreal pos);
52 static QColor colorAt(const QGradient &gradient, qreal pos);
52
53
@@ -55,6 +56,14 protected:
55 QList<QColor> m_seriesColors;
56 QList<QColor> m_seriesColors;
56 QList<QGradient> m_seriesGradients;
57 QList<QGradient> m_seriesGradients;
57 QLinearGradient m_backgroundGradient;
58 QLinearGradient m_backgroundGradient;
59
60 // TODO: Add something like the following to themes:
61 // QPen axisLinePen;
62 // QPen backgroundHorizontalGridPen;
63 // QPen backgroundVerticalGridPen;
64 // // FillAll, FillEverySecondRow, FillEverySecondColumn, FillEverySecondRowAndColumn, FillNone
65 // int backgroundType;
66 // QFont masterFont;
58 };
67 };
59
68
60 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -7,13 +7,11 class ChartThemeDefault: public ChartTheme
7 public:
7 public:
8 ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault)
8 ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault)
9 {
9 {
10 m_seriesColors << QRgb(0xff000000);
10 // TODO: replace this dummy theme with an actual theme
11 m_seriesColors << QRgb(0xff707070);
11 m_seriesColors << QRgb(0xff707070);
12 m_seriesColors << QRgb(0xffA0A0A0);
12
13
13 QLinearGradient g1;
14 generateSeriesGradients();
14 g1.setColorAt(0.0, m_seriesColors.at(0));
15 g1.setColorAt(1.0, m_seriesColors.at(1));
16 m_seriesGradients << g1;
17
15
18 QLinearGradient backgroundGradient;
16 QLinearGradient backgroundGradient;
19 backgroundGradient.setColorAt(0.0, QRgb(0xffffffff));
17 backgroundGradient.setColorAt(0.0, QRgb(0xffffffff));
@@ -12,20 +12,7 public:
12 m_seriesColors << QRgb(0xFFE8FFFC);
12 m_seriesColors << QRgb(0xFFE8FFFC);
13 m_seriesColors << QRgb(0xFFCCC2C2);
13 m_seriesColors << QRgb(0xFFCCC2C2);
14
14
15 QLinearGradient g1;
15 generateSeriesGradients();
16 g1.setColorAt(0.0, m_seriesColors.at(0));
17 g1.setColorAt(1.0, m_seriesColors.at(1));
18 m_seriesGradients << g1;
19
20 QLinearGradient g2;
21 g2.setColorAt(0.0, m_seriesColors.at(1));
22 g2.setColorAt(1.0, m_seriesColors.at(2));
23 m_seriesGradients << g2;
24
25 QLinearGradient g3;
26 g3.setColorAt(0.0, m_seriesColors.at(2));
27 g3.setColorAt(1.0, m_seriesColors.at(3));
28 m_seriesGradients << g3;
29
16
30 QLinearGradient backgroundGradient;
17 QLinearGradient backgroundGradient;
31 backgroundGradient.setColorAt(0.0, QRgb(0xffffffff));
18 backgroundGradient.setColorAt(0.0, QRgb(0xffffffff));
@@ -12,20 +12,7 public:
12 m_seriesColors << QRgb(0xFF3DADD9);
12 m_seriesColors << QRgb(0xFF3DADD9);
13 m_seriesColors << QRgb(0xFF62C3D9);
13 m_seriesColors << QRgb(0xFF62C3D9);
14
14
15 QLinearGradient g1;
15 generateSeriesGradients();
16 g1.setColorAt(0.0, m_seriesColors.at(0));
17 g1.setColorAt(1.0, m_seriesColors.at(1));
18 m_seriesGradients << g1;
19
20 QLinearGradient g2;
21 g2.setColorAt(0.0, m_seriesColors.at(1));
22 g2.setColorAt(1.0, m_seriesColors.at(2));
23 m_seriesGradients << g2;
24
25 QLinearGradient g3;
26 g3.setColorAt(0.0, m_seriesColors.at(2));
27 g3.setColorAt(1.0, m_seriesColors.at(3));
28 m_seriesGradients << g3;
29
16
30 QLinearGradient backgroundGradient;
17 QLinearGradient backgroundGradient;
31 backgroundGradient.setColorAt(0.0, QRgb(0xffBDE3F2));
18 backgroundGradient.setColorAt(0.0, QRgb(0xffBDE3F2));
@@ -13,25 +13,7 public:
13 m_seriesColors << QColor(210, 210, 52);
13 m_seriesColors << QColor(210, 210, 52);
14 m_seriesColors << QColor(136, 114, 58);
14 m_seriesColors << QColor(136, 114, 58);
15
15
16 QLinearGradient g1;
16 generateSeriesGradients();
17 g1.setColorAt(0.0, m_seriesColors.at(0));
18 g1.setColorAt(1.0, m_seriesColors.at(1));
19 m_seriesGradients << g1;
20
21 QLinearGradient g2;
22 g2.setColorAt(0.0, m_seriesColors.at(1));
23 g2.setColorAt(1.0, m_seriesColors.at(2));
24 m_seriesGradients << g2;
25
26 QLinearGradient g3;
27 g3.setColorAt(0.0, m_seriesColors.at(2));
28 g3.setColorAt(1.0, m_seriesColors.at(3));
29 m_seriesGradients << g3;
30
31 QLinearGradient g4;
32 g4.setColorAt(0.0, m_seriesColors.at(3));
33 g4.setColorAt(1.0, m_seriesColors.at(4));
34 m_seriesGradients << g4;
35
17
36 QLinearGradient backgroundGradient;
18 QLinearGradient backgroundGradient;
37 backgroundGradient.setColorAt(0.0, QRgb(0xff9d844d));
19 backgroundGradient.setColorAt(0.0, QRgb(0xff9d844d));
General Comments 0
You need to be logged in to leave comments. Login now