##// END OF EJS Templates
White spaces fixes in Theme and animation classes
Marek Rosa -
r948:afb39ce1ff74
parent child
Show More
@@ -1,46 +1,46
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef CHARTANIMATION_H_
21 #ifndef CHARTANIMATION_H_
22 #define CHARTANIMATION_H_
22 #define CHARTANIMATION_H_
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include <QVariantAnimation>
25 #include <QVariantAnimation>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class ChartAnimation: public QVariantAnimation
29 class ChartAnimation: public QVariantAnimation
30 {
30 {
31 public:
31 public:
32 enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation };
32 enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation };
33 ChartAnimation(QObject* parent=0):QVariantAnimation(parent), m_type(MoveDownAnimation){}
33 ChartAnimation(QObject *parent = 0):QVariantAnimation(parent), m_type(MoveDownAnimation){}
34 void setAnimationType(Animation type){
34 void setAnimationType(Animation type){
35 m_type=type;
35 m_type=type;
36 }
36 }
37 protected:
37 protected:
38 Animation m_type;
38 Animation m_type;
39
39
40 };
40 };
41
41
42 QTCOMMERCIALCHART_END_NAMESPACE
42 QTCOMMERCIALCHART_END_NAMESPACE
43
43
44
44
45
45
46 #endif /* AXISITEM_H_ */
46 #endif /* AXISITEM_H_ */
@@ -1,52 +1,52
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef SPLINEANIMATION_P_H_
21 #ifndef SPLINEANIMATION_P_H_
22 #define SPLINEANIMATION_P_H_
22 #define SPLINEANIMATION_P_H_
23 #include "chartanimation_p.h"
23 #include "chartanimation_p.h"
24 #include <QPointF>
24 #include <QPointF>
25
25
26 typedef QPair<QVector<QPointF >, QVector<QPointF > > SplineVector;
26 typedef QPair<QVector<QPointF >, QVector<QPointF > > SplineVector;
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class SplineChartItem;
30 class SplineChartItem;
31
31
32 class SplineAnimation : public ChartAnimation
32 class SplineAnimation : public ChartAnimation
33 {
33 {
34 public:
34 public:
35
35
36 SplineAnimation(SplineChartItem* item);
36 SplineAnimation(SplineChartItem *item);
37 ~SplineAnimation();
37 ~SplineAnimation();
38 void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index);
38 void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, QVector<QPointF> &oldContorlPoints, QVector<QPointF> &newControlPoints, int index);
39
39
40 protected:
40 protected:
41 QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const;
41 QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const;
42 void updateCurrentValue(const QVariant &value);
42 void updateCurrentValue(const QVariant &value);
43
43
44 private:
44 private:
45 SplineVector m_oldSpline;
45 SplineVector m_oldSpline;
46 SplineChartItem *m_item;
46 SplineChartItem *m_item;
47 bool m_dirty;
47 bool m_dirty;
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif
52 #endif
@@ -1,398 +1,398
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charttheme_p.h"
21 #include "charttheme_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qchartview.h"
23 #include "qchartview.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qchartaxis.h"
25 #include "qchartaxis.h"
26 #include <QTime>
26 #include <QTime>
27
27
28 //series
28 //series
29 #include "qbarset.h"
29 #include "qbarset.h"
30 #include "qbarseries.h"
30 #include "qbarseries.h"
31 #include "qstackedbarseries.h"
31 #include "qstackedbarseries.h"
32 #include "qpercentbarseries.h"
32 #include "qpercentbarseries.h"
33 #include "qlineseries.h"
33 #include "qlineseries.h"
34 #include "qareaseries.h"
34 #include "qareaseries.h"
35 #include "qscatterseries.h"
35 #include "qscatterseries.h"
36 #include "qpieseries.h"
36 #include "qpieseries.h"
37 #include "qpieslice.h"
37 #include "qpieslice.h"
38 #include "qsplineseries.h"
38 #include "qsplineseries.h"
39
39
40 //items
40 //items
41 #include "axisitem_p.h"
41 #include "axisitem_p.h"
42 #include "barchartitem_p.h"
42 #include "barchartitem_p.h"
43 #include "stackedbarchartitem_p.h"
43 #include "stackedbarchartitem_p.h"
44 #include "percentbarchartitem_p.h"
44 #include "percentbarchartitem_p.h"
45 #include "linechartitem_p.h"
45 #include "linechartitem_p.h"
46 #include "areachartitem_p.h"
46 #include "areachartitem_p.h"
47 #include "scatterchartitem_p.h"
47 #include "scatterchartitem_p.h"
48 #include "piechartitem_p.h"
48 #include "piechartitem_p.h"
49 #include "splinechartitem_p.h"
49 #include "splinechartitem_p.h"
50
50
51 //themes
51 //themes
52 #include "chartthemesystem_p.h"
52 #include "chartthemesystem_p.h"
53 #include "chartthemelight_p.h"
53 #include "chartthemelight_p.h"
54 #include "chartthemebluecerulean_p.h"
54 #include "chartthemebluecerulean_p.h"
55 #include "chartthemedark_p.h"
55 #include "chartthemedark_p.h"
56 #include "chartthemebrownsand_p.h"
56 #include "chartthemebrownsand_p.h"
57 #include "chartthemebluencs_p.h"
57 #include "chartthemebluencs_p.h"
58 #include "chartthemehighcontrast_p.h"
58 #include "chartthemehighcontrast_p.h"
59 #include "chartthemeblueicy_p.h"
59 #include "chartthemeblueicy_p.h"
60
60
61 QTCOMMERCIALCHART_BEGIN_NAMESPACE
61 QTCOMMERCIALCHART_BEGIN_NAMESPACE
62
62
63 ChartTheme::ChartTheme(QChart::ChartTheme id) :
63 ChartTheme::ChartTheme(QChart::ChartTheme id) :
64 m_masterFont(QFont("arial", 14)),
64 m_masterFont(QFont("arial", 14)),
65 m_labelFont(QFont("arial", 10)),
65 m_labelFont(QFont("arial", 10)),
66 m_titleBrush(QColor(QRgb(0x000000))),
66 m_titleBrush(QColor(QRgb(0x000000))),
67 m_axisLinePen(QPen(QRgb(0x000000))),
67 m_axisLinePen(QPen(QRgb(0x000000))),
68 m_axisLabelBrush(QColor(QRgb(0x000000))),
68 m_axisLabelBrush(QColor(QRgb(0x000000))),
69 m_backgroundShadesPen(Qt::NoPen),
69 m_backgroundShadesPen(Qt::NoPen),
70 m_backgroundShadesBrush(Qt::NoBrush),
70 m_backgroundShadesBrush(Qt::NoBrush),
71 m_backgroundShades(BackgroundShadesNone),
71 m_backgroundShades(BackgroundShadesNone),
72 m_gridLinePen(QPen(QRgb(0x000000))),
72 m_gridLinePen(QPen(QRgb(0x000000))),
73 m_force(false)
73 m_force(false)
74 {
74 {
75 m_id = id;
75 m_id = id;
76 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
76 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
77 }
77 }
78
78
79
79
80 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
80 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
81 {
81 {
82 switch(theme) {
82 switch(theme) {
83 case QChart::ChartThemeLight:
83 case QChart::ChartThemeLight:
84 return new ChartThemeLight();
84 return new ChartThemeLight();
85 case QChart::ChartThemeBlueCerulean:
85 case QChart::ChartThemeBlueCerulean:
86 return new ChartThemeBlueCerulean();
86 return new ChartThemeBlueCerulean();
87 case QChart::ChartThemeDark:
87 case QChart::ChartThemeDark:
88 return new ChartThemeDark();
88 return new ChartThemeDark();
89 case QChart::ChartThemeBrownSand:
89 case QChart::ChartThemeBrownSand:
90 return new ChartThemeBrownSand();
90 return new ChartThemeBrownSand();
91 case QChart::ChartThemeBlueNcs:
91 case QChart::ChartThemeBlueNcs:
92 return new ChartThemeBlueNcs();
92 return new ChartThemeBlueNcs();
93 case QChart::ChartThemeHighContrast:
93 case QChart::ChartThemeHighContrast:
94 return new ChartThemeHighContrast();
94 return new ChartThemeHighContrast();
95 case QChart::ChartThemeBlueIcy:
95 case QChart::ChartThemeBlueIcy:
96 return new ChartThemeBlueIcy();
96 return new ChartThemeBlueIcy();
97 default:
97 default:
98 return new ChartThemeSystem();
98 return new ChartThemeSystem();
99 }
99 }
100 }
100 }
101
101
102 void ChartTheme::decorate(QChart* chart)
102 void ChartTheme::decorate(QChart *chart)
103 {
103 {
104 QBrush brush;
104 QBrush brush;
105
105
106 if(brush == chart->backgroundBrush() || m_force)
106 if(brush == chart->backgroundBrush() || m_force)
107 chart->setBackgroundBrush(m_chartBackgroundGradient);
107 chart->setBackgroundBrush(m_chartBackgroundGradient);
108 chart->setTitleFont(m_masterFont);
108 chart->setTitleFont(m_masterFont);
109 chart->setTitleBrush(m_titleBrush);
109 chart->setTitleBrush(m_titleBrush);
110 }
110 }
111
111
112 void ChartTheme::decorate(QLegend* legend)
112 void ChartTheme::decorate(QLegend *legend)
113 {
113 {
114 QPen pen;
114 QPen pen;
115 QBrush brush;
115 QBrush brush;
116
116
117 if (pen == legend->pen() || m_force){
117 if (pen == legend->pen() || m_force){
118 legend->setPen(Qt::NoPen);
118 legend->setPen(Qt::NoPen);
119 }
119 }
120
120
121
121
122 if (brush == legend->brush() || m_force) {
122 if (brush == legend->brush() || m_force) {
123 legend->setBrush(m_chartBackgroundGradient);
123 legend->setBrush(m_chartBackgroundGradient);
124 }
124 }
125 }
125 }
126
126
127 void ChartTheme::decorate(QAreaSeries* series, int index)
127 void ChartTheme::decorate(QAreaSeries *series, int index)
128 {
128 {
129 QPen pen;
129 QPen pen;
130 QBrush brush;
130 QBrush brush;
131
131
132 if (pen == series->pen() || m_force){
132 if (pen == series->pen() || m_force){
133 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
133 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
134 pen.setWidthF(2);
134 pen.setWidthF(2);
135 series->setPen(pen);
135 series->setPen(pen);
136 }
136 }
137
137
138 if (brush == series->brush() || m_force) {
138 if (brush == series->brush() || m_force) {
139 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
139 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
140 series->setBrush(brush);
140 series->setBrush(brush);
141 }
141 }
142 }
142 }
143
143
144
144
145 void ChartTheme::decorate(QLineSeries* series,int index)
145 void ChartTheme::decorate(QLineSeries *series,int index)
146 {
146 {
147 QPen pen;
147 QPen pen;
148 if(pen == series->pen() || m_force ){
148 if(pen == series->pen() || m_force ){
149 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
149 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
150 pen.setWidthF(2);
150 pen.setWidthF(2);
151 series->setPen(pen);
151 series->setPen(pen);
152 }
152 }
153 }
153 }
154
154
155 void ChartTheme::decorate(QBarSeries* series, int index)
155 void ChartTheme::decorate(QBarSeries *series, int index)
156 {
156 {
157 QBrush brush;
157 QBrush brush;
158 QPen pen;
158 QPen pen;
159 QList<QBarSet*> sets = series->barSets();
159 QList<QBarSet *> sets = series->barSets();
160
160
161 qreal takeAtPos = 0.5;
161 qreal takeAtPos = 0.5;
162 qreal step = 0.2;
162 qreal step = 0.2;
163 if (sets.count() > 1 ) {
163 if (sets.count() > 1 ) {
164 step = 1.0 / (qreal) sets.count();
164 step = 1.0 / (qreal) sets.count();
165 if (sets.count() % m_seriesGradients.count())
165 if (sets.count() % m_seriesGradients.count())
166 step *= m_seriesGradients.count();
166 step *= m_seriesGradients.count();
167 else
167 else
168 step *= (m_seriesGradients.count() - 1);
168 step *= (m_seriesGradients.count() - 1);
169 }
169 }
170
170
171 for (int i(0); i < sets.count(); i++) {
171 for (int i(0); i < sets.count(); i++) {
172 int colorIndex = (index + i) % m_seriesGradients.count();
172 int colorIndex = (index + i) % m_seriesGradients.count();
173 if (i > 0 && i % m_seriesGradients.count() == 0) {
173 if (i > 0 && i % m_seriesGradients.count() == 0) {
174 // There is no dedicated base color for each sets, generate more colors
174 // There is no dedicated base color for each sets, generate more colors
175 takeAtPos += step;
175 takeAtPos += step;
176 if (takeAtPos == 1.0)
176 if (takeAtPos == 1.0)
177 takeAtPos += step;
177 takeAtPos += step;
178 takeAtPos -= (int) takeAtPos;
178 takeAtPos -= (int) takeAtPos;
179 }
179 }
180 if (brush == sets.at(i)->brush() || m_force )
180 if (brush == sets.at(i)->brush() || m_force )
181 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
181 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
182
182
183 // Pick label color from the opposite end of the gradient.
183 // Pick label color from the opposite end of the gradient.
184 // 0.3 as a boundary seems to work well.
184 // 0.3 as a boundary seems to work well.
185 if (takeAtPos < 0.3)
185 if (takeAtPos < 0.3)
186 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
186 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
187 else
187 else
188 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
188 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
189
189
190 if (pen == sets.at(i)->pen() || m_force) {
190 if (pen == sets.at(i)->pen() || m_force) {
191 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
191 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
192 sets.at(i)->setPen(c);
192 sets.at(i)->setPen(c);
193 }
193 }
194 }
194 }
195 }
195 }
196
196
197 void ChartTheme::decorate(QScatterSeries* series, int index)
197 void ChartTheme::decorate(QScatterSeries *series, int index)
198 {
198 {
199 QPen pen;
199 QPen pen;
200 QBrush brush;
200 QBrush brush;
201
201
202 if (pen == series->pen() || m_force) {
202 if (pen == series->pen() || m_force) {
203 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
203 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
204 pen.setWidthF(2);
204 pen.setWidthF(2);
205 series->setPen(pen);
205 series->setPen(pen);
206 }
206 }
207
207
208 if (brush == series->brush() || m_force) {
208 if (brush == series->brush() || m_force) {
209 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
209 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
210 series->setBrush(brush);
210 series->setBrush(brush);
211 }
211 }
212 }
212 }
213
213
214 void ChartTheme::decorate(QPieSeries* series, int index)
214 void ChartTheme::decorate(QPieSeries *series, int index)
215 {
215 {
216
216
217 for (int i(0); i < series->slices().count(); i++) {
217 for (int i(0); i < series->slices().count(); i++) {
218
218
219 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
219 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
220
220
221 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
221 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
222 qreal pos = (qreal) (i + 1) / (qreal) series->count();
222 qreal pos = (qreal) (i + 1) / (qreal) series->count();
223 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
223 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
224
224
225 QPieSlice *s = series->slices().at(i);
225 QPieSlice *s = series->slices().at(i);
226 PieSliceData data = PieSliceData::data(s);
226 PieSliceData data = PieSliceData::data(s);
227
227
228 if (data.m_slicePen.isThemed() || m_force) {
228 if (data.m_slicePen.isThemed() || m_force) {
229 data.m_slicePen = penColor;
229 data.m_slicePen = penColor;
230 data.m_slicePen.setThemed(true);
230 data.m_slicePen.setThemed(true);
231 }
231 }
232
232
233 if (data.m_sliceBrush.isThemed() || m_force) {
233 if (data.m_sliceBrush.isThemed() || m_force) {
234 data.m_sliceBrush = brushColor;
234 data.m_sliceBrush = brushColor;
235 data.m_sliceBrush.setThemed(true);
235 data.m_sliceBrush.setThemed(true);
236 }
236 }
237
237
238 if (data.m_labelPen.isThemed() || m_force) {
238 if (data.m_labelPen.isThemed() || m_force) {
239 data.m_labelPen = QPen(m_titleBrush.color());
239 data.m_labelPen = QPen(m_titleBrush.color());
240 data.m_labelPen.setThemed(true);
240 data.m_labelPen.setThemed(true);
241 }
241 }
242
242
243 if (data.m_labelFont.isThemed() || m_force) {
243 if (data.m_labelFont.isThemed() || m_force) {
244 data.m_labelFont = m_labelFont;
244 data.m_labelFont = m_labelFont;
245 data.m_labelFont.setThemed(true);
245 data.m_labelFont.setThemed(true);
246 }
246 }
247
247
248 if (PieSliceData::data(s) != data) {
248 if (PieSliceData::data(s) != data) {
249 PieSliceData::data(s) = data;
249 PieSliceData::data(s) = data;
250 emit PieSliceData::data(s).emitChangedSignal(s);
250 emit PieSliceData::data(s).emitChangedSignal(s);
251 }
251 }
252 }
252 }
253 }
253 }
254
254
255 void ChartTheme::decorate(QSplineSeries* series, int index)
255 void ChartTheme::decorate(QSplineSeries *series, int index)
256 {
256 {
257 QPen pen;
257 QPen pen;
258 if(pen == series->pen() || m_force){
258 if(pen == series->pen() || m_force){
259 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
259 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
260 pen.setWidthF(2);
260 pen.setWidthF(2);
261 series->setPen(pen);
261 series->setPen(pen);
262 }
262 }
263 }
263 }
264
264
265 void ChartTheme::decorate(QChartAxis* axis,bool axisX)
265 void ChartTheme::decorate(QChartAxis *axis,bool axisX)
266 {
266 {
267 QPen pen;
267 QPen pen;
268 QBrush brush;
268 QBrush brush;
269 QFont font;
269 QFont font;
270
270
271 if (axis->isAxisVisible()) {
271 if (axis->isAxisVisible()) {
272
272
273 if(brush == axis->labelsBrush() || m_force){
273 if(brush == axis->labelsBrush() || m_force){
274 axis->setLabelsBrush(m_axisLabelBrush);
274 axis->setLabelsBrush(m_axisLabelBrush);
275 }
275 }
276 if(pen == axis->labelsPen() || m_force){
276 if(pen == axis->labelsPen() || m_force){
277 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
277 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
278 }
278 }
279
279
280
280
281 if (axis->shadesVisible() || m_force) {
281 if (axis->shadesVisible() || m_force) {
282
282
283 if(brush == axis->shadesBrush() || m_force){
283 if(brush == axis->shadesBrush() || m_force){
284 axis->setShadesBrush(m_backgroundShadesBrush);
284 axis->setShadesBrush(m_backgroundShadesBrush);
285 }
285 }
286
286
287 if(pen == axis->shadesPen() || m_force){
287 if(pen == axis->shadesPen() || m_force){
288 axis->setShadesPen(m_backgroundShadesPen);
288 axis->setShadesPen(m_backgroundShadesPen);
289 }
289 }
290
290
291 if( m_force && (m_backgroundShades == BackgroundShadesBoth
291 if( m_force && (m_backgroundShades == BackgroundShadesBoth
292 || (m_backgroundShades == BackgroundShadesVertical && axisX)
292 || (m_backgroundShades == BackgroundShadesVertical && axisX)
293 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
293 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
294 axis->setShadesVisible(true);
294 axis->setShadesVisible(true);
295
295
296 }
296 }
297 }
297 }
298
298
299 if(pen == axis->axisPen() || m_force){
299 if(pen == axis->axisPen() || m_force){
300 axis->setAxisPen(m_axisLinePen);
300 axis->setAxisPen(m_axisLinePen);
301 }
301 }
302
302
303 if(pen == axis->gridLinePen() || m_force){
303 if(pen == axis->gridLinePen() || m_force){
304 axis->setGridLinePen(m_gridLinePen);
304 axis->setGridLinePen(m_gridLinePen);
305 }
305 }
306
306
307 if(font == axis->labelsFont() || m_force){
307 if(font == axis->labelsFont() || m_force){
308 axis->setLabelsFont(m_labelFont);
308 axis->setLabelsFont(m_labelFont);
309 }
309 }
310 }
310 }
311 }
311 }
312
312
313 void ChartTheme::generateSeriesGradients()
313 void ChartTheme::generateSeriesGradients()
314 {
314 {
315 // Generate gradients in HSV color space
315 // Generate gradients in HSV color space
316 foreach (QColor color, m_seriesColors) {
316 foreach (QColor color, m_seriesColors) {
317 QLinearGradient g;
317 QLinearGradient g;
318 qreal h = color.hsvHueF();
318 qreal h = color.hsvHueF();
319 qreal s = color.hsvSaturationF();
319 qreal s = color.hsvSaturationF();
320
320
321 // TODO: tune the algorithm to give nice results with most base colors defined in
321 // TODO: tune the algorithm to give nice results with most base colors defined in
322 // most themes. The rest of the gradients we can define manually in theme specific
322 // most themes. The rest of the gradients we can define manually in theme specific
323 // implementation.
323 // implementation.
324 QColor start = color;
324 QColor start = color;
325 start.setHsvF(h, 0.0, 1.0);
325 start.setHsvF(h, 0.0, 1.0);
326 g.setColorAt(0.0, start);
326 g.setColorAt(0.0, start);
327
327
328 g.setColorAt(0.5, color);
328 g.setColorAt(0.5, color);
329
329
330 QColor end = color;
330 QColor end = color;
331 end.setHsvF(h, s, 0.25);
331 end.setHsvF(h, s, 0.25);
332 g.setColorAt(1.0, end);
332 g.setColorAt(1.0, end);
333
333
334 m_seriesGradients << g;
334 m_seriesGradients << g;
335 }
335 }
336 }
336 }
337
337
338
338
339 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
339 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
340 {
340 {
341 Q_ASSERT(pos >=0.0 && pos <= 1.0);
341 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
342 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
342 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
343 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
343 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
344 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
344 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
345 QColor c;
345 QColor c;
346 c.setRgbF(r, g, b);
346 c.setRgbF(r, g, b);
347 return c;
347 return c;
348 }
348 }
349
349
350 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
350 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
351 {
351 {
352 Q_ASSERT(pos >=0 && pos <= 1.0);
352 Q_ASSERT(pos >= 0 && pos <= 1.0);
353
353
354 // another possibility:
354 // another possibility:
355 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
355 // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient
356
356
357 QGradientStops stops = gradient.stops();
357 QGradientStops stops = gradient.stops();
358 int count = stops.count();
358 int count = stops.count();
359
359
360 // find previous stop relative to position
360 // find previous stop relative to position
361 QGradientStop prev = stops.first();
361 QGradientStop prev = stops.first();
362 for (int i=0; i<count; i++) {
362 for (int i = 0; i < count; i++) {
363 QGradientStop stop = stops.at(i);
363 QGradientStop stop = stops.at(i);
364 if (pos > stop.first)
364 if (pos > stop.first)
365 prev = stop;
365 prev = stop;
366
366
367 // given position is actually a stop position?
367 // given position is actually a stop position?
368 if (pos == stop.first) {
368 if (pos == stop.first) {
369 //qDebug() << "stop color" << pos;
369 //qDebug() << "stop color" << pos;
370 return stop.second;
370 return stop.second;
371 }
371 }
372 }
372 }
373
373
374 // find next stop relative to position
374 // find next stop relative to position
375 QGradientStop next = stops.last();
375 QGradientStop next = stops.last();
376 for (int i=count-1; i>=0; i--) {
376 for (int i = count - 1; i >= 0; i--) {
377 QGradientStop stop = stops.at(i);
377 QGradientStop stop = stops.at(i);
378 if (pos < stop.first)
378 if (pos < stop.first)
379 next = stop;
379 next = stop;
380 }
380 }
381
381
382 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
382 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
383
383
384 qreal range = next.first - prev.first;
384 qreal range = next.first - prev.first;
385 qreal posDelta = pos - prev.first;
385 qreal posDelta = pos - prev.first;
386 qreal relativePos = posDelta / range;
386 qreal relativePos = posDelta / range;
387
387
388 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
388 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
389
389
390 return colorAt(prev.second, next.second, relativePos);
390 return colorAt(prev.second, next.second, relativePos);
391 }
391 }
392
392
393 void ChartTheme::setForced(bool enabled)
393 void ChartTheme::setForced(bool enabled)
394 {
394 {
395 m_force=enabled;
395 m_force=enabled;
396 }
396 }
397
397
398 QTCOMMERCIALCHART_END_NAMESPACE
398 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,102 +1,102
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef CHARTTHEME_H
21 #ifndef CHARTTHEME_H
22 #define CHARTTHEME_H
22 #define CHARTTHEME_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include <QColor>
26 #include <QColor>
27 #include <QGradientStops>
27 #include <QGradientStops>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class ChartItem;
31 class ChartItem;
32 class QSeries;
32 class QSeries;
33 class LineChartItem;
33 class LineChartItem;
34 class QLineSeries;
34 class QLineSeries;
35 class BarChartItem;
35 class BarChartItem;
36 class QBarSeries;
36 class QBarSeries;
37 class StackedBarChartItem;
37 class StackedBarChartItem;
38 class QStackedBarSeries;
38 class QStackedBarSeries;
39 class QPercentBarSeries;
39 class QPercentBarSeries;
40 class PercentBarChartItem;
40 class PercentBarChartItem;
41 class QScatterSeries;
41 class QScatterSeries;
42 class ScatterChartItem;
42 class ScatterChartItem;
43 class PieChartItem;
43 class PieChartItem;
44 class QPieSeries;
44 class QPieSeries;
45 class SplineChartItem;
45 class SplineChartItem;
46 class QSplineSeries;
46 class QSplineSeries;
47 class AreaChartItem;
47 class AreaChartItem;
48 class QAreaSeries;
48 class QAreaSeries;
49
49
50 class ChartTheme
50 class ChartTheme
51 {
51 {
52 public:
52 public:
53 enum BackgroundShadesMode {
53 enum BackgroundShadesMode {
54 BackgroundShadesNone = 0,
54 BackgroundShadesNone = 0,
55 BackgroundShadesVertical,
55 BackgroundShadesVertical,
56 BackgroundShadesHorizontal,
56 BackgroundShadesHorizontal,
57 BackgroundShadesBoth
57 BackgroundShadesBoth
58 };
58 };
59
59
60 protected:
60 protected:
61 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight);
61 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight);
62 public:
62 public:
63 static ChartTheme* createTheme(QChart::ChartTheme theme);
63 static ChartTheme *createTheme(QChart::ChartTheme theme);
64 QChart::ChartTheme id() const {return m_id;}
64 QChart::ChartTheme id() const {return m_id;}
65 void decorate(QChart* chart);
65 void decorate(QChart *chart);
66 void decorate(QLegend* legend);
66 void decorate(QLegend *legend);
67 void decorate(QBarSeries* series, int index);
67 void decorate(QBarSeries *series, int index);
68 void decorate(QLineSeries* series, int index);
68 void decorate(QLineSeries *series, int index);
69 void decorate(QAreaSeries* series, int index);
69 void decorate(QAreaSeries *series, int index);
70 void decorate(QScatterSeries* series, int index);
70 void decorate(QScatterSeries *series, int index);
71 void decorate(QPieSeries* series, int index);
71 void decorate(QPieSeries *series, int index);
72 void decorate(QSplineSeries* series, int index);
72 void decorate(QSplineSeries *series, int index);
73 void decorate(QChartAxis* axis, bool axisX);
73 void decorate(QChartAxis *axis, bool axisX);
74 void setForced(bool enabled);
74 void setForced(bool enabled);
75 bool isForced() { return m_force; }
75 bool isForced() { return m_force; }
76
76
77 public: // utils
77 public: // utils
78 void generateSeriesGradients();
78 void generateSeriesGradients();
79 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
79 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
80 static QColor colorAt(const QGradient &gradient, qreal pos);
80 static QColor colorAt(const QGradient &gradient, qreal pos);
81
81
82 protected:
82 protected:
83 QChart::ChartTheme m_id;
83 QChart::ChartTheme m_id;
84 QList<QColor> m_seriesColors;
84 QList<QColor> m_seriesColors;
85 QList<QGradient> m_seriesGradients;
85 QList<QGradient> m_seriesGradients;
86 QLinearGradient m_chartBackgroundGradient;
86 QLinearGradient m_chartBackgroundGradient;
87
87
88 QFont m_masterFont;
88 QFont m_masterFont;
89 QFont m_labelFont;
89 QFont m_labelFont;
90 QBrush m_titleBrush;
90 QBrush m_titleBrush;
91 QPen m_axisLinePen;
91 QPen m_axisLinePen;
92 QBrush m_axisLabelBrush;
92 QBrush m_axisLabelBrush;
93 QPen m_backgroundShadesPen;
93 QPen m_backgroundShadesPen;
94 QBrush m_backgroundShadesBrush;
94 QBrush m_backgroundShadesBrush;
95 BackgroundShadesMode m_backgroundShades;
95 BackgroundShadesMode m_backgroundShades;
96 QPen m_gridLinePen;
96 QPen m_gridLinePen;
97 bool m_force;
97 bool m_force;
98 };
98 };
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
101
101
102 #endif // CHARTTHEME_H
102 #endif // CHARTTHEME_H
General Comments 0
You need to be logged in to leave comments. Login now