##// END OF EJS Templates
Adds charts create selection to chartviewer
Michal Klocek -
r1840:8077b9f83c91
parent child
Show More
@@ -1,41 +1,42
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef VIEW_H_
21 #ifndef VIEW_H_
22 #define VIEW_H_
22 #define VIEW_H_
23 #include <QGraphicsView>
23 #include <QGraphicsView>
24
24
25 class QGraphicsScene;
25 class QGraphicsScene;
26 class QResizeEvent;
26 class QResizeEvent;
27
27
28 class View: public QGraphicsView
28 class View: public QGraphicsView
29 {
29 {
30 public:
30 public:
31 View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0);
31 View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0);
32
32
33 protected:
33 protected:
34 void resizeEvent(QResizeEvent *event);
34 void resizeEvent(QResizeEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
37
37 private:
38 private:
38 QGraphicsWidget *m_form;
39 QGraphicsWidget *m_form;
39 };
40 };
40
41
41 #endif
42 #endif
@@ -1,392 +1,450
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "window.h"
21 #include "window.h"
22 #include "view.h"
22 #include "view.h"
23 #include "charts.h"
23 #include "charts.h"
24 #include <QChartView>
24 #include <QChartView>
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QGridLayout>
27 #include <QGridLayout>
28 #include <QFormLayout>
28 #include <QFormLayout>
29 #include <QComboBox>
29 #include <QComboBox>
30 #include <QSpinBox>
30 #include <QSpinBox>
31 #include <QCheckBox>
31 #include <QCheckBox>
32 #include <QGroupBox>
32 #include <QGroupBox>
33 #include <QLabel>
33 #include <QLabel>
34 #include <QGraphicsScene>
34 #include <QGraphicsScene>
35 #include <QGraphicsGridLayout>
35 #include <QGraphicsGridLayout>
36 #include <QGraphicsLinearLayout>
36 #include <QGraphicsLinearLayout>
37 #include <QGraphicsProxyWidget>
37 #include <QGraphicsProxyWidget>
38 #include <QGLWidget>
38 #include <QGLWidget>
39 #include <QApplication>
39 #include <QApplication>
40 #include <QDebug>
40 #include <QDebug>
41 #include <QMenu>
41
42
42 Window::Window(QWidget* parent) :
43 Window::Window(QWidget* parent) :
43 QMainWindow(parent),
44 QMainWindow(parent),
44 m_listCount(3),
45 m_listCount(3),
45 m_valueMax(10),
46 m_valueMax(10),
46 m_valueCount(7),
47 m_valueCount(7),
47 m_scene(new QGraphicsScene(this)),
48 m_scene(new QGraphicsScene(this)),
48 m_view(0),
49 m_view(0),
49 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
50 m_form(0),
51 m_form(0),
51 m_themeComboBox(0),
52 m_themeComboBox(0),
52 m_antialiasCheckBox(0),
53 m_antialiasCheckBox(0),
53 m_animatedComboBox(0),
54 m_animatedComboBox(0),
54 m_legendComboBox(0),
55 m_legendComboBox(0),
55 m_openGLCheckBox(0),
56 m_openGLCheckBox(0),
56 m_zoomCheckBox(0),
57 m_zoomCheckBox(0),
57 m_scrollCheckBox(0),
58 m_scrollCheckBox(0),
58 m_rubberBand(new QGraphicsRectItem()),
59 m_rubberBand(new QGraphicsRectItem()),
59 m_isScrolling(false),
60 m_baseLayout(new QGraphicsGridLayout()),
60 m_isZooming(false),
61 m_menu(new QMenu(this)),
61 m_scroll(false),
62 m_state(NoState),
62 m_zoom(false)
63 m_currentState(NoState)
63 {
64 {
64 createProxyWidgets();
65 createProxyWidgets();
65 connectSignals();
66 connectSignals();
66
67
67 // create layout
68 // create layout
68 QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout();
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
69 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
70 settingsLayout->setOrientation(Qt::Vertical);
70 settingsLayout->setOrientation(Qt::Vertical);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
71 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
72 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
73 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
74 settingsLayout->addItem(m_widgetHash["themeLabel"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
75 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
76 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
77 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
78 settingsLayout->addItem(m_widgetHash["legendLabel"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
79 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
80 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
80 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
82 settingsLayout->addStretch();
82 settingsLayout->addStretch();
83 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
83 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
84
84 //create charts
85 //create charts
85 Charts::ChartList list = Charts::chartList();
86 Charts::ChartList list = Charts::chartList();
86
87
87 for(int i = 0 ; i < 9 && i<list.size() ; ++i)
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
88 {
89 QChart* chart = list.at(i)->createChart(m_dataTable);
89 QChart* chart = list.at(i)->createChart(m_dataTable);
90 baseLayout->addItem(chart, i/3, i%3);
90 m_baseLayout->addItem(chart, i / 3, i % 3);
91 m_chartList << chart;
91 m_chartHash[chart] = i;
92 }
93
94 foreach(Chart* chart, list) {
95 createMenuAction(m_menu, QIcon(), chart->name(), qVariantFromValue((void *) chart));
92 }
96 }
93
97
94 m_form = new QGraphicsWidget();
98 m_form = new QGraphicsWidget();
95 m_form->setLayout(baseLayout);
99 m_form->setLayout(m_baseLayout);
96 m_scene->addItem(m_form);
100 m_scene->addItem(m_form);
97 m_scene->addItem(m_rubberBand);
101 m_scene->addItem(m_rubberBand);
98 m_rubberBand->setVisible(false);
102 m_rubberBand->setVisible(false);
99
103
100 m_view = new View(m_scene, m_form);
104 m_view = new View(m_scene, m_form);
101 m_view->setMinimumSize(m_form->preferredSize().toSize());
105 m_view->setMinimumSize(m_form->preferredSize().toSize());
102
106
103 // Set defaults
107 // Set defaults
104 m_antialiasCheckBox->setChecked(true);
108 m_antialiasCheckBox->setChecked(true);
105 updateUI();
109 updateUI();
106 setCentralWidget(m_view);
110 setCentralWidget(m_view);
107 }
111 }
108
112
109 Window::~Window()
113 Window::~Window()
110 {
114 {
111 }
115 }
112
116
113 void Window::connectSignals()
117 void Window::connectSignals()
114 {
118 {
115 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
119 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
117 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
121 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
118 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
122 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
119 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
123 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
124 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
121 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
122 }
126 }
123
127
124 void Window::createProxyWidgets()
128 void Window::createProxyWidgets()
125 {
129 {
126 m_themeComboBox = createThemeBox();
130 m_themeComboBox = createThemeBox();
127 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
128 m_animatedComboBox = createAnimationBox();
132 m_animatedComboBox = createAnimationBox();
129 m_legendComboBox = createLegendBox();
133 m_legendComboBox = createLegendBox();
130 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
131 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
132 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
133 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
137 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
134 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
138 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
135 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
139 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
136 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
140 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
137 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
141 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
138 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
142 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
139 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
143 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
140 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
144 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
141 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
145 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
142 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
146 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
143 }
147 }
144
148
145 QComboBox* Window::createThemeBox()
149 QComboBox* Window::createThemeBox()
146 {
150 {
147 QComboBox* themeComboBox = new ComboBox(this);
151 QComboBox* themeComboBox = new ComboBox(this);
148 themeComboBox->addItem("Light", QChart::ChartThemeLight);
152 themeComboBox->addItem("Light", QChart::ChartThemeLight);
149 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
153 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
150 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
154 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
151 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
155 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
152 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
156 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
153 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
157 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
154 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
158 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
155 return themeComboBox;
159 return themeComboBox;
156 }
160 }
157
161
158 QComboBox* Window::createAnimationBox()
162 QComboBox* Window::createAnimationBox()
159 {
163 {
160 QComboBox* animationComboBox = new ComboBox(this);
164 QComboBox* animationComboBox = new ComboBox(this);
161 animationComboBox->addItem("No Animations", QChart::NoAnimation);
165 animationComboBox->addItem("No Animations", QChart::NoAnimation);
162 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
166 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
163 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
167 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
164 animationComboBox->addItem("All Animations", QChart::AllAnimations);
168 animationComboBox->addItem("All Animations", QChart::AllAnimations);
165 return animationComboBox;
169 return animationComboBox;
166 }
170 }
167
171
168 QComboBox* Window::createLegendBox()
172 QComboBox* Window::createLegendBox()
169 {
173 {
170 QComboBox* legendComboBox = new ComboBox(this);
174 QComboBox* legendComboBox = new ComboBox(this);
171 legendComboBox->addItem("No Legend ", 0);
175 legendComboBox->addItem("No Legend ", 0);
172 legendComboBox->addItem("Legend Top", Qt::AlignTop);
176 legendComboBox->addItem("Legend Top", Qt::AlignTop);
173 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
177 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
174 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
178 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
175 legendComboBox->addItem("Legend Right", Qt::AlignRight);
179 legendComboBox->addItem("Legend Right", Qt::AlignRight);
176 return legendComboBox;
180 return legendComboBox;
177 }
181 }
178
182
179 void Window::updateUI()
183 void Window::updateUI()
180 {
184 {
185 checkOpenGL();
186 checkTheme();
187 checkAnimationOptions();
188 checkLegend();
189 checkState();
190 }
191
192 void Window::checkLegend()
193 {
194 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
195
196 if (!alignment) {
197 foreach (QChart *chart, m_chartHash.keys()) {
198 chart->legend()->hide();
199 }
200 }
201 else {
202 foreach (QChart *chart, m_chartHash.keys()) {
203 chart->legend()->setAlignment(alignment);
204 chart->legend()->show();
205 }
206 }
207 }
208
209 void Window::checkOpenGL()
210 {
181 bool opengl = m_openGLCheckBox->isChecked();
211 bool opengl = m_openGLCheckBox->isChecked();
182 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
212 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
183 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
213 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
184 m_view->deleteLater();
214 m_view->deleteLater();
185 m_view = new View(m_scene, m_form);
215 m_view = new View(m_scene, m_form);
186 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
216 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
187 setCentralWidget(m_view);
217 setCentralWidget(m_view);
188 }
218 }
189
219
220 bool antialias = m_antialiasCheckBox->isChecked();
221
222 if (opengl)
223 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
224 else
225 m_view->setRenderHint(QPainter::Antialiasing, antialias);
226 }
227
228 void Window::checkAnimationOptions()
229 {
230 QChart::AnimationOptions options(
231 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
232 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
233 foreach (QChart *chart, m_chartHash.keys())
234 chart->setAnimationOptions(options);
235 }
236 }
237
238 void Window::checkState()
239 {
240 bool scroll = m_scrollCheckBox->isChecked();
241
242 if (m_state != ScrollState && scroll) {
243 m_state = ScrollState;
244 m_zoomCheckBox->setChecked(false);
245 }
246 else if (!scroll && m_state == ScrollState) {
247 m_state = NoState;
248 }
249
250 bool zoom = m_zoomCheckBox->isChecked();
251
252 if (m_state != ZoomState && zoom) {
253 m_state = ZoomState;
254 m_scrollCheckBox->setChecked(false);
255 }
256 else if (!zoom && m_state == ZoomState) {
257 m_state = NoState;
258 }
259 }
260
261 void Window::checkTheme()
262 {
190 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
263 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
191 m_themeComboBox->currentIndex()).toInt();
264 m_themeComboBox->currentIndex()).toInt();
192
265
193 foreach (QChart *chart, m_chartList)
266 foreach (QChart *chart, m_chartHash.keys())
194 chart->setTheme(theme);
267 chart->setTheme(theme);
195
268
196 QPalette pal = window()->palette();
269 QPalette pal = window()->palette();
197 if (theme == QChart::ChartThemeLight) {
270 if (theme == QChart::ChartThemeLight) {
198 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
271 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
199 pal.setColor(QPalette::WindowText, QRgb(0x404044));
272 pal.setColor(QPalette::WindowText, QRgb(0x404044));
200 }
273 }
201 else if (theme == QChart::ChartThemeDark) {
274 else if (theme == QChart::ChartThemeDark) {
202 pal.setColor(QPalette::Window, QRgb(0x121218));
275 pal.setColor(QPalette::Window, QRgb(0x121218));
203 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
276 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
204 }
277 }
205 else if (theme == QChart::ChartThemeBlueCerulean) {
278 else if (theme == QChart::ChartThemeBlueCerulean) {
206 pal.setColor(QPalette::Window, QRgb(0x40434a));
279 pal.setColor(QPalette::Window, QRgb(0x40434a));
207 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
280 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
208 }
281 }
209 else if (theme == QChart::ChartThemeBrownSand) {
282 else if (theme == QChart::ChartThemeBrownSand) {
210 pal.setColor(QPalette::Window, QRgb(0x9e8965));
283 pal.setColor(QPalette::Window, QRgb(0x9e8965));
211 pal.setColor(QPalette::WindowText, QRgb(0x404044));
284 pal.setColor(QPalette::WindowText, QRgb(0x404044));
212 }
285 }
213 else if (theme == QChart::ChartThemeBlueNcs) {
286 else if (theme == QChart::ChartThemeBlueNcs) {
214 pal.setColor(QPalette::Window, QRgb(0x018bba));
287 pal.setColor(QPalette::Window, QRgb(0x018bba));
215 pal.setColor(QPalette::WindowText, QRgb(0x404044));
288 pal.setColor(QPalette::WindowText, QRgb(0x404044));
216 }
289 }
217 else if (theme == QChart::ChartThemeHighContrast) {
290 else if (theme == QChart::ChartThemeHighContrast) {
218 pal.setColor(QPalette::Window, QRgb(0xffab03));
291 pal.setColor(QPalette::Window, QRgb(0xffab03));
219 pal.setColor(QPalette::WindowText, QRgb(0x181818));
292 pal.setColor(QPalette::WindowText, QRgb(0x181818));
220 }
293 }
221 else if (theme == QChart::ChartThemeBlueIcy) {
294 else if (theme == QChart::ChartThemeBlueIcy) {
222 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
295 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
223 pal.setColor(QPalette::WindowText, QRgb(0x404044));
296 pal.setColor(QPalette::WindowText, QRgb(0x404044));
224 }
297 }
225 else {
298 else {
226 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
299 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
227 pal.setColor(QPalette::WindowText, QRgb(0x404044));
300 pal.setColor(QPalette::WindowText, QRgb(0x404044));
228 }
301 }
229 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
302 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
230 widget->setPalette(pal);
303 widget->setPalette(pal);
231 }
304 }
232 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
305 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
233 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
306 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
234
235 QChart::AnimationOptions options(
236 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
237 if (!m_chartList.isEmpty() && m_chartList.at(0)->animationOptions() != options) {
238 foreach (QChart *chart, m_chartList)
239 chart->setAnimationOptions(options);
240 }
241
242 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
243
244 if (!alignment) {
245 foreach (QChart *chart, m_chartList) {
246 chart->legend()->hide();
247 }
248 }
249 else {
250 foreach (QChart *chart, m_chartList) {
251 chart->legend()->setAlignment(alignment);
252 chart->legend()->show();
253 }
254 }
255
256 bool antialias = m_antialiasCheckBox->isChecked();
257
258 if (opengl)
259 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
260 else
261 m_view->setRenderHint(QPainter::Antialiasing, antialias);
262
263 bool scroll = m_scrollCheckBox->isChecked();
264
265 if(!m_scroll & scroll){
266 m_scroll=true;
267 m_zoom=false;
268 m_zoomCheckBox->setChecked(false);
269 }
270
271 bool zoom = m_zoomCheckBox->isChecked();
272
273 if(!m_zoom & zoom){
274 m_scroll=false;
275 m_zoom=true;
276 m_scrollCheckBox->setChecked(false);
277 }
278
279 }
307 }
280
308
281 void Window::mousePressEvent(QMouseEvent *event)
309 void Window::mousePressEvent(QMouseEvent *event)
282 {
310 {
283 if (event->button() == Qt::LeftButton) {
311 if (event->button() == Qt::LeftButton) {
284
312
285 m_origin = event->pos();
313 m_origin = event->pos();
286 m_isScrolling = false;
314 m_currentState = NoState;
287 m_isZooming = false;
288
315
289 foreach (QChart *chart, m_chartList) {
316 foreach (QChart *chart, m_chartHash.keys()) {
290
317
291 QRectF geometryRect = chart->geometry();
318 QRectF geometryRect = chart->geometry();
292 QRectF plotArea = chart->plotArea();
319 QRectF plotArea = chart->plotArea();
293 plotArea.translate(geometryRect.topLeft());
320 plotArea.translate(geometryRect.topLeft());
294 if (plotArea.contains(m_origin)) {
321 if (plotArea.contains(m_origin)) {
295 m_isScrolling = m_scroll;
322 m_currentState = m_state;
296 m_isZooming = m_zoom;
323
324 if (m_currentState == NoState) {
325 showMenu(chart);
326 }
297 break;
327 break;
298 }
328 }
299 }
329 }
300
330
301 if (m_isZooming) {
331 if (m_currentState == ZoomState) {
302 m_rubberBand->setRect(QRectF(m_origin, QSize()));
332 m_rubberBand->setRect(QRectF(m_origin, QSize()));
303 m_rubberBand->setVisible(true);
333 m_rubberBand->setVisible(true);
304 }
334 }
335
305 event->accept();
336 event->accept();
306 }
337 }
307
338
308 if (event->button() == Qt::RightButton) {
339 if (event->button() == Qt::RightButton) {
309 m_origin = event->pos();
340 m_origin = event->pos();
310 m_isZooming = m_zoom;
341 m_currentState = m_state;
311 }
342 }
312 }
343 }
313
344
314 void Window::mouseMoveEvent(QMouseEvent *event)
345 void Window::mouseMoveEvent(QMouseEvent *event)
315 {
346 {
316 if (m_isScrolling || m_isZooming) {
347 if ( m_currentState != NoState) {
317
348
318 foreach (QChart *chart, m_chartList) {
349 foreach (QChart *chart, m_chartHash.keys()) {
319
350
320 QRectF geometryRect = chart->geometry();
351 QRectF geometryRect = chart->geometry();
321 QRectF plotArea = chart->plotArea();
352 QRectF plotArea = chart->plotArea();
322 plotArea.translate(geometryRect.topLeft());
353 plotArea.translate(geometryRect.topLeft());
323
354
324 if (plotArea.contains(m_origin)) {
355 if (plotArea.contains(m_origin)) {
325 if (m_isScrolling) {
356 if (m_currentState == ScrollState) {
326 QPointF delta = m_origin - event->pos();
357 QPointF delta = m_origin - event->pos();
327 chart->scroll(delta.x(), -delta.y());
358 chart->scroll(delta.x(), -delta.y());
328 }
359 }
329 if (m_isZooming && plotArea.contains(event->pos())) {
360 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
330 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
361 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
331 }
362 }
332 break;
363 break;
333 }
364 }
334 }
365 }
335 if(m_isScrolling) m_origin = event->pos();
366 if(m_currentState == ScrollState) m_origin = event->pos();
336 event->accept();
367 event->accept();
337 }
368 }
338 }
369 }
339
370
340 void Window::mouseReleaseEvent(QMouseEvent *event)
371 void Window::mouseReleaseEvent(QMouseEvent *event)
341 {
372 {
342 if (event->button() == Qt::LeftButton) {
373 if (event->button() == Qt::LeftButton) {
343 m_isScrolling = false;
374 if (m_currentState == ZoomState) {
344 if (m_isZooming) {
345 m_isZooming = false;
346 m_rubberBand->setVisible(false);
375 m_rubberBand->setVisible(false);
347
376
348 foreach (QChart *chart, m_chartList) {
377 foreach (QChart *chart, m_chartHash.keys()) {
349
378
350 QRectF geometryRect = chart->geometry();
379 QRectF geometryRect = chart->geometry();
351 QRectF plotArea = chart->plotArea();
380 QRectF plotArea = chart->plotArea();
352 plotArea.translate(geometryRect.topLeft());
381 plotArea.translate(geometryRect.topLeft());
353
382
354 if (plotArea.contains(m_origin)) {
383 if (plotArea.contains(m_origin)) {
355 QRectF rect = m_rubberBand->rect();
384 QRectF rect = m_rubberBand->rect();
356 rect.translate(-geometryRect.topLeft());
385 rect.translate(-geometryRect.topLeft());
357 chart->zoomIn(rect);
386 chart->zoomIn(rect);
358 break;
387 break;
359 }
388 }
360 }
389 }
361 }
390 }
391
392 m_currentState = NoState;
362 event->accept();
393 event->accept();
363 }
394 }
364
395
365 if (event->button() == Qt::RightButton) {
396 if (event->button() == Qt::RightButton) {
366
397
367 if (m_isZooming) {
398 if (m_currentState == ZoomState) {
368 foreach (QChart *chart, m_chartList) {
399 foreach (QChart *chart, m_chartHash.keys()) {
369
400
370 QRectF geometryRect = chart->geometry();
401 QRectF geometryRect = chart->geometry();
371 QRectF plotArea = chart->plotArea();
402 QRectF plotArea = chart->plotArea();
372 plotArea.translate(geometryRect.topLeft());
403 plotArea.translate(geometryRect.topLeft());
373
404
374 if (plotArea.contains(m_origin)) {
405 if (plotArea.contains(m_origin)) {
375 QRectF rect = m_rubberBand->rect();
406 QRectF rect = m_rubberBand->rect();
376 chart->zoomOut();
407 chart->zoomOut();
377 break;
408 break;
378 }
409 }
379 }
410 }
380 }
411 }
381 }
412 }
382 }
413 }
383
414
384 void Window::comboBoxFocused(QComboBox *combobox)
415 void Window::comboBoxFocused(QComboBox *combobox)
385 {
416 {
386 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
417 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
387 if(widget->widget()==combobox)
418 if(widget->widget()==combobox)
388 widget->setZValue(2.0);
419 widget->setZValue(2.0);
389 else
420 else
390 widget->setZValue(0.0);
421 widget->setZValue(0.0);
391 }
422 }
392 }
423 }
424
425 void Window::showMenu(QChart* qchart)
426 {
427 QAction *chosen = m_menu->exec(QCursor::pos());
428
429 if (chosen) {
430 Chart* chart = (Chart *) chosen->data().value<void *>();
431 int index = m_chartHash[qchart];
432 m_baseLayout->removeItem(qchart);
433 m_chartHash.remove(qchart);
434 QChart* newChart = chart->createChart(m_dataTable);
435 m_baseLayout->addItem(newChart, index / 3, index % 3);
436 m_chartHash[newChart] = index;
437 delete qchart;
438 updateUI();
439 }
440
441 }
442
443 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
444 const QVariant &data)
445 {
446 QAction *action = menu->addAction(icon, text);
447 action->setCheckable(false);
448 action->setData(data);
449 return action;
450 }
@@ -1,110 +1,118
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef WINDOW_H_
21 #ifndef WINDOW_H_
22 #define WINDOW_H_
22 #define WINDOW_H_
23 #include "model.h"
23 #include "model.h"
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <QChartGlobal>
25 #include <QChartGlobal>
26 #include <QHash>
26 #include <QHash>
27 #include <QComboBox>
27 #include <QComboBox>
28
28
29 class QCheckBox;
29 class QCheckBox;
30 class QGraphicsRectItem;
30 class QGraphicsRectItem;
31 class QGraphicsScene;
31 class QGraphicsScene;
32 class QGraphicsWidget;
32 class QGraphicsWidget;
33 class View;
33 class View;
34 class QGraphicsGridLayout;
35 class Chart;
34
36
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 class QChart;
38 class QChart;
37 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
38
40
39 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
40
42
41
43
42 class Window: public QMainWindow
44 class Window: public QMainWindow
43 {
45 {
44 Q_OBJECT
46 Q_OBJECT
47 enum State{ NoState = 0, ZoomState, ScrollState};
45 public:
48 public:
46 explicit Window(QWidget *parent = 0);
49 explicit Window(QWidget *parent = 0);
47 ~Window();
50 ~Window();
48
51
49 private Q_SLOTS:
52 private Q_SLOTS:
50 void updateUI();
53 void updateUI();
51 private:
54 private:
52 QComboBox* createThemeBox();
55 QComboBox* createThemeBox();
53 QComboBox* createAnimationBox();
56 QComboBox* createAnimationBox();
54 QComboBox* createLegendBox();
57 QComboBox* createLegendBox();
55 void connectSignals();
58 void connectSignals();
56 void createProxyWidgets();
59 void createProxyWidgets();
57 void comboBoxFocused(QComboBox *combox);
60 void comboBoxFocused(QComboBox *combox);
61 inline void checkAnimationOptions();
62 inline void checkLegend();
63 inline void checkOpenGL();
64 inline void checkTheme();
65 inline void checkState();
66 void showMenu(QChart * chart);
67 QAction* createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
58
68
59 protected:
69 protected:
60 void mousePressEvent(QMouseEvent *event);
70 void mousePressEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
71 void mouseMoveEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
72 void mouseReleaseEvent(QMouseEvent *event);
63
73
64
65 private:
74 private:
66 int m_listCount;
75 int m_listCount;
67 int m_valueMax;
76 int m_valueMax;
68 int m_valueCount;
77 int m_valueCount;
69 QGraphicsScene* m_scene;
78 QGraphicsScene* m_scene;
70 View* m_view;
79 View* m_view;
71 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
80 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
72 QList<QChart*> m_chartList;
81 QHash<QChart*, int> m_chartHash;
73 DataTable m_dataTable;
82 DataTable m_dataTable;
74
83
75 QGraphicsWidget *m_form;
84 QGraphicsWidget *m_form;
76 QComboBox *m_themeComboBox;
85 QComboBox *m_themeComboBox;
77 QCheckBox *m_antialiasCheckBox;
86 QCheckBox *m_antialiasCheckBox;
78 QComboBox *m_animatedComboBox;
87 QComboBox *m_animatedComboBox;
79 QComboBox *m_legendComboBox;
88 QComboBox *m_legendComboBox;
80 QCheckBox *m_openGLCheckBox;
89 QCheckBox *m_openGLCheckBox;
81 QCheckBox *m_zoomCheckBox;
90 QCheckBox *m_zoomCheckBox;
82 QCheckBox *m_scrollCheckBox;
91 QCheckBox *m_scrollCheckBox;
83 QPoint m_origin;
92 QPoint m_origin;
84 QGraphicsRectItem* m_rubberBand;
93 QGraphicsRectItem* m_rubberBand;
85
94 QGraphicsGridLayout* m_baseLayout;
86 bool m_isScrolling;
95 QMenu* m_menu;
87 bool m_isZooming;
96 State m_state;
88 bool m_scroll;
97 State m_currentState;
89 bool m_zoom;
90
98
91 friend class ComboBox;
99 friend class ComboBox;
92 };
100 };
93
101
94 class ComboBox: public QComboBox
102 class ComboBox: public QComboBox
95 {
103 {
96 public:
104 public:
97 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
105 ComboBox(Window* window,QWidget *parent = 0):QComboBox(parent),m_window(window)
98 {}
106 {}
99
107
100 protected:
108 protected:
101 void focusInEvent(QFocusEvent *e)
109 void focusInEvent(QFocusEvent *e)
102 {
110 {
103 QComboBox::focusInEvent(e);
111 QComboBox::focusInEvent(e);
104 m_window->comboBoxFocused(this);
112 m_window->comboBoxFocused(this);
105 }
113 }
106 private:
114 private:
107 Window* m_window;
115 Window* m_window;
108 };
116 };
109
117
110 #endif
118 #endif
General Comments 0
You need to be logged in to leave comments. Login now