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