##// END OF EJS Templates
Fix layouting in mapviewer
Michal Klocek -
r1964:f20e471e2754
parent child
Show More
@@ -1,583 +1,589
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 #include "charts.h"
24 24 #include <QChartView>
25 25 #include <QAreaSeries>
26 26 #include <QLegend>
27 27 #include <QGridLayout>
28 28 #include <QFormLayout>
29 29 #include <QComboBox>
30 30 #include <QSpinBox>
31 31 #include <QCheckBox>
32 32 #include <QGroupBox>
33 33 #include <QLabel>
34 34 #include <QGraphicsScene>
35 35 #include <QGraphicsGridLayout>
36 36 #include <QGraphicsLinearLayout>
37 37 #include <QGraphicsProxyWidget>
38 38 #include <QGLWidget>
39 39 #include <QApplication>
40 40 #include <QDebug>
41 41 #include <QMenu>
42 42
43 43 Window::Window(QWidget* parent) :
44 44 QMainWindow(parent),
45 45 m_listCount(3),
46 46 m_valueMax(10),
47 47 m_valueCount(7),
48 48 m_scene(new QGraphicsScene(this)),
49 49 m_view(0),
50 50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
51 51 m_form(0),
52 52 m_themeComboBox(0),
53 53 m_antialiasCheckBox(0),
54 54 m_animatedComboBox(0),
55 55 m_legendComboBox(0),
56 56 m_templateComboBox(0),
57 57 m_openGLCheckBox(0),
58 58 m_zoomCheckBox(0),
59 59 m_scrollCheckBox(0),
60 60 m_rubberBand(new QGraphicsRectItem()),
61 61 m_baseLayout(new QGraphicsGridLayout()),
62 62 m_menu(createMenu()),
63 63 m_state(NoState),
64 64 m_currentState(NoState),
65 65 m_template(0)
66 66 {
67 67 createProxyWidgets();
68 connectSignals();
69
70 68 // create layout
71 69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
72 70 settingsLayout->setOrientation(Qt::Vertical);
73 71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
74 72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
75 73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
76 74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
77 75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
78 76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
79 77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
80 78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
81 79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
82 80 settingsLayout->addItem(m_widgetHash["templateLabel"]);
83 81 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
84 82 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
85 83 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
86 84 settingsLayout->addStretch();
87 85 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
88 86
89 87 //create charts
90 88 Charts::ChartList list = Charts::chartList();
91 89
92 90 for (int i = 0; i < 9; ++i) {
93 91 QChart* chart = 0;
94 92 if(i<list.size()){
95 93 chart = list.at(i)->createChart(m_dataTable);
96 94 }else{
97 95 chart = new QChart();
98 96 chart->setTitle(tr("Empty"));
99 97 }
100 98
101 99 m_baseLayout->addItem(chart, i / 3, i % 3);
102 100 m_chartHash[chart] = i;
103 101 }
104 102
105 103 m_form = new QGraphicsWidget();
106 104 m_form->setLayout(m_baseLayout);
107 105 m_scene->addItem(m_form);
108 106 m_scene->addItem(m_rubberBand);
109 107 m_rubberBand->setVisible(false);
110 108
111 109 m_view = new View(m_scene, m_form);
112 m_view->setMinimumSize(m_form->preferredSize().toSize());
110 m_view->setMinimumSize(m_form->minimumSize().toSize());
113 111
114 112 // Set defaults
115 113 m_antialiasCheckBox->setChecked(true);
116 114 updateUI();
117 115 setCentralWidget(m_view);
116
117 connectSignals();
118 118 }
119 119
120 120 Window::~Window()
121 121 {
122 122 }
123 123
124 124 void Window::connectSignals()
125 125 {
126 QObject::connect(m_form, SIGNAL(geometryChanged()),this ,SLOT(handleGeometryChanged()));
126 127 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
127 128 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
128 129 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
129 130 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
130 131 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
131 132 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
132 133 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
133 134 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
134 135 }
135 136
136 137 void Window::createProxyWidgets()
137 138 {
138 139 m_themeComboBox = createThemeBox();
139 140 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
140 141 m_animatedComboBox = createAnimationBox();
141 142 m_legendComboBox = createLegendBox();
142 143 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
143 144 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
144 145 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
145 146 m_templateComboBox= createTempleteBox();
146 147 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
147 148 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
148 149 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
149 150 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
150 151 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
151 152 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
152 153 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
153 154 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
154 155 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
155 156 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
156 157 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
157 158 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
158 159
159 160 }
160 161
161 162 QComboBox* Window::createThemeBox()
162 163 {
163 164 QComboBox* themeComboBox = new ComboBox(this);
164 165 themeComboBox->addItem("Light", QChart::ChartThemeLight);
165 166 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
166 167 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
167 168 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
168 169 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
169 170 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
170 171 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
171 172 return themeComboBox;
172 173 }
173 174
174 175 QComboBox* Window::createAnimationBox()
175 176 {
176 177 QComboBox* animationComboBox = new ComboBox(this);
177 178 animationComboBox->addItem("No Animations", QChart::NoAnimation);
178 179 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
179 180 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
180 181 animationComboBox->addItem("All Animations", QChart::AllAnimations);
181 182 return animationComboBox;
182 183 }
183 184
184 185 QComboBox* Window::createLegendBox()
185 186 {
186 187 QComboBox* legendComboBox = new ComboBox(this);
187 188 legendComboBox->addItem("No Legend ", 0);
188 189 legendComboBox->addItem("Legend Top", Qt::AlignTop);
189 190 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
190 191 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
191 192 legendComboBox->addItem("Legend Right", Qt::AlignRight);
192 193 return legendComboBox;
193 194 }
194 195
195 196 QComboBox* Window::createTempleteBox()
196 197 {
197 198 QComboBox* templateComboBox = new ComboBox(this);
198 199 templateComboBox->addItem("No Template", 0);
199 200
200 201 Charts::ChartList list = Charts::chartList();
201 202 QMultiMap<QString, Chart*> categoryMap;
202 203
203 204 foreach(Chart* chart, list) {
204 205 categoryMap.insertMulti(chart->category(), chart);
205 206 }
206 207 foreach(const QString& category, categoryMap.uniqueKeys()) {
207 208 templateComboBox->addItem(category, category);
208 209 }
209 210 return templateComboBox;
210 211 }
211 212
212 213
213 214 void Window::updateUI()
214 215 {
215 216 checkTemplate();
216 217 checkOpenGL();
217 218 checkTheme();
218 219 checkAnimationOptions();
219 220 checkLegend();
220 221 checkState();
221 222 }
222 223
223 224 void Window::checkLegend()
224 225 {
225 226 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
226 227
227 228 if (!alignment) {
228 229 foreach (QChart *chart, m_chartHash.keys()) {
229 230 chart->legend()->hide();
230 231 }
231 232 }
232 233 else {
233 234 foreach (QChart *chart, m_chartHash.keys()) {
234 235 chart->legend()->setAlignment(alignment);
235 236 chart->legend()->show();
236 237 }
237 238 }
238 239 }
239 240
240 241 void Window::checkOpenGL()
241 242 {
242 243 bool opengl = m_openGLCheckBox->isChecked();
243 244 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
244 245 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
245 246 m_view->deleteLater();
246 247 m_view = new View(m_scene, m_form);
247 248 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
248 249 setCentralWidget(m_view);
249 250 }
250 251
251 252 bool antialias = m_antialiasCheckBox->isChecked();
252 253
253 254 if (opengl)
254 255 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
255 256 else
256 257 m_view->setRenderHint(QPainter::Antialiasing, antialias);
257 258 }
258 259
259 260 void Window::checkAnimationOptions()
260 261 {
261 262 QChart::AnimationOptions options(
262 263 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
263 264 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
264 265 foreach (QChart *chart, m_chartHash.keys())
265 266 chart->setAnimationOptions(options);
266 267 }
267 268 }
268 269
269 270 void Window::checkState()
270 271 {
271 272 bool scroll = m_scrollCheckBox->isChecked();
272 273
273 274 if (m_state != ScrollState && scroll) {
274 275 m_state = ScrollState;
275 276 m_zoomCheckBox->setChecked(false);
276 277 }
277 278 else if (!scroll && m_state == ScrollState) {
278 279 m_state = NoState;
279 280 }
280 281
281 282 bool zoom = m_zoomCheckBox->isChecked();
282 283
283 284 if (m_state != ZoomState && zoom) {
284 285 m_state = ZoomState;
285 286 m_scrollCheckBox->setChecked(false);
286 287 }
287 288 else if (!zoom && m_state == ZoomState) {
288 289 m_state = NoState;
289 290 }
290 291 }
291 292
292 293 void Window::checkTemplate()
293 294 {
294 295
295 296 int index = m_templateComboBox->currentIndex();
296 297 if (m_template == index || index == 0)
297 298 return;
298 299
299 300 m_template = index;
300 301
301 302 QString category = m_templateComboBox->itemData(index).toString();
302 303 Charts::ChartList list = Charts::chartList();
303 304
304 305 QList<QChart*> qchartList = m_chartHash.keys();
305 306
306 307 foreach(QChart* qchart,qchartList){
307 308 for(int i = 0 ; i < m_baseLayout->count();++i)
308 309 {
309 310 if(m_baseLayout->itemAt(i)==qchart){
310 311 m_baseLayout->removeAt(i);
311 312 break;
312 313 }
313 314 }
314 315 }
315 316
316 317 m_chartHash.clear();
317 318 qDeleteAll(qchartList);
318 319
319 320 QChart* qchart(0);
320 321
321 322 int j=0;
322 323 for (int i = 0; i < list.size(); ++i) {
323 324 Chart* chart = list.at(i);
324 325 if (chart->category() == category && j < 9) {
325 326 qchart = list.at(i)->createChart(m_dataTable);
326 327 m_baseLayout->addItem(qchart, j / 3, j % 3);
327 328 m_chartHash[qchart] = j;
328 329 j++;
329 330 }
330 331 }
331 332 for (; j < 9; ++j) {
332 333 qchart = new QChart();
333 334 qchart->setTitle(tr("Empty"));
334 335 m_baseLayout->addItem(qchart, j / 3, j % 3);
335 336 m_chartHash[qchart] = j;
336 337 }
337 338 m_baseLayout->activate();
338 339 }
339 340
340 341 void Window::checkTheme()
341 342 {
342 343 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
343 344 m_themeComboBox->currentIndex()).toInt();
344 345
345 346 foreach (QChart *chart, m_chartHash.keys())
346 347 chart->setTheme(theme);
347 348
348 349 QPalette pal = window()->palette();
349 350 if (theme == QChart::ChartThemeLight) {
350 351 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
351 352 pal.setColor(QPalette::WindowText, QRgb(0x404044));
352 353 }
353 354 else if (theme == QChart::ChartThemeDark) {
354 355 pal.setColor(QPalette::Window, QRgb(0x121218));
355 356 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
356 357 }
357 358 else if (theme == QChart::ChartThemeBlueCerulean) {
358 359 pal.setColor(QPalette::Window, QRgb(0x40434a));
359 360 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
360 361 }
361 362 else if (theme == QChart::ChartThemeBrownSand) {
362 363 pal.setColor(QPalette::Window, QRgb(0x9e8965));
363 364 pal.setColor(QPalette::WindowText, QRgb(0x404044));
364 365 }
365 366 else if (theme == QChart::ChartThemeBlueNcs) {
366 367 pal.setColor(QPalette::Window, QRgb(0x018bba));
367 368 pal.setColor(QPalette::WindowText, QRgb(0x404044));
368 369 }
369 370 else if (theme == QChart::ChartThemeHighContrast) {
370 371 pal.setColor(QPalette::Window, QRgb(0xffab03));
371 372 pal.setColor(QPalette::WindowText, QRgb(0x181818));
372 373 }
373 374 else if (theme == QChart::ChartThemeBlueIcy) {
374 375 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
375 376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
376 377 }
377 378 else {
378 379 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
379 380 pal.setColor(QPalette::WindowText, QRgb(0x404044));
380 381 }
381 382 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
382 383 widget->setPalette(pal);
383 384 }
384 385 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
385 386 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
386 387 }
387 388
388 389 void Window::mousePressEvent(QMouseEvent *event)
389 390 {
390 391 if (event->button() == Qt::LeftButton) {
391 392
392 393 m_origin = event->pos();
393 394 m_currentState = NoState;
394 395
395 396 foreach (QChart *chart, m_chartHash.keys()) {
396 397
397 398 QRectF geometryRect = chart->geometry();
398 399 QRectF plotArea = chart->plotArea();
399 400 plotArea.translate(geometryRect.topLeft());
400 401 if (plotArea.contains(m_origin)) {
401 402 m_currentState = m_state;
402 403
403 404 if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) {
404 405 handleMenu(chart);
405 406 }
406 407 break;
407 408 }
408 409 }
409 410
410 411 if (m_currentState == ZoomState) {
411 412 m_rubberBand->setRect(QRectF(m_origin, QSize()));
412 413 m_rubberBand->setVisible(true);
413 414 }
414 415
415 416 event->accept();
416 417 }
417 418
418 419 if (event->button() == Qt::RightButton) {
419 420 m_origin = event->pos();
420 421 m_currentState = m_state;
421 422 }
422 423 }
423 424
424 425 void Window::mouseMoveEvent(QMouseEvent *event)
425 426 {
426 427 if ( m_currentState != NoState) {
427 428
428 429 foreach (QChart *chart, m_chartHash.keys()) {
429 430
430 431 QRectF geometryRect = chart->geometry();
431 432 QRectF plotArea = chart->plotArea();
432 433 plotArea.translate(geometryRect.topLeft());
433 434
434 435 if (plotArea.contains(m_origin)) {
435 436 if (m_currentState == ScrollState) {
436 437 QPointF delta = m_origin - event->pos();
437 438 chart->scroll(delta.x(), -delta.y());
438 439 }
439 440 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
440 441 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
441 442 }
442 443 break;
443 444 }
444 445 }
445 446 if(m_currentState == ScrollState) m_origin = event->pos();
446 447 event->accept();
447 448 }
448 449 }
449 450
450 451 void Window::mouseReleaseEvent(QMouseEvent *event)
451 452 {
452 453 if (event->button() == Qt::LeftButton) {
453 454 if (m_currentState == ZoomState) {
454 455 m_rubberBand->setVisible(false);
455 456
456 457 foreach (QChart *chart, m_chartHash.keys()) {
457 458
458 459 QRectF geometryRect = chart->geometry();
459 460 QRectF plotArea = chart->plotArea();
460 461 plotArea.translate(geometryRect.topLeft());
461 462
462 463 if (plotArea.contains(m_origin)) {
463 464 QRectF rect = m_rubberBand->rect();
464 465 rect.translate(-geometryRect.topLeft());
465 466 chart->zoomIn(rect);
466 467 break;
467 468 }
468 469 }
469 470 }
470 471
471 472 m_currentState = NoState;
472 473 event->accept();
473 474 }
474 475
475 476 if (event->button() == Qt::RightButton) {
476 477
477 478 if (m_currentState == ZoomState) {
478 479 foreach (QChart *chart, m_chartHash.keys()) {
479 480
480 481 QRectF geometryRect = chart->geometry();
481 482 QRectF plotArea = chart->plotArea();
482 483 plotArea.translate(geometryRect.topLeft());
483 484
484 485 if (plotArea.contains(m_origin)) {
485 486 chart->zoomOut();
486 487 break;
487 488 }
488 489 }
489 490 }
490 491 }
491 492 }
492 493
493 494 void Window::comboBoxFocused(QComboBox *combobox)
494 495 {
495 496 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
496 497 if(widget->widget()==combobox)
497 498 widget->setZValue(2.0);
498 499 else
499 500 widget->setZValue(0.0);
500 501 }
501 502 }
502 503
503 504 void Window::handleMenu(QChart* qchart)
504 505 {
505 506 QAction *chosen = m_menu->exec(QCursor::pos());
506 507
507 508 if (chosen) {
508 509 Chart* chart = (Chart *) chosen->data().value<void *>();
509 510 int index = m_chartHash[qchart];
510 511 //not in 4.7.2 m_baseLayout->removeItem(qchart);
511 512 for(int i = 0 ; i < m_baseLayout->count();++i)
512 513 {
513 514 if(m_baseLayout->itemAt(i)==qchart){
514 515 m_baseLayout->removeAt(i);
515 516 break;
516 517 }
517 518 }
518 519
519 520 m_chartHash.remove(qchart);
520 521 QChart* newChart = chart->createChart(m_dataTable);
521 522 m_baseLayout->addItem(newChart, index / 3, index % 3);
522 523 m_chartHash[newChart] = index;
523 524 delete qchart;
524 525 updateUI();
525 526 }
526 527
527 528 }
528 529
529 530 QMenu* Window::createMenu()
530 531 {
531 532 Charts::ChartList list = Charts::chartList();
532 533 QMultiMap<QString, Chart*> categoryMap;
533 534
534 535 QMenu* result = new QMenu(this);
535 536
536 537 foreach(Chart* chart, list) {
537 538 categoryMap.insertMulti(chart->category(), chart);
538 539 }
539 540
540 541 foreach(const QString& category, categoryMap.uniqueKeys()) {
541 542 QMenu* menu(0);
542 543 QMultiMap<QString, Chart*> subCategoryMap;
543 544 if (category.isEmpty()) {
544 545 menu = result;
545 546 }
546 547 else {
547 548 menu = new QMenu(category, this);
548 549 result->addMenu(menu);
549 550 }
550 551
551 552 foreach(Chart* chart , categoryMap.values(category)) {
552 553 subCategoryMap.insert(chart->subCategory(), chart);
553 554 }
554 555
555 556 foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) {
556 557 QMenu* subMenu(0);
557 558 if (subCategory.isEmpty()) {
558 559 subMenu = menu;
559 560 }
560 561 else {
561 562 subMenu = new QMenu(subCategory, this);
562 563 menu->addMenu(subMenu);
563 564 }
564 565
565 566 foreach(Chart* chart , subCategoryMap.values(subCategory)) {
566 567
567 568 createMenuAction(subMenu, QIcon(), chart->name(),
568 569 qVariantFromValue((void *) chart));
569 570 }
570 571 }
571 572 }
572 573
573 574 return result;
574 575 }
575 576
576 577 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
577 578 const QVariant &data)
578 579 {
579 580 QAction *action = menu->addAction(icon, text);
580 581 action->setCheckable(false);
581 582 action->setData(data);
582 583 return action;
583 584 }
585
586 void Window::handleGeometryChanged()
587 {
588 m_view->scene()->setSceneRect(0, 0, this->width(), this->height());
589 }
@@ -1,123 +1,124
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 #ifndef WINDOW_H
22 22 #define WINDOW_H
23 23 #include "model.h"
24 24 #include <QMainWindow>
25 25 #include <QChartGlobal>
26 26 #include <QHash>
27 27 #include <QComboBox>
28 28
29 29 class QCheckBox;
30 30 class QGraphicsRectItem;
31 31 class QGraphicsScene;
32 32 class QGraphicsWidget;
33 33 class View;
34 34 class QGraphicsGridLayout;
35 35 class Chart;
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38 class QChart;
39 39 QTCOMMERCIALCHART_END_NAMESPACE
40 40
41 41 QTCOMMERCIALCHART_USE_NAMESPACE
42 42
43 43
44 44 class Window: public QMainWindow
45 45 {
46 46 Q_OBJECT
47 47 enum State{ NoState = 0, ZoomState, ScrollState};
48 48 public:
49 49 explicit Window(QWidget *parent = 0);
50 50 ~Window();
51 51
52 52 private Q_SLOTS:
53 53 void updateUI();
54 void handleGeometryChanged();
54 55 private:
55 56 QComboBox* createThemeBox();
56 57 QComboBox* createAnimationBox();
57 58 QComboBox* createLegendBox();
58 59 QComboBox* createTempleteBox();
59 60 void connectSignals();
60 61 void createProxyWidgets();
61 62 void comboBoxFocused(QComboBox *combox);
62 63 inline void checkAnimationOptions();
63 64 inline void checkLegend();
64 65 inline void checkOpenGL();
65 66 inline void checkTheme();
66 67 inline void checkState();
67 68 inline void checkTemplate();
68 69 QMenu* createMenu();
69 70 void handleMenu(QChart * chart);
70 71 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
71 72
72 73 protected:
73 74 void mousePressEvent(QMouseEvent *event);
74 75 void mouseMoveEvent(QMouseEvent *event);
75 76 void mouseReleaseEvent(QMouseEvent *event);
76 77
77 78 private:
78 79 int m_listCount;
79 80 int m_valueMax;
80 81 int m_valueCount;
81 82 QGraphicsScene* m_scene;
82 83 View* m_view;
83 84 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
84 85 QHash<QChart*, int> m_chartHash;
85 86 DataTable m_dataTable;
86 87
87 88 QGraphicsWidget *m_form;
88 89 QComboBox *m_themeComboBox;
89 90 QCheckBox *m_antialiasCheckBox;
90 91 QComboBox *m_animatedComboBox;
91 92 QComboBox *m_legendComboBox;
92 93 QComboBox *m_templateComboBox;
93 94 QCheckBox *m_openGLCheckBox;
94 95 QCheckBox *m_zoomCheckBox;
95 96 QCheckBox *m_scrollCheckBox;
96 97 QPoint m_origin;
97 98 QGraphicsRectItem* m_rubberBand;
98 99 QGraphicsGridLayout* m_baseLayout;
99 100 QMenu* m_menu;
100 101 State m_state;
101 102 State m_currentState;
102 103 int m_template;
103 104
104 105 friend class ComboBox;
105 106 };
106 107
107 108 class ComboBox: public QComboBox
108 109 {
109 110 public:
110 111 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
111 112 {}
112 113
113 114 protected:
114 115 void focusInEvent(QFocusEvent *e)
115 116 {
116 117 QComboBox::focusInEvent(e);
117 118 m_window->comboBoxFocused(this);
118 119 }
119 120 private:
120 121 Window* m_window;
121 122 };
122 123
123 124 #endif
General Comments 0
You need to be logged in to leave comments. Login now