@@ -1,502 +1,560 | |||
|
1 | 1 | #include <QtGui/QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <qchartglobal.h> |
|
4 | 4 | #include <qchartview.h> |
|
5 | 5 | #include <qpieseries.h> |
|
6 | 6 | #include <qpieslice.h> |
|
7 | 7 | #include <QGridLayout> |
|
8 | 8 | #include <QFormLayout> |
|
9 | 9 | #include <QComboBox> |
|
10 | 10 | #include <QSpinBox> |
|
11 | 11 | #include <QCheckBox> |
|
12 | 12 | #include <QGroupBox> |
|
13 | 13 | #include <QLabel> |
|
14 | 14 | #include <QPushButton> |
|
15 | 15 | #include <QColorDialog> |
|
16 | 16 | #include <QFontDialog> |
|
17 | 17 | |
|
18 | 18 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
19 | 19 | |
|
20 | 20 | class PenTool : public QWidget |
|
21 | 21 | { |
|
22 | 22 | Q_OBJECT |
|
23 | 23 | |
|
24 | 24 | public: |
|
25 | 25 | explicit PenTool(QString title, QWidget *parent = 0) |
|
26 | 26 | :QWidget(parent) |
|
27 | 27 | { |
|
28 | 28 | setWindowTitle(title); |
|
29 | 29 | setWindowFlags(Qt::Tool); |
|
30 | 30 | |
|
31 | 31 | m_colorButton = new QPushButton(); |
|
32 | ||
|
32 | 33 | m_widthSpinBox = new QDoubleSpinBox(); |
|
33 | 34 | |
|
35 | m_styleCombo = new QComboBox(); | |
|
36 | m_styleCombo->addItem("NoPen"); | |
|
37 | m_styleCombo->addItem("SolidLine"); | |
|
38 | m_styleCombo->addItem("DashLine"); | |
|
39 | m_styleCombo->addItem("DotLine"); | |
|
40 | m_styleCombo->addItem("DashDotLine"); | |
|
41 | m_styleCombo->addItem("DashDotDotLine"); | |
|
42 | ||
|
43 | m_capStyleCombo = new QComboBox(); | |
|
44 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | |
|
45 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | |
|
46 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | |
|
47 | ||
|
48 | m_joinStyleCombo = new QComboBox(); | |
|
49 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | |
|
50 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | |
|
51 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | |
|
52 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | |
|
53 | ||
|
34 | 54 | QFormLayout *layout = new QFormLayout(); |
|
35 | 55 | layout->addRow("Color", m_colorButton); |
|
36 | 56 | layout->addRow("Width", m_widthSpinBox); |
|
57 | layout->addRow("Style", m_styleCombo); | |
|
58 | layout->addRow("Cap style", m_capStyleCombo); | |
|
59 | layout->addRow("Join style", m_joinStyleCombo); | |
|
37 | 60 | setLayout(layout); |
|
38 | 61 | |
|
39 | 62 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
40 | 63 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); |
|
64 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | |
|
65 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | |
|
66 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | |
|
41 | 67 | } |
|
42 | 68 | |
|
43 | 69 | void setPen(QPen pen) |
|
44 | 70 | { |
|
45 | 71 | m_pen = pen; |
|
46 | 72 | m_colorButton->setText(m_pen.color().name()); |
|
47 | 73 | m_widthSpinBox->setValue(m_pen.widthF()); |
|
74 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | |
|
75 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | |
|
76 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | |
|
48 | 77 | } |
|
49 | 78 | |
|
50 | 79 | QPen pen() const |
|
51 | 80 | { |
|
52 | 81 | return m_pen; |
|
53 | 82 | } |
|
54 | 83 | |
|
55 | 84 | QString name() |
|
56 | 85 | { |
|
57 | 86 | return name(m_pen); |
|
58 | 87 | } |
|
59 | 88 | |
|
60 | 89 | static QString name(const QPen &pen) |
|
61 | 90 | { |
|
62 | 91 | return pen.color().name() + ":" + QString::number(pen.widthF()); |
|
63 | 92 | } |
|
64 | 93 | |
|
65 | 94 | Q_SIGNALS: |
|
66 | 95 | void changed(); |
|
67 | 96 | |
|
68 | 97 | public Q_SLOTS: |
|
69 | 98 | |
|
70 | 99 | void showColorDialog() |
|
71 | 100 | { |
|
72 | 101 | QColorDialog dialog(m_pen.color()); |
|
73 | 102 | dialog.show(); |
|
74 | 103 | dialog.exec(); |
|
75 | 104 | m_pen.setColor(dialog.selectedColor()); |
|
76 | 105 | m_colorButton->setText(m_pen.color().name()); |
|
77 | 106 | emit changed(); |
|
78 | 107 | } |
|
79 | 108 | |
|
80 | 109 | void updateWidth(double width) |
|
81 | 110 | { |
|
82 | 111 | if (width != m_pen.widthF()) { |
|
83 | 112 | m_pen.setWidthF(width); |
|
84 | 113 | emit changed(); |
|
85 | 114 | } |
|
86 | 115 | } |
|
87 | 116 | |
|
117 | void updateStyle(int style) | |
|
118 | { | |
|
119 | if (m_pen.style() != style) { | |
|
120 | m_pen.setStyle((Qt::PenStyle) style); | |
|
121 | emit changed(); | |
|
122 | } | |
|
123 | } | |
|
124 | ||
|
125 | void updateCapStyle(int index) | |
|
126 | { | |
|
127 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | |
|
128 | if (m_pen.capStyle() != capStyle) { | |
|
129 | m_pen.setCapStyle(capStyle); | |
|
130 | emit changed(); | |
|
131 | } | |
|
132 | } | |
|
133 | ||
|
134 | void updateJoinStyle(int index) | |
|
135 | { | |
|
136 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | |
|
137 | if (m_pen.joinStyle() != joinStyle) { | |
|
138 | m_pen.setJoinStyle(joinStyle); | |
|
139 | emit changed(); | |
|
140 | } | |
|
141 | } | |
|
142 | ||
|
88 | 143 | private: |
|
89 | 144 | QPen m_pen; |
|
90 | 145 | QPushButton *m_colorButton; |
|
91 | 146 | QDoubleSpinBox *m_widthSpinBox; |
|
147 | QComboBox *m_styleCombo; | |
|
148 | QComboBox *m_capStyleCombo; | |
|
149 | QComboBox *m_joinStyleCombo; | |
|
92 | 150 | }; |
|
93 | 151 | |
|
94 | 152 | class BrushTool : public QWidget |
|
95 | 153 | { |
|
96 | 154 | Q_OBJECT |
|
97 | 155 | |
|
98 | 156 | public: |
|
99 | 157 | explicit BrushTool(QString title, QWidget *parent = 0) |
|
100 | 158 | :QWidget(parent) |
|
101 | 159 | { |
|
102 | 160 | setWindowTitle(title); |
|
103 | 161 | setWindowFlags(Qt::Tool); |
|
104 | 162 | |
|
105 | 163 | m_colorButton = new QPushButton(); |
|
106 | 164 | m_styleCombo = new QComboBox(); |
|
107 | 165 | m_styleCombo->addItem("Nobrush", Qt::NoBrush); |
|
108 | 166 | m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); |
|
109 | 167 | m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); |
|
110 | 168 | m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); |
|
111 | 169 | m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); |
|
112 | 170 | m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); |
|
113 | 171 | m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); |
|
114 | 172 | m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); |
|
115 | 173 | m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); |
|
116 | 174 | m_styleCombo->addItem("HorPattern", Qt::HorPattern); |
|
117 | 175 | m_styleCombo->addItem("VerPattern", Qt::VerPattern); |
|
118 | 176 | m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); |
|
119 | 177 | m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); |
|
120 | 178 | m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); |
|
121 | 179 | m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); |
|
122 | 180 | |
|
123 | 181 | QFormLayout *layout = new QFormLayout(); |
|
124 | 182 | layout->addRow("Color", m_colorButton); |
|
125 | 183 | layout->addRow("Style", m_styleCombo); |
|
126 | 184 | setLayout(layout); |
|
127 | 185 | |
|
128 | 186 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
129 | 187 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); |
|
130 | 188 | } |
|
131 | 189 | |
|
132 | 190 | void setBrush(QBrush brush) |
|
133 | 191 | { |
|
134 | 192 | m_brush = brush; |
|
135 | 193 | m_colorButton->setText(m_brush.color().name()); |
|
136 | 194 | m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum |
|
137 | 195 | } |
|
138 | 196 | |
|
139 | 197 | QBrush brush() const |
|
140 | 198 | { |
|
141 | 199 | return m_brush; |
|
142 | 200 | } |
|
143 | 201 | |
|
144 | 202 | QString name() |
|
145 | 203 | { |
|
146 | 204 | return name(m_brush); |
|
147 | 205 | } |
|
148 | 206 | |
|
149 | 207 | static QString name(const QBrush &brush) |
|
150 | 208 | { |
|
151 | 209 | return brush.color().name(); |
|
152 | 210 | } |
|
153 | 211 | |
|
154 | 212 | Q_SIGNALS: |
|
155 | 213 | void changed(); |
|
156 | 214 | |
|
157 | 215 | public Q_SLOTS: |
|
158 | 216 | |
|
159 | 217 | void showColorDialog() |
|
160 | 218 | { |
|
161 | 219 | QColorDialog dialog(m_brush.color()); |
|
162 | 220 | dialog.show(); |
|
163 | 221 | dialog.exec(); |
|
164 | 222 | m_brush.setColor(dialog.selectedColor()); |
|
165 | 223 | m_colorButton->setText(m_brush.color().name()); |
|
166 | 224 | emit changed(); |
|
167 | 225 | } |
|
168 | 226 | |
|
169 | 227 | void updateStyle() |
|
170 | 228 | { |
|
171 | 229 | Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); |
|
172 | 230 | if (m_brush.style() != style) { |
|
173 | 231 | m_brush.setStyle(style); |
|
174 | 232 | emit changed(); |
|
175 | 233 | } |
|
176 | 234 | } |
|
177 | 235 | |
|
178 | 236 | private: |
|
179 | 237 | QBrush m_brush; |
|
180 | 238 | QPushButton *m_colorButton; |
|
181 | 239 | QComboBox *m_styleCombo; |
|
182 | 240 | }; |
|
183 | 241 | |
|
184 | 242 | class CustomSlice : public QPieSlice |
|
185 | 243 | { |
|
186 | 244 | Q_OBJECT |
|
187 | 245 | public: |
|
188 | 246 | CustomSlice(qreal value, QString label) |
|
189 | 247 | :QPieSlice(value, label) |
|
190 | 248 | { |
|
191 | 249 | connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); |
|
192 | 250 | connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); |
|
193 | 251 | } |
|
194 | 252 | |
|
195 | 253 | public: |
|
196 | 254 | QBrush originalBrush() |
|
197 | 255 | { |
|
198 | 256 | return m_originalBrush; |
|
199 | 257 | } |
|
200 | 258 | |
|
201 | 259 | public Q_SLOTS: |
|
202 | 260 | |
|
203 | 261 | void handleHoverEnter() |
|
204 | 262 | { |
|
205 | 263 | QBrush brush = this->sliceBrush(); |
|
206 | 264 | m_originalBrush = brush; |
|
207 | 265 | brush.setColor(brush.color().lighter()); |
|
208 | 266 | setSliceBrush(brush); |
|
209 | 267 | } |
|
210 | 268 | |
|
211 | 269 | void handleHoverLeave() |
|
212 | 270 | { |
|
213 | 271 | setSliceBrush(m_originalBrush); |
|
214 | 272 | } |
|
215 | 273 | |
|
216 | 274 | private: |
|
217 | 275 | QBrush m_originalBrush; |
|
218 | 276 | }; |
|
219 | 277 | |
|
220 | 278 | class MainWidget : public QWidget |
|
221 | 279 | { |
|
222 | 280 | Q_OBJECT |
|
223 | 281 | |
|
224 | 282 | public: |
|
225 | 283 | explicit MainWidget(QWidget* parent = 0) |
|
226 | 284 | :QWidget(parent), |
|
227 | 285 | m_slice(0) |
|
228 | 286 | { |
|
229 | 287 | // create chart |
|
230 | 288 | m_chartView = new QChartView(); |
|
231 | 289 | m_chartView->setChartTitle("Piechart customization"); |
|
232 | 290 | |
|
233 | 291 | // create series |
|
234 | 292 | m_series = new QPieSeries(); |
|
235 | 293 | *m_series << new CustomSlice(10.0, "Slice 1"); |
|
236 | 294 | *m_series << new CustomSlice(20.0, "Slice 2"); |
|
237 | 295 | *m_series << new CustomSlice(30.0, "Slice 3"); |
|
238 | 296 | *m_series << new CustomSlice(40.0, "Slice 4"); |
|
239 | 297 | *m_series << new CustomSlice(50.0, "Slice 5"); |
|
240 | 298 | m_chartView->addSeries(m_series); |
|
241 | 299 | |
|
242 | 300 | connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); |
|
243 | 301 | |
|
244 | 302 | // chart settings |
|
245 | 303 | m_themeComboBox = new QComboBox(); |
|
246 | 304 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
247 | 305 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); |
|
248 | 306 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); |
|
249 | 307 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); |
|
250 | 308 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); |
|
251 | 309 | |
|
252 | 310 | m_aaCheckBox = new QCheckBox(); |
|
253 | 311 | |
|
254 | 312 | QFormLayout* chartSettingsLayout = new QFormLayout(); |
|
255 | 313 | chartSettingsLayout->addRow("Theme", m_themeComboBox); |
|
256 | 314 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); |
|
257 | 315 | QGroupBox* chartSettings = new QGroupBox("Chart"); |
|
258 | 316 | chartSettings->setLayout(chartSettingsLayout); |
|
259 | 317 | |
|
260 | 318 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); |
|
261 | 319 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
262 | 320 | |
|
263 | 321 | // series settings |
|
264 | 322 | m_hPosition = new QDoubleSpinBox(); |
|
265 | 323 | m_hPosition->setMinimum(0.0); |
|
266 | 324 | m_hPosition->setMaximum(1.0); |
|
267 | 325 | m_hPosition->setSingleStep(0.1); |
|
268 | 326 | m_hPosition->setValue(m_series->pieHorizontalPosition()); |
|
269 | 327 | |
|
270 | 328 | m_vPosition = new QDoubleSpinBox(); |
|
271 | 329 | m_vPosition->setMinimum(0.0); |
|
272 | 330 | m_vPosition->setMaximum(1.0); |
|
273 | 331 | m_vPosition->setSingleStep(0.1); |
|
274 | 332 | m_vPosition->setValue(m_series->pieVerticalPosition()); |
|
275 | 333 | |
|
276 | 334 | m_sizeFactor = new QDoubleSpinBox(); |
|
277 | 335 | m_sizeFactor->setMinimum(0.0); |
|
278 | 336 | m_sizeFactor->setMaximum(1.0); |
|
279 | 337 | m_sizeFactor->setSingleStep(0.1); |
|
280 | 338 | m_sizeFactor->setValue(m_series->pieSize()); |
|
281 | 339 | |
|
282 | 340 | m_startAngle = new QDoubleSpinBox(); |
|
283 | 341 | m_startAngle->setMinimum(0.0); |
|
284 | 342 | m_startAngle->setMaximum(360); |
|
285 | 343 | m_startAngle->setValue(m_series->pieStartAngle()); |
|
286 | 344 | m_startAngle->setSingleStep(1); |
|
287 | 345 | |
|
288 | 346 | m_endAngle = new QDoubleSpinBox(); |
|
289 | 347 | m_endAngle->setMinimum(0.0); |
|
290 | 348 | m_endAngle->setMaximum(360); |
|
291 | 349 | m_endAngle->setValue(m_series->pieEndAngle()); |
|
292 | 350 | m_endAngle->setSingleStep(1); |
|
293 | 351 | |
|
294 | 352 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
295 | 353 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
296 | 354 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
297 | 355 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
298 | 356 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
299 | 357 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
300 | 358 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
301 | 359 | seriesSettings->setLayout(seriesSettingsLayout); |
|
302 | 360 | |
|
303 | 361 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
304 | 362 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
305 | 363 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
306 | 364 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
307 | 365 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
308 | 366 | |
|
309 | 367 | // slice settings |
|
310 | 368 | m_sliceName = new QLabel("<click a slice>"); |
|
311 | 369 | m_sliceValue = new QDoubleSpinBox(); |
|
312 | 370 | m_sliceValue->setMaximum(1000); |
|
313 | 371 | m_sliceLabelVisible = new QCheckBox(); |
|
314 | 372 | m_sliceLabelArmFactor = new QDoubleSpinBox(); |
|
315 | 373 | m_sliceLabelArmFactor->setSingleStep(0.01); |
|
316 | 374 | m_sliceExploded = new QCheckBox(); |
|
317 | 375 | m_sliceExplodedFactor = new QDoubleSpinBox(); |
|
318 | 376 | m_sliceExplodedFactor->setSingleStep(0.01); |
|
319 | 377 | m_pen = new QPushButton(); |
|
320 | 378 | m_penTool = new PenTool("Slice pen", this); |
|
321 | 379 | m_brush = new QPushButton(); |
|
322 | 380 | m_brushTool = new BrushTool("Slice brush", this); |
|
323 | 381 | m_font = new QPushButton(); |
|
324 | 382 | m_labelArmPen = new QPushButton(); |
|
325 | 383 | m_labelArmPenTool = new PenTool("Label arm pen", this); |
|
326 | 384 | |
|
327 | 385 | QFormLayout* sliceSettingsLayout = new QFormLayout(); |
|
328 | 386 | sliceSettingsLayout->addRow("Selected", m_sliceName); |
|
329 | 387 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
330 | 388 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
331 | 389 | sliceSettingsLayout->addRow("Brush", m_brush); |
|
332 | 390 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); |
|
333 | 391 | sliceSettingsLayout->addRow("Label font", m_font); |
|
334 | 392 | sliceSettingsLayout->addRow("Label arm pen", m_labelArmPen); |
|
335 | 393 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
336 | 394 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
337 | 395 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
338 | 396 | QGroupBox* sliceSettings = new QGroupBox("Slice"); |
|
339 | 397 | sliceSettings->setLayout(sliceSettingsLayout); |
|
340 | 398 | |
|
341 | 399 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
342 | 400 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
343 | 401 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
344 | 402 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); |
|
345 | 403 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
346 | 404 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); |
|
347 | 405 | connect(m_labelArmPen, SIGNAL(clicked()), m_labelArmPenTool, SLOT(show())); |
|
348 | 406 | connect(m_labelArmPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
349 | 407 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
350 | 408 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
351 | 409 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
352 | 410 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
353 | 411 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
354 | 412 | |
|
355 | 413 | // create main layout |
|
356 | 414 | QVBoxLayout *settingsLayout = new QVBoxLayout(); |
|
357 | 415 | settingsLayout->addWidget(chartSettings); |
|
358 | 416 | settingsLayout->addWidget(seriesSettings); |
|
359 | 417 | settingsLayout->addWidget(sliceSettings); |
|
360 | 418 | settingsLayout->addStretch(); |
|
361 | 419 | |
|
362 | 420 | QGridLayout* baseLayout = new QGridLayout(); |
|
363 | 421 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
364 | 422 | baseLayout->addWidget(m_chartView, 0, 1); |
|
365 | 423 | setLayout(baseLayout); |
|
366 | 424 | |
|
367 | 425 | updateSerieSettings(); |
|
368 | 426 | } |
|
369 | 427 | |
|
370 | 428 | public Q_SLOTS: |
|
371 | 429 | |
|
372 | 430 | void updateChartSettings() |
|
373 | 431 | { |
|
374 | 432 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
375 | 433 | m_chartView->setChartTheme(theme); |
|
376 | 434 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); |
|
377 | 435 | } |
|
378 | 436 | |
|
379 | 437 | void updateSerieSettings() |
|
380 | 438 | { |
|
381 | 439 | m_series->setPiePosition(m_vPosition->value(), m_hPosition->value()); |
|
382 | 440 | m_series->setPieSize(m_sizeFactor->value()); |
|
383 | 441 | m_series->setPieStartAngle(m_startAngle->value()); |
|
384 | 442 | m_series->setPieEndAngle(m_endAngle->value()); |
|
385 | 443 | } |
|
386 | 444 | |
|
387 | 445 | void updateSliceSettings() |
|
388 | 446 | { |
|
389 | 447 | if (!m_slice) |
|
390 | 448 | return; |
|
391 | 449 | |
|
392 | 450 | m_slice->setValue(m_sliceValue->value()); |
|
393 | 451 | |
|
394 | 452 | m_slice->setSlicePen(m_penTool->pen()); |
|
395 | 453 | m_slice->setSliceBrush(m_brushTool->brush()); |
|
396 | 454 | |
|
397 | 455 | m_slice->setLabelArmPen(m_labelArmPenTool->pen()); |
|
398 | 456 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); |
|
399 | 457 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); |
|
400 | 458 | |
|
401 | 459 | m_slice->setExploded(m_sliceExploded->isChecked()); |
|
402 | 460 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
403 | 461 | } |
|
404 | 462 | |
|
405 | 463 | void handleSliceClicked(QPieSlice* slice) |
|
406 | 464 | { |
|
407 | 465 | m_slice = static_cast<CustomSlice*>(slice); |
|
408 | 466 | |
|
409 | 467 | // name |
|
410 | 468 | m_sliceName->setText(slice->label()); |
|
411 | 469 | |
|
412 | 470 | // value |
|
413 | 471 | m_sliceValue->blockSignals(true); |
|
414 | 472 | m_sliceValue->setValue(slice->value()); |
|
415 | 473 | m_sliceValue->blockSignals(false); |
|
416 | 474 | |
|
417 | 475 | // pen |
|
418 | 476 | m_pen->setText(PenTool::name(m_slice->slicePen())); |
|
419 | 477 | m_penTool->setPen(m_slice->slicePen()); |
|
420 | 478 | |
|
421 | 479 | // brush |
|
422 | 480 | m_brush->setText(m_slice->originalBrush().color().name()); |
|
423 | 481 | m_brushTool->setBrush(m_slice->originalBrush()); |
|
424 | 482 | |
|
425 | 483 | // label |
|
426 | 484 | m_labelArmPen->setText(PenTool::name(m_slice->labelArmPen())); |
|
427 | 485 | m_labelArmPenTool->setPen(m_slice->labelArmPen()); |
|
428 | 486 | m_font->setText(slice->labelFont().toString()); |
|
429 | 487 | m_sliceLabelVisible->blockSignals(true); |
|
430 | 488 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); |
|
431 | 489 | m_sliceLabelVisible->blockSignals(false); |
|
432 | 490 | m_sliceLabelArmFactor->blockSignals(true); |
|
433 | 491 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); |
|
434 | 492 | m_sliceLabelArmFactor->blockSignals(false); |
|
435 | 493 | |
|
436 | 494 | // exploded |
|
437 | 495 | m_sliceExploded->blockSignals(true); |
|
438 | 496 | m_sliceExploded->setChecked(slice->isExploded()); |
|
439 | 497 | m_sliceExploded->blockSignals(false); |
|
440 | 498 | m_sliceExplodedFactor->blockSignals(true); |
|
441 | 499 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); |
|
442 | 500 | m_sliceExplodedFactor->blockSignals(false); |
|
443 | 501 | } |
|
444 | 502 | |
|
445 | 503 | void showFontDialog() |
|
446 | 504 | { |
|
447 | 505 | if (!m_slice) |
|
448 | 506 | return; |
|
449 | 507 | |
|
450 | 508 | QFontDialog dialog(m_slice->labelFont()); |
|
451 | 509 | dialog.show(); |
|
452 | 510 | dialog.exec(); |
|
453 | 511 | |
|
454 | 512 | m_slice->setLabelFont(dialog.currentFont()); |
|
455 | 513 | m_font->setText(dialog.currentFont().toString()); |
|
456 | 514 | } |
|
457 | 515 | |
|
458 | 516 | private: |
|
459 | 517 | QComboBox *m_themeComboBox; |
|
460 | 518 | QCheckBox *m_aaCheckBox; |
|
461 | 519 | |
|
462 | 520 | QChartView* m_chartView; |
|
463 | 521 | QPieSeries* m_series; |
|
464 | 522 | CustomSlice* m_slice; |
|
465 | 523 | |
|
466 | 524 | QDoubleSpinBox* m_hPosition; |
|
467 | 525 | QDoubleSpinBox* m_vPosition; |
|
468 | 526 | QDoubleSpinBox* m_sizeFactor; |
|
469 | 527 | QDoubleSpinBox* m_startAngle; |
|
470 | 528 | QDoubleSpinBox* m_endAngle; |
|
471 | 529 | |
|
472 | 530 | QLabel* m_sliceName; |
|
473 | 531 | QDoubleSpinBox* m_sliceValue; |
|
474 | 532 | QCheckBox* m_sliceLabelVisible; |
|
475 | 533 | QDoubleSpinBox* m_sliceLabelArmFactor; |
|
476 | 534 | QCheckBox* m_sliceExploded; |
|
477 | 535 | QDoubleSpinBox* m_sliceExplodedFactor; |
|
478 | 536 | QPushButton *m_brush; |
|
479 | 537 | BrushTool *m_brushTool; |
|
480 | 538 | QPushButton *m_pen; |
|
481 | 539 | PenTool *m_penTool; |
|
482 | 540 | QPushButton *m_font; |
|
483 | 541 | QPushButton *m_labelArmPen; |
|
484 | 542 | PenTool *m_labelArmPenTool; |
|
485 | 543 | }; |
|
486 | 544 | |
|
487 | 545 | int main(int argc, char *argv[]) |
|
488 | 546 | { |
|
489 | 547 | QApplication a(argc, argv); |
|
490 | 548 | |
|
491 | 549 | QMainWindow window; |
|
492 | 550 | |
|
493 | 551 | MainWidget* widget = new MainWidget(); |
|
494 | 552 | |
|
495 | 553 | window.setCentralWidget(widget); |
|
496 | 554 | window.resize(900, 600); |
|
497 | 555 | window.show(); |
|
498 | 556 | |
|
499 | 557 | return a.exec(); |
|
500 | 558 | } |
|
501 | 559 | |
|
502 | 560 | #include "main.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now