@@ -1,584 +1,585 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "window.h" |
|
22 | 22 | #include "view.h" |
|
23 | 23 | |
|
24 | 24 | #include <QChartView> |
|
25 | 25 | #include <QPieSeries> |
|
26 | 26 | #include <QPieSlice> |
|
27 | 27 | #include <QPercentBarSeries> |
|
28 | 28 | #include <QStackedBarSeries> |
|
29 | 29 | #include <QBarSeries> |
|
30 | 30 | #include <QBarSet> |
|
31 | 31 | #include <QLineSeries> |
|
32 | 32 | #include <QSplineSeries> |
|
33 | 33 | #include <QScatterSeries> |
|
34 | 34 | #include <QAreaSeries> |
|
35 | 35 | #include <QLegend> |
|
36 | 36 | #include <QGridLayout> |
|
37 | 37 | #include <QFormLayout> |
|
38 | 38 | #include <QComboBox> |
|
39 | 39 | #include <QSpinBox> |
|
40 | 40 | #include <QCheckBox> |
|
41 | 41 | #include <QGroupBox> |
|
42 | 42 | #include <QLabel> |
|
43 | 43 | #include <QTime> |
|
44 | 44 | #include <QBarCategoriesAxis> |
|
45 | 45 | #include <QGraphicsScene> |
|
46 | 46 | #include <QGraphicsGridLayout> |
|
47 | 47 | #include <QGraphicsLinearLayout> |
|
48 | 48 | #include <QGraphicsProxyWidget> |
|
49 | 49 | #include <QGLWidget> |
|
50 | 50 | #include <QApplication> |
|
51 | 51 | #include <QDebug> |
|
52 | 52 | |
|
53 | 53 | Window::Window(QWidget* parent) : |
|
54 | 54 | QMainWindow(parent), |
|
55 | 55 | m_listCount(3), |
|
56 | 56 | m_valueMax(10), |
|
57 | 57 | m_valueCount(7), |
|
58 | 58 | m_scene(new QGraphicsScene(this)), |
|
59 | 59 | m_view(0), |
|
60 | 60 | m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)), |
|
61 | 61 | m_form(0), |
|
62 | 62 | m_themeComboBox(0), |
|
63 | 63 | m_antialiasCheckBox(0), |
|
64 | 64 | m_animatedComboBox(0), |
|
65 | 65 | m_legendComboBox(0), |
|
66 | 66 | m_openGLCheckBox(0), |
|
67 | 67 | m_zoomCheckBox(0), |
|
68 | 68 | m_scrollCheckBox(0), |
|
69 | 69 | m_rubberBand(new QGraphicsRectItem()), |
|
70 | 70 | m_isScrolling(false), |
|
71 | 71 | m_isZooming(false), |
|
72 | 72 | m_scroll(false), |
|
73 | 73 | m_zoom(false) |
|
74 | 74 | { |
|
75 | 75 | createProxyWidgets(); |
|
76 | 76 | connectSignals(); |
|
77 | 77 | |
|
78 | 78 | // create layout |
|
79 | 79 | QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout(); |
|
80 | 80 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
81 | 81 | settingsLayout->setOrientation(Qt::Vertical); |
|
82 | 82 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
83 | 83 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
84 | 84 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
85 | 85 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
86 | 86 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
87 | 87 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
|
88 | 88 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
|
89 | 89 | settingsLayout->addItem(m_widgetHash["legendLabel"]); |
|
90 | 90 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
|
91 | 91 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
92 | 92 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
93 | 93 | settingsLayout->addStretch(); |
|
94 | 94 | baseLayout->addItem(settingsLayout, 0, 3, 2, 1); |
|
95 | 95 | //create charts |
|
96 | 96 | |
|
97 | 97 | int i = m_widgetHash.count(); |
|
98 | 98 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
99 | 99 | widget->setZValue(i--); |
|
100 | 100 | widget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | QChart* chart; |
|
104 | 104 | |
|
105 | 105 | chart = createAreaChart(); |
|
106 | 106 | baseLayout->addItem(chart, 0, 0); |
|
107 | 107 | m_chartList << chart; |
|
108 | 108 | |
|
109 | 109 | chart = createBarChart(m_valueCount); |
|
110 | 110 | baseLayout->addItem(chart, 0, 1); |
|
111 | 111 | m_chartList << chart; |
|
112 | 112 | |
|
113 | 113 | chart = createLineChart(); |
|
114 | 114 | baseLayout->addItem(chart, 0, 2); |
|
115 | 115 | m_chartList << chart; |
|
116 | 116 | |
|
117 | 117 | chart = createPieChart(); |
|
118 | 118 | baseLayout->addItem(chart, 1, 0); |
|
119 | 119 | m_chartList << chart; |
|
120 | 120 | |
|
121 | 121 | chart = createSplineChart(); |
|
122 | 122 | baseLayout->addItem(chart, 1, 1); |
|
123 | 123 | m_chartList << chart; |
|
124 | 124 | |
|
125 | 125 | chart = createScatterChart(); |
|
126 | 126 | baseLayout->addItem(chart, 1, 2); |
|
127 | 127 | m_chartList << chart; |
|
128 | 128 | |
|
129 | 129 | m_form = new QGraphicsWidget(); |
|
130 | 130 | m_form->setLayout(baseLayout); |
|
131 | 131 | m_scene->addItem(m_form); |
|
132 | 132 | m_scene->addItem(m_rubberBand); |
|
133 | 133 | m_rubberBand->setVisible(false); |
|
134 | 134 | |
|
135 | 135 | m_view = new View(m_scene, m_form); |
|
136 | 136 | m_view->setMinimumSize(m_form->preferredSize().toSize()); |
|
137 | 137 | |
|
138 | 138 | // Set defaults |
|
139 | 139 | m_antialiasCheckBox->setChecked(true); |
|
140 | 140 | updateUI(); |
|
141 | 141 | setCentralWidget(m_view); |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | Window::~Window() |
|
145 | 145 | { |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | 148 | void Window::connectSignals() |
|
149 | 149 | { |
|
150 | 150 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
151 | 151 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
152 | 152 | connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
153 | 153 | connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
154 | 154 | connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
155 | 155 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
156 | 156 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | DataTable Window::generateRandomData(int listCount, int valueMax, int valueCount) const |
|
160 | 160 | { |
|
161 | 161 | DataTable dataTable; |
|
162 | 162 | |
|
163 | 163 | // set seed for random stuff |
|
164 | 164 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
165 | 165 | |
|
166 | 166 | // generate random data |
|
167 | 167 | for (int i(0); i < listCount; i++) { |
|
168 | 168 | DataList dataList; |
|
169 | 169 | qreal yValue(0); |
|
170 | 170 | for (int j(0); j < valueCount; j++) { |
|
171 | 171 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
172 | 172 | QPointF value( |
|
173 | 173 | (j + (qreal) qrand() / (qreal) RAND_MAX) |
|
174 | 174 | * ((qreal) m_valueMax / (qreal) valueCount), yValue); |
|
175 | 175 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
176 | 176 | dataList << Data(value, label); |
|
177 | 177 | } |
|
178 | 178 | dataTable << dataList; |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | return dataTable; |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void Window::createProxyWidgets() |
|
185 | 185 | { |
|
186 | 186 | m_themeComboBox = createThemeBox(); |
|
187 | 187 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
188 | 188 | m_animatedComboBox = createAnimationBox(); |
|
189 | 189 | m_legendComboBox = createLegendBox(); |
|
190 | 190 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
191 | 191 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
192 | 192 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
193 | 193 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
194 | 194 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
195 | 195 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
196 | 196 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
|
197 | 197 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
|
198 | 198 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
|
199 | 199 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
|
200 | 200 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
|
201 | 201 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
202 | 202 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | QComboBox* Window::createThemeBox() const |
|
206 | 206 | { |
|
207 | 207 | // settings layoutQGLWidgetβ |
|
208 | 208 | QComboBox* themeComboBox = new QComboBox(); |
|
209 | 209 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
210 | 210 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
211 | 211 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
212 | 212 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
213 | 213 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
214 | 214 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
215 | 215 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
216 | 216 | return themeComboBox; |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | QComboBox* Window::createAnimationBox() const |
|
220 | 220 | { |
|
221 | 221 | // settings layout |
|
222 | 222 | QComboBox* animationComboBox = new QComboBox(); |
|
223 | 223 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
224 | 224 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
225 | 225 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
226 | 226 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
227 | 227 | return animationComboBox; |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | QComboBox* Window::createLegendBox() const |
|
231 | 231 | { |
|
232 | 232 | QComboBox* legendComboBox = new QComboBox(); |
|
233 | 233 | legendComboBox->addItem("No Legend ", 0); |
|
234 | 234 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
235 | 235 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
236 | 236 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
237 | 237 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
238 | 238 | return legendComboBox; |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | QChart* Window::createAreaChart() const |
|
242 | 242 | { |
|
243 | 243 | QChart *chart = new QChart(); |
|
244 | 244 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
245 | 245 | // chart->axisY()->setNiceNumbersEnabled(true); |
|
246 | 246 | chart->setTitle("Area chart"); |
|
247 | 247 | |
|
248 | 248 | // The lower series initialized to zero values |
|
249 | 249 | QLineSeries *lowerSeries = 0; |
|
250 | 250 | QString name("Series "); |
|
251 | 251 | int nameIndex = 0; |
|
252 | 252 | for (int i(0); i < m_dataTable.count(); i++) { |
|
253 | 253 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
254 | 254 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
255 | 255 | Data data = m_dataTable[i].at(j); |
|
256 | 256 | if (lowerSeries) { |
|
257 | 257 | const QList<QPointF>& points = lowerSeries->points(); |
|
258 | 258 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
259 | 259 | } |
|
260 | 260 | else |
|
261 | 261 | upperSeries->append(QPointF(j, data.first.y())); |
|
262 | 262 | } |
|
263 | 263 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
264 | 264 | area->setName(name + QString::number(nameIndex)); |
|
265 | 265 | nameIndex++; |
|
266 | 266 | chart->addSeries(area); |
|
267 | 267 | chart->createDefaultAxes(); |
|
268 | 268 | lowerSeries = upperSeries; |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | return chart; |
|
272 | 272 | } |
|
273 | 273 | |
|
274 | 274 | QChart* Window::createBarChart(int valueCount) const |
|
275 | 275 | { |
|
276 | 276 | Q_UNUSED(valueCount); |
|
277 | 277 | QChart* chart = new QChart(); |
|
278 | 278 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
279 | 279 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
280 | 280 | chart->setTitle("Bar chart"); |
|
281 | 281 | |
|
282 | 282 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
283 | 283 | for (int i(0); i < m_dataTable.count(); i++) { |
|
284 | 284 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
285 | 285 | foreach (Data data, m_dataTable[i]) |
|
286 | 286 | *set << data.first.y(); |
|
287 | 287 | series->append(set); |
|
288 | 288 | } |
|
289 | 289 | chart->addSeries(series); |
|
290 | 290 | chart->createDefaultAxes(); |
|
291 | 291 | |
|
292 | 292 | return chart; |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | QChart* Window::createLineChart() const |
|
296 | 296 | { |
|
297 | 297 | QChart* chart = new QChart(); |
|
298 | 298 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
299 | 299 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
300 | 300 | chart->setTitle("Line chart"); |
|
301 | 301 | |
|
302 | 302 | QString name("Series "); |
|
303 | 303 | int nameIndex = 0; |
|
304 | 304 | foreach (DataList list, m_dataTable) { |
|
305 | 305 | QLineSeries *series = new QLineSeries(chart); |
|
306 | 306 | foreach (Data data, list) |
|
307 | 307 | series->append(data.first); |
|
308 | 308 | series->setName(name + QString::number(nameIndex)); |
|
309 | 309 | nameIndex++; |
|
310 | 310 | chart->addSeries(series); |
|
311 | 311 | } |
|
312 | 312 | chart->createDefaultAxes(); |
|
313 | 313 | |
|
314 | 314 | return chart; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | QChart* Window::createPieChart() const |
|
318 | 318 | { |
|
319 | 319 | QChart* chart = new QChart(); |
|
320 | 320 | chart->setTitle("Pie chart"); |
|
321 | 321 | |
|
322 | 322 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
323 | 323 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
324 | 324 | QPieSeries *series = new QPieSeries(chart); |
|
325 | 325 | foreach (Data data, m_dataTable[i]) { |
|
326 | 326 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
327 | 327 | if (data == m_dataTable[i].first()) { |
|
328 | 328 | slice->setLabelVisible(); |
|
329 | 329 | slice->setExploded(); |
|
330 | 330 | } |
|
331 | 331 | } |
|
332 | 332 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
333 | 333 | series->setPieSize(pieSize); |
|
334 | 334 | series->setHorizontalPosition(hPos); |
|
335 | 335 | series->setVerticalPosition(0.5); |
|
336 | 336 | chart->addSeries(series); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | return chart; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | QChart* Window::createSplineChart() const |
|
343 | 343 | { |
|
344 | 344 | QChart* chart = new QChart(); |
|
345 | 345 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
346 | 346 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
347 | 347 | chart->setTitle("Spline chart"); |
|
348 | 348 | QString name("Series "); |
|
349 | 349 | int nameIndex = 0; |
|
350 | 350 | foreach (DataList list, m_dataTable) { |
|
351 | 351 | QSplineSeries *series = new QSplineSeries(chart); |
|
352 | 352 | foreach (Data data, list) |
|
353 | 353 | series->append(data.first); |
|
354 | 354 | series->setName(name + QString::number(nameIndex)); |
|
355 | 355 | nameIndex++; |
|
356 | 356 | chart->addSeries(series); |
|
357 | 357 | } |
|
358 | 358 | chart->createDefaultAxes(); |
|
359 | 359 | return chart; |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | QChart* Window::createScatterChart() const |
|
363 | 363 | { |
|
364 | 364 | QChart* chart = new QChart(); |
|
365 | 365 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
366 | 366 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
367 | 367 | chart->setTitle("Scatter chart"); |
|
368 | 368 | QString name("Series "); |
|
369 | 369 | int nameIndex = 0; |
|
370 | 370 | foreach (DataList list, m_dataTable) { |
|
371 | 371 | QScatterSeries *series = new QScatterSeries(chart); |
|
372 | 372 | foreach (Data data, list) |
|
373 | 373 | series->append(data.first); |
|
374 | 374 | series->setName(name + QString::number(nameIndex)); |
|
375 | 375 | nameIndex++; |
|
376 | 376 | chart->addSeries(series); |
|
377 | 377 | } |
|
378 | 378 | chart->createDefaultAxes(); |
|
379 | 379 | return chart; |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | void Window::updateUI() |
|
383 | 383 | { |
|
384 | 384 | bool opengl = m_openGLCheckBox->isChecked(); |
|
385 | 385 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); |
|
386 | 386 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
387 | 387 | m_view->deleteLater(); |
|
388 | 388 | m_view = new View(m_scene, m_form); |
|
389 | 389 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); |
|
390 | 390 | setCentralWidget(m_view); |
|
391 | 391 | } |
|
392 | 392 | |
|
393 | 393 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
394 | 394 | m_themeComboBox->currentIndex()).toInt(); |
|
395 | 395 | |
|
396 | 396 | foreach (QChart *chart, m_chartList) |
|
397 | 397 | chart->setTheme(theme); |
|
398 | 398 | |
|
399 | 399 | QPalette pal = window()->palette(); |
|
400 | 400 | if (theme == QChart::ChartThemeLight) { |
|
401 | 401 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
402 | 402 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
403 | 403 | } |
|
404 | 404 | else if (theme == QChart::ChartThemeDark) { |
|
405 | 405 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
406 | 406 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
407 | 407 | } |
|
408 | 408 | else if (theme == QChart::ChartThemeBlueCerulean) { |
|
409 | 409 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
410 | 410 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
411 | 411 | } |
|
412 | 412 | else if (theme == QChart::ChartThemeBrownSand) { |
|
413 | 413 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
414 | 414 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
415 | 415 | } |
|
416 | 416 | else if (theme == QChart::ChartThemeBlueNcs) { |
|
417 | 417 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
418 | 418 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
419 | 419 | } |
|
420 | 420 | else if (theme == QChart::ChartThemeHighContrast) { |
|
421 | 421 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
422 | 422 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
423 | 423 | } |
|
424 | 424 | else if (theme == QChart::ChartThemeBlueIcy) { |
|
425 | 425 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
426 | 426 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
427 | 427 | } |
|
428 | 428 | else { |
|
429 | 429 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
430 | 430 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
431 | 431 | } |
|
432 | 432 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
433 | 433 | widget->setPalette(pal); |
|
434 | 434 | } |
|
435 | 435 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
436 | 436 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); |
|
437 | 437 | |
|
438 | 438 | QChart::AnimationOptions options( |
|
439 | 439 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
440 | 440 | if (m_chartList.at(0)->animationOptions() != options) { |
|
441 | 441 | foreach (QChart *chart, m_chartList) |
|
442 | 442 | chart->setAnimationOptions(options); |
|
443 | 443 | } |
|
444 | 444 | |
|
445 | 445 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
446 | 446 | |
|
447 | 447 | if (!alignment) { |
|
448 | 448 | foreach (QChart *chart, m_chartList) { |
|
449 | 449 | chart->legend()->hide(); |
|
450 | 450 | } |
|
451 | 451 | } |
|
452 | 452 | else { |
|
453 | 453 | foreach (QChart *chart, m_chartList) { |
|
454 | 454 | chart->legend()->setAlignment(alignment); |
|
455 | 455 | chart->legend()->show(); |
|
456 | 456 | } |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
460 | 460 | |
|
461 | 461 | if (opengl) |
|
462 | 462 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); |
|
463 | 463 | else |
|
464 | 464 | m_view->setRenderHint(QPainter::Antialiasing, antialias); |
|
465 | 465 | |
|
466 | 466 | bool scroll = m_scrollCheckBox->isChecked(); |
|
467 | 467 | |
|
468 | 468 | if(!m_scroll & scroll){ |
|
469 | 469 | m_scroll=true; |
|
470 | 470 | m_zoom=false; |
|
471 | 471 | m_zoomCheckBox->setChecked(false); |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | bool zoom = m_zoomCheckBox->isChecked(); |
|
475 | 475 | |
|
476 | 476 | if(!m_zoom & zoom){ |
|
477 | 477 | m_scroll=false; |
|
478 | 478 | m_zoom=true; |
|
479 | 479 | m_scrollCheckBox->setChecked(false); |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | } |
|
483 | 483 | |
|
484 | 484 | void Window::mousePressEvent(QMouseEvent *event) |
|
485 | 485 | { |
|
486 | 486 | if (event->button() == Qt::LeftButton) { |
|
487 | 487 | |
|
488 | 488 | m_origin = event->pos(); |
|
489 | 489 | m_isScrolling = false; |
|
490 | 490 | m_isZooming = false; |
|
491 | 491 | |
|
492 | 492 | foreach (QChart *chart, m_chartList) { |
|
493 | 493 | |
|
494 | 494 | QRectF geometryRect = chart->geometry(); |
|
495 | 495 | QRectF plotArea = chart->plotArea(); |
|
496 | 496 | plotArea.translate(geometryRect.topLeft()); |
|
497 | 497 | if (plotArea.contains(m_origin)) { |
|
498 | 498 | m_isScrolling = m_scroll; |
|
499 | 499 | m_isZooming = m_zoom; |
|
500 | 500 | break; |
|
501 | 501 | } |
|
502 | 502 | } |
|
503 | 503 | |
|
504 | 504 | if (m_isZooming) { |
|
505 | 505 | m_rubberBand->setRect(QRectF(m_origin, QSize())); |
|
506 | 506 | m_rubberBand->setVisible(true); |
|
507 | 507 | } |
|
508 | 508 | event->accept(); |
|
509 | 509 | } |
|
510 | 510 | |
|
511 | 511 | if (event->button() == Qt::RightButton) { |
|
512 | 512 | m_origin = event->pos(); |
|
513 | 513 | m_isZooming = m_zoom; |
|
514 | 514 | } |
|
515 | 515 | } |
|
516 | 516 | |
|
517 | 517 | void Window::mouseMoveEvent(QMouseEvent *event) |
|
518 | 518 | { |
|
519 | 519 | if (m_isScrolling || m_isZooming) { |
|
520 | 520 | |
|
521 | 521 | foreach (QChart *chart, m_chartList) { |
|
522 | 522 | |
|
523 | 523 | QRectF geometryRect = chart->geometry(); |
|
524 | 524 | QRectF plotArea = chart->plotArea(); |
|
525 | 525 | plotArea.translate(geometryRect.topLeft()); |
|
526 | 526 | |
|
527 | 527 | if (plotArea.contains(m_origin)) { |
|
528 | 528 | if (m_isScrolling) { |
|
529 | 529 | QPointF delta = m_origin - event->pos(); |
|
530 | 530 | chart->scroll(delta.x(), -delta.y()); |
|
531 | 531 | } |
|
532 | 532 | if (m_isZooming && plotArea.contains(event->pos())) { |
|
533 | 533 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
534 | 534 | } |
|
535 | 535 | break; |
|
536 | 536 | } |
|
537 | 537 | } |
|
538 | 538 | if(m_isScrolling) m_origin = event->pos(); |
|
539 | 539 | event->accept(); |
|
540 | 540 | } |
|
541 | 541 | } |
|
542 | 542 | |
|
543 | 543 | void Window::mouseReleaseEvent(QMouseEvent *event) |
|
544 | 544 | { |
|
545 | 545 | if (event->button() == Qt::LeftButton) { |
|
546 | 546 | m_isScrolling = false; |
|
547 | 547 | if (m_isZooming) { |
|
548 | 548 | m_isZooming = false; |
|
549 | 549 | m_rubberBand->setVisible(false); |
|
550 | 550 | |
|
551 | 551 | foreach (QChart *chart, m_chartList) { |
|
552 | 552 | |
|
553 | 553 | QRectF geometryRect = chart->geometry(); |
|
554 | 554 | QRectF plotArea = chart->plotArea(); |
|
555 | 555 | plotArea.translate(geometryRect.topLeft()); |
|
556 | 556 | |
|
557 | 557 | if (plotArea.contains(m_origin)) { |
|
558 | 558 | QRectF rect = m_rubberBand->rect(); |
|
559 | rect.translate(-geometryRect.topLeft()); | |
|
559 | 560 | chart->zoomIn(rect); |
|
560 | 561 | break; |
|
561 | 562 | } |
|
562 | 563 | } |
|
563 | 564 | } |
|
564 | 565 | event->accept(); |
|
565 | 566 | } |
|
566 | 567 | |
|
567 | 568 | if (event->button() == Qt::RightButton) { |
|
568 | 569 | |
|
569 | 570 | if (m_isZooming) { |
|
570 | 571 | foreach (QChart *chart, m_chartList) { |
|
571 | 572 | |
|
572 | 573 | QRectF geometryRect = chart->geometry(); |
|
573 | 574 | QRectF plotArea = chart->plotArea(); |
|
574 | 575 | plotArea.translate(geometryRect.topLeft()); |
|
575 | 576 | |
|
576 | 577 | if (plotArea.contains(m_origin)) { |
|
577 | 578 | QRectF rect = m_rubberBand->rect(); |
|
578 | 579 | chart->zoomOut(); |
|
579 | 580 | break; |
|
580 | 581 | } |
|
581 | 582 | } |
|
582 | 583 | } |
|
583 | 584 | } |
|
584 | 585 | } |
General Comments 0
You need to be logged in to leave comments.
Login now