##// END OF EJS Templates
Compiltion fix for 4.7.2
Michal Klocek -
r1853:d57474518199
parent child
Show More
@@ -1,450 +1,458
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 #include <QMenu>
42
42
43 Window::Window(QWidget* parent) :
43 Window::Window(QWidget* parent) :
44 QMainWindow(parent),
44 QMainWindow(parent),
45 m_listCount(3),
45 m_listCount(3),
46 m_valueMax(10),
46 m_valueMax(10),
47 m_valueCount(7),
47 m_valueCount(7),
48 m_scene(new QGraphicsScene(this)),
48 m_scene(new QGraphicsScene(this)),
49 m_view(0),
49 m_view(0),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
51 m_form(0),
51 m_form(0),
52 m_themeComboBox(0),
52 m_themeComboBox(0),
53 m_antialiasCheckBox(0),
53 m_antialiasCheckBox(0),
54 m_animatedComboBox(0),
54 m_animatedComboBox(0),
55 m_legendComboBox(0),
55 m_legendComboBox(0),
56 m_openGLCheckBox(0),
56 m_openGLCheckBox(0),
57 m_zoomCheckBox(0),
57 m_zoomCheckBox(0),
58 m_scrollCheckBox(0),
58 m_scrollCheckBox(0),
59 m_rubberBand(new QGraphicsRectItem()),
59 m_rubberBand(new QGraphicsRectItem()),
60 m_baseLayout(new QGraphicsGridLayout()),
60 m_baseLayout(new QGraphicsGridLayout()),
61 m_menu(new QMenu(this)),
61 m_menu(new QMenu(this)),
62 m_state(NoState),
62 m_state(NoState),
63 m_currentState(NoState)
63 m_currentState(NoState)
64 {
64 {
65 createProxyWidgets();
65 createProxyWidgets();
66 connectSignals();
66 connectSignals();
67
67
68 // create layout
68 // create layout
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 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
83 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
84
84
85 //create charts
85 //create charts
86 Charts::ChartList list = Charts::chartList();
86 Charts::ChartList list = Charts::chartList();
87
87
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
88 for (int i = 0; i < 9 && i < list.size(); ++i) {
89 QChart* chart = list.at(i)->createChart(m_dataTable);
89 QChart* chart = list.at(i)->createChart(m_dataTable);
90 m_baseLayout->addItem(chart, i / 3, i % 3);
90 m_baseLayout->addItem(chart, i / 3, i % 3);
91 m_chartHash[chart] = i;
91 m_chartHash[chart] = i;
92 }
92 }
93
93
94 foreach(Chart* chart, list) {
94 foreach(Chart* chart, list) {
95 createMenuAction(m_menu, QIcon(), chart->name(), qVariantFromValue((void *) chart));
95 createMenuAction(m_menu, QIcon(), chart->name(), qVariantFromValue((void *) chart));
96 }
96 }
97
97
98 m_form = new QGraphicsWidget();
98 m_form = new QGraphicsWidget();
99 m_form->setLayout(m_baseLayout);
99 m_form->setLayout(m_baseLayout);
100 m_scene->addItem(m_form);
100 m_scene->addItem(m_form);
101 m_scene->addItem(m_rubberBand);
101 m_scene->addItem(m_rubberBand);
102 m_rubberBand->setVisible(false);
102 m_rubberBand->setVisible(false);
103
103
104 m_view = new View(m_scene, m_form);
104 m_view = new View(m_scene, m_form);
105 m_view->setMinimumSize(m_form->preferredSize().toSize());
105 m_view->setMinimumSize(m_form->preferredSize().toSize());
106
106
107 // Set defaults
107 // Set defaults
108 m_antialiasCheckBox->setChecked(true);
108 m_antialiasCheckBox->setChecked(true);
109 updateUI();
109 updateUI();
110 setCentralWidget(m_view);
110 setCentralWidget(m_view);
111 }
111 }
112
112
113 Window::~Window()
113 Window::~Window()
114 {
114 {
115 }
115 }
116
116
117 void Window::connectSignals()
117 void Window::connectSignals()
118 {
118 {
119 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
119 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
120 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
121 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
121 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
122 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
122 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
123 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
123 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
124 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
124 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
126 }
126 }
127
127
128 void Window::createProxyWidgets()
128 void Window::createProxyWidgets()
129 {
129 {
130 m_themeComboBox = createThemeBox();
130 m_themeComboBox = createThemeBox();
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
132 m_animatedComboBox = createAnimationBox();
132 m_animatedComboBox = createAnimationBox();
133 m_legendComboBox = createLegendBox();
133 m_legendComboBox = createLegendBox();
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
137 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
137 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
138 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
138 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
139 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
139 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
140 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
140 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
141 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
141 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
142 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
142 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
143 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
143 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
144 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
144 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
145 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
145 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
146 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
146 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
147 }
147 }
148
148
149 QComboBox* Window::createThemeBox()
149 QComboBox* Window::createThemeBox()
150 {
150 {
151 QComboBox* themeComboBox = new ComboBox(this);
151 QComboBox* themeComboBox = new ComboBox(this);
152 themeComboBox->addItem("Light", QChart::ChartThemeLight);
152 themeComboBox->addItem("Light", QChart::ChartThemeLight);
153 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
153 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
154 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
154 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
155 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
155 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
156 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
156 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
157 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
157 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
158 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
158 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
159 return themeComboBox;
159 return themeComboBox;
160 }
160 }
161
161
162 QComboBox* Window::createAnimationBox()
162 QComboBox* Window::createAnimationBox()
163 {
163 {
164 QComboBox* animationComboBox = new ComboBox(this);
164 QComboBox* animationComboBox = new ComboBox(this);
165 animationComboBox->addItem("No Animations", QChart::NoAnimation);
165 animationComboBox->addItem("No Animations", QChart::NoAnimation);
166 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
166 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
167 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
167 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
168 animationComboBox->addItem("All Animations", QChart::AllAnimations);
168 animationComboBox->addItem("All Animations", QChart::AllAnimations);
169 return animationComboBox;
169 return animationComboBox;
170 }
170 }
171
171
172 QComboBox* Window::createLegendBox()
172 QComboBox* Window::createLegendBox()
173 {
173 {
174 QComboBox* legendComboBox = new ComboBox(this);
174 QComboBox* legendComboBox = new ComboBox(this);
175 legendComboBox->addItem("No Legend ", 0);
175 legendComboBox->addItem("No Legend ", 0);
176 legendComboBox->addItem("Legend Top", Qt::AlignTop);
176 legendComboBox->addItem("Legend Top", Qt::AlignTop);
177 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
177 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
178 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
178 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
179 legendComboBox->addItem("Legend Right", Qt::AlignRight);
179 legendComboBox->addItem("Legend Right", Qt::AlignRight);
180 return legendComboBox;
180 return legendComboBox;
181 }
181 }
182
182
183 void Window::updateUI()
183 void Window::updateUI()
184 {
184 {
185 checkOpenGL();
185 checkOpenGL();
186 checkTheme();
186 checkTheme();
187 checkAnimationOptions();
187 checkAnimationOptions();
188 checkLegend();
188 checkLegend();
189 checkState();
189 checkState();
190 }
190 }
191
191
192 void Window::checkLegend()
192 void Window::checkLegend()
193 {
193 {
194 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
194 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
195
195
196 if (!alignment) {
196 if (!alignment) {
197 foreach (QChart *chart, m_chartHash.keys()) {
197 foreach (QChart *chart, m_chartHash.keys()) {
198 chart->legend()->hide();
198 chart->legend()->hide();
199 }
199 }
200 }
200 }
201 else {
201 else {
202 foreach (QChart *chart, m_chartHash.keys()) {
202 foreach (QChart *chart, m_chartHash.keys()) {
203 chart->legend()->setAlignment(alignment);
203 chart->legend()->setAlignment(alignment);
204 chart->legend()->show();
204 chart->legend()->show();
205 }
205 }
206 }
206 }
207 }
207 }
208
208
209 void Window::checkOpenGL()
209 void Window::checkOpenGL()
210 {
210 {
211 bool opengl = m_openGLCheckBox->isChecked();
211 bool opengl = m_openGLCheckBox->isChecked();
212 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
212 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
213 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
213 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
214 m_view->deleteLater();
214 m_view->deleteLater();
215 m_view = new View(m_scene, m_form);
215 m_view = new View(m_scene, m_form);
216 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
216 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
217 setCentralWidget(m_view);
217 setCentralWidget(m_view);
218 }
218 }
219
219
220 bool antialias = m_antialiasCheckBox->isChecked();
220 bool antialias = m_antialiasCheckBox->isChecked();
221
221
222 if (opengl)
222 if (opengl)
223 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
223 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
224 else
224 else
225 m_view->setRenderHint(QPainter::Antialiasing, antialias);
225 m_view->setRenderHint(QPainter::Antialiasing, antialias);
226 }
226 }
227
227
228 void Window::checkAnimationOptions()
228 void Window::checkAnimationOptions()
229 {
229 {
230 QChart::AnimationOptions options(
230 QChart::AnimationOptions options(
231 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
231 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
232 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
232 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
233 foreach (QChart *chart, m_chartHash.keys())
233 foreach (QChart *chart, m_chartHash.keys())
234 chart->setAnimationOptions(options);
234 chart->setAnimationOptions(options);
235 }
235 }
236 }
236 }
237
237
238 void Window::checkState()
238 void Window::checkState()
239 {
239 {
240 bool scroll = m_scrollCheckBox->isChecked();
240 bool scroll = m_scrollCheckBox->isChecked();
241
241
242 if (m_state != ScrollState && scroll) {
242 if (m_state != ScrollState && scroll) {
243 m_state = ScrollState;
243 m_state = ScrollState;
244 m_zoomCheckBox->setChecked(false);
244 m_zoomCheckBox->setChecked(false);
245 }
245 }
246 else if (!scroll && m_state == ScrollState) {
246 else if (!scroll && m_state == ScrollState) {
247 m_state = NoState;
247 m_state = NoState;
248 }
248 }
249
249
250 bool zoom = m_zoomCheckBox->isChecked();
250 bool zoom = m_zoomCheckBox->isChecked();
251
251
252 if (m_state != ZoomState && zoom) {
252 if (m_state != ZoomState && zoom) {
253 m_state = ZoomState;
253 m_state = ZoomState;
254 m_scrollCheckBox->setChecked(false);
254 m_scrollCheckBox->setChecked(false);
255 }
255 }
256 else if (!zoom && m_state == ZoomState) {
256 else if (!zoom && m_state == ZoomState) {
257 m_state = NoState;
257 m_state = NoState;
258 }
258 }
259 }
259 }
260
260
261 void Window::checkTheme()
261 void Window::checkTheme()
262 {
262 {
263 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
263 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
264 m_themeComboBox->currentIndex()).toInt();
264 m_themeComboBox->currentIndex()).toInt();
265
265
266 foreach (QChart *chart, m_chartHash.keys())
266 foreach (QChart *chart, m_chartHash.keys())
267 chart->setTheme(theme);
267 chart->setTheme(theme);
268
268
269 QPalette pal = window()->palette();
269 QPalette pal = window()->palette();
270 if (theme == QChart::ChartThemeLight) {
270 if (theme == QChart::ChartThemeLight) {
271 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
271 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
272 pal.setColor(QPalette::WindowText, QRgb(0x404044));
272 pal.setColor(QPalette::WindowText, QRgb(0x404044));
273 }
273 }
274 else if (theme == QChart::ChartThemeDark) {
274 else if (theme == QChart::ChartThemeDark) {
275 pal.setColor(QPalette::Window, QRgb(0x121218));
275 pal.setColor(QPalette::Window, QRgb(0x121218));
276 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
276 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
277 }
277 }
278 else if (theme == QChart::ChartThemeBlueCerulean) {
278 else if (theme == QChart::ChartThemeBlueCerulean) {
279 pal.setColor(QPalette::Window, QRgb(0x40434a));
279 pal.setColor(QPalette::Window, QRgb(0x40434a));
280 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
280 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
281 }
281 }
282 else if (theme == QChart::ChartThemeBrownSand) {
282 else if (theme == QChart::ChartThemeBrownSand) {
283 pal.setColor(QPalette::Window, QRgb(0x9e8965));
283 pal.setColor(QPalette::Window, QRgb(0x9e8965));
284 pal.setColor(QPalette::WindowText, QRgb(0x404044));
284 pal.setColor(QPalette::WindowText, QRgb(0x404044));
285 }
285 }
286 else if (theme == QChart::ChartThemeBlueNcs) {
286 else if (theme == QChart::ChartThemeBlueNcs) {
287 pal.setColor(QPalette::Window, QRgb(0x018bba));
287 pal.setColor(QPalette::Window, QRgb(0x018bba));
288 pal.setColor(QPalette::WindowText, QRgb(0x404044));
288 pal.setColor(QPalette::WindowText, QRgb(0x404044));
289 }
289 }
290 else if (theme == QChart::ChartThemeHighContrast) {
290 else if (theme == QChart::ChartThemeHighContrast) {
291 pal.setColor(QPalette::Window, QRgb(0xffab03));
291 pal.setColor(QPalette::Window, QRgb(0xffab03));
292 pal.setColor(QPalette::WindowText, QRgb(0x181818));
292 pal.setColor(QPalette::WindowText, QRgb(0x181818));
293 }
293 }
294 else if (theme == QChart::ChartThemeBlueIcy) {
294 else if (theme == QChart::ChartThemeBlueIcy) {
295 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
295 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
296 pal.setColor(QPalette::WindowText, QRgb(0x404044));
296 pal.setColor(QPalette::WindowText, QRgb(0x404044));
297 }
297 }
298 else {
298 else {
299 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
299 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
300 pal.setColor(QPalette::WindowText, QRgb(0x404044));
300 pal.setColor(QPalette::WindowText, QRgb(0x404044));
301 }
301 }
302 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
302 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
303 widget->setPalette(pal);
303 widget->setPalette(pal);
304 }
304 }
305 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
305 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
306 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
306 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
307 }
307 }
308
308
309 void Window::mousePressEvent(QMouseEvent *event)
309 void Window::mousePressEvent(QMouseEvent *event)
310 {
310 {
311 if (event->button() == Qt::LeftButton) {
311 if (event->button() == Qt::LeftButton) {
312
312
313 m_origin = event->pos();
313 m_origin = event->pos();
314 m_currentState = NoState;
314 m_currentState = NoState;
315
315
316 foreach (QChart *chart, m_chartHash.keys()) {
316 foreach (QChart *chart, m_chartHash.keys()) {
317
317
318 QRectF geometryRect = chart->geometry();
318 QRectF geometryRect = chart->geometry();
319 QRectF plotArea = chart->plotArea();
319 QRectF plotArea = chart->plotArea();
320 plotArea.translate(geometryRect.topLeft());
320 plotArea.translate(geometryRect.topLeft());
321 if (plotArea.contains(m_origin)) {
321 if (plotArea.contains(m_origin)) {
322 m_currentState = m_state;
322 m_currentState = m_state;
323
323
324 if (m_currentState == NoState) {
324 if (m_currentState == NoState) {
325 showMenu(chart);
325 showMenu(chart);
326 }
326 }
327 break;
327 break;
328 }
328 }
329 }
329 }
330
330
331 if (m_currentState == ZoomState) {
331 if (m_currentState == ZoomState) {
332 m_rubberBand->setRect(QRectF(m_origin, QSize()));
332 m_rubberBand->setRect(QRectF(m_origin, QSize()));
333 m_rubberBand->setVisible(true);
333 m_rubberBand->setVisible(true);
334 }
334 }
335
335
336 event->accept();
336 event->accept();
337 }
337 }
338
338
339 if (event->button() == Qt::RightButton) {
339 if (event->button() == Qt::RightButton) {
340 m_origin = event->pos();
340 m_origin = event->pos();
341 m_currentState = m_state;
341 m_currentState = m_state;
342 }
342 }
343 }
343 }
344
344
345 void Window::mouseMoveEvent(QMouseEvent *event)
345 void Window::mouseMoveEvent(QMouseEvent *event)
346 {
346 {
347 if ( m_currentState != NoState) {
347 if ( m_currentState != NoState) {
348
348
349 foreach (QChart *chart, m_chartHash.keys()) {
349 foreach (QChart *chart, m_chartHash.keys()) {
350
350
351 QRectF geometryRect = chart->geometry();
351 QRectF geometryRect = chart->geometry();
352 QRectF plotArea = chart->plotArea();
352 QRectF plotArea = chart->plotArea();
353 plotArea.translate(geometryRect.topLeft());
353 plotArea.translate(geometryRect.topLeft());
354
354
355 if (plotArea.contains(m_origin)) {
355 if (plotArea.contains(m_origin)) {
356 if (m_currentState == ScrollState) {
356 if (m_currentState == ScrollState) {
357 QPointF delta = m_origin - event->pos();
357 QPointF delta = m_origin - event->pos();
358 chart->scroll(delta.x(), -delta.y());
358 chart->scroll(delta.x(), -delta.y());
359 }
359 }
360 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
360 if (m_currentState == ZoomState && plotArea.contains(event->pos())) {
361 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
361 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
362 }
362 }
363 break;
363 break;
364 }
364 }
365 }
365 }
366 if(m_currentState == ScrollState) m_origin = event->pos();
366 if(m_currentState == ScrollState) m_origin = event->pos();
367 event->accept();
367 event->accept();
368 }
368 }
369 }
369 }
370
370
371 void Window::mouseReleaseEvent(QMouseEvent *event)
371 void Window::mouseReleaseEvent(QMouseEvent *event)
372 {
372 {
373 if (event->button() == Qt::LeftButton) {
373 if (event->button() == Qt::LeftButton) {
374 if (m_currentState == ZoomState) {
374 if (m_currentState == ZoomState) {
375 m_rubberBand->setVisible(false);
375 m_rubberBand->setVisible(false);
376
376
377 foreach (QChart *chart, m_chartHash.keys()) {
377 foreach (QChart *chart, m_chartHash.keys()) {
378
378
379 QRectF geometryRect = chart->geometry();
379 QRectF geometryRect = chart->geometry();
380 QRectF plotArea = chart->plotArea();
380 QRectF plotArea = chart->plotArea();
381 plotArea.translate(geometryRect.topLeft());
381 plotArea.translate(geometryRect.topLeft());
382
382
383 if (plotArea.contains(m_origin)) {
383 if (plotArea.contains(m_origin)) {
384 QRectF rect = m_rubberBand->rect();
384 QRectF rect = m_rubberBand->rect();
385 rect.translate(-geometryRect.topLeft());
385 rect.translate(-geometryRect.topLeft());
386 chart->zoomIn(rect);
386 chart->zoomIn(rect);
387 break;
387 break;
388 }
388 }
389 }
389 }
390 }
390 }
391
391
392 m_currentState = NoState;
392 m_currentState = NoState;
393 event->accept();
393 event->accept();
394 }
394 }
395
395
396 if (event->button() == Qt::RightButton) {
396 if (event->button() == Qt::RightButton) {
397
397
398 if (m_currentState == ZoomState) {
398 if (m_currentState == ZoomState) {
399 foreach (QChart *chart, m_chartHash.keys()) {
399 foreach (QChart *chart, m_chartHash.keys()) {
400
400
401 QRectF geometryRect = chart->geometry();
401 QRectF geometryRect = chart->geometry();
402 QRectF plotArea = chart->plotArea();
402 QRectF plotArea = chart->plotArea();
403 plotArea.translate(geometryRect.topLeft());
403 plotArea.translate(geometryRect.topLeft());
404
404
405 if (plotArea.contains(m_origin)) {
405 if (plotArea.contains(m_origin)) {
406 QRectF rect = m_rubberBand->rect();
406 QRectF rect = m_rubberBand->rect();
407 chart->zoomOut();
407 chart->zoomOut();
408 break;
408 break;
409 }
409 }
410 }
410 }
411 }
411 }
412 }
412 }
413 }
413 }
414
414
415 void Window::comboBoxFocused(QComboBox *combobox)
415 void Window::comboBoxFocused(QComboBox *combobox)
416 {
416 {
417 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
417 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
418 if(widget->widget()==combobox)
418 if(widget->widget()==combobox)
419 widget->setZValue(2.0);
419 widget->setZValue(2.0);
420 else
420 else
421 widget->setZValue(0.0);
421 widget->setZValue(0.0);
422 }
422 }
423 }
423 }
424
424
425 void Window::showMenu(QChart* qchart)
425 void Window::showMenu(QChart* qchart)
426 {
426 {
427 QAction *chosen = m_menu->exec(QCursor::pos());
427 QAction *chosen = m_menu->exec(QCursor::pos());
428
428
429 if (chosen) {
429 if (chosen) {
430 Chart* chart = (Chart *) chosen->data().value<void *>();
430 Chart* chart = (Chart *) chosen->data().value<void *>();
431 int index = m_chartHash[qchart];
431 int index = m_chartHash[qchart];
432 m_baseLayout->removeItem(qchart);
432 //not in 4.7.2 m_baseLayout->removeItem(qchart);
433 for(int i = 0 ; i < m_baseLayout->count();++i)
434 {
435 if(m_baseLayout->itemAt(i)==qchart){
436 m_baseLayout->removeAt(i);
437 break;
438 }
439 }
440
433 m_chartHash.remove(qchart);
441 m_chartHash.remove(qchart);
434 QChart* newChart = chart->createChart(m_dataTable);
442 QChart* newChart = chart->createChart(m_dataTable);
435 m_baseLayout->addItem(newChart, index / 3, index % 3);
443 m_baseLayout->addItem(newChart, index / 3, index % 3);
436 m_chartHash[newChart] = index;
444 m_chartHash[newChart] = index;
437 delete qchart;
445 delete qchart;
438 updateUI();
446 updateUI();
439 }
447 }
440
448
441 }
449 }
442
450
443 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
451 QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
444 const QVariant &data)
452 const QVariant &data)
445 {
453 {
446 QAction *action = menu->addAction(icon, text);
454 QAction *action = menu->addAction(icon, text);
447 action->setCheckable(false);
455 action->setCheckable(false);
448 action->setData(data);
456 action->setData(data);
449 return action;
457 return action;
450 }
458 }
General Comments 0
You need to be logged in to leave comments. Login now