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