##// END OF EJS Templates
Modified scientific theme
Tero Ahola -
r523:768ce5aee641
parent child
Show More
@@ -1,353 +1,359
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QTime>
4 #include <QTime>
5
5
6 //series
6 //series
7 #include "qbarset.h"
7 #include "qbarset.h"
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qareaseries.h"
13 #include "qscatterseries.h"
13 #include "qscatterseries.h"
14 #include "qpieseries.h"
14 #include "qpieseries.h"
15 #include "qpieslice.h"
15 #include "qpieslice.h"
16 #include "qsplineseries.h"
16 #include "qsplineseries.h"
17
17
18 //items
18 //items
19 #include "axisitem_p.h"
19 #include "axisitem_p.h"
20 #include "barpresenter_p.h"
20 #include "barpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
21 #include "stackedbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
22 #include "percentbarpresenter_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "scatterchartitem_p.h"
25 #include "scatterchartitem_p.h"
26 #include "piepresenter_p.h"
26 #include "piepresenter_p.h"
27 #include "splinechartitem_p.h"
27 #include "splinechartitem_p.h"
28
28
29 //themes
29 //themes
30 #include "chartthemedefault_p.h"
30 #include "chartthemedefault_p.h"
31 #include "chartthemevanilla_p.h"
31 #include "chartthemevanilla_p.h"
32 #include "chartthemeicy_p.h"
32 #include "chartthemeicy_p.h"
33 #include "chartthemegrayscale_p.h"
33 #include "chartthemegrayscale_p.h"
34 #include "chartthemescientific_p.h"
34 #include "chartthemescientific_p.h"
35
35
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 ChartTheme::ChartTheme(QChart::ChartTheme id)
39 ChartTheme::ChartTheme(QChart::ChartTheme id)
40 {
40 {
41 m_id = id;
41 m_id = id;
42 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
42 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
43 }
43 }
44
44
45
45
46 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
46 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
47 {
47 {
48 switch(theme) {
48 switch(theme) {
49 case QChart::ChartThemeVanilla:
49 case QChart::ChartThemeVanilla:
50 return new ChartThemeVanilla();
50 return new ChartThemeVanilla();
51 case QChart::ChartThemeIcy:
51 case QChart::ChartThemeIcy:
52 return new ChartThemeIcy();
52 return new ChartThemeIcy();
53 case QChart::ChartThemeGrayscale:
53 case QChart::ChartThemeGrayscale:
54 return new ChartThemeGrayscale();
54 return new ChartThemeGrayscale();
55 case QChart::ChartThemeScientific:
55 case QChart::ChartThemeScientific:
56 return new ChartThemeScientific();
56 return new ChartThemeScientific();
57 default:
57 default:
58 return new ChartThemeDefault();
58 return new ChartThemeDefault();
59 }
59 }
60 }
60 }
61
61
62 void ChartTheme::decorate(QChart* chart)
62 void ChartTheme::decorate(QChart* chart)
63 {
63 {
64 chart->setChartBackgroundBrush(m_backgroundGradient);
64 chart->setChartBackgroundBrush(m_backgroundGradient);
65 }
65 }
66 //TODO helper to by removed later
66 //TODO helper to by removed later
67 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
67 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
68 {
68 {
69 switch(series->type())
69 switch(series->type())
70 {
70 {
71 case QSeries::SeriesTypeLine: {
71 case QSeries::SeriesTypeLine: {
72 QLineSeries* s = static_cast<QLineSeries*>(series);
72 QLineSeries* s = static_cast<QLineSeries*>(series);
73 LineChartItem* i = static_cast<LineChartItem*>(item);
73 LineChartItem* i = static_cast<LineChartItem*>(item);
74 decorate(i,s,count);
74 decorate(i,s,count);
75 break;
75 break;
76 }
76 }
77 case QSeries::SeriesTypeArea: {
77 case QSeries::SeriesTypeArea: {
78 QAreaSeries* s = static_cast<QAreaSeries*>(series);
78 QAreaSeries* s = static_cast<QAreaSeries*>(series);
79 AreaChartItem* i = static_cast<AreaChartItem*>(item);
79 AreaChartItem* i = static_cast<AreaChartItem*>(item);
80 decorate(i,s,count);
80 decorate(i,s,count);
81 break;
81 break;
82 }
82 }
83 case QSeries::SeriesTypeBar: {
83 case QSeries::SeriesTypeBar: {
84 QBarSeries* b = static_cast<QBarSeries*>(series);
84 QBarSeries* b = static_cast<QBarSeries*>(series);
85 BarPresenter* i = static_cast<BarPresenter*>(item);
85 BarPresenter* i = static_cast<BarPresenter*>(item);
86 decorate(i,b,count);
86 decorate(i,b,count);
87 break;
87 break;
88 }
88 }
89 case QSeries::SeriesTypeStackedBar: {
89 case QSeries::SeriesTypeStackedBar: {
90 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
90 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
91 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
91 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
92 decorate(i,s,count);
92 decorate(i,s,count);
93 break;
93 break;
94 }
94 }
95 case QSeries::SeriesTypePercentBar: {
95 case QSeries::SeriesTypePercentBar: {
96 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
96 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
97 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
97 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
98 decorate(i,s,count);
98 decorate(i,s,count);
99 break;
99 break;
100 }
100 }
101 case QSeries::SeriesTypeScatter: {
101 case QSeries::SeriesTypeScatter: {
102 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
102 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
103 Q_ASSERT(s);
103 Q_ASSERT(s);
104 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
104 ScatterChartItem* i = static_cast<ScatterChartItem*>(item);
105 Q_ASSERT(i);
105 Q_ASSERT(i);
106 decorate(i, s, count);
106 decorate(i, s, count);
107 break;
107 break;
108 }
108 }
109 case QSeries::SeriesTypePie: {
109 case QSeries::SeriesTypePie: {
110 QPieSeries* s = static_cast<QPieSeries*>(series);
110 QPieSeries* s = static_cast<QPieSeries*>(series);
111 PiePresenter* i = static_cast<PiePresenter*>(item);
111 PiePresenter* i = static_cast<PiePresenter*>(item);
112 decorate(i,s,count);
112 decorate(i,s,count);
113 break;
113 break;
114 }
114 }
115 default:
115 default:
116 qDebug()<<"Wrong item to be decorated by theme";
116 qDebug()<<"Wrong item to be decorated by theme";
117 break;
117 break;
118 }
118 }
119
119
120 }
120 }
121
121
122 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
122 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
123 {
123 {
124 QPen pen;
124 QPen pen;
125 QBrush brush;
125 QBrush brush;
126
126
127 if (pen != series->pen()){
127 if (pen != series->pen()){
128 item->setPen(series->pen());
128 item->setPen(series->pen());
129 } else {
129 } else {
130 pen.setColor(colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1.0));
130 pen.setColor(colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1.0));
131 pen.setWidthF(2);
131 pen.setWidthF(2);
132 item->setPen(pen);
132 item->setPen(pen);
133 }
133 }
134
134
135 if (brush != series->brush()) {
135 if (brush != series->brush()) {
136 item->setBrush(series->brush());
136 item->setBrush(series->brush());
137 } else {
137 } else {
138 QBrush brush(m_seriesColors.at(count % m_seriesColors.size()));
138 QBrush brush(m_seriesColors.at(count % m_seriesColors.size()));
139 item->setBrush(brush);
139 item->setBrush(brush);
140 }
140 }
141 }
141 }
142
142
143
143
144 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
144 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
145 {
145 {
146 QPen pen;
146 QPen pen;
147 if(pen != series->pen()){
147 if(pen != series->pen()){
148 item->setLinePen(series->pen());
148 item->setLinePen(series->pen());
149 return;
149 return;
150 }
150 }
151 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
151 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
152 pen.setWidthF(2);
152 pen.setWidthF(2);
153 item->setLinePen(pen);
153 item->setLinePen(pen);
154 }
154 }
155
155
156 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
156 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
157 {
157 {
158 QList<QBarSet*> sets = series->barSets();
158 QList<QBarSet*> sets = series->barSets();
159 for (int i=0; i<sets.count(); i++) {
159 for (int i=0; i<sets.count(); i++) {
160 qreal pos = (qreal) i / (qreal) sets.count();
160 qreal pos = 0.5;
161 if (sets.count() > 1)
162 pos = (qreal) i / (qreal) (sets.count() - 1);
161 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
163 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
162 sets.at(i)->setBrush(QBrush(c));
164 sets.at(i)->setBrush(QBrush(c));
163
165
164 // Pick label color as far as possible from bar color (within gradient).
166 // Pick label color as far as possible from bar color (within gradient).
165 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
167 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
166 // TODO: better picking of label color?
168 // TODO: better picking of label color?
167 if (pos < 0.3) {
169 if (pos < 0.3) {
168 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
170 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
169 } else {
171 } else {
170 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
172 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
171 }
173 }
172 sets.at(i)->setFloatingValuePen(QPen(c));
174 sets.at(i)->setFloatingValuePen(QPen(c));
173 }
175 }
174 }
176 }
175
177
176 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
178 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
177 {
179 {
178 QList<QBarSet*> sets = series->barSets();
180 QList<QBarSet*> sets = series->barSets();
179 for (int i=0; i<sets.count(); i++) {
181 for (int i=0; i<sets.count(); i++) {
180 qreal pos = (qreal) i / (qreal) sets.count();
182 qreal pos = 0.5;
183 if (sets.count() > 1)
184 pos = (qreal) i / (qreal) (sets.count() - 1);
181 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
185 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
182 sets.at(i)->setBrush(QBrush(c));
186 sets.at(i)->setBrush(QBrush(c));
183
187
184 if (pos < 0.3) {
188 if (pos < 0.3) {
185 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
189 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
186 } else {
190 } else {
187 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
191 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
188 }
192 }
189 sets.at(i)->setFloatingValuePen(QPen(c));
193 sets.at(i)->setFloatingValuePen(QPen(c));
190 }
194 }
191 }
195 }
192
196
193 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
197 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
194 {
198 {
195 QList<QBarSet*> sets = series->barSets();
199 QList<QBarSet*> sets = series->barSets();
196 for (int i=0; i<sets.count(); i++) {
200 for (int i=0; i<sets.count(); i++) {
197 qreal pos = (qreal) i / (qreal) sets.count();
201 qreal pos = 0.5;
202 if (sets.count() > 1)
203 pos = (qreal) i / (qreal) (sets.count() - 1);
198 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
204 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
199 sets.at(i)->setBrush(QBrush(c));
205 sets.at(i)->setBrush(QBrush(c));
200
206
201 if (pos < 0.3) {
207 if (pos < 0.3) {
202 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
208 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
203 } else {
209 } else {
204 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
210 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
205 }
211 }
206 sets.at(i)->setFloatingValuePen(QPen(c));
212 sets.at(i)->setFloatingValuePen(QPen(c));
207 }
213 }
208 }
214 }
209
215
210 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
216 void ChartTheme::decorate(ScatterChartItem* item, QScatterSeries* series, int count)
211 {
217 {
212 Q_ASSERT(item);
218 Q_ASSERT(item);
213 Q_ASSERT(series);
219 Q_ASSERT(series);
214
220
215 // Use a base color for brush
221 // Use a base color for brush
216 item->setBrush(m_seriesColors.at(count % m_seriesColors.size()));
222 item->setBrush(m_seriesColors.at(count % m_seriesColors.size()));
217
223
218 // Take pen near from gradient start, effectively using a lighter color for outline
224 // Take pen near from gradient start, effectively using a lighter color for outline
219 QPen pen(QBrush(Qt::SolidPattern), 3);
225 QPen pen(QBrush(Qt::SolidPattern), 3);
220 pen.setColor(colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1.0));
226 pen.setColor(colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1.0));
221 item->setPen(pen);
227 item->setPen(pen);
222 }
228 }
223
229
224 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
230 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int count)
225 {
231 {
226 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
232 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
227 for (int i(0); i < series->slices().count(); i++) {
233 for (int i(0); i < series->slices().count(); i++) {
228 qreal pos = (qreal) i / (qreal) series->count();
234 qreal pos = (qreal) i / (qreal) series->count();
229 QColor penColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0.1);
235 QColor penColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0.1);
230 series->slices().at(i)->setSlicePen(penColor);
236 series->slices().at(i)->setSlicePen(penColor);
231 QColor brushColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
237 QColor brushColor = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
232 series->slices().at(i)->setSliceBrush(brushColor);
238 series->slices().at(i)->setSliceBrush(brushColor);
233 }
239 }
234 }
240 }
235
241
236
242
237 void ChartTheme::decorate(QChartAxis* axis, AxisItem* item)
243 void ChartTheme::decorate(QChartAxis* axis, AxisItem* item)
238 {
244 {
239 //TODO: dummy defults for now
245 //TODO: dummy defults for now
240 axis->setLabelsBrush(Qt::black);
246 axis->setLabelsBrush(Qt::black);
241 axis->setLabelsPen(Qt::NoPen);
247 axis->setLabelsPen(Qt::NoPen);
242 axis->setShadesPen(Qt::NoPen);
248 axis->setShadesPen(Qt::NoPen);
243 axis->setShadesOpacity(0.5);
249 axis->setShadesOpacity(0.5);
244 }
250 }
245
251
246 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
252 void ChartTheme::decorate(SplineChartItem* item, QSplineSeries* series, int count)
247 {
253 {
248 Q_ASSERT(item);
254 Q_ASSERT(item);
249 Q_ASSERT(series);
255 Q_ASSERT(series);
250
256
251 QPen pen;
257 QPen pen;
252
258
253 if(pen != series->pen()){
259 if(pen != series->pen()){
254 item->setLinePen(series->pen());
260 item->setLinePen(series->pen());
255 }else{
261 }else{
256 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
262 pen.setColor(m_seriesColors.at(count%m_seriesColors.size()));
257 pen.setWidthF(series->pen().widthF());
263 pen.setWidthF(series->pen().widthF());
258 item->setLinePen(series->pen());
264 item->setLinePen(series->pen());
259 }
265 }
260
266
261 // QColor color = m_seriesColors.at(count % m_seriesColors.size());
267 // QColor color = m_seriesColors.at(count % m_seriesColors.size());
262 // TODO: define alpha in the theme? or in the series?
268 // TODO: define alpha in the theme? or in the series?
263 //color.setAlpha(120);
269 //color.setAlpha(120);
264
270
265 // QBrush brush(color, Qt::SolidPattern);
271 // QBrush brush(color, Qt::SolidPattern);
266 // presenter->m_markerBrush = brush;
272 // presenter->m_markerBrush = brush;
267
273
268 // QPen pen(brush, 3);
274 // QPen pen(brush, 3);
269 // pen.setColor(color);
275 // pen.setColor(color);
270 // presenter->m_markerPen = pen;
276 // presenter->m_markerPen = pen;
271 }
277 }
272
278
273 void ChartTheme::generateSeriesGradients()
279 void ChartTheme::generateSeriesGradients()
274 {
280 {
275 // Generate gradients in HSV color space
281 // Generate gradients in HSV color space
276 foreach (QColor color, m_seriesColors) {
282 foreach (QColor color, m_seriesColors) {
277 QLinearGradient g;
283 QLinearGradient g;
278 qreal h = color.hsvHueF();
284 qreal h = color.hsvHueF();
279 qreal s = color.hsvSaturationF();
285 qreal s = color.hsvSaturationF();
280
286
281 // TODO: tune the algorithm to give nice results with most base colors defined in
287 // TODO: tune the algorithm to give nice results with most base colors defined in
282 // most themes. The rest of the gradients we can define manually in theme specific
288 // most themes. The rest of the gradients we can define manually in theme specific
283 // implementation.
289 // implementation.
284 QColor start = color;
290 QColor start = color;
285 start.setHsvF(h, 0.05, 0.95);
291 start.setHsvF(h, 0.05, 0.95);
286 g.setColorAt(0.0, start);
292 g.setColorAt(0.0, start);
287
293
288 g.setColorAt(0.5, color);
294 g.setColorAt(0.5, color);
289
295
290 QColor end = color;
296 QColor end = color;
291 end.setHsvF(h, s, 0.25);
297 end.setHsvF(h, s, 0.25);
292 g.setColorAt(1.0, end);
298 g.setColorAt(1.0, end);
293
299
294 m_seriesGradients << g;
300 m_seriesGradients << g;
295 }
301 }
296 }
302 }
297
303
298
304
299 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
305 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
300 {
306 {
301 Q_ASSERT(pos >=0.0 && pos <= 1.0);
307 Q_ASSERT(pos >=0.0 && pos <= 1.0);
302 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
308 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
303 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
309 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
304 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
310 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
305 QColor c;
311 QColor c;
306 c.setRgbF(r, g, b);
312 c.setRgbF(r, g, b);
307 return c;
313 return c;
308 }
314 }
309
315
310 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
316 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
311 {
317 {
312 Q_ASSERT(pos >=0 && pos <= 1.0);
318 Q_ASSERT(pos >=0 && pos <= 1.0);
313
319
314 // another possibility:
320 // another possibility:
315 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
321 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
316
322
317 QGradientStops stops = gradient.stops();
323 QGradientStops stops = gradient.stops();
318 int count = stops.count();
324 int count = stops.count();
319
325
320 // find previous stop relative to position
326 // find previous stop relative to position
321 QGradientStop prev = stops.first();
327 QGradientStop prev = stops.first();
322 for (int i=0; i<count; i++) {
328 for (int i=0; i<count; i++) {
323 QGradientStop stop = stops.at(i);
329 QGradientStop stop = stops.at(i);
324 if (pos > stop.first)
330 if (pos > stop.first)
325 prev = stop;
331 prev = stop;
326
332
327 // given position is actually a stop position?
333 // given position is actually a stop position?
328 if (pos == stop.first) {
334 if (pos == stop.first) {
329 //qDebug() << "stop color" << pos;
335 //qDebug() << "stop color" << pos;
330 return stop.second;
336 return stop.second;
331 }
337 }
332 }
338 }
333
339
334 // find next stop relative to position
340 // find next stop relative to position
335 QGradientStop next = stops.last();
341 QGradientStop next = stops.last();
336 for (int i=count-1; i>=0; i--) {
342 for (int i=count-1; i>=0; i--) {
337 QGradientStop stop = stops.at(i);
343 QGradientStop stop = stops.at(i);
338 if (pos < stop.first)
344 if (pos < stop.first)
339 next = stop;
345 next = stop;
340 }
346 }
341
347
342 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
348 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
343
349
344 qreal range = next.first - prev.first;
350 qreal range = next.first - prev.first;
345 qreal posDelta = pos - prev.first;
351 qreal posDelta = pos - prev.first;
346 qreal relativePos = posDelta / range;
352 qreal relativePos = posDelta / range;
347
353
348 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
354 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
349
355
350 return colorAt(prev.second, next.second, relativePos);
356 return colorAt(prev.second, next.second, relativePos);
351 }
357 }
352
358
353 QTCOMMERCIALCHART_END_NAMESPACE
359 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,38 +1,25
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 class ChartThemeScientific: public ChartTheme
5 class ChartThemeScientific: public ChartTheme
6 {
6 {
7 public:
7 public:
8 ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific)
8 ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific)
9 {
9 {
10 m_seriesColors << QRgb(0xFF000000);
11 m_seriesColors << QRgb(0xFFFFAD00);
10 m_seriesColors << QRgb(0xFFFFAD00);
12 m_seriesColors << QRgb(0xFF596A75);
11 m_seriesColors << QRgb(0xFF596A75);
12 m_seriesColors << QRgb(0xFF202020);
13 m_seriesColors << QRgb(0xFF474747);
13 m_seriesColors << QRgb(0xFF474747);
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(0xffafafaf));
18 backgroundGradient.setColorAt(0.0, QRgb(0xffafafaf));
32 backgroundGradient.setColorAt(1.0, QRgb(0xffafafaf));
19 backgroundGradient.setColorAt(1.0, QRgb(0xffafafaf));
33 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
20 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
34 m_backgroundGradient = backgroundGradient;
21 m_backgroundGradient = backgroundGradient;
35 }
22 }
36 };
23 };
37
24
38 QTCOMMERCIALCHART_END_NAMESPACE
25 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now