@@ -0,0 +1,36 | |||
|
1 | #include "charttheme_p.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | class ChartThemeLight: public ChartTheme | |
|
6 | { | |
|
7 | public: | |
|
8 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) | |
|
9 | { | |
|
10 | // Series colors | |
|
11 | m_seriesColors << QRgb(0x1c9dde); | |
|
12 | m_seriesColors << QRgb(0xf7a015); | |
|
13 | m_seriesColors << QRgb(0x8dc444); | |
|
14 | generateSeriesGradients(); | |
|
15 | ||
|
16 | // Background | |
|
17 | QLinearGradient backgroundGradient; | |
|
18 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
|
19 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
|
20 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
21 | m_chartBackgroundGradient = backgroundGradient; | |
|
22 | ||
|
23 | // Axes and other | |
|
24 | m_masterFont = QFont(); | |
|
25 | m_axisLinePen = QPen(QRgb(0x424242)); | |
|
26 | m_axisLinePen.setWidth(1); | |
|
27 | m_axisLabelBrush = QBrush(QRgb(0x424242)); | |
|
28 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
|
29 | m_backgroundShadesPen = Qt::NoPen; | |
|
30 | m_backgroundShades = BackgroundShadesNone; | |
|
31 | m_gridLinePen = QPen(QRgb(0x424242)); | |
|
32 | m_gridLinePen.setWidth(1); | |
|
33 | } | |
|
34 | }; | |
|
35 | ||
|
36 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,310 +1,314 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | #include "qchartview.h" | |
|
3 | 4 | #include "qlegend.h" |
|
4 | 5 | #include "qchartaxis.h" |
|
5 | 6 | #include <QTime> |
|
6 | 7 | |
|
7 | 8 | //series |
|
8 | 9 | #include "qbarset.h" |
|
9 | 10 | #include "qbarseries.h" |
|
10 | 11 | #include "qstackedbarseries.h" |
|
11 | 12 | #include "qpercentbarseries.h" |
|
12 | 13 | #include "qlineseries.h" |
|
13 | 14 | #include "qareaseries.h" |
|
14 | 15 | #include "qscatterseries.h" |
|
15 | 16 | #include "qpieseries.h" |
|
16 | 17 | #include "qpieslice.h" |
|
17 | 18 | #include "qsplineseries.h" |
|
18 | 19 | |
|
19 | 20 | //items |
|
20 | 21 | #include "axisitem_p.h" |
|
21 | 22 | #include "barpresenter_p.h" |
|
22 | 23 | #include "stackedbarpresenter_p.h" |
|
23 | 24 | #include "percentbarpresenter_p.h" |
|
24 | 25 | #include "linechartitem_p.h" |
|
25 | 26 | #include "areachartitem_p.h" |
|
26 | 27 | #include "scatterchartitem_p.h" |
|
27 | 28 | #include "piechartitem_p.h" |
|
28 | 29 | #include "splinechartitem_p.h" |
|
29 | 30 | |
|
30 | 31 | //themes |
|
31 | 32 | #include "chartthemedefault_p.h" |
|
32 | 33 | #include "chartthemevanilla_p.h" |
|
33 | 34 | #include "chartthemeicy_p.h" |
|
34 | 35 | #include "chartthemegrayscale_p.h" |
|
35 | 36 | #include "chartthemescientific_p.h" |
|
36 | 37 | #include "chartthemebluecerulean_p.h" |
|
38 | #include "chartthemelight_p.h" | |
|
37 | 39 | |
|
38 | 40 | |
|
39 | 41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 42 | |
|
41 | 43 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
42 | 44 | { |
|
43 | 45 | m_id = id; |
|
44 | 46 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
45 | 47 | } |
|
46 | 48 | |
|
47 | 49 | |
|
48 | 50 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
49 | 51 | { |
|
50 | 52 | switch(theme) { |
|
51 | 53 | case QChart::ChartThemeVanilla: |
|
52 | 54 | return new ChartThemeVanilla(); |
|
53 | 55 | case QChart::ChartThemeIcy: |
|
54 | 56 | return new ChartThemeIcy(); |
|
55 | 57 | case QChart::ChartThemeGrayscale: |
|
56 | 58 | return new ChartThemeGrayscale(); |
|
57 | 59 | case QChart::ChartThemeScientific: |
|
58 | 60 | return new ChartThemeScientific(); |
|
59 | 61 | case QChart::ChartThemeBlueCerulean: |
|
60 | 62 | return new ChartThemeBlueCerulean(); |
|
63 | case QChart::ChartThemeLight: | |
|
64 | return new ChartThemeLight(); | |
|
61 | 65 | default: |
|
62 | 66 | return new ChartThemeDefault(); |
|
63 | 67 | } |
|
64 | 68 | } |
|
65 | 69 | |
|
66 | 70 | void ChartTheme::decorate(QChart* chart) |
|
67 | 71 | { |
|
68 | if (m_backgroundShades == BackgroundShadesNone) | |
|
69 |
chart->setChartBackgroundBrush(m_ |
|
|
70 | else | |
|
72 | if (m_backgroundShades == BackgroundShadesNone) { | |
|
73 | chart->setChartBackgroundBrush(m_chartBackgroundGradient); | |
|
74 | } else { | |
|
71 | 75 | chart->setChartBackgroundBrush(Qt::NoBrush); |
|
76 | } | |
|
72 | 77 | chart->setChartTitleFont(m_masterFont); |
|
73 | 78 | } |
|
74 | 79 | |
|
75 | 80 | void ChartTheme::decorate(QLegend* legend) |
|
76 | 81 | { |
|
77 |
legend->setBackgroundBrush(m_ |
|
|
82 | legend->setBackgroundBrush(m_chartBackgroundGradient); | |
|
78 | 83 | } |
|
79 | 84 | |
|
80 | 85 | void ChartTheme::decorate(QAreaSeries* series, int index) |
|
81 | 86 | { |
|
82 | 87 | QPen pen; |
|
83 | 88 | QBrush brush; |
|
84 | 89 | |
|
85 | 90 | if (pen == series->pen()){ |
|
86 | 91 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
87 | 92 | pen.setWidthF(2); |
|
88 | 93 | series->setPen(pen); |
|
89 | 94 | } |
|
90 | 95 | |
|
91 | 96 | if (brush == series->brush()) { |
|
92 | 97 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
93 | 98 | series->setBrush(brush); |
|
94 | 99 | } |
|
95 | 100 | } |
|
96 | 101 | |
|
97 | 102 | |
|
98 | 103 | void ChartTheme::decorate(QLineSeries* series,int index) |
|
99 | 104 | { |
|
100 | 105 | QPen pen; |
|
101 | 106 | if(pen == series->pen()){ |
|
102 | 107 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
103 | 108 | pen.setWidthF(2); |
|
104 | 109 | series->setPen(pen); |
|
105 | 110 | } |
|
106 | 111 | } |
|
107 | 112 | |
|
108 | 113 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) |
|
109 | 114 | { |
|
110 | 115 | QList<QBarSet*> sets = series->barSets(); |
|
111 | 116 | for (int i=0; i<sets.count(); i++) { |
|
112 | 117 | qreal pos = 0.5; |
|
113 | 118 | if (sets.count() > 1) |
|
114 | 119 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
115 | 120 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
116 | 121 | sets.at(i)->setBrush(QBrush(c)); |
|
117 | 122 | |
|
118 | 123 | // Pick label color as far as possible from bar color (within gradient). |
|
119 | 124 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
120 | 125 | // TODO: better picking of label color? |
|
121 | 126 | if (pos < 0.3) { |
|
122 | 127 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
123 | 128 | } else { |
|
124 | 129 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
125 | 130 | } |
|
126 | 131 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
127 | 132 | } |
|
128 | 133 | } |
|
129 | 134 | |
|
130 | 135 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) |
|
131 | 136 | { |
|
132 | 137 | QList<QBarSet*> sets = series->barSets(); |
|
133 | 138 | for (int i=0; i<sets.count(); i++) { |
|
134 | 139 | qreal pos = 0.5; |
|
135 | 140 | if (sets.count() > 1) |
|
136 | 141 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
137 | 142 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
138 | 143 | sets.at(i)->setBrush(QBrush(c)); |
|
139 | 144 | |
|
140 | 145 | if (pos < 0.3) { |
|
141 | 146 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
142 | 147 | } else { |
|
143 | 148 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
144 | 149 | } |
|
145 | 150 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
146 | 151 | } |
|
147 | 152 | } |
|
148 | 153 | |
|
149 | 154 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) |
|
150 | 155 | { |
|
151 | 156 | QList<QBarSet*> sets = series->barSets(); |
|
152 | 157 | for (int i=0; i<sets.count(); i++) { |
|
153 | 158 | qreal pos = 0.5; |
|
154 | 159 | if (sets.count() > 1) |
|
155 | 160 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
156 | 161 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
157 | 162 | sets.at(i)->setBrush(QBrush(c)); |
|
158 | 163 | |
|
159 | 164 | if (pos < 0.3) { |
|
160 | 165 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
161 | 166 | } else { |
|
162 | 167 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
163 | 168 | } |
|
164 | 169 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
165 | 170 | } |
|
166 | 171 | } |
|
167 | 172 | |
|
168 | 173 | void ChartTheme::decorate(QScatterSeries* series, int index) |
|
169 | 174 | { |
|
170 | 175 | |
|
171 | 176 | QPen pen; |
|
172 | 177 | QBrush brush; |
|
173 | 178 | |
|
174 | 179 | if (pen == series->pen()) { |
|
175 | 180 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
176 | 181 | pen.setWidthF(2); |
|
177 | 182 | series->setPen(pen); |
|
178 | 183 | } |
|
179 | 184 | |
|
180 | 185 | if (brush == series->brush()) { |
|
181 | 186 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
182 | 187 | series->setBrush(brush); |
|
183 | 188 | } |
|
184 | 189 | } |
|
185 | 190 | |
|
186 | 191 | void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index) |
|
187 | 192 | { |
|
188 | 193 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
189 | 194 | for (int i(0); i < series->slices().count(); i++) { |
|
190 | 195 | qreal pos = (qreal) i / (qreal) series->count(); |
|
191 | 196 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
192 | 197 | series->slices().at(i)->setSlicePen(penColor); |
|
193 | 198 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
194 | 199 | series->slices().at(i)->setSliceBrush(brushColor); |
|
195 | 200 | } |
|
196 | 201 | } |
|
197 | 202 | |
|
198 | 203 | void ChartTheme::decorate(QSplineSeries* series, int index) |
|
199 | 204 | { |
|
200 | 205 | QPen pen; |
|
201 | 206 | if(pen == series->pen()){ |
|
202 | 207 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
203 | 208 | pen.setWidthF(2); |
|
204 | 209 | series->setPen(pen); |
|
205 | 210 | } |
|
206 | 211 | } |
|
207 | 212 | |
|
208 | 213 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) |
|
209 | 214 | { |
|
210 | 215 | if (axis->isAxisVisible()) { |
|
211 | 216 | axis->setLabelsBrush(m_axisLabelBrush); |
|
212 | 217 | axis->setLabelsPen(m_axisLabelPen); |
|
213 | // TODO: check the axis type (x or y) should define whether to show the shades or not | |
|
214 | 218 | if (m_backgroundShades == BackgroundShadesBoth |
|
215 | 219 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
216 | 220 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { |
|
217 | 221 | axis->setShadesPen(m_backgroundShadesPen); |
|
218 | 222 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
219 | 223 | } else { |
|
220 | 224 | // The shades not supposed to be shown for this axis, clear possible brush and pen |
|
221 | 225 | axis->setShadesPen(Qt::NoPen); |
|
222 | 226 | axis->setShadesBrush(Qt::NoBrush); |
|
223 | 227 | } |
|
224 | 228 | axis->setAxisPen(m_axisLinePen); |
|
225 | 229 | axis->setGridLinePen(m_gridLinePen); |
|
226 | 230 | axis->setLabelsFont(m_masterFont); |
|
227 | 231 | } |
|
228 | 232 | } |
|
229 | 233 | |
|
230 | 234 | void ChartTheme::generateSeriesGradients() |
|
231 | 235 | { |
|
232 | 236 | // Generate gradients in HSV color space |
|
233 | 237 | foreach (QColor color, m_seriesColors) { |
|
234 | 238 | QLinearGradient g; |
|
235 | 239 | qreal h = color.hsvHueF(); |
|
236 | 240 | qreal s = color.hsvSaturationF(); |
|
237 | 241 | |
|
238 | 242 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
239 | 243 | // most themes. The rest of the gradients we can define manually in theme specific |
|
240 | 244 | // implementation. |
|
241 | 245 | QColor start = color; |
|
242 | 246 | start.setHsvF(h, 0.05, 0.95); |
|
243 | 247 | g.setColorAt(0.0, start); |
|
244 | 248 | |
|
245 | 249 | g.setColorAt(0.5, color); |
|
246 | 250 | |
|
247 | 251 | QColor end = color; |
|
248 | 252 | end.setHsvF(h, s, 0.25); |
|
249 | 253 | g.setColorAt(1.0, end); |
|
250 | 254 | |
|
251 | 255 | m_seriesGradients << g; |
|
252 | 256 | } |
|
253 | 257 | } |
|
254 | 258 | |
|
255 | 259 | |
|
256 | 260 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
257 | 261 | { |
|
258 | 262 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
259 | 263 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
260 | 264 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
261 | 265 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
262 | 266 | QColor c; |
|
263 | 267 | c.setRgbF(r, g, b); |
|
264 | 268 | return c; |
|
265 | 269 | } |
|
266 | 270 | |
|
267 | 271 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
268 | 272 | { |
|
269 | 273 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
270 | 274 | |
|
271 | 275 | // another possibility: |
|
272 | 276 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
273 | 277 | |
|
274 | 278 | QGradientStops stops = gradient.stops(); |
|
275 | 279 | int count = stops.count(); |
|
276 | 280 | |
|
277 | 281 | // find previous stop relative to position |
|
278 | 282 | QGradientStop prev = stops.first(); |
|
279 | 283 | for (int i=0; i<count; i++) { |
|
280 | 284 | QGradientStop stop = stops.at(i); |
|
281 | 285 | if (pos > stop.first) |
|
282 | 286 | prev = stop; |
|
283 | 287 | |
|
284 | 288 | // given position is actually a stop position? |
|
285 | 289 | if (pos == stop.first) { |
|
286 | 290 | //qDebug() << "stop color" << pos; |
|
287 | 291 | return stop.second; |
|
288 | 292 | } |
|
289 | 293 | } |
|
290 | 294 | |
|
291 | 295 | // find next stop relative to position |
|
292 | 296 | QGradientStop next = stops.last(); |
|
293 | 297 | for (int i=count-1; i>=0; i--) { |
|
294 | 298 | QGradientStop stop = stops.at(i); |
|
295 | 299 | if (pos < stop.first) |
|
296 | 300 | next = stop; |
|
297 | 301 | } |
|
298 | 302 | |
|
299 | 303 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
300 | 304 | |
|
301 | 305 | qreal range = next.first - prev.first; |
|
302 | 306 | qreal posDelta = pos - prev.first; |
|
303 | 307 | qreal relativePos = posDelta / range; |
|
304 | 308 | |
|
305 | 309 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
306 | 310 | |
|
307 | 311 | return colorAt(prev.second, next.second, relativePos); |
|
308 | 312 | } |
|
309 | 313 | |
|
310 | 314 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,81 | |||
|
1 | 1 | #ifndef CHARTTHEME_H |
|
2 | 2 | #define CHARTTHEME_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchart.h" |
|
6 | 6 | #include <QColor> |
|
7 | 7 | #include <QGradientStops> |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | class ChartItem; |
|
12 | 12 | class QSeries; |
|
13 | 13 | class LineChartItem; |
|
14 | 14 | class QLineSeries; |
|
15 | 15 | class BarPresenter; |
|
16 | 16 | class QBarSeries; |
|
17 | 17 | class StackedBarPresenter; |
|
18 | 18 | class QStackedBarSeries; |
|
19 | 19 | class QPercentBarSeries; |
|
20 | 20 | class PercentBarPresenter; |
|
21 | 21 | class QScatterSeries; |
|
22 | 22 | class ScatterChartItem; |
|
23 | 23 | class PieChartItem; |
|
24 | 24 | class QPieSeries; |
|
25 | 25 | class SplineChartItem; |
|
26 | 26 | class QSplineSeries; |
|
27 | 27 | class AreaChartItem; |
|
28 | 28 | class QAreaSeries; |
|
29 | 29 | |
|
30 | 30 | class ChartTheme |
|
31 | 31 | { |
|
32 | 32 | public: |
|
33 | 33 | enum BackgroundShadesMode { |
|
34 | 34 | BackgroundShadesNone = 0, |
|
35 | 35 | BackgroundShadesVertical, |
|
36 | 36 | BackgroundShadesHorizontal, |
|
37 | 37 | BackgroundShadesBoth |
|
38 | 38 | }; |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 | 41 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
42 | 42 | public: |
|
43 | 43 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
44 | 44 | QChart::ChartTheme id() const {return m_id;} |
|
45 | 45 | void decorate(QChart* chart); |
|
46 | 46 | void decorate(QLegend* legend); |
|
47 | 47 | //void decorate(ChartItem* item, QSeries* series,int index); |
|
48 | 48 | void decorate(BarPresenter* item, QBarSeries* series, int index); |
|
49 | 49 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); |
|
50 | 50 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); |
|
51 | 51 | void decorate(QLineSeries* series, int index); |
|
52 | 52 | void decorate(QAreaSeries* series, int index); |
|
53 | 53 | void decorate(QScatterSeries* series, int index); |
|
54 | 54 | void decorate(PieChartItem* item, QPieSeries* series, int index); |
|
55 | 55 | void decorate(QSplineSeries* series, int index); |
|
56 | 56 | void decorate(QChartAxis* axis, bool axisX); |
|
57 | 57 | |
|
58 | 58 | public: // utils |
|
59 | 59 | void generateSeriesGradients(); |
|
60 | 60 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
61 | 61 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
62 | 62 | |
|
63 | 63 | protected: |
|
64 | 64 | QChart::ChartTheme m_id; |
|
65 | 65 | QList<QColor> m_seriesColors; |
|
66 | 66 | QList<QGradient> m_seriesGradients; |
|
67 |
QLinearGradient m_ |
|
|
67 | QLinearGradient m_chartBackgroundGradient; | |
|
68 | 68 | |
|
69 | 69 | QFont m_masterFont; |
|
70 | 70 | QPen m_axisLinePen; |
|
71 | 71 | QBrush m_axisLabelBrush; |
|
72 | 72 | QPen m_axisLabelPen; |
|
73 | 73 | QPen m_backgroundShadesPen; |
|
74 | 74 | QBrush m_backgroundShadesBrush; |
|
75 | 75 | BackgroundShadesMode m_backgroundShades; |
|
76 | 76 | QPen m_gridLinePen; |
|
77 | 77 | }; |
|
78 | 78 | |
|
79 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | 80 | |
|
81 | 81 | #endif // CHARTTHEME_H |
@@ -1,355 +1,356 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | #include "qlegend.h" |
|
4 | 4 | #include "chartpresenter_p.h" |
|
5 | 5 | #include "chartdataset_p.h" |
|
6 | 6 | #include <QGraphicsScene> |
|
7 | 7 | #include <QGraphicsSceneResizeEvent> |
|
8 | 8 | #include <QDebug> |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | 12 | /*! |
|
13 | 13 | \enum QChart::ChartTheme |
|
14 | 14 | |
|
15 | 15 | This enum describes the theme used by the chart. |
|
16 | 16 | |
|
17 | 17 | \value ChartThemeDefault Follows the GUI style of the Operating System |
|
18 | 18 | \value ChartThemeVanilla |
|
19 | 19 | \value ChartThemeIcy |
|
20 | 20 | \value ChartThemeGrayscale |
|
21 | 21 | \value ChartThemeScientific |
|
22 | 22 | \value ChartThemeBlueCerulean |
|
23 | \value ChartThemeLight | |
|
23 | 24 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
24 | 25 | */ |
|
25 | 26 | |
|
26 | 27 | /*! |
|
27 | 28 | \enum QChart::AnimationOption |
|
28 | 29 | |
|
29 | 30 | For enabling/disabling animations. Defaults to NoAnimation. |
|
30 | 31 | |
|
31 | 32 | \value NoAnimation |
|
32 | 33 | \value GridAxisAnimations |
|
33 | 34 | \value SeriesAnimations |
|
34 | 35 | \value AllAnimations |
|
35 | 36 | */ |
|
36 | 37 | |
|
37 | 38 | /*! |
|
38 | 39 | \class QChart |
|
39 | 40 | \brief QtCommercial chart API. |
|
40 | 41 | |
|
41 | 42 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
42 | 43 | representation of different types of QChartSeries and other chart related objects like |
|
43 | 44 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
44 | 45 | convenience class QChartView instead of QChart. |
|
45 | 46 | \sa QChartView |
|
46 | 47 | */ |
|
47 | 48 | |
|
48 | 49 | /*! |
|
49 | 50 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
50 | 51 | */ |
|
51 | 52 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
52 | 53 | m_backgroundItem(0), |
|
53 | 54 | m_titleItem(0), |
|
54 | 55 | m_legend(new QLegend(this)), |
|
55 | 56 | m_dataset(new ChartDataSet(this)), |
|
56 | 57 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
57 | 58 | { |
|
58 | 59 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
59 | 60 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
60 | 61 | } |
|
61 | 62 | |
|
62 | 63 | /*! |
|
63 | 64 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
64 | 65 | */ |
|
65 | 66 | QChart::~QChart() |
|
66 | 67 | { |
|
67 | 68 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
68 | 69 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
69 | 70 | } |
|
70 | 71 | |
|
71 | 72 | /*! |
|
72 | 73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
73 | 74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
74 | 75 | the y axis). |
|
75 | 76 | */ |
|
76 | 77 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
77 | 78 | { |
|
78 | 79 | m_dataset->addSeries(series, axisY); |
|
79 | 80 | } |
|
80 | 81 | |
|
81 | 82 | /*! |
|
82 | 83 | Removes the \a series specified in a perameter from the QChartView. |
|
83 | 84 | It releses its ownership of the specified QChartSeries object. |
|
84 | 85 | It does not delete the pointed QChartSeries data object |
|
85 | 86 | \sa addSeries(), removeAllSeries() |
|
86 | 87 | */ |
|
87 | 88 | void QChart::removeSeries(QSeries* series) |
|
88 | 89 | { |
|
89 | 90 | m_dataset->removeSeries(series); |
|
90 | 91 | } |
|
91 | 92 | |
|
92 | 93 | /*! |
|
93 | 94 | Removes all the QChartSeries that have been added to the QChartView |
|
94 | 95 | It also deletes the pointed QChartSeries data objects |
|
95 | 96 | \sa addSeries(), removeSeries() |
|
96 | 97 | */ |
|
97 | 98 | void QChart::removeAllSeries() |
|
98 | 99 | { |
|
99 | 100 | m_dataset->removeAllSeries(); |
|
100 | 101 | } |
|
101 | 102 | |
|
102 | 103 | /*! |
|
103 | 104 | Sets the \a brush that is used for painting the background of the chart area. |
|
104 | 105 | */ |
|
105 | 106 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
106 | 107 | { |
|
107 | 108 | createChartBackgroundItem(); |
|
108 | 109 | m_backgroundItem->setBrush(brush); |
|
109 | 110 | m_backgroundItem->update(); |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | /*! |
|
113 | 114 | Sets the \a pen that is used for painting the background of the chart area. |
|
114 | 115 | */ |
|
115 | 116 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
116 | 117 | { |
|
117 | 118 | createChartBackgroundItem(); |
|
118 | 119 | m_backgroundItem->setPen(pen); |
|
119 | 120 | m_backgroundItem->update(); |
|
120 | 121 | } |
|
121 | 122 | |
|
122 | 123 | /*! |
|
123 | 124 | Sets the chart \a title. The description text that is drawn above the chart. |
|
124 | 125 | */ |
|
125 | 126 | void QChart::setChartTitle(const QString& title) |
|
126 | 127 | { |
|
127 | 128 | createChartTitleItem(); |
|
128 | 129 | m_titleItem->setText(title); |
|
129 | 130 | updateLayout(); |
|
130 | 131 | } |
|
131 | 132 | |
|
132 | 133 | /*! |
|
133 | 134 | Returns the chart title. The description text that is drawn above the chart. |
|
134 | 135 | */ |
|
135 | 136 | QString QChart::chartTitle() const |
|
136 | 137 | { |
|
137 | 138 | if(m_titleItem) |
|
138 | 139 | return m_titleItem->text(); |
|
139 | 140 | else |
|
140 | 141 | return QString(); |
|
141 | 142 | } |
|
142 | 143 | |
|
143 | 144 | /*! |
|
144 | 145 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
145 | 146 | */ |
|
146 | 147 | void QChart::setChartTitleFont(const QFont& font) |
|
147 | 148 | { |
|
148 | 149 | createChartTitleItem(); |
|
149 | 150 | m_titleItem->setFont(font); |
|
150 | 151 | updateLayout(); |
|
151 | 152 | } |
|
152 | 153 | |
|
153 | 154 | /*! |
|
154 | 155 | Sets the \a brush used for rendering the title text. |
|
155 | 156 | */ |
|
156 | 157 | void QChart::setChartTitleBrush(const QBrush &brush) |
|
157 | 158 | { |
|
158 | 159 | createChartTitleItem(); |
|
159 | 160 | m_titleItem->setBrush(brush); |
|
160 | 161 | updateLayout(); |
|
161 | 162 | } |
|
162 | 163 | |
|
163 | 164 | /*! |
|
164 | 165 | Returns the brush used for rendering the title text. |
|
165 | 166 | */ |
|
166 | 167 | QBrush QChart::chartTitleBrush() |
|
167 | 168 | { |
|
168 | 169 | createChartTitleItem(); |
|
169 | 170 | return m_titleItem->brush(); |
|
170 | 171 | } |
|
171 | 172 | |
|
172 | 173 | void QChart::createChartBackgroundItem() |
|
173 | 174 | { |
|
174 | 175 | if(!m_backgroundItem) { |
|
175 | 176 | m_backgroundItem = new QGraphicsRectItem(this); |
|
176 | 177 | m_backgroundItem->setPen(Qt::NoPen); |
|
177 | 178 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
178 | 179 | } |
|
179 | 180 | } |
|
180 | 181 | |
|
181 | 182 | void QChart::createChartTitleItem() |
|
182 | 183 | { |
|
183 | 184 | if(!m_titleItem) { |
|
184 | 185 | m_titleItem = new QGraphicsSimpleTextItem(this); |
|
185 | 186 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
186 | 187 | } |
|
187 | 188 | } |
|
188 | 189 | |
|
189 | 190 | /*! |
|
190 | 191 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
191 | 192 | \sa setMargin() |
|
192 | 193 | */ |
|
193 | 194 | int QChart::margin() const |
|
194 | 195 | { |
|
195 | 196 | return m_presenter->margin(); |
|
196 | 197 | } |
|
197 | 198 | |
|
198 | 199 | /*! |
|
199 | 200 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
200 | 201 | \sa margin() |
|
201 | 202 | */ |
|
202 | 203 | void QChart::setMargin(int margin) |
|
203 | 204 | { |
|
204 | 205 | m_presenter->setMargin(margin); |
|
205 | 206 | updateLayout(); |
|
206 | 207 | } |
|
207 | 208 | |
|
208 | 209 | /*! |
|
209 | 210 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
210 | 211 | \sa ChartTheme, chartTheme() |
|
211 | 212 | */ |
|
212 | 213 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
213 | 214 | { |
|
214 | 215 | m_presenter->setChartTheme(theme); |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | /*! |
|
218 | 219 | Returns the theme enum used by the chart. |
|
219 | 220 | \sa ChartTheme, setChartTheme() |
|
220 | 221 | */ |
|
221 | 222 | QChart::ChartTheme QChart::chartTheme() const |
|
222 | 223 | { |
|
223 | 224 | return m_presenter->chartTheme(); |
|
224 | 225 | } |
|
225 | 226 | |
|
226 | 227 | /*! |
|
227 | 228 | Zooms in the view by a factor of 2 |
|
228 | 229 | */ |
|
229 | 230 | void QChart::zoomIn() |
|
230 | 231 | { |
|
231 | 232 | m_presenter->zoomIn(); |
|
232 | 233 | } |
|
233 | 234 | |
|
234 | 235 | /*! |
|
235 | 236 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
236 | 237 | */ |
|
237 | 238 | void QChart::zoomIn(const QRectF& rect) |
|
238 | 239 | { |
|
239 | 240 | |
|
240 | 241 | if(!rect.isValid()) return; |
|
241 | 242 | m_presenter->zoomIn(rect); |
|
242 | 243 | } |
|
243 | 244 | |
|
244 | 245 | /*! |
|
245 | 246 | Restores the view zoom level to the previous one. |
|
246 | 247 | */ |
|
247 | 248 | void QChart::zoomOut() |
|
248 | 249 | { |
|
249 | 250 | m_presenter->zoomOut(); |
|
250 | 251 | } |
|
251 | 252 | |
|
252 | 253 | /*! |
|
253 | 254 | Resets to the default view. |
|
254 | 255 | */ |
|
255 | 256 | void QChart::zoomReset() |
|
256 | 257 | { |
|
257 | 258 | m_presenter->zoomReset(); |
|
258 | 259 | } |
|
259 | 260 | |
|
260 | 261 | /*! |
|
261 | 262 | Returns the pointer to the x axis object of the chart |
|
262 | 263 | */ |
|
263 | 264 | QChartAxis* QChart::axisX() const |
|
264 | 265 | { |
|
265 | 266 | return m_dataset->axisX(); |
|
266 | 267 | } |
|
267 | 268 | |
|
268 | 269 | /*! |
|
269 | 270 | Returns the pointer to the y axis object of the chart |
|
270 | 271 | */ |
|
271 | 272 | QChartAxis* QChart::axisY() const |
|
272 | 273 | { |
|
273 | 274 | return m_dataset->axisY(); |
|
274 | 275 | } |
|
275 | 276 | |
|
276 | 277 | /*! |
|
277 | 278 | Returns the legend object of the chart |
|
278 | 279 | */ |
|
279 | 280 | QLegend* QChart::legend() |
|
280 | 281 | { |
|
281 | 282 | return m_legend; |
|
282 | 283 | } |
|
283 | 284 | |
|
284 | 285 | /*! |
|
285 | 286 | Resizes and updates the chart area using the \a event data |
|
286 | 287 | */ |
|
287 | 288 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
288 | 289 | { |
|
289 | 290 | |
|
290 | 291 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
291 | 292 | updateLayout(); |
|
292 | 293 | QGraphicsWidget::resizeEvent(event); |
|
293 | 294 | update(); |
|
294 | 295 | } |
|
295 | 296 | |
|
296 | 297 | /*! |
|
297 | 298 | Sets animation \a options for the chart |
|
298 | 299 | */ |
|
299 | 300 | void QChart::setAnimationOptions(AnimationOptions options) |
|
300 | 301 | { |
|
301 | 302 | m_presenter->setAnimationOptions(options); |
|
302 | 303 | } |
|
303 | 304 | |
|
304 | 305 | /*! |
|
305 | 306 | Returns animation options for the chart |
|
306 | 307 | */ |
|
307 | 308 | QChart::AnimationOptions QChart::animationOptions() const |
|
308 | 309 | { |
|
309 | 310 | return m_presenter->animationOptions(); |
|
310 | 311 | } |
|
311 | 312 | |
|
312 | 313 | void QChart::scroll(int dx,int dy) |
|
313 | 314 | { |
|
314 | 315 | //temporary |
|
315 | 316 | if(dx>0) |
|
316 | 317 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
317 | 318 | if(dx<0) |
|
318 | 319 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
319 | 320 | if(dy>0) |
|
320 | 321 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
321 | 322 | if(dy<0) |
|
322 | 323 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
323 | 324 | } |
|
324 | 325 | |
|
325 | 326 | void QChart::updateLayout() |
|
326 | 327 | { |
|
327 | 328 | if(!m_rect.isValid()) return; |
|
328 | 329 | |
|
329 | 330 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
330 | 331 | |
|
331 | 332 | // recalculate title position |
|
332 | 333 | if (m_titleItem) { |
|
333 | 334 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
334 | 335 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
335 | 336 | } |
|
336 | 337 | |
|
337 | 338 | //recalculate background gradient |
|
338 | 339 | if (m_backgroundItem) { |
|
339 | 340 | m_backgroundItem->setRect(rect); |
|
340 | 341 | } |
|
341 | 342 | |
|
342 | 343 | // recalculate legend position |
|
343 | 344 | // TODO: better layout |
|
344 | 345 | if (m_legend) { |
|
345 | 346 | QRectF boundingRect(m_rect.adjusted(margin(), |
|
346 | 347 | rect.height() + margin() + margin()/2 - m_legend->minimumSize().height()/2, |
|
347 | 348 | -margin(), |
|
348 | 349 | -margin()/2 + m_legend->minimumSize().height()/2)); |
|
349 | 350 | m_legend->handleGeometryChanged(boundingRect); |
|
350 | 351 | qDebug() << "legend rect:" << m_legend->boundingRect(); |
|
351 | 352 | } |
|
352 | 353 | } |
|
353 | 354 | #include "moc_qchart.cpp" |
|
354 | 355 | |
|
355 | 356 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,104 +1,105 | |||
|
1 | 1 | #ifndef QCHART_H |
|
2 | 2 | #define QCHART_H |
|
3 | 3 | |
|
4 | 4 | #include <qchartglobal.h> |
|
5 | 5 | #include <qseries.h> |
|
6 | 6 | #include <QGraphicsWidget> |
|
7 | 7 | #include <QLinearGradient> |
|
8 | 8 | #include <QFont> |
|
9 | 9 | |
|
10 | 10 | class QGraphicsSceneResizeEvent; |
|
11 | 11 | |
|
12 | 12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | 13 | |
|
14 | 14 | class AxisItem; |
|
15 | 15 | class QSeries; |
|
16 | 16 | class PlotDomain; |
|
17 | 17 | class BarPresenter; |
|
18 | 18 | class QChartAxis; |
|
19 | 19 | class ChartTheme; |
|
20 | 20 | class ChartItem; |
|
21 | 21 | class ChartDataSet; |
|
22 | 22 | class ChartPresenter; |
|
23 | 23 | class QLegend; |
|
24 | 24 | |
|
25 | 25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
26 | 26 | { |
|
27 | 27 | Q_OBJECT |
|
28 | 28 | public: |
|
29 | 29 | enum ChartTheme { |
|
30 | 30 | ChartThemeDefault, |
|
31 | 31 | ChartThemeVanilla, |
|
32 | 32 | ChartThemeIcy, |
|
33 | 33 | ChartThemeGrayscale, |
|
34 | 34 | ChartThemeScientific, |
|
35 | 35 | ChartThemeBlueCerulean, |
|
36 | ChartThemeLight, | |
|
36 | 37 | ChartThemeCount |
|
37 | 38 | }; |
|
38 | 39 | |
|
39 | 40 | enum AnimationOption { |
|
40 | 41 | NoAnimation = 0x0, |
|
41 | 42 | GridAxisAnimations = 0x1, |
|
42 | 43 | SeriesAnimations =0x2, |
|
43 | 44 | AllAnimations = 0x3 |
|
44 | 45 | }; |
|
45 | 46 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
46 | 47 | |
|
47 | 48 | public: |
|
48 | 49 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
49 | 50 | ~QChart(); |
|
50 | 51 | |
|
51 | 52 | void addSeries(QSeries* series, QChartAxis* axisY = 0); |
|
52 | 53 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
53 | 54 | void removeAllSeries(); // deletes series and axis |
|
54 | 55 | |
|
55 | 56 | void setMargin(int margin); |
|
56 | 57 | int margin() const; |
|
57 | 58 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | 59 | QChart::ChartTheme chartTheme() const; |
|
59 | 60 | |
|
60 | 61 | void setChartTitle(const QString& title); |
|
61 | 62 | QString chartTitle() const; |
|
62 | 63 | void setChartTitleFont(const QFont& font); |
|
63 | 64 | void setChartTitleBrush(const QBrush &brush); |
|
64 | 65 | QBrush chartTitleBrush(); |
|
65 | 66 | void setChartBackgroundBrush(const QBrush& brush); |
|
66 | 67 | void setChartBackgroundPen(const QPen& pen); |
|
67 | 68 | |
|
68 | 69 | void setAnimationOptions(AnimationOptions options); |
|
69 | 70 | AnimationOptions animationOptions() const; |
|
70 | 71 | |
|
71 | 72 | void zoomIn(); |
|
72 | 73 | void zoomIn(const QRectF& rect); |
|
73 | 74 | void zoomOut(); |
|
74 | 75 | void zoomReset(); |
|
75 | 76 | void scroll(int dx,int dy); |
|
76 | 77 | |
|
77 | 78 | QChartAxis* axisX() const; |
|
78 | 79 | QChartAxis* axisY() const; |
|
79 | 80 | |
|
80 | 81 | QLegend* legend(); |
|
81 | 82 | |
|
82 | 83 | protected: |
|
83 | 84 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
84 | 85 | |
|
85 | 86 | private: |
|
86 | 87 | inline void createChartBackgroundItem(); |
|
87 | 88 | inline void createChartTitleItem(); |
|
88 | 89 | void updateLayout(); |
|
89 | 90 | |
|
90 | 91 | private: |
|
91 | 92 | Q_DISABLE_COPY(QChart) |
|
92 | 93 | QGraphicsRectItem* m_backgroundItem; |
|
93 | 94 | QGraphicsSimpleTextItem* m_titleItem; |
|
94 | 95 | QRectF m_rect; |
|
95 | 96 | QLegend* m_legend; |
|
96 | 97 | ChartDataSet *m_dataset; |
|
97 | 98 | ChartPresenter *m_presenter; |
|
98 | 99 | }; |
|
99 | 100 | |
|
100 | 101 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | 102 | |
|
102 | 103 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
103 | 104 | |
|
104 | 105 | #endif |
@@ -1,388 +1,399 | |||
|
1 | 1 | #include "qchartview.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | 3 | #include "qchartaxis.h" |
|
4 | 4 | #include <QGraphicsView> |
|
5 | 5 | #include <QGraphicsScene> |
|
6 | 6 | #include <QRubberBand> |
|
7 | 7 | #include <QResizeEvent> |
|
8 | 8 | #include <QDebug> |
|
9 | 9 | |
|
10 | 10 | /*! |
|
11 | 11 | \enum QChartView::RubberBandPolicy |
|
12 | 12 | |
|
13 | 13 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
14 | 14 | |
|
15 | 15 | \value NoRubberBand |
|
16 | 16 | \value VerticalRubberBand |
|
17 | 17 | \value HorizonalRubberBand |
|
18 | 18 | \value RectangleRubberBand |
|
19 | 19 | */ |
|
20 | 20 | |
|
21 | 21 | /*! |
|
22 | 22 | \class QChartView |
|
23 | 23 | \brief Standalone charting widget. |
|
24 | 24 | |
|
25 | 25 | QChartView is a standalone widget that can display charts. It does not require separate |
|
26 | 26 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
27 | 27 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to |
|
28 | 28 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
29 | 29 | |
|
30 | 30 | \sa QChart |
|
31 | 31 | */ |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | Constructs a chartView object which is a child of a\a parent. |
|
37 | 37 | */ |
|
38 | 38 | QChartView::QChartView(QWidget *parent) : |
|
39 | QGraphicsView(parent), | |
|
40 | m_scene(new QGraphicsScene(this)), | |
|
41 | m_chart(new QChart()), | |
|
42 | m_rubberBand(0), | |
|
43 | m_verticalRubberBand(false), | |
|
44 | m_horizonalRubberBand(false) | |
|
39 | QGraphicsView(parent), | |
|
40 | m_scene(new QGraphicsScene(this)), | |
|
41 | m_chart(new QChart()), | |
|
42 | m_rubberBand(0), | |
|
43 | m_verticalRubberBand(false), | |
|
44 | m_horizonalRubberBand(false) | |
|
45 | 45 | { |
|
46 | 46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
47 | 47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
48 | 48 | setScene(m_scene); |
|
49 | 49 | m_chart->setMargin(50); |
|
50 | 50 | m_scene->addItem(m_chart); |
|
51 | 51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
57 | 57 | */ |
|
58 | 58 | QChartView::~QChartView() |
|
59 | 59 | { |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | Resizes and updates the chart area using the \a event data |
|
64 | 64 | */ |
|
65 | 65 | void QChartView::resizeEvent(QResizeEvent *event) |
|
66 | 66 | { |
|
67 | 67 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
68 | 68 | m_chart->resize(size()); |
|
69 | 69 | QWidget::resizeEvent(event); |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
74 | 74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
75 | 75 | the y axis). |
|
76 | 76 | \sa removeSeries(), removeAllSeries() |
|
77 | 77 | */ |
|
78 | 78 | void QChartView::addSeries(QSeries* series,QChartAxis *axisY) |
|
79 | 79 | { |
|
80 | 80 | m_chart->addSeries(series,axisY); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | Removes the \a series specified in a perameter from the QChartView. |
|
85 | 85 | It releses its ownership of the specified QChartSeries object. |
|
86 | 86 | It does not delete the pointed QChartSeries data object |
|
87 | 87 | \sa addSeries(), removeAllSeries() |
|
88 | 88 | */ |
|
89 | 89 | void QChartView::removeSeries(QSeries* series) |
|
90 | 90 | { |
|
91 | 91 | m_chart->removeSeries(series); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | Removes all the QChartSeries that have been added to the QChartView |
|
96 | 96 | It also deletes the pointed QChartSeries data objects |
|
97 | 97 | \sa addSeries(), removeSeries() |
|
98 | 98 | */ |
|
99 | 99 | void QChartView::removeAllSeries() |
|
100 | 100 | { |
|
101 | 101 | m_chart->removeAllSeries(); |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | Zooms in the view by a factor of 2 |
|
106 | 106 | */ |
|
107 | 107 | void QChartView::zoomIn() |
|
108 | 108 | { |
|
109 | 109 | m_chart->zoomIn(); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
114 | 114 | */ |
|
115 | 115 | void QChartView::zoomIn(const QRect& rect) |
|
116 | 116 | { |
|
117 | 117 | m_chart->zoomIn(rect); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | Restores the view zoom level to the previous one. |
|
122 | 122 | */ |
|
123 | 123 | void QChartView::zoomOut() |
|
124 | 124 | { |
|
125 | 125 | m_chart->zoomOut(); |
|
126 | 126 | } |
|
127 | 127 | |
|
128 | 128 | /*! |
|
129 | 129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
130 | 130 | */ |
|
131 | 131 | int QChartView::margin() const |
|
132 | 132 | { |
|
133 | 133 | return m_chart->margin(); |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | Sets the chart \a title. A description text that is drawn above the chart. |
|
138 | 138 | */ |
|
139 | 139 | void QChartView::setChartTitle(const QString& title) |
|
140 | 140 | { |
|
141 | 141 | m_chart->setChartTitle(title); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | Returns the chart's title. A description text that is drawn above the chart. |
|
146 | 146 | */ |
|
147 | 147 | QString QChartView::chartTitle() const |
|
148 | 148 | { |
|
149 | 149 | return m_chart->chartTitle(); |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | /*! |
|
153 | 153 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
154 | 154 | */ |
|
155 | 155 | void QChartView::setChartTitleFont(const QFont& font) |
|
156 | 156 | { |
|
157 | 157 | m_chart->setChartTitleFont(font); |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | Sets the \a brush used for rendering the title text. |
|
162 | 162 | */ |
|
163 | 163 | void QChartView::setChartTitleBrush(const QBrush &brush) |
|
164 | 164 | { |
|
165 | 165 | m_chart->setChartTitleBrush(brush); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | Returns the brush used for rendering the title text. |
|
170 | 170 | */ |
|
171 | 171 | QBrush QChartView::chartTitleBrush() |
|
172 | 172 | { |
|
173 | 173 | return m_chart->chartTitleBrush(); |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. |
|
178 | 178 | */ |
|
179 | 179 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
180 | 180 | { |
|
181 | 181 | m_chart->setChartBackgroundBrush(brush); |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | /*! |
|
185 | 185 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. |
|
186 | 186 | */ |
|
187 | 187 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
188 | 188 | { |
|
189 | 189 | m_chart->setChartBackgroundPen(pen); |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
194 | 194 | */ |
|
195 | 195 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
196 | 196 | { |
|
197 | 197 | switch(policy) { |
|
198 | 198 | case VerticalRubberBand: |
|
199 | 199 | m_verticalRubberBand = true; |
|
200 | 200 | m_horizonalRubberBand = false; |
|
201 | 201 | break; |
|
202 | 202 | case HorizonalRubberBand: |
|
203 | 203 | m_verticalRubberBand = false; |
|
204 | 204 | m_horizonalRubberBand = true; |
|
205 | 205 | break; |
|
206 | 206 | case RectangleRubberBand: |
|
207 | 207 | m_verticalRubberBand = true; |
|
208 | 208 | m_horizonalRubberBand = true; |
|
209 | 209 | break; |
|
210 | 210 | case NoRubberBand: |
|
211 | 211 | default: |
|
212 | 212 | delete m_rubberBand; |
|
213 | 213 | m_rubberBand=0; |
|
214 | 214 | m_horizonalRubberBand = false; |
|
215 | 215 | m_verticalRubberBand = false; |
|
216 | 216 | return; |
|
217 | 217 | } |
|
218 | 218 | if(!m_rubberBand) { |
|
219 | 219 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
220 | 220 | m_rubberBand->setEnabled(true); |
|
221 | 221 | } |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 | 225 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
226 | 226 | */ |
|
227 | 227 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
228 | 228 | { |
|
229 | 229 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
230 | 230 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
231 | 231 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
232 | 232 | return NoRubberBand; |
|
233 | 233 | } |
|
234 | 234 | |
|
235 | 235 | /*! |
|
236 | 236 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
237 | 237 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. |
|
238 | 238 | */ |
|
239 | 239 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
240 | 240 | { |
|
241 | 241 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
242 | 242 | |
|
243 | 243 | int margin = m_chart->margin(); |
|
244 | 244 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
245 | 245 | |
|
246 | 246 | if (rect.contains(event->pos())) { |
|
247 | 247 | m_rubberBandOrigin = event->pos(); |
|
248 | 248 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
249 | 249 | m_rubberBand->show(); |
|
250 | 250 | event->accept(); |
|
251 | 251 | } |
|
252 | 252 | } |
|
253 | 253 | else { |
|
254 | 254 | QGraphicsView::mousePressEvent(event); |
|
255 | 255 | } |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
260 | 260 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
261 | 261 | */ |
|
262 | 262 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
263 | 263 | { |
|
264 | 264 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
265 | 265 | int margin = m_chart->margin(); |
|
266 | 266 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
267 | 267 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
268 | 268 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
269 | 269 | if(!m_verticalRubberBand) { |
|
270 | 270 | m_rubberBandOrigin.setY(rect.top()); |
|
271 | 271 | height = rect.height(); |
|
272 | 272 | } |
|
273 | 273 | if(!m_horizonalRubberBand) { |
|
274 | 274 | m_rubberBandOrigin.setX(rect.left()); |
|
275 | 275 | width= rect.width(); |
|
276 | 276 | } |
|
277 | 277 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
278 | 278 | } |
|
279 | 279 | else { |
|
280 | 280 | QGraphicsView::mouseMoveEvent(event); |
|
281 | 281 | } |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | /*! |
|
285 | 285 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
286 | 286 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
287 | 287 | */ |
|
288 | 288 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
289 | 289 | { |
|
290 | 290 | if(m_rubberBand) { |
|
291 | 291 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
292 | 292 | m_rubberBand->hide(); |
|
293 | 293 | QRect rect = m_rubberBand->geometry(); |
|
294 | 294 | m_chart->zoomIn(rect); |
|
295 | 295 | event->accept(); |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | if(event->button()==Qt::RightButton) |
|
299 | 299 | m_chart->zoomReset(); |
|
300 | 300 | } |
|
301 | 301 | else { |
|
302 | 302 | QGraphicsView::mouseReleaseEvent(event); |
|
303 | 303 | } |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | /*! |
|
307 | 307 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
308 | 308 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
309 | 309 | */ |
|
310 | 310 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
311 | 311 | { |
|
312 | 312 | switch (event->key()) { |
|
313 | 313 | case Qt::Key_Plus: |
|
314 | 314 | zoomIn(); |
|
315 | 315 | break; |
|
316 | 316 | case Qt::Key_Minus: |
|
317 | 317 | zoomOut(); |
|
318 | 318 | break; |
|
319 | 319 | default: |
|
320 | 320 | QGraphicsView::keyPressEvent(event); |
|
321 | 321 | break; |
|
322 | 322 | } |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
327 | 327 | \sa QChart::ChartTheme, chartTheme() |
|
328 | 328 | */ |
|
329 | 329 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
330 | 330 | { |
|
331 | if (theme == QChart::ChartThemeBlueCerulean) { | |
|
332 | QLinearGradient backgroundGradient; | |
|
333 | backgroundGradient.setColorAt(0.0, QRgb(0x056188)); | |
|
334 | backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); | |
|
335 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
336 | setBackgroundBrush(backgroundGradient); | |
|
337 | } else { | |
|
338 | setBackgroundBrush(Qt::NoBrush); | |
|
339 | } | |
|
331 | 340 | m_chart->setChartTheme(theme); |
|
332 | 341 | } |
|
333 | 342 | |
|
334 | 343 | /*! |
|
335 | 344 | Returns the theme enum used by the chart. |
|
336 | 345 | \sa setChartTheme() |
|
337 | 346 | */ |
|
338 | 347 | QChart::ChartTheme QChartView::chartTheme() const |
|
339 | 348 | { |
|
340 | 349 | return m_chart->chartTheme(); |
|
341 | 350 | } |
|
342 | 351 | |
|
343 | 352 | /*! |
|
344 | 353 | Returns the pointer to the x axis object of the chart |
|
345 | 354 | */ |
|
346 | 355 | QChartAxis* QChartView::axisX() const |
|
347 | 356 | { |
|
348 | 357 | return m_chart->axisX(); |
|
349 | 358 | } |
|
350 | 359 | |
|
351 | 360 | /*! |
|
352 | 361 | Returns the pointer to the y axis object of the chart |
|
353 | 362 | */ |
|
354 | 363 | QChartAxis* QChartView::axisY() const |
|
355 | 364 | { |
|
356 | 365 | return m_chart->axisY(); |
|
357 | 366 | } |
|
358 | 367 | |
|
359 | 368 | /*! |
|
360 | 369 | Returns the pointer to legend object of the chart |
|
361 | 370 | */ |
|
362 | 371 | QLegend* QChartView::legend() const |
|
363 | 372 | { |
|
364 | 373 | return m_chart->legend(); |
|
365 | 374 | } |
|
366 | 375 | |
|
367 | 376 | /*! |
|
368 | 377 | Sets animation \a options for the chart |
|
369 | 378 | */ |
|
370 | 379 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) |
|
371 | 380 | { |
|
372 | 381 | m_chart->setAnimationOptions(options); |
|
373 | 382 | } |
|
374 | 383 | |
|
375 | 384 | /*! |
|
376 | 385 | Returns animation options for the chart |
|
377 | 386 | */ |
|
378 | 387 | QChart::AnimationOptions QChartView::animationOptions() const |
|
379 | 388 | { |
|
380 | 389 | return m_chart->animationOptions(); |
|
381 | 390 | } |
|
382 | 391 | |
|
383 | 392 | void QChartView::scroll(int dx,int dy) |
|
384 | 393 | { |
|
385 | 394 | m_chart->scroll(dx,dy); |
|
386 | 395 | } |
|
387 | 396 | |
|
397 | #include "moc_qchartview.cpp" | |
|
398 | ||
|
388 | 399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,81 | |||
|
1 | 1 | #ifndef QCHARTWIDGET_H |
|
2 | 2 | #define QCHARTWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchartaxis.h" |
|
6 | 6 | #include "qseries.h" |
|
7 | 7 | #include "qchart.h" |
|
8 | 8 | #include <QGraphicsView> |
|
9 | 9 | |
|
10 | 10 | class QGraphicsScene; |
|
11 | 11 | class QRubberBand; |
|
12 | 12 | |
|
13 | 13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
14 | 14 | |
|
15 | 15 | class QChart; |
|
16 | 16 | |
|
17 | 17 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
18 | 18 | { |
|
19 | Q_OBJECT | |
|
20 | ||
|
19 | 21 | public: |
|
20 | 22 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
21 | 23 | |
|
22 | 24 | explicit QChartView(QWidget *parent = 0); |
|
23 | 25 | ~QChartView(); |
|
24 | 26 | |
|
25 | 27 | //implement from QWidget |
|
26 | 28 | void resizeEvent(QResizeEvent *event); |
|
27 | 29 | |
|
28 | 30 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership |
|
29 | 31 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
30 | 32 | void removeAllSeries(); // deletes series and axis |
|
31 | 33 | int margin() const; |
|
32 | 34 | |
|
33 | 35 | void setChartTitle(const QString& title); |
|
34 | 36 | QString chartTitle() const; |
|
35 | 37 | void setChartTitleFont(const QFont& font); |
|
36 | 38 | void setChartTitleBrush(const QBrush &brush); |
|
37 | 39 | QBrush chartTitleBrush(); |
|
38 | 40 | void setChartBackgroundBrush(const QBrush& brush); |
|
39 | 41 | void setChartBackgroundPen(const QPen& pen); |
|
40 | 42 | |
|
41 | 43 | void zoomIn(); |
|
42 | 44 | void zoomIn(const QRect& rect); |
|
43 | 45 | void zoomOut(); |
|
44 | 46 | |
|
45 | 47 | void scroll(int dx,int dy); |
|
46 | 48 | |
|
47 | 49 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
48 | 50 | RubberBandPolicy rubberBandPolicy() const; |
|
49 | 51 | |
|
50 | 52 | void setChartTheme(QChart::ChartTheme theme); |
|
51 | 53 | QChart::ChartTheme chartTheme() const; |
|
52 | 54 | |
|
53 | 55 | void setAnimationOptions(QChart::AnimationOptions options); |
|
54 | 56 | QChart::AnimationOptions animationOptions() const; |
|
55 | 57 | |
|
56 | 58 | QChartAxis* axisX() const; |
|
57 | 59 | QChartAxis* axisY() const; |
|
58 | 60 | |
|
59 | 61 | QLegend* legend() const; |
|
60 | 62 | |
|
61 | 63 | protected: |
|
62 | 64 | void mousePressEvent(QMouseEvent *event); |
|
63 | 65 | void mouseMoveEvent(QMouseEvent *event); |
|
64 | 66 | void mouseReleaseEvent(QMouseEvent *event); |
|
65 | 67 | void keyPressEvent(QKeyEvent *event); |
|
66 | 68 | |
|
67 | ||
|
68 | 69 | private: |
|
69 | 70 | QGraphicsScene *m_scene; |
|
70 | 71 | QChart* m_chart; |
|
71 | 72 | QPoint m_rubberBandOrigin; |
|
72 | 73 | QRubberBand* m_rubberBand; |
|
73 | 74 | bool m_verticalRubberBand; |
|
74 | 75 | bool m_horizonalRubberBand; |
|
75 | 76 | Q_DISABLE_COPY(QChartView) |
|
76 | ||
|
77 | ||
|
78 | 77 | }; |
|
79 | 78 | |
|
80 | 79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | 80 | |
|
82 | 81 | #endif // QCHARTWIDGET_H |
@@ -1,99 +1,101 | |||
|
1 | 1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
2 | 2 | TARGET = QtCommercialChart |
|
3 | 3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
4 | 4 | TEMPLATE = lib |
|
5 | 5 | QT += core \ |
|
6 | 6 | gui |
|
7 | 7 | CONFIG += debug_and_release |
|
8 | 8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | 9 | SOURCES += \ |
|
10 | 10 | chartdataset.cpp \ |
|
11 | 11 | chartpresenter.cpp \ |
|
12 | 12 | charttheme.cpp \ |
|
13 | 13 | domain.cpp \ |
|
14 | 14 | qchart.cpp \ |
|
15 | 15 | qchartview.cpp \ |
|
16 | 16 | qseries.cpp \ |
|
17 | 17 | qlegend.cpp \ |
|
18 | 18 | legendmarker.cpp |
|
19 | 19 | PRIVATE_HEADERS += \ |
|
20 | 20 | chartdataset_p.h \ |
|
21 | 21 | chartitem_p.h \ |
|
22 | 22 | chartpresenter_p.h \ |
|
23 | 23 | charttheme_p.h \ |
|
24 | 24 | domain_p.h \ |
|
25 | 25 | legendmarker_p.h |
|
26 | 26 | PUBLIC_HEADERS += \ |
|
27 | 27 | qchart.h \ |
|
28 | 28 | qchartglobal.h \ |
|
29 | 29 | qseries.h \ |
|
30 | 30 | qchartview.h \ |
|
31 | 31 | qlegend.h |
|
32 | 32 | |
|
33 | 33 | include(animations/animations.pri) |
|
34 | 34 | include(axis/axis.pri) |
|
35 | 35 | include(xychart/xychart.pri) |
|
36 | 36 | include(linechart/linechart.pri) |
|
37 | 37 | include(areachart/areachart.pri) |
|
38 | 38 | include(barchart/barchart.pri) |
|
39 | 39 | include(piechart/piechart.pri) |
|
40 | 40 | include(scatterseries/scatter.pri) |
|
41 | 41 | include(splinechart/splinechart.pri) |
|
42 | 42 | |
|
43 | 43 | THEMES += themes/chartthemedefault_p.h \ |
|
44 | 44 | themes/chartthemeicy_p.h \ |
|
45 | 45 | themes/chartthemegrayscale_p.h \ |
|
46 | 46 | themes/chartthemescientific_p.h \ |
|
47 | 47 | themes/chartthemevanilla_p.h \ |
|
48 | themes/chartthemebluecerulean_p.h | |
|
48 | themes/chartthemebluecerulean_p.h \ | |
|
49 | themes/chartthemelight_p.h | |
|
50 | ||
|
49 | 51 | HEADERS += $$PUBLIC_HEADERS |
|
50 | 52 | HEADERS += $$PRIVATE_HEADERS |
|
51 | 53 | HEADERS += $$THEMES |
|
52 | 54 | INCLUDEPATH += linechart \ |
|
53 | 55 | barchart \ |
|
54 | 56 | themes \ |
|
55 | 57 | . |
|
56 | 58 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
57 | 59 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
58 | 60 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
59 | 61 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
60 | 62 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
61 | 63 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
62 | 64 | public_headers.files = $$PUBLIC_HEADERS |
|
63 | 65 | target.path = $$[QT_INSTALL_LIBS] |
|
64 | 66 | INSTALLS += target \ |
|
65 | 67 | public_headers |
|
66 | 68 | install_build_public_headers.name = bild_public_headers |
|
67 | 69 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
68 | 70 | install_build_public_headers.input = PUBLIC_HEADERS |
|
69 | 71 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
70 | 72 | ${QMAKE_FILE_NAME} \ |
|
71 | 73 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
72 | 74 | install_build_public_headers.CONFIG += target_predeps \ |
|
73 | 75 | no_link |
|
74 | 76 | install_build_private_headers.name = bild_private_headers |
|
75 | 77 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
76 | 78 | install_build_private_headers.input = PRIVATE_HEADERS |
|
77 | 79 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
78 | 80 | ${QMAKE_FILE_NAME} \ |
|
79 | 81 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
80 | 82 | install_build_private_headers.CONFIG += target_predeps \ |
|
81 | 83 | no_link |
|
82 | 84 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
83 | 85 | install_build_private_headers |
|
84 | 86 | chartversion.target = qchartversion_p.h |
|
85 | 87 | chartversion.commands = @echo \ |
|
86 | 88 | "build_time" \ |
|
87 | 89 | > \ |
|
88 | 90 | $$chartversion.target; |
|
89 | 91 | chartversion.depends = $$HEADERS \ |
|
90 | 92 | $$SOURCES |
|
91 | 93 | PRE_TARGETDEPS += qchartversion_p.h |
|
92 | 94 | QMAKE_CLEAN += qchartversion_p.h |
|
93 | 95 | QMAKE_EXTRA_TARGETS += chartversion |
|
94 | 96 | unix:QMAKE_DISTCLEAN += -r \ |
|
95 | 97 | $$CHART_BUILD_HEADER_DIR \ |
|
96 | 98 | $$CHART_BUILD_LIB_DIR |
|
97 | 99 | win32:QMAKE_DISTCLEAN += /Q \ |
|
98 | 100 | $$CHART_BUILD_HEADER_DIR \ |
|
99 | 101 | $$CHART_BUILD_LIB_DIR |
@@ -1,36 +1,32 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | class ChartThemeBlueCerulean: public ChartTheme |
|
6 | 6 | { |
|
7 | 7 | public: |
|
8 | 8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) |
|
9 | 9 | { |
|
10 | 10 | // Series colors |
|
11 | 11 | m_seriesColors << QRgb(0xc7e85b); |
|
12 | 12 | m_seriesColors << QRgb(0x5dbe9b); |
|
13 | 13 | m_seriesColors << QRgb(0x4fbef3); |
|
14 | 14 | generateSeriesGradients(); |
|
15 | 15 | |
|
16 | // Background | |
|
17 | QLinearGradient backgroundGradient; | |
|
18 | backgroundGradient.setColorAt(0.0, QRgb(0x056188)); | |
|
19 | backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); | |
|
20 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
21 | m_backgroundGradient = backgroundGradient; | |
|
16 | // No chart background, chart view specifies a background | |
|
17 | // TODO: what if the chart is drawn on custom graphics scene instead of QChartView? | |
|
22 | 18 | |
|
23 | 19 | // Axes and other |
|
24 | 20 | m_masterFont = QFont(); |
|
25 |
m_axisLinePen = QPen(QRgb(0x |
|
|
21 | m_axisLinePen = QPen(QRgb(0xf7f7ff)); | |
|
26 | 22 | m_axisLinePen.setWidth(2); |
|
27 |
m_axisLabelBrush = QBrush(QRgb(0x |
|
|
23 | m_axisLabelBrush = QBrush(QRgb(0xf7f7ff)); | |
|
28 | 24 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
29 | 25 | m_backgroundShadesPen = Qt::NoPen; |
|
30 | 26 | m_backgroundShades = BackgroundShadesNone; |
|
31 |
m_gridLinePen = QPen(QRgb(0x |
|
|
32 |
m_gridLinePen.setWidth( |
|
|
27 | m_gridLinePen = QPen(QRgb(0xf7f7ff)); | |
|
28 | m_gridLinePen.setWidth(1); | |
|
33 | 29 | } |
|
34 | 30 | }; |
|
35 | 31 | |
|
36 | 32 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,154 +1,154 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | #ifdef Q_OS_WIN |
|
3 | 3 | #include <windows.h> |
|
4 | 4 | #include <stdio.h> |
|
5 | 5 | #endif |
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | 9 | class ChartThemeDefault: public ChartTheme |
|
10 | 10 | { |
|
11 | 11 | public: |
|
12 | 12 | ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault) |
|
13 | 13 | { |
|
14 | 14 | #ifdef Q_OS_WIN |
|
15 | 15 | // TODO: use theme specific window frame color as a series base color (it would give more |
|
16 | 16 | // variation to the base colors in addition to the blue and black used now) |
|
17 | 17 | // TODO: COLOR_WINDOWTEXT for text color? |
|
18 | 18 | // TODO: COLOR_INFOTEXT for tooltip text color? |
|
19 | 19 | // TODO: COLOR_INFOBK for tooltip background color? |
|
20 | 20 | |
|
21 | 21 | // First series base color from COLOR_HIGHLIGHT |
|
22 | 22 | DWORD colorHighlight; |
|
23 | 23 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
24 | 24 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
25 | 25 | GetGValue(colorHighlight), |
|
26 | 26 | GetBValue(colorHighlight))); |
|
27 | 27 | |
|
28 | 28 | // Second series base color from COLOR_WINDOWFRAME |
|
29 | 29 | DWORD colorWindowFrame; |
|
30 | 30 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
31 | 31 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
32 | 32 | GetGValue(colorWindowFrame), |
|
33 | 33 | GetBValue(colorWindowFrame))); |
|
34 | 34 | |
|
35 | 35 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
36 | 36 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
37 | 37 | DWORD colorGradientActiveCaptionLeft; |
|
38 | 38 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
39 | 39 | DWORD colorGradientActiveCaptionRight; |
|
40 | 40 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
41 | 41 | QLinearGradient g; |
|
42 | 42 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
43 | 43 | GetGValue(colorGradientActiveCaptionLeft), |
|
44 | 44 | GetBValue(colorGradientActiveCaptionLeft)); |
|
45 | 45 | g.setColorAt(0.0, start); |
|
46 | 46 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
47 | 47 | GetGValue(colorGradientActiveCaptionRight), |
|
48 | 48 | GetBValue(colorGradientActiveCaptionRight)); |
|
49 | 49 | g.setColorAt(1.0, end); |
|
50 | 50 | m_seriesColors.append(colorAt(g, 0.5)); |
|
51 | 51 | |
|
52 | 52 | // Generate gradients from the base colors |
|
53 | 53 | generateSeriesGradients(); |
|
54 | 54 | |
|
55 | 55 | // Background fill color from COLOR_WINDOW |
|
56 | 56 | QLinearGradient backgroundGradient; |
|
57 | 57 | DWORD colorWindow; |
|
58 | 58 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
59 | 59 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
60 | 60 | GetGValue(colorWindow), |
|
61 | 61 | GetBValue(colorWindow))); |
|
62 | 62 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
63 | 63 | GetGValue(colorWindow), |
|
64 | 64 | GetBValue(colorWindow))); |
|
65 | 65 | // Axes and other |
|
66 | 66 | m_masterFont = QFont(); |
|
67 | 67 | m_masterFont.setPointSizeF(10.0); |
|
68 | 68 | m_axisLinePen = QPen(Qt::black); |
|
69 | 69 | m_axisLinePen.setWidth(2); |
|
70 | 70 | m_axisLabelBrush = QBrush(Qt::black); |
|
71 | 71 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
72 | 72 | m_backgroundShadesPen = Qt::NoPen; |
|
73 | 73 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
74 | 74 | m_backgroundShades = BackgroundShadesVertical; |
|
75 | 75 | |
|
76 | 76 | #elif defined(Q_OS_LINUX) |
|
77 | 77 | // TODO: replace this dummy theme with linux specific theme |
|
78 | 78 | m_seriesColors << QRgb(0x60a6e6); |
|
79 | 79 | m_seriesColors << QRgb(0x92ca66); |
|
80 | 80 | m_seriesColors << QRgb(0xeba85f); |
|
81 | 81 | m_seriesColors << QRgb(0xfc5751); |
|
82 | 82 | generateSeriesGradients(); |
|
83 | 83 | |
|
84 | 84 | QLinearGradient backgroundGradient; |
|
85 | 85 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
86 | 86 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); |
|
87 | 87 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
88 | 88 | m_backgroundGradient = backgroundGradient; |
|
89 | 89 | |
|
90 | 90 | // Axes and other |
|
91 | 91 | m_masterFont = QFont(); |
|
92 | 92 | m_masterFont.setPointSizeF(10.0); |
|
93 | 93 | m_axisLinePen = QPen(Qt::black); |
|
94 | 94 | m_axisLinePen.setWidth(2); |
|
95 | 95 | m_axisLabelBrush = QBrush(Qt::black); |
|
96 | 96 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
97 | 97 | m_backgroundShadesPen = Qt::NoPen; |
|
98 | 98 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
99 | 99 | m_backgroundShades = BackgroundShadesVertical; |
|
100 | 100 | |
|
101 | 101 | #elif defined(Q_OS_MAC) |
|
102 | 102 | // TODO: replace this dummy theme with OSX specific theme |
|
103 | 103 | m_seriesColors << QRgb(0x60a6e6); |
|
104 | 104 | m_seriesColors << QRgb(0x92ca66); |
|
105 | 105 | m_seriesColors << QRgb(0xeba85f); |
|
106 | 106 | m_seriesColors << QRgb(0xfc5751); |
|
107 | 107 | generateSeriesGradients(); |
|
108 | 108 | |
|
109 | 109 | QLinearGradient backgroundGradient; |
|
110 | 110 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
111 | 111 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); |
|
112 | 112 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
113 |
m_ |
|
|
113 | m_chartBackgroundGradient = backgroundGradient; | |
|
114 | 114 | |
|
115 | 115 | // Axes and other |
|
116 | 116 | m_masterFont = QFont(); |
|
117 | 117 | m_masterFont.setPointSizeF(10.0); |
|
118 | 118 | m_axisLinePen = QPen(Qt::black); |
|
119 | 119 | m_axisLinePen.setWidth(2); |
|
120 | 120 | m_axisLabelBrush = QBrush(Qt::black); |
|
121 | 121 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
122 | 122 | m_backgroundShadesPen = Qt::NoPen; |
|
123 | 123 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
124 | 124 | m_backgroundShades = BackgroundShadesVertical; |
|
125 | 125 | |
|
126 | 126 | #else |
|
127 | 127 | // TODO: replace this dummy theme with generic (not OS specific) theme |
|
128 | 128 | m_seriesColors << QRgb(0x60a6e6); |
|
129 | 129 | m_seriesColors << QRgb(0x92ca66); |
|
130 | 130 | m_seriesColors << QRgb(0xeba85f); |
|
131 | 131 | m_seriesColors << QRgb(0xfc5751); |
|
132 | 132 | generateSeriesGradients(); |
|
133 | 133 | |
|
134 | 134 | QLinearGradient backgroundGradient; |
|
135 | 135 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
136 | 136 | backgroundGradient.setColorAt(1.0, QRgb(0xafafaf)); |
|
137 | 137 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
138 | 138 | m_backgroundGradient = backgroundGradient; |
|
139 | 139 | |
|
140 | 140 | // Axes and other |
|
141 | 141 | m_masterFont = QFont(); |
|
142 | 142 | m_masterFont.setPointSizeF(10.0); |
|
143 | 143 | m_axisLinePen = QPen(Qt::black); |
|
144 | 144 | m_axisLinePen.setWidth(2); |
|
145 | 145 | m_axisLabelBrush = QBrush(Qt::black); |
|
146 | 146 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
147 | 147 | m_backgroundShadesPen = Qt::NoPen; |
|
148 | 148 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
149 | 149 | m_backgroundShades = BackgroundShadesVertical; |
|
150 | 150 | #endif |
|
151 | 151 | } |
|
152 | 152 | }; |
|
153 | 153 | |
|
154 | 154 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | class ChartThemeGrayscale: public ChartTheme |
|
6 | 6 | { |
|
7 | 7 | public: |
|
8 | 8 | ChartThemeGrayscale():ChartTheme(QChart::ChartThemeGrayscale) |
|
9 | 9 | { |
|
10 | 10 | // Series colors |
|
11 | 11 | m_seriesColors << QRgb(0x869299); |
|
12 | 12 | m_seriesColors << QRgb(0xa5bdcc); |
|
13 | 13 | m_seriesColors << QRgb(0xe8fffc); |
|
14 | 14 | m_seriesColors << QRgb(0xccc2c2); |
|
15 | 15 | generateSeriesGradients(); |
|
16 | 16 | |
|
17 | 17 | // Background |
|
18 | 18 | QLinearGradient backgroundGradient; |
|
19 | 19 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
20 | 20 | backgroundGradient.setColorAt(1.0, QRgb(0xe0e3e5)); |
|
21 | 21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 |
m_ |
|
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
|
23 | 23 | |
|
24 | 24 | // Axes and other |
|
25 | 25 | m_masterFont = QFont(); |
|
26 | 26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
27 | 27 | m_axisLinePen.setWidth(2); |
|
28 | 28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
29 | 29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
30 | 30 | m_backgroundShadesPen = Qt::NoPen; |
|
31 | m_backgroundShades = BackgroundShadesNone; | |
|
31 | 32 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
32 | 33 | m_gridLinePen.setWidth(2); |
|
33 | 34 | } |
|
34 | 35 | }; |
|
35 | 36 | |
|
36 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | class ChartThemeIcy: public ChartTheme |
|
6 | 6 | { |
|
7 | 7 | public: |
|
8 | 8 | ChartThemeIcy():ChartTheme(QChart::ChartThemeIcy) |
|
9 | 9 | { |
|
10 | 10 | // Series |
|
11 | 11 | m_seriesColors << QRgb(0x0d2673); |
|
12 | 12 | m_seriesColors << QRgb(0x2685bf); |
|
13 | 13 | m_seriesColors << QRgb(0x3dadd9); |
|
14 | 14 | m_seriesColors << QRgb(0x62c3d9); |
|
15 | 15 | generateSeriesGradients(); |
|
16 | 16 | |
|
17 | 17 | // Background |
|
18 | 18 | QLinearGradient backgroundGradient; |
|
19 | 19 | backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); |
|
20 | 20 | backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); |
|
21 | 21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 |
m_ |
|
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
|
23 | 23 | |
|
24 | 24 | // Axes and other |
|
25 | 25 | m_masterFont = QFont(); |
|
26 | 26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
27 | 27 | m_axisLinePen.setWidth(2); |
|
28 | 28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
29 | 29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
30 | 30 | m_backgroundShadesPen = Qt::NoPen; |
|
31 | m_backgroundShades = BackgroundShadesNone; | |
|
31 | 32 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
32 | 33 | m_gridLinePen.setWidth(2); |
|
33 | 34 | } |
|
34 | 35 | }; |
|
35 | 36 | |
|
36 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,39 +1,39 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | class ChartThemeScientific: public ChartTheme |
|
6 | 6 | { |
|
7 | 7 | public: |
|
8 | 8 | ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) |
|
9 | 9 | { |
|
10 | 10 | // Series |
|
11 | 11 | m_seriesColors << QRgb(0xFFAD00); |
|
12 | 12 | m_seriesColors << QRgb(0x596A75); |
|
13 | 13 | m_seriesColors << QRgb(0x202020); |
|
14 | 14 | m_seriesColors << QRgb(0x474747); |
|
15 | 15 | generateSeriesGradients(); |
|
16 | 16 | |
|
17 | 17 | // Background |
|
18 | 18 | QLinearGradient backgroundGradient; |
|
19 | 19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); |
|
20 | 20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); |
|
21 | 21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 |
m_ |
|
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
|
23 | 23 | |
|
24 | 24 | // Axes and other |
|
25 | 25 | m_masterFont = QFont(); |
|
26 | 26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
27 | 27 | m_axisLinePen.setWidth(2); |
|
28 | 28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
29 | 29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
30 | 30 | m_backgroundShadesPen = Qt::NoPen; |
|
31 | 31 | // m_backgroundShadesBrush = QBrush(QColor(0x0f, 0x0f, 0x0f, 0x80)); |
|
32 | 32 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); |
|
33 | 33 | m_backgroundShades = BackgroundShadesHorizontal; |
|
34 | 34 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
35 | 35 | m_gridLinePen.setWidth(2); |
|
36 | 36 | } |
|
37 | 37 | }; |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,38 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | class ChartThemeVanilla: public ChartTheme |
|
6 | 6 | { |
|
7 | 7 | public: |
|
8 | 8 | ChartThemeVanilla():ChartTheme(QChart::ChartThemeVanilla) |
|
9 | 9 | { |
|
10 | 10 | // Series |
|
11 | 11 | m_seriesColors << QRgb(0xd9c574); |
|
12 | 12 | m_seriesColors << QRgb(0xd6a896); |
|
13 | 13 | m_seriesColors << QRgb(0xa0a071); |
|
14 | 14 | m_seriesColors << QRgb(0xd2d234); |
|
15 | 15 | m_seriesColors << QRgb(0x88723a); |
|
16 | 16 | generateSeriesGradients(); |
|
17 | 17 | |
|
18 | 18 | // Background |
|
19 | 19 | QLinearGradient backgroundGradient; |
|
20 | 20 | backgroundGradient.setColorAt(0.0, QRgb(0xfbf9f1)); |
|
21 | 21 | backgroundGradient.setColorAt(1.0, QRgb(0xf5f0dc)); |
|
22 | 22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
23 |
m_ |
|
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
|
24 | 24 | |
|
25 | 25 | // Axes and other |
|
26 | 26 | m_masterFont = QFont(); |
|
27 | 27 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
28 | 28 | m_axisLinePen.setWidth(2); |
|
29 | 29 | m_axisLabelBrush = QBrush(QRgb(0xa0a071)); |
|
30 | 30 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
31 | 31 | m_backgroundShadesPen = Qt::NoPen; |
|
32 | m_backgroundShades = BackgroundShadesNone; | |
|
32 | 33 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
33 | 34 | m_gridLinePen.setWidth(2); |
|
34 | 35 | } |
|
35 | 36 | }; |
|
36 | 37 | |
|
37 | 38 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now