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