@@ -1,391 +1,389 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qaxis.h" |
|
26 | #include "qaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qbarseries.h" |
|
31 | #include "qbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qpieslice_p.h" |
|
39 | #include "qpieslice_p.h" | |
40 | #include "qsplineseries.h" |
|
40 | #include "qsplineseries.h" | |
41 |
|
41 | |||
42 | //items |
|
42 | //items | |
43 | #include "chartaxis_p.h" |
|
43 | #include "chartaxis_p.h" | |
44 | #include "barchartitem_p.h" |
|
44 | #include "barchartitem_p.h" | |
45 | #include "stackedbarchartitem_p.h" |
|
45 | #include "stackedbarchartitem_p.h" | |
46 | #include "percentbarchartitem_p.h" |
|
46 | #include "percentbarchartitem_p.h" | |
47 | #include "linechartitem_p.h" |
|
47 | #include "linechartitem_p.h" | |
48 | #include "areachartitem_p.h" |
|
48 | #include "areachartitem_p.h" | |
49 | #include "scatterchartitem_p.h" |
|
49 | #include "scatterchartitem_p.h" | |
50 | #include "piechartitem_p.h" |
|
50 | #include "piechartitem_p.h" | |
51 | #include "splinechartitem_p.h" |
|
51 | #include "splinechartitem_p.h" | |
52 |
|
52 | |||
53 | //themes |
|
53 | //themes | |
54 | #include "chartthemesystem_p.h" |
|
54 | #include "chartthemesystem_p.h" | |
55 | #include "chartthemelight_p.h" |
|
55 | #include "chartthemelight_p.h" | |
56 | #include "chartthemebluecerulean_p.h" |
|
56 | #include "chartthemebluecerulean_p.h" | |
57 | #include "chartthemedark_p.h" |
|
57 | #include "chartthemedark_p.h" | |
58 | #include "chartthemebrownsand_p.h" |
|
58 | #include "chartthemebrownsand_p.h" | |
59 | #include "chartthemebluencs_p.h" |
|
59 | #include "chartthemebluencs_p.h" | |
60 | #include "chartthemehighcontrast_p.h" |
|
60 | #include "chartthemehighcontrast_p.h" | |
61 | #include "chartthemeblueicy_p.h" |
|
61 | #include "chartthemeblueicy_p.h" | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
64 |
|
64 | |||
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
66 | m_masterFont(QFont("arial", 14)), |
|
66 | m_masterFont(QFont("arial", 14)), | |
67 | m_labelFont(QFont("arial", 10)), |
|
67 | m_labelFont(QFont("arial", 10)), | |
68 |
m_ |
|
68 | m_labelBrush(QColor(QRgb(0x000000))), | |
69 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
69 | m_axisLinePen(QPen(QRgb(0x000000))), | |
70 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
|||
71 | m_backgroundShadesPen(Qt::NoPen), |
|
70 | m_backgroundShadesPen(Qt::NoPen), | |
72 | m_backgroundShadesBrush(Qt::NoBrush), |
|
71 | m_backgroundShadesBrush(Qt::NoBrush), | |
73 | m_backgroundShades(BackgroundShadesNone), |
|
72 | m_backgroundShades(BackgroundShadesNone), | |
74 | m_backgroundDropShadowEnabled(false), |
|
73 | m_backgroundDropShadowEnabled(false), | |
75 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
74 | m_gridLinePen(QPen(QRgb(0x000000))), | |
76 | m_force(false) |
|
75 | m_force(false) | |
77 | { |
|
76 | { | |
78 | m_id = id; |
|
77 | m_id = id; | |
79 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
80 | } |
|
79 | } | |
81 |
|
80 | |||
82 |
|
81 | |||
83 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
84 | { |
|
83 | { | |
85 | switch(theme) { |
|
84 | switch(theme) { | |
86 | case QChart::ChartThemeLight: |
|
85 | case QChart::ChartThemeLight: | |
87 | return new ChartThemeLight(); |
|
86 | return new ChartThemeLight(); | |
88 | case QChart::ChartThemeBlueCerulean: |
|
87 | case QChart::ChartThemeBlueCerulean: | |
89 | return new ChartThemeBlueCerulean(); |
|
88 | return new ChartThemeBlueCerulean(); | |
90 | case QChart::ChartThemeDark: |
|
89 | case QChart::ChartThemeDark: | |
91 | return new ChartThemeDark(); |
|
90 | return new ChartThemeDark(); | |
92 | case QChart::ChartThemeBrownSand: |
|
91 | case QChart::ChartThemeBrownSand: | |
93 | return new ChartThemeBrownSand(); |
|
92 | return new ChartThemeBrownSand(); | |
94 | case QChart::ChartThemeBlueNcs: |
|
93 | case QChart::ChartThemeBlueNcs: | |
95 | return new ChartThemeBlueNcs(); |
|
94 | return new ChartThemeBlueNcs(); | |
96 | case QChart::ChartThemeHighContrast: |
|
95 | case QChart::ChartThemeHighContrast: | |
97 | return new ChartThemeHighContrast(); |
|
96 | return new ChartThemeHighContrast(); | |
98 | case QChart::ChartThemeBlueIcy: |
|
97 | case QChart::ChartThemeBlueIcy: | |
99 | return new ChartThemeBlueIcy(); |
|
98 | return new ChartThemeBlueIcy(); | |
100 | default: |
|
99 | default: | |
101 | return new ChartThemeSystem(); |
|
100 | return new ChartThemeSystem(); | |
102 | } |
|
101 | } | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
106 | { |
|
105 | { | |
107 | QBrush brush; |
|
106 | QBrush brush; | |
108 |
|
107 | |||
109 | if(brush == chart->backgroundBrush() || m_force) |
|
108 | if(brush == chart->backgroundBrush() || m_force) | |
110 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
111 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
112 |
chart->setTitleBrush(m_ |
|
111 | chart->setTitleBrush(m_labelBrush); | |
113 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); | |
114 | } |
|
113 | } | |
115 |
|
114 | |||
116 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
117 | { |
|
116 | { | |
118 | QPen pen; |
|
117 | QPen pen; | |
119 | QBrush brush; |
|
118 | QBrush brush; | |
120 | QFont font; |
|
119 | QFont font; | |
121 |
|
120 | |||
122 | if (pen == legend->pen() || m_force) |
|
121 | if (pen == legend->pen() || m_force) | |
123 | legend->setPen(m_axisLinePen); |
|
122 | legend->setPen(m_axisLinePen); | |
124 |
|
123 | |||
125 | if (brush == legend->brush() || m_force) |
|
124 | if (brush == legend->brush() || m_force) | |
126 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
127 |
|
126 | |||
128 | // TODO: should legend have own brush & font defined by theme? |
|
|||
129 | if (font == legend->font() || m_force) |
|
127 | if (font == legend->font() || m_force) | |
130 | legend->setFont(m_labelFont); |
|
128 | legend->setFont(m_labelFont); | |
131 |
|
129 | |||
132 | if (brush == legend->labelBrush() || m_force) |
|
130 | if (brush == legend->labelBrush() || m_force) | |
133 |
legend->setLabelBrush(m_ |
|
131 | legend->setLabelBrush(m_labelBrush); | |
134 | } |
|
132 | } | |
135 |
|
133 | |||
136 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
134 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
137 | { |
|
135 | { | |
138 | QPen pen; |
|
136 | QPen pen; | |
139 | QBrush brush; |
|
137 | QBrush brush; | |
140 |
|
138 | |||
141 | if (pen == series->pen() || m_force){ |
|
139 | if (pen == series->pen() || m_force){ | |
142 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
143 | pen.setWidthF(2); |
|
141 | pen.setWidthF(2); | |
144 | series->setPen(pen); |
|
142 | series->setPen(pen); | |
145 | } |
|
143 | } | |
146 |
|
144 | |||
147 | if (brush == series->brush() || m_force) { |
|
145 | if (brush == series->brush() || m_force) { | |
148 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
149 | series->setBrush(brush); |
|
147 | series->setBrush(brush); | |
150 | } |
|
148 | } | |
151 | } |
|
149 | } | |
152 |
|
150 | |||
153 |
|
151 | |||
154 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
152 | void ChartTheme::decorate(QLineSeries *series,int index) | |
155 | { |
|
153 | { | |
156 | QPen pen; |
|
154 | QPen pen; | |
157 | if(pen == series->pen() || m_force ){ |
|
155 | if(pen == series->pen() || m_force ){ | |
158 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
159 | pen.setWidthF(2); |
|
157 | pen.setWidthF(2); | |
160 | series->setPen(pen); |
|
158 | series->setPen(pen); | |
161 | } |
|
159 | } | |
162 | } |
|
160 | } | |
163 |
|
161 | |||
164 | void ChartTheme::decorate(QBarSeries *series, int index) |
|
162 | void ChartTheme::decorate(QBarSeries *series, int index) | |
165 | { |
|
163 | { | |
166 | QBrush brush; |
|
164 | QBrush brush; | |
167 | QPen pen; |
|
165 | QPen pen; | |
168 | QList<QBarSet *> sets = series->barSets(); |
|
166 | QList<QBarSet *> sets = series->barSets(); | |
169 |
|
167 | |||
170 | qreal takeAtPos = 0.5; |
|
168 | qreal takeAtPos = 0.5; | |
171 | qreal step = 0.2; |
|
169 | qreal step = 0.2; | |
172 | if (sets.count() > 1 ) { |
|
170 | if (sets.count() > 1 ) { | |
173 | step = 1.0 / (qreal) sets.count(); |
|
171 | step = 1.0 / (qreal) sets.count(); | |
174 | if (sets.count() % m_seriesGradients.count()) |
|
172 | if (sets.count() % m_seriesGradients.count()) | |
175 | step *= m_seriesGradients.count(); |
|
173 | step *= m_seriesGradients.count(); | |
176 | else |
|
174 | else | |
177 | step *= (m_seriesGradients.count() - 1); |
|
175 | step *= (m_seriesGradients.count() - 1); | |
178 | } |
|
176 | } | |
179 |
|
177 | |||
180 | for (int i(0); i < sets.count(); i++) { |
|
178 | for (int i(0); i < sets.count(); i++) { | |
181 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
179 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
182 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
183 | // There is no dedicated base color for each sets, generate more colors |
|
181 | // There is no dedicated base color for each sets, generate more colors | |
184 | takeAtPos += step; |
|
182 | takeAtPos += step; | |
185 | if (takeAtPos == 1.0) |
|
183 | if (takeAtPos == 1.0) | |
186 | takeAtPos += step; |
|
184 | takeAtPos += step; | |
187 | takeAtPos -= (int) takeAtPos; |
|
185 | takeAtPos -= (int) takeAtPos; | |
188 | } |
|
186 | } | |
189 | if (brush == sets.at(i)->brush() || m_force ) |
|
187 | if (brush == sets.at(i)->brush() || m_force ) | |
190 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
191 |
|
189 | |||
192 | // Pick label color from the opposite end of the gradient. |
|
190 | // Pick label color from the opposite end of the gradient. | |
193 | // 0.3 as a boundary seems to work well. |
|
191 | // 0.3 as a boundary seems to work well. | |
194 | if (takeAtPos < 0.3) |
|
192 | if (takeAtPos < 0.3) | |
195 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
193 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
196 | else |
|
194 | else | |
197 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
195 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
198 |
|
196 | |||
199 | if (pen == sets.at(i)->pen() || m_force) { |
|
197 | if (pen == sets.at(i)->pen() || m_force) { | |
200 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
198 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
201 | sets.at(i)->setPen(c); |
|
199 | sets.at(i)->setPen(c); | |
202 | } |
|
200 | } | |
203 | } |
|
201 | } | |
204 | } |
|
202 | } | |
205 |
|
203 | |||
206 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
204 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
207 | { |
|
205 | { | |
208 | QPen pen; |
|
206 | QPen pen; | |
209 | QBrush brush; |
|
207 | QBrush brush; | |
210 |
|
208 | |||
211 | if (pen == series->pen() || m_force) { |
|
209 | if (pen == series->pen() || m_force) { | |
212 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
210 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
213 | pen.setWidthF(2); |
|
211 | pen.setWidthF(2); | |
214 | series->setPen(pen); |
|
212 | series->setPen(pen); | |
215 | } |
|
213 | } | |
216 |
|
214 | |||
217 | if (brush == series->brush() || m_force) { |
|
215 | if (brush == series->brush() || m_force) { | |
218 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
216 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
219 | series->setBrush(brush); |
|
217 | series->setBrush(brush); | |
220 | } |
|
218 | } | |
221 | } |
|
219 | } | |
222 |
|
220 | |||
223 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
221 | void ChartTheme::decorate(QPieSeries *series, int index) | |
224 | { |
|
222 | { | |
225 |
|
223 | |||
226 | for (int i(0); i < series->slices().count(); i++) { |
|
224 | for (int i(0); i < series->slices().count(); i++) { | |
227 |
|
225 | |||
228 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
226 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
229 |
|
227 | |||
230 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
228 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
231 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
229 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
232 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
230 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
233 |
|
231 | |||
234 | QPieSlice *s = series->slices().at(i); |
|
232 | QPieSlice *s = series->slices().at(i); | |
235 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
233 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
236 |
|
234 | |||
237 | if (d->m_data.m_slicePen.isThemed() || m_force) |
|
235 | if (d->m_data.m_slicePen.isThemed() || m_force) | |
238 | d->setPen(penColor, true); |
|
236 | d->setPen(penColor, true); | |
239 |
|
237 | |||
240 | if (d->m_data.m_sliceBrush.isThemed() || m_force) |
|
238 | if (d->m_data.m_sliceBrush.isThemed() || m_force) | |
241 | d->setBrush(brushColor, true); |
|
239 | d->setBrush(brushColor, true); | |
242 |
|
240 | |||
243 | if (d->m_data.m_labelBrush.isThemed() || m_force) |
|
241 | if (d->m_data.m_labelBrush.isThemed() || m_force) | |
244 |
d->setLabelBrush( |
|
242 | d->setLabelBrush(m_labelBrush.color(), true); | |
245 |
|
243 | |||
246 | if (d->m_data.m_labelFont.isThemed() || m_force) |
|
244 | if (d->m_data.m_labelFont.isThemed() || m_force) | |
247 | d->setLabelFont(m_labelFont, true); |
|
245 | d->setLabelFont(m_labelFont, true); | |
248 | } |
|
246 | } | |
249 | } |
|
247 | } | |
250 |
|
248 | |||
251 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
249 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
252 | { |
|
250 | { | |
253 | QPen pen; |
|
251 | QPen pen; | |
254 | if(pen == series->pen() || m_force){ |
|
252 | if(pen == series->pen() || m_force){ | |
255 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
253 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
256 | pen.setWidthF(2); |
|
254 | pen.setWidthF(2); | |
257 | series->setPen(pen); |
|
255 | series->setPen(pen); | |
258 | } |
|
256 | } | |
259 | } |
|
257 | } | |
260 |
|
258 | |||
261 | void ChartTheme::decorate(QAxis *axis,bool axisX) |
|
259 | void ChartTheme::decorate(QAxis *axis,bool axisX) | |
262 | { |
|
260 | { | |
263 | QPen pen; |
|
261 | QPen pen; | |
264 | QBrush brush; |
|
262 | QBrush brush; | |
265 | QFont font; |
|
263 | QFont font; | |
266 |
|
264 | |||
267 | if (axis->isAxisVisible()) { |
|
265 | if (axis->isAxisVisible()) { | |
268 |
|
266 | |||
269 | if(brush == axis->labelsBrush() || m_force){ |
|
267 | if(brush == axis->labelsBrush() || m_force){ | |
270 |
axis->setLabelsBrush(m_ |
|
268 | axis->setLabelsBrush(m_labelBrush); | |
271 | } |
|
269 | } | |
272 | if(pen == axis->labelsPen() || m_force){ |
|
270 | if(pen == axis->labelsPen() || m_force){ | |
273 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
271 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
274 | } |
|
272 | } | |
275 |
|
273 | |||
276 |
|
274 | |||
277 | if (axis->shadesVisible() || m_force) { |
|
275 | if (axis->shadesVisible() || m_force) { | |
278 |
|
276 | |||
279 | if(brush == axis->shadesBrush() || m_force){ |
|
277 | if(brush == axis->shadesBrush() || m_force){ | |
280 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
278 | axis->setShadesBrush(m_backgroundShadesBrush); | |
281 | } |
|
279 | } | |
282 |
|
280 | |||
283 | if(pen == axis->shadesPen() || m_force){ |
|
281 | if(pen == axis->shadesPen() || m_force){ | |
284 | axis->setShadesPen(m_backgroundShadesPen); |
|
282 | axis->setShadesPen(m_backgroundShadesPen); | |
285 | } |
|
283 | } | |
286 |
|
284 | |||
287 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
285 | if( m_force && (m_backgroundShades == BackgroundShadesBoth | |
288 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
286 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
289 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
287 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
290 | axis->setShadesVisible(true); |
|
288 | axis->setShadesVisible(true); | |
291 |
|
289 | |||
292 | } |
|
290 | } | |
293 | } |
|
291 | } | |
294 |
|
292 | |||
295 | if(pen == axis->axisPen() || m_force){ |
|
293 | if(pen == axis->axisPen() || m_force){ | |
296 | axis->setAxisPen(m_axisLinePen); |
|
294 | axis->setAxisPen(m_axisLinePen); | |
297 | } |
|
295 | } | |
298 |
|
296 | |||
299 | if(pen == axis->gridLinePen() || m_force){ |
|
297 | if(pen == axis->gridLinePen() || m_force){ | |
300 | axis->setGridLinePen(m_gridLinePen); |
|
298 | axis->setGridLinePen(m_gridLinePen); | |
301 | } |
|
299 | } | |
302 |
|
300 | |||
303 | if(font == axis->labelsFont() || m_force){ |
|
301 | if(font == axis->labelsFont() || m_force){ | |
304 | axis->setLabelsFont(m_labelFont); |
|
302 | axis->setLabelsFont(m_labelFont); | |
305 | } |
|
303 | } | |
306 | } |
|
304 | } | |
307 | } |
|
305 | } | |
308 |
|
306 | |||
309 | void ChartTheme::generateSeriesGradients() |
|
307 | void ChartTheme::generateSeriesGradients() | |
310 | { |
|
308 | { | |
311 | // Generate gradients in HSV color space |
|
309 | // Generate gradients in HSV color space | |
312 | foreach (const QColor& color, m_seriesColors) { |
|
310 | foreach (const QColor& color, m_seriesColors) { | |
313 | QLinearGradient g; |
|
311 | QLinearGradient g; | |
314 | qreal h = color.hsvHueF(); |
|
312 | qreal h = color.hsvHueF(); | |
315 | qreal s = color.hsvSaturationF(); |
|
313 | qreal s = color.hsvSaturationF(); | |
316 |
|
314 | |||
317 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
315 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
318 | // most themes. The rest of the gradients we can define manually in theme specific |
|
316 | // most themes. The rest of the gradients we can define manually in theme specific | |
319 | // implementation. |
|
317 | // implementation. | |
320 | QColor start = color; |
|
318 | QColor start = color; | |
321 | start.setHsvF(h, 0.0, 1.0); |
|
319 | start.setHsvF(h, 0.0, 1.0); | |
322 | g.setColorAt(0.0, start); |
|
320 | g.setColorAt(0.0, start); | |
323 |
|
321 | |||
324 | g.setColorAt(0.5, color); |
|
322 | g.setColorAt(0.5, color); | |
325 |
|
323 | |||
326 | QColor end = color; |
|
324 | QColor end = color; | |
327 | end.setHsvF(h, s, 0.25); |
|
325 | end.setHsvF(h, s, 0.25); | |
328 | g.setColorAt(1.0, end); |
|
326 | g.setColorAt(1.0, end); | |
329 |
|
327 | |||
330 | m_seriesGradients << g; |
|
328 | m_seriesGradients << g; | |
331 | } |
|
329 | } | |
332 | } |
|
330 | } | |
333 |
|
331 | |||
334 |
|
332 | |||
335 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
333 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
336 | { |
|
334 | { | |
337 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
335 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
338 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
336 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
339 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
337 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
340 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
338 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
341 | QColor c; |
|
339 | QColor c; | |
342 | c.setRgbF(r, g, b); |
|
340 | c.setRgbF(r, g, b); | |
343 | return c; |
|
341 | return c; | |
344 | } |
|
342 | } | |
345 |
|
343 | |||
346 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
344 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
347 | { |
|
345 | { | |
348 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
346 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
349 |
|
347 | |||
350 | QGradientStops stops = gradient.stops(); |
|
348 | QGradientStops stops = gradient.stops(); | |
351 | int count = stops.count(); |
|
349 | int count = stops.count(); | |
352 |
|
350 | |||
353 | // find previous stop relative to position |
|
351 | // find previous stop relative to position | |
354 | QGradientStop prev = stops.first(); |
|
352 | QGradientStop prev = stops.first(); | |
355 | for (int i = 0; i < count; i++) { |
|
353 | for (int i = 0; i < count; i++) { | |
356 | QGradientStop stop = stops.at(i); |
|
354 | QGradientStop stop = stops.at(i); | |
357 | if (pos > stop.first) |
|
355 | if (pos > stop.first) | |
358 | prev = stop; |
|
356 | prev = stop; | |
359 |
|
357 | |||
360 | // given position is actually a stop position? |
|
358 | // given position is actually a stop position? | |
361 | if (pos == stop.first) { |
|
359 | if (pos == stop.first) { | |
362 | //qDebug() << "stop color" << pos; |
|
360 | //qDebug() << "stop color" << pos; | |
363 | return stop.second; |
|
361 | return stop.second; | |
364 | } |
|
362 | } | |
365 | } |
|
363 | } | |
366 |
|
364 | |||
367 | // find next stop relative to position |
|
365 | // find next stop relative to position | |
368 | QGradientStop next = stops.last(); |
|
366 | QGradientStop next = stops.last(); | |
369 | for (int i = count - 1; i >= 0; i--) { |
|
367 | for (int i = count - 1; i >= 0; i--) { | |
370 | QGradientStop stop = stops.at(i); |
|
368 | QGradientStop stop = stops.at(i); | |
371 | if (pos < stop.first) |
|
369 | if (pos < stop.first) | |
372 | next = stop; |
|
370 | next = stop; | |
373 | } |
|
371 | } | |
374 |
|
372 | |||
375 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
373 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
376 |
|
374 | |||
377 | qreal range = next.first - prev.first; |
|
375 | qreal range = next.first - prev.first; | |
378 | qreal posDelta = pos - prev.first; |
|
376 | qreal posDelta = pos - prev.first; | |
379 | qreal relativePos = posDelta / range; |
|
377 | qreal relativePos = posDelta / range; | |
380 |
|
378 | |||
381 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
379 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
382 |
|
380 | |||
383 | return colorAt(prev.second, next.second, relativePos); |
|
381 | return colorAt(prev.second, next.second, relativePos); | |
384 | } |
|
382 | } | |
385 |
|
383 | |||
386 | void ChartTheme::setForced(bool enabled) |
|
384 | void ChartTheme::setForced(bool enabled) | |
387 | { |
|
385 | { | |
388 | m_force=enabled; |
|
386 | m_force=enabled; | |
389 | } |
|
387 | } | |
390 |
|
388 | |||
391 | QTCOMMERCIALCHART_END_NAMESPACE |
|
389 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,111 +1,110 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEME_H |
|
30 | #ifndef CHARTTHEME_H | |
31 | #define CHARTTHEME_H |
|
31 | #define CHARTTHEME_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qchart.h" |
|
34 | #include "qchart.h" | |
35 | #include <QColor> |
|
35 | #include <QColor> | |
36 | #include <QGradientStops> |
|
36 | #include <QGradientStops> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class ChartItem; |
|
40 | class ChartItem; | |
41 | class LineChartItem; |
|
41 | class LineChartItem; | |
42 | class QLineSeries; |
|
42 | class QLineSeries; | |
43 | class BarChartItem; |
|
43 | class BarChartItem; | |
44 | class QBarSeries; |
|
44 | class QBarSeries; | |
45 | class StackedBarChartItem; |
|
45 | class StackedBarChartItem; | |
46 | class QStackedBarSeries; |
|
46 | class QStackedBarSeries; | |
47 | class QPercentBarSeries; |
|
47 | class QPercentBarSeries; | |
48 | class PercentBarChartItem; |
|
48 | class PercentBarChartItem; | |
49 | class QScatterSeries; |
|
49 | class QScatterSeries; | |
50 | class ScatterChartItem; |
|
50 | class ScatterChartItem; | |
51 | class PieChartItem; |
|
51 | class PieChartItem; | |
52 | class QPieSeries; |
|
52 | class QPieSeries; | |
53 | class SplineChartItem; |
|
53 | class SplineChartItem; | |
54 | class QSplineSeries; |
|
54 | class QSplineSeries; | |
55 | class AreaChartItem; |
|
55 | class AreaChartItem; | |
56 | class QAreaSeries; |
|
56 | class QAreaSeries; | |
57 |
|
57 | |||
58 | class ChartTheme |
|
58 | class ChartTheme | |
59 | { |
|
59 | { | |
60 | public: |
|
60 | public: | |
61 | enum BackgroundShadesMode { |
|
61 | enum BackgroundShadesMode { | |
62 | BackgroundShadesNone = 0, |
|
62 | BackgroundShadesNone = 0, | |
63 | BackgroundShadesVertical, |
|
63 | BackgroundShadesVertical, | |
64 | BackgroundShadesHorizontal, |
|
64 | BackgroundShadesHorizontal, | |
65 | BackgroundShadesBoth |
|
65 | BackgroundShadesBoth | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 | protected: |
|
68 | protected: | |
69 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight); |
|
69 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight); | |
70 | public: |
|
70 | public: | |
71 | static ChartTheme *createTheme(QChart::ChartTheme theme); |
|
71 | static ChartTheme *createTheme(QChart::ChartTheme theme); | |
72 | QChart::ChartTheme id() const {return m_id;} |
|
72 | QChart::ChartTheme id() const {return m_id;} | |
73 | void decorate(QChart *chart); |
|
73 | void decorate(QChart *chart); | |
74 | void decorate(QLegend *legend); |
|
74 | void decorate(QLegend *legend); | |
75 | void decorate(QBarSeries *series, int index); |
|
75 | void decorate(QBarSeries *series, int index); | |
76 | void decorate(QLineSeries *series, int index); |
|
76 | void decorate(QLineSeries *series, int index); | |
77 | void decorate(QAreaSeries *series, int index); |
|
77 | void decorate(QAreaSeries *series, int index); | |
78 | void decorate(QScatterSeries *series, int index); |
|
78 | void decorate(QScatterSeries *series, int index); | |
79 | void decorate(QPieSeries *series, int index); |
|
79 | void decorate(QPieSeries *series, int index); | |
80 | void decorate(QSplineSeries *series, int index); |
|
80 | void decorate(QSplineSeries *series, int index); | |
81 | void decorate(QAxis *axis, bool axisX); |
|
81 | void decorate(QAxis *axis, bool axisX); | |
82 | void setForced(bool enabled); |
|
82 | void setForced(bool enabled); | |
83 | bool isForced() { return m_force; } |
|
83 | bool isForced() { return m_force; } | |
84 |
|
84 | |||
85 | public: // utils |
|
85 | public: // utils | |
86 | void generateSeriesGradients(); |
|
86 | void generateSeriesGradients(); | |
87 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
87 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |
88 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
88 | static QColor colorAt(const QGradient &gradient, qreal pos); | |
89 |
|
89 | |||
90 | protected: |
|
90 | protected: | |
91 | QChart::ChartTheme m_id; |
|
91 | QChart::ChartTheme m_id; | |
92 | QList<QColor> m_seriesColors; |
|
92 | QList<QColor> m_seriesColors; | |
93 | QList<QGradient> m_seriesGradients; |
|
93 | QList<QGradient> m_seriesGradients; | |
94 | QLinearGradient m_chartBackgroundGradient; |
|
94 | QLinearGradient m_chartBackgroundGradient; | |
95 |
|
95 | |||
96 | QFont m_masterFont; |
|
96 | QFont m_masterFont; | |
97 | QFont m_labelFont; |
|
97 | QFont m_labelFont; | |
98 |
QBrush m_ |
|
98 | QBrush m_labelBrush; | |
99 | QPen m_axisLinePen; |
|
99 | QPen m_axisLinePen; | |
100 | QBrush m_axisLabelBrush; |
|
|||
101 | QPen m_backgroundShadesPen; |
|
100 | QPen m_backgroundShadesPen; | |
102 | QBrush m_backgroundShadesBrush; |
|
101 | QBrush m_backgroundShadesBrush; | |
103 | BackgroundShadesMode m_backgroundShades; |
|
102 | BackgroundShadesMode m_backgroundShades; | |
104 | bool m_backgroundDropShadowEnabled; |
|
103 | bool m_backgroundDropShadowEnabled; | |
105 | QPen m_gridLinePen; |
|
104 | QPen m_gridLinePen; | |
106 | bool m_force; |
|
105 | bool m_force; | |
107 | }; |
|
106 | }; | |
108 |
|
107 | |||
109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE | |
110 |
|
109 | |||
111 | #endif // CHARTTHEME_H |
|
110 | #endif // CHARTTHEME_H |
@@ -1,231 +1,220 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "legendmarker_p.h" |
|
21 | #include "legendmarker_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qpieseries.h" |
|
26 | #include "qpieseries.h" | |
27 | #include "qpieslice.h" |
|
27 | #include "qpieslice.h" | |
28 | #include "qbarset.h" |
|
28 | #include "qbarset.h" | |
29 | #include "qbarset_p.h" |
|
29 | #include "qbarset_p.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qareaseries_p.h" |
|
31 | #include "qareaseries_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 | #include <QGraphicsSceneEvent> |
|
33 | #include <QGraphicsSceneEvent> | |
34 | #include <QGraphicsSimpleTextItem> |
|
34 | #include <QGraphicsSimpleTextItem> | |
35 | #include <QDebug> |
|
35 | #include <QDebug> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : |
|
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : | |
40 | QGraphicsObject(legend), |
|
40 | QGraphicsObject(legend), | |
41 | m_series(series), |
|
41 | m_series(series), | |
42 | m_markerRect(0,0,10.0,10.0), |
|
42 | m_markerRect(0,0,10.0,10.0), | |
43 | m_boundingRect(0,0,0,0), |
|
43 | m_boundingRect(0,0,0,0), | |
44 | m_legend(legend), |
|
44 | m_legend(legend), | |
45 | m_textItem(new QGraphicsSimpleTextItem(this)), |
|
45 | m_textItem(new QGraphicsSimpleTextItem(this)), | |
46 | m_rectItem(new QGraphicsRectItem(this)) |
|
46 | m_rectItem(new QGraphicsRectItem(this)) | |
47 | { |
|
47 | { | |
48 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
48 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
49 | m_rectItem->setRect(m_markerRect); |
|
49 | m_rectItem->setRect(m_markerRect); | |
50 | updateLayout(); |
|
50 | updateLayout(); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | void LegendMarker::setPen(const QPen &pen) |
|
53 | void LegendMarker::setPen(const QPen &pen) | |
54 | { |
|
54 | { | |
55 |
m_ |
|
55 | m_rectItem->setPen(pen); | |
56 | updateLayout(); |
|
56 | updateLayout(); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QPen LegendMarker::pen() const |
|
59 | QPen LegendMarker::pen() const | |
60 | { |
|
60 | { | |
61 |
return m_ |
|
61 | return m_rectItem->pen(); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void LegendMarker::setBrush(const QBrush &brush) |
|
64 | void LegendMarker::setBrush(const QBrush &brush) | |
65 | { |
|
65 | { | |
66 | m_rectItem->setBrush(brush); |
|
66 | m_rectItem->setBrush(brush); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | QBrush LegendMarker::brush() const |
|
69 | QBrush LegendMarker::brush() const | |
70 | { |
|
70 | { | |
71 | return m_rectItem->brush(); |
|
71 | return m_rectItem->brush(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void LegendMarker::setFont(const QFont &font) |
|
74 | void LegendMarker::setFont(const QFont &font) | |
75 | { |
|
75 | { | |
76 | m_textItem->setFont(font); |
|
76 | m_textItem->setFont(font); | |
77 | updateLayout(); |
|
77 | updateLayout(); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | QFont LegendMarker::font() const |
|
80 | QFont LegendMarker::font() const | |
81 | { |
|
81 | { | |
82 | return m_textItem->font(); |
|
82 | return m_textItem->font(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void LegendMarker::setLabel(const QString label) |
|
85 | void LegendMarker::setLabel(const QString label) | |
86 | { |
|
86 | { | |
87 | m_textItem->setText(label); |
|
87 | m_textItem->setText(label); | |
88 | updateLayout(); |
|
88 | updateLayout(); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void LegendMarker::setSize(const QSize& size) |
|
91 | void LegendMarker::setSize(const QSize& size) | |
92 | { |
|
92 | { | |
93 | m_markerRect = QRectF(0,0,size.width(),size.height()); |
|
93 | m_markerRect = QRectF(0,0,size.width(),size.height()); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | QString LegendMarker::label() const |
|
96 | QString LegendMarker::label() const | |
97 | { |
|
97 | { | |
98 | return m_textItem->text(); |
|
98 | return m_textItem->text(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void LegendMarker::setLabelBrush(const QBrush &brush) |
|
101 | void LegendMarker::setLabelBrush(const QBrush &brush) | |
102 | { |
|
102 | { | |
103 | m_textItem->setBrush(brush); |
|
103 | m_textItem->setBrush(brush); | |
104 | updateLayout(); |
|
104 | updateLayout(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | QBrush LegendMarker::labelBrush() const |
|
107 | QBrush LegendMarker::labelBrush() const | |
108 | { |
|
108 | { | |
109 | return m_textItem->brush(); |
|
109 | return m_textItem->brush(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void LegendMarker::setLabelPen(const QPen &pen) |
|
|||
113 | { |
|
|||
114 | m_textItem->setPen(pen); |
|
|||
115 | updateLayout(); |
|
|||
116 | } |
|
|||
117 |
|
||||
118 | QPen LegendMarker::labelPen() const |
|
|||
119 | { |
|
|||
120 | return m_textItem->pen(); |
|
|||
121 | } |
|
|||
122 |
|
||||
123 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
112 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
124 | { |
|
113 | { | |
125 | Q_UNUSED(option) |
|
114 | Q_UNUSED(option) | |
126 | Q_UNUSED(widget) |
|
115 | Q_UNUSED(widget) | |
127 | Q_UNUSED(painter) |
|
116 | Q_UNUSED(painter) | |
128 | } |
|
117 | } | |
129 |
|
118 | |||
130 | QRectF LegendMarker::boundingRect() const |
|
119 | QRectF LegendMarker::boundingRect() const | |
131 | { |
|
120 | { | |
132 | return m_boundingRect; |
|
121 | return m_boundingRect; | |
133 | } |
|
122 | } | |
134 |
|
123 | |||
135 | void LegendMarker::updateLayout() |
|
124 | void LegendMarker::updateLayout() | |
136 | { |
|
125 | { | |
137 |
|
126 | |||
138 | static const qreal margin = 2; |
|
127 | static const qreal margin = 2; | |
139 | static const qreal space = 4; |
|
128 | static const qreal space = 4; | |
140 |
|
129 | |||
141 | const QRectF& textRect = m_textItem->boundingRect(); |
|
130 | const QRectF& textRect = m_textItem->boundingRect(); | |
142 | prepareGeometryChange(); |
|
131 | prepareGeometryChange(); | |
143 | m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin)); |
|
132 | m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin)); | |
144 | m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2); |
|
133 | m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2); | |
145 | m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2); |
|
134 | m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2); | |
146 |
|
135 | |||
147 | } |
|
136 | } | |
148 |
|
137 | |||
149 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
138 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
150 | { |
|
139 | { | |
151 | QGraphicsObject::mousePressEvent(event); |
|
140 | QGraphicsObject::mousePressEvent(event); | |
152 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now |
|
141 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now | |
153 | } |
|
142 | } | |
154 |
|
143 | |||
155 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
144 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
156 |
|
145 | |||
157 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), |
|
146 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), | |
158 | m_series(series) |
|
147 | m_series(series) | |
159 | { |
|
148 | { | |
160 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
149 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
161 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
150 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
162 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
151 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
163 | updated(); |
|
152 | updated(); | |
164 | } |
|
153 | } | |
165 |
|
154 | |||
166 | void AreaLegendMarker::updated() |
|
155 | void AreaLegendMarker::updated() | |
167 | { |
|
156 | { | |
168 | setBrush(m_series->brush()); |
|
157 | setBrush(m_series->brush()); | |
169 | setLabel(m_series->name()); |
|
158 | setLabel(m_series->name()); | |
170 | } |
|
159 | } | |
171 |
|
160 | |||
172 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
161 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
173 |
|
162 | |||
174 | BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), |
|
163 | BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), | |
175 | m_barset(barset) |
|
164 | m_barset(barset) | |
176 | { |
|
165 | { | |
177 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); |
|
166 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); | |
178 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); |
|
167 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); | |
179 | updated(); |
|
168 | updated(); | |
180 | } |
|
169 | } | |
181 |
|
170 | |||
182 | void BarLegendMarker::updated() |
|
171 | void BarLegendMarker::updated() | |
183 | { |
|
172 | { | |
184 | setBrush(m_barset->brush()); |
|
173 | setBrush(m_barset->brush()); | |
185 | setLabel(m_barset->label()); |
|
174 | setLabel(m_barset->label()); | |
186 | } |
|
175 | } | |
187 |
|
176 | |||
188 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
189 |
|
178 | |||
190 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), |
|
179 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), | |
191 | m_pieslice(pieslice) |
|
180 | m_pieslice(pieslice) | |
192 | { |
|
181 | { | |
193 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
182 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
194 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
183 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
195 | updated(); |
|
184 | updated(); | |
196 | } |
|
185 | } | |
197 |
|
186 | |||
198 | void PieLegendMarker::updated() |
|
187 | void PieLegendMarker::updated() | |
199 | { |
|
188 | { | |
200 | setBrush(m_pieslice->brush()); |
|
189 | setBrush(m_pieslice->brush()); | |
201 | setLabel(m_pieslice->label()); |
|
190 | setLabel(m_pieslice->label()); | |
202 | } |
|
191 | } | |
203 |
|
192 | |||
204 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
193 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
205 |
|
194 | |||
206 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), |
|
195 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), | |
207 | m_series(series) |
|
196 | m_series(series) | |
208 | { |
|
197 | { | |
209 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
198 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
210 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
199 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
211 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
200 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
212 | updated(); |
|
201 | updated(); | |
213 | } |
|
202 | } | |
214 |
|
203 | |||
215 | void XYLegendMarker::updated() |
|
204 | void XYLegendMarker::updated() | |
216 | { |
|
205 | { | |
217 | setLabel(m_series->name()); |
|
206 | setLabel(m_series->name()); | |
218 |
|
207 | |||
219 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) |
|
208 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) | |
220 | { |
|
209 | { | |
221 | setBrush(m_series->brush()); |
|
210 | setBrush(m_series->brush()); | |
222 |
|
211 | |||
223 | } |
|
212 | } | |
224 | else { |
|
213 | else { | |
225 | setBrush(QBrush(m_series->pen().color())); |
|
214 | setBrush(QBrush(m_series->pen().color())); | |
226 | } |
|
215 | } | |
227 | } |
|
216 | } | |
228 |
|
217 | |||
229 | #include "moc_legendmarker_p.cpp" |
|
218 | #include "moc_legendmarker_p.cpp" | |
230 |
|
219 | |||
231 | QTCOMMERCIALCHART_END_NAMESPACE |
|
220 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,141 +1,139 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef LEGENDMARKER_P_H |
|
30 | #ifndef LEGENDMARKER_P_H | |
31 | #define LEGENDMARKER_P_H |
|
31 | #define LEGENDMARKER_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsObject> |
|
34 | #include <QGraphicsObject> | |
35 | #include <QBrush> |
|
35 | #include <QBrush> | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QGraphicsSimpleTextItem> |
|
37 | #include <QGraphicsSimpleTextItem> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class QAbstractSeries; |
|
41 | class QAbstractSeries; | |
42 | class QAreaSeries; |
|
42 | class QAreaSeries; | |
43 | class QXYSeries; |
|
43 | class QXYSeries; | |
44 | class QBarSet; |
|
44 | class QBarSet; | |
45 | class QBarSeries; |
|
45 | class QBarSeries; | |
46 | class QPieSlice; |
|
46 | class QPieSlice; | |
47 | class QLegend; |
|
47 | class QLegend; | |
48 | class QPieSeries; |
|
48 | class QPieSeries; | |
49 |
|
49 | |||
50 | class LegendMarker : public QGraphicsObject |
|
50 | class LegendMarker : public QGraphicsObject | |
51 | { |
|
51 | { | |
52 | Q_OBJECT |
|
52 | Q_OBJECT | |
53 |
|
53 | |||
54 | public: |
|
54 | public: | |
55 | explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent); |
|
55 | explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent); | |
56 |
|
56 | |||
57 | void setPen(const QPen &pen); |
|
57 | void setPen(const QPen &pen); | |
58 | QPen pen() const; |
|
58 | QPen pen() const; | |
59 | void setBrush(const QBrush &brush); |
|
59 | void setBrush(const QBrush &brush); | |
60 | QBrush brush() const; |
|
60 | QBrush brush() const; | |
61 |
|
61 | |||
62 | void setFont(const QFont &font); |
|
62 | void setFont(const QFont &font); | |
63 | QFont font() const; |
|
63 | QFont font() const; | |
64 |
|
64 | |||
65 | void setSize(const QSize& size); |
|
65 | void setSize(const QSize& size); | |
66 |
|
66 | |||
67 | void setLabel(const QString label); |
|
67 | void setLabel(const QString label); | |
68 | QString label() const; |
|
68 | QString label() const; | |
69 | void setLabelBrush(const QBrush &brush); |
|
69 | void setLabelBrush(const QBrush &brush); | |
70 | QBrush labelBrush() const; |
|
70 | QBrush labelBrush() const; | |
71 | void setLabelPen(const QPen &pen); |
|
|||
72 | QPen labelPen() const; |
|
|||
73 |
|
71 | |||
74 | QAbstractSeries *series() const { return m_series;} |
|
72 | QAbstractSeries *series() const { return m_series;} | |
75 |
|
73 | |||
76 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
74 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
77 |
|
75 | |||
78 | QRectF boundingRect() const; |
|
76 | QRectF boundingRect() const; | |
79 |
|
77 | |||
80 | void updateLayout(); |
|
78 | void updateLayout(); | |
81 |
|
79 | |||
82 | protected: |
|
80 | protected: | |
83 | // From QGraphicsObject |
|
81 | // From QGraphicsObject | |
84 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
82 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
85 |
|
83 | |||
86 | public Q_SLOTS: |
|
84 | public Q_SLOTS: | |
87 | virtual void updated() = 0; |
|
85 | virtual void updated() = 0; | |
88 |
|
86 | |||
89 | protected: |
|
87 | protected: | |
90 | QAbstractSeries *m_series; |
|
88 | QAbstractSeries *m_series; | |
91 | QRectF m_markerRect; |
|
89 | QRectF m_markerRect; | |
92 | QRectF m_boundingRect; |
|
90 | QRectF m_boundingRect; | |
93 | QLegend* m_legend; |
|
91 | QLegend* m_legend; | |
94 | QGraphicsSimpleTextItem *m_textItem; |
|
92 | QGraphicsSimpleTextItem *m_textItem; | |
95 | QGraphicsRectItem *m_rectItem; |
|
93 | QGraphicsRectItem *m_rectItem; | |
96 |
|
94 | |||
97 | }; |
|
95 | }; | |
98 |
|
96 | |||
99 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
100 | class XYLegendMarker : public LegendMarker |
|
98 | class XYLegendMarker : public LegendMarker | |
101 | { |
|
99 | { | |
102 | public: |
|
100 | public: | |
103 | XYLegendMarker(QXYSeries *series, QLegend *legend); |
|
101 | XYLegendMarker(QXYSeries *series, QLegend *legend); | |
104 | protected: |
|
102 | protected: | |
105 | void updated(); |
|
103 | void updated(); | |
106 | private: |
|
104 | private: | |
107 | QXYSeries *m_series; |
|
105 | QXYSeries *m_series; | |
108 | }; |
|
106 | }; | |
109 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
110 | class AreaLegendMarker : public LegendMarker |
|
108 | class AreaLegendMarker : public LegendMarker | |
111 | { |
|
109 | { | |
112 | public: |
|
110 | public: | |
113 | AreaLegendMarker(QAreaSeries *series, QLegend *legend); |
|
111 | AreaLegendMarker(QAreaSeries *series, QLegend *legend); | |
114 | protected: |
|
112 | protected: | |
115 | void updated(); |
|
113 | void updated(); | |
116 | private: |
|
114 | private: | |
117 | QAreaSeries *m_series; |
|
115 | QAreaSeries *m_series; | |
118 | }; |
|
116 | }; | |
119 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
120 | class BarLegendMarker : public LegendMarker |
|
118 | class BarLegendMarker : public LegendMarker | |
121 | { |
|
119 | { | |
122 | public: |
|
120 | public: | |
123 | BarLegendMarker(QBarSeries *barseries, QBarSet *barset,QLegend *legend); |
|
121 | BarLegendMarker(QBarSeries *barseries, QBarSet *barset,QLegend *legend); | |
124 | protected: |
|
122 | protected: | |
125 | void updated(); |
|
123 | void updated(); | |
126 | private: |
|
124 | private: | |
127 | QBarSet *m_barset; |
|
125 | QBarSet *m_barset; | |
128 | }; |
|
126 | }; | |
129 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
130 | class PieLegendMarker : public LegendMarker |
|
128 | class PieLegendMarker : public LegendMarker | |
131 | { |
|
129 | { | |
132 | public: |
|
130 | public: | |
133 | PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend); |
|
131 | PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend); | |
134 | protected: |
|
132 | protected: | |
135 | void updated(); |
|
133 | void updated(); | |
136 | private: |
|
134 | private: | |
137 | QPieSlice *m_pieslice; |
|
135 | QPieSlice *m_pieslice; | |
138 | }; |
|
136 | }; | |
139 |
|
137 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
138 | QTCOMMERCIALCHART_END_NAMESPACE | |
141 | #endif // LEGENDMARKER_P_H |
|
139 | #endif // LEGENDMARKER_P_H |
@@ -1,873 +1,844 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 |
|
26 | |||
27 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 |
|
44 | |||
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \class QLegend |
|
50 | \class QLegend | |
51 | \brief Legend object |
|
51 | \brief Legend object | |
52 | \mainclass |
|
52 | \mainclass | |
53 |
|
53 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
56 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
58 | |||
59 | \image examples_percentbarchart_legend.png |
|
59 | \image examples_percentbarchart_legend.png | |
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlclass Legend QLegend |
|
64 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
66 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is used via ChartView class. For example: |
|
68 | series have been changed. Legend is used via ChartView class. For example: | |
69 | \code |
|
69 | \code | |
70 | ChartView { |
|
70 | ChartView { | |
71 | legend.visible: true |
|
71 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
72 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 |
|
76 | |||
77 | \image examples_percentbarchart_legend.png |
|
77 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLegend::alignment |
|
81 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
82 | \brief The alignment of the legend. | |
83 |
|
83 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
89 | \brief The alignment of the legend. | |
90 |
|
90 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QLegend::backgroundVisible |
|
96 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
97 | Whether the legend background is visible or not. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
100 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QLegend::color |
|
105 | \property QLegend::color | |
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty color Legend::color |
|
110 | \qmlproperty color Legend::color | |
111 | The color of the legend, i.e. the background (brush) color. |
|
111 | The color of the legend, i.e. the background (brush) color. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \property QLegend::borderColor |
|
115 | \property QLegend::borderColor | |
116 | The border color of the legend, i.e. the line color. |
|
116 | The border color of the legend, i.e. the line color. | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty color Legend::borderColor |
|
119 | \qmlproperty color Legend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
120 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \property QLegend::font |
|
124 | \property QLegend::font | |
125 | The font of markers used by legend |
|
125 | The font of markers used by legend | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlproperty color Legend::font |
|
128 | \qmlproperty color Legend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
133 | \fn void QLegend::backgroundVisibleChanged(bool) | |
134 | The visibility of the legend background changed to \a visible. |
|
134 | The visibility of the legend background changed to \a visible. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QLegend::colorChanged(QColor) |
|
138 | \fn void QLegend::colorChanged(QColor) | |
139 | The color of the legend background changed to \a color. |
|
139 | The color of the legend background changed to \a color. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \fn void QLegend::borderColorChanged(QColor) |
|
143 | \fn void QLegend::borderColorChanged(QColor) | |
144 | The border color of the legend background changed to \a color. |
|
144 | The border color of the legend background changed to \a color. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QLegend::fontChanged(QFont) |
|
148 | \fn void QLegend::fontChanged(QFont) | |
149 | The font of markers of the legend changed to \a font. |
|
149 | The font of markers of the legend changed to \a font. | |
150 | */ |
|
150 | */ | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \fn qreal QLegend::minWidth() const |
|
153 | \fn qreal QLegend::minWidth() const | |
154 | Returns minimum width of the legend |
|
154 | Returns minimum width of the legend | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \fn qreal QLegend::minHeight() const |
|
158 | \fn qreal QLegend::minHeight() const | |
159 | Returns minimum height of the legend |
|
159 | Returns minimum height of the legend | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | Constructs the legend object and sets the parent to \a parent |
|
163 | Constructs the legend object and sets the parent to \a parent | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
166 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
167 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
167 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) | |
168 | { |
|
168 | { | |
169 | setZValue(ChartPresenter::LegendZValue); |
|
169 | setZValue(ChartPresenter::LegendZValue); | |
170 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
170 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
171 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
171 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
172 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
172 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
173 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
173 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
177 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
178 | */ |
|
178 | */ | |
179 | QLegend::~QLegend() |
|
179 | QLegend::~QLegend() | |
180 | { |
|
180 | { | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | \internal |
|
184 | \internal | |
185 | */ |
|
185 | */ | |
186 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
186 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
187 | { |
|
187 | { | |
188 | Q_UNUSED(option) |
|
188 | Q_UNUSED(option) | |
189 | Q_UNUSED(widget) |
|
189 | Q_UNUSED(widget) | |
190 | if(!d_ptr->m_backgroundVisible) return; |
|
190 | if(!d_ptr->m_backgroundVisible) return; | |
191 |
|
191 | |||
192 | painter->setOpacity(opacity()); |
|
192 | painter->setOpacity(opacity()); | |
193 | painter->setPen(d_ptr->m_pen); |
|
193 | painter->setPen(d_ptr->m_pen); | |
194 | painter->setBrush(d_ptr->m_brush); |
|
194 | painter->setBrush(d_ptr->m_brush); | |
195 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
195 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal |
|
199 | \internal | |
200 | */ |
|
200 | */ | |
201 | QRectF QLegend::boundingRect() const |
|
201 | QRectF QLegend::boundingRect() const | |
202 | { |
|
202 | { | |
203 | return d_ptr->m_rect; |
|
203 | return d_ptr->m_rect; | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the \a brush of legend. Brush affects the background of legend. |
|
207 | Sets the \a brush of legend. Brush affects the background of legend. | |
208 | */ |
|
208 | */ | |
209 | void QLegend::setBrush(const QBrush &brush) |
|
209 | void QLegend::setBrush(const QBrush &brush) | |
210 | { |
|
210 | { | |
211 | if (d_ptr->m_brush != brush) { |
|
211 | if (d_ptr->m_brush != brush) { | |
212 | d_ptr->m_brush = brush; |
|
212 | d_ptr->m_brush = brush; | |
213 | update(); |
|
213 | update(); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Returns the brush used by legend. |
|
218 | Returns the brush used by legend. | |
219 | */ |
|
219 | */ | |
220 | QBrush QLegend::brush() const |
|
220 | QBrush QLegend::brush() const | |
221 | { |
|
221 | { | |
222 | return d_ptr->m_brush; |
|
222 | return d_ptr->m_brush; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QLegend::setColor(QColor color) |
|
225 | void QLegend::setColor(QColor color) | |
226 | { |
|
226 | { | |
227 | QBrush b = d_ptr->m_brush; |
|
227 | QBrush b = d_ptr->m_brush; | |
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
229 | b.setStyle(Qt::SolidPattern); |
|
229 | b.setStyle(Qt::SolidPattern); | |
230 | b.setColor(color); |
|
230 | b.setColor(color); | |
231 | setBrush(b); |
|
231 | setBrush(b); | |
232 | emit colorChanged(color); |
|
232 | emit colorChanged(color); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QColor QLegend::color() |
|
236 | QColor QLegend::color() | |
237 | { |
|
237 | { | |
238 | return d_ptr->m_brush.color(); |
|
238 | return d_ptr->m_brush.color(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Sets the \a pen of legend. Pen affects the legend borders. |
|
242 | Sets the \a pen of legend. Pen affects the legend borders. | |
243 | */ |
|
243 | */ | |
244 | void QLegend::setPen(const QPen &pen) |
|
244 | void QLegend::setPen(const QPen &pen) | |
245 | { |
|
245 | { | |
246 | if (d_ptr->m_pen != pen) { |
|
246 | if (d_ptr->m_pen != pen) { | |
247 | d_ptr->m_pen = pen; |
|
247 | d_ptr->m_pen = pen; | |
248 | update(); |
|
248 | update(); | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | Returns the pen used by legend |
|
253 | Returns the pen used by legend | |
254 | */ |
|
254 | */ | |
255 |
|
255 | |||
256 | QPen QLegend::pen() const |
|
256 | QPen QLegend::pen() const | |
257 | { |
|
257 | { | |
258 | return d_ptr->m_pen; |
|
258 | return d_ptr->m_pen; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void QLegend::setBorderColor(QColor color) |
|
261 | void QLegend::setBorderColor(QColor color) | |
262 | { |
|
262 | { | |
263 | QPen p = d_ptr->m_pen; |
|
263 | QPen p = d_ptr->m_pen; | |
264 | if (p.color() != color) { |
|
264 | if (p.color() != color) { | |
265 | p.setColor(color); |
|
265 | p.setColor(color); | |
266 | setPen(p); |
|
266 | setPen(p); | |
267 | emit borderColorChanged(color); |
|
267 | emit borderColorChanged(color); | |
268 | } |
|
268 | } | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | QColor QLegend::borderColor() |
|
271 | QColor QLegend::borderColor() | |
272 | { |
|
272 | { | |
273 | return d_ptr->m_pen.color(); |
|
273 | return d_ptr->m_pen.color(); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void QLegend::setFont(const QFont &font) |
|
276 | void QLegend::setFont(const QFont &font) | |
277 | { |
|
277 | { | |
278 | if (d_ptr->m_font != font) { |
|
278 | if (d_ptr->m_font != font) { | |
279 | d_ptr->setFont(font); |
|
279 | d_ptr->setFont(font); | |
280 | emit fontChanged(font); |
|
280 | emit fontChanged(font); | |
281 | } |
|
281 | } | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | QFont QLegend::font() const |
|
284 | QFont QLegend::font() const | |
285 | { |
|
285 | { | |
286 | return d_ptr->m_font; |
|
286 | return d_ptr->m_font; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void QLegend::setLabelPen(const QPen &pen) |
|
|||
290 | { |
|
|||
291 | if (d_ptr->m_labelPen != pen) { |
|
|||
292 | d_ptr->setLabelPen(pen); |
|
|||
293 | emit labelPenChanged(pen); |
|
|||
294 | } |
|
|||
295 | } |
|
|||
296 |
|
||||
297 | QPen QLegend::labelPen() const |
|
|||
298 | { |
|
|||
299 | return d_ptr->m_labelPen; |
|
|||
300 | } |
|
|||
301 |
|
||||
302 | void QLegend::setLabelBrush(const QBrush &brush) |
|
289 | void QLegend::setLabelBrush(const QBrush &brush) | |
303 | { |
|
290 | { | |
304 | qDebug() << "setting legend brush 1"; |
|
|||
305 | if (d_ptr->m_labelBrush != brush) { |
|
291 | if (d_ptr->m_labelBrush != brush) { | |
306 | d_ptr->setLabelBrush(brush); |
|
292 | d_ptr->setLabelBrush(brush); | |
307 | emit labelBrushChanged(brush); |
|
293 | emit labelBrushChanged(brush); | |
308 | qDebug() << "setting legend brush 2"; |
|
|||
309 | } |
|
294 | } | |
310 | } |
|
295 | } | |
311 |
|
296 | |||
312 | QBrush QLegend::labelBrush() const |
|
297 | QBrush QLegend::labelBrush() const | |
313 | { |
|
298 | { | |
314 | return d_ptr->m_labelBrush; |
|
299 | return d_ptr->m_labelBrush; | |
315 | } |
|
300 | } | |
316 |
|
301 | |||
317 | void QLegend::setLabelColor(QColor color) |
|
302 | void QLegend::setLabelColor(QColor color) | |
318 | { |
|
303 | { | |
319 | QBrush b = d_ptr->m_labelBrush; |
|
304 | QBrush b = d_ptr->m_labelBrush; | |
320 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
305 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
321 | b.setStyle(Qt::SolidPattern); |
|
306 | b.setStyle(Qt::SolidPattern); | |
322 | b.setColor(color); |
|
307 | b.setColor(color); | |
323 | setLabelBrush(b); |
|
308 | setLabelBrush(b); | |
324 | emit labelColorChanged(color); |
|
309 | emit labelColorChanged(color); | |
325 | } |
|
310 | } | |
326 | } |
|
311 | } | |
327 |
|
312 | |||
328 | QColor QLegend::labelColor() const |
|
313 | QColor QLegend::labelColor() const | |
329 | { |
|
314 | { | |
330 | return d_ptr->m_labelBrush.color(); |
|
315 | return d_ptr->m_labelBrush.color(); | |
331 | } |
|
316 | } | |
332 |
|
317 | |||
333 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
318 | void QLegend::setAlignment(Qt::Alignment alignment) | |
334 | { |
|
319 | { | |
335 | if(d_ptr->m_alignment!=alignment) { |
|
320 | if(d_ptr->m_alignment!=alignment) { | |
336 | d_ptr->m_alignment = alignment; |
|
321 | d_ptr->m_alignment = alignment; | |
337 | d_ptr->updateLayout(); |
|
322 | d_ptr->updateLayout(); | |
338 | } |
|
323 | } | |
339 | } |
|
324 | } | |
340 |
|
325 | |||
341 | Qt::Alignment QLegend::alignment() const |
|
326 | Qt::Alignment QLegend::alignment() const | |
342 | { |
|
327 | { | |
343 | return d_ptr->m_alignment; |
|
328 | return d_ptr->m_alignment; | |
344 | } |
|
329 | } | |
345 |
|
330 | |||
346 | /*! |
|
331 | /*! | |
347 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
332 | Detaches the legend from chart. Chart won't change layout of the legend. | |
348 | */ |
|
333 | */ | |
349 | void QLegend::detachFromChart() |
|
334 | void QLegend::detachFromChart() | |
350 | { |
|
335 | { | |
351 | d_ptr->m_attachedToChart = false; |
|
336 | d_ptr->m_attachedToChart = false; | |
352 | } |
|
337 | } | |
353 |
|
338 | |||
354 | /*! |
|
339 | /*! | |
355 | Attaches the legend to chart. Chart may change layout of the legend. |
|
340 | Attaches the legend to chart. Chart may change layout of the legend. | |
356 | */ |
|
341 | */ | |
357 | void QLegend::attachToChart() |
|
342 | void QLegend::attachToChart() | |
358 | { |
|
343 | { | |
359 | d_ptr->attachToChart(); |
|
344 | d_ptr->attachToChart(); | |
360 | } |
|
345 | } | |
361 |
|
346 | |||
362 | /*! |
|
347 | /*! | |
363 | Returns true, if legend is attached to chart. |
|
348 | Returns true, if legend is attached to chart. | |
364 | */ |
|
349 | */ | |
365 | bool QLegend::isAttachedToChart() |
|
350 | bool QLegend::isAttachedToChart() | |
366 | { |
|
351 | { | |
367 | return d_ptr->m_attachedToChart; |
|
352 | return d_ptr->m_attachedToChart; | |
368 | } |
|
353 | } | |
369 |
|
354 | |||
370 | /*! |
|
355 | /*! | |
371 | Sets the visibility of legend background to \a visible |
|
356 | Sets the visibility of legend background to \a visible | |
372 | */ |
|
357 | */ | |
373 | void QLegend::setBackgroundVisible(bool visible) |
|
358 | void QLegend::setBackgroundVisible(bool visible) | |
374 | { |
|
359 | { | |
375 | if(d_ptr->m_backgroundVisible != visible) { |
|
360 | if(d_ptr->m_backgroundVisible != visible) { | |
376 | d_ptr->m_backgroundVisible = visible; |
|
361 | d_ptr->m_backgroundVisible = visible; | |
377 | update(); |
|
362 | update(); | |
378 | emit backgroundVisibleChanged(visible); |
|
363 | emit backgroundVisibleChanged(visible); | |
379 | } |
|
364 | } | |
380 | } |
|
365 | } | |
381 |
|
366 | |||
382 | /*! |
|
367 | /*! | |
383 | Returns the visibility of legend background |
|
368 | Returns the visibility of legend background | |
384 | */ |
|
369 | */ | |
385 | bool QLegend::isBackgroundVisible() const |
|
370 | bool QLegend::isBackgroundVisible() const | |
386 | { |
|
371 | { | |
387 | return d_ptr->m_backgroundVisible; |
|
372 | return d_ptr->m_backgroundVisible; | |
388 | } |
|
373 | } | |
389 |
|
374 | |||
390 | /*! |
|
375 | /*! | |
391 | \internal \a event see QGraphicsWidget for details |
|
376 | \internal \a event see QGraphicsWidget for details | |
392 | */ |
|
377 | */ | |
393 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
378 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
394 | { |
|
379 | { | |
395 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
380 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
396 | QGraphicsWidget::resizeEvent(event); |
|
381 | QGraphicsWidget::resizeEvent(event); | |
397 | if(d_ptr->m_rect != rect) { |
|
382 | if(d_ptr->m_rect != rect) { | |
398 | d_ptr->m_rect = rect; |
|
383 | d_ptr->m_rect = rect; | |
399 | d_ptr->updateLayout(); |
|
384 | d_ptr->updateLayout(); | |
400 | } |
|
385 | } | |
401 | } |
|
386 | } | |
402 |
|
387 | |||
403 | /*! |
|
388 | /*! | |
404 | \internal \a event see QGraphicsWidget for details |
|
389 | \internal \a event see QGraphicsWidget for details | |
405 | */ |
|
390 | */ | |
406 | void QLegend::hideEvent(QHideEvent *event) |
|
391 | void QLegend::hideEvent(QHideEvent *event) | |
407 | { |
|
392 | { | |
408 | QGraphicsWidget::hideEvent(event); |
|
393 | QGraphicsWidget::hideEvent(event); | |
409 | setEnabled(false); |
|
394 | setEnabled(false); | |
410 | d_ptr->updateLayout(); |
|
395 | d_ptr->updateLayout(); | |
411 | } |
|
396 | } | |
412 |
|
397 | |||
413 | /*! |
|
398 | /*! | |
414 | \internal \a event see QGraphicsWidget for details |
|
399 | \internal \a event see QGraphicsWidget for details | |
415 | */ |
|
400 | */ | |
416 | void QLegend::showEvent(QShowEvent *event) |
|
401 | void QLegend::showEvent(QShowEvent *event) | |
417 | { |
|
402 | { | |
418 | QGraphicsWidget::showEvent(event); |
|
403 | QGraphicsWidget::showEvent(event); | |
419 | setEnabled(true); |
|
404 | setEnabled(true); | |
420 | d_ptr->updateLayout(); |
|
405 | d_ptr->updateLayout(); | |
421 | } |
|
406 | } | |
422 |
|
407 | |||
423 | qreal QLegend::minWidth() const |
|
408 | qreal QLegend::minWidth() const | |
424 | { |
|
409 | { | |
425 | return d_ptr->m_minWidth; |
|
410 | return d_ptr->m_minWidth; | |
426 | } |
|
411 | } | |
427 |
|
412 | |||
428 | qreal QLegend::minHeight() const |
|
413 | qreal QLegend::minHeight() const | |
429 | { |
|
414 | { | |
430 | return d_ptr->m_minHeight; |
|
415 | return d_ptr->m_minHeight; | |
431 | } |
|
416 | } | |
432 |
|
417 | |||
433 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
418 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
434 |
|
419 | |||
435 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
420 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): | |
436 | q_ptr(q), |
|
421 | q_ptr(q), | |
437 | m_presenter(presenter), |
|
422 | m_presenter(presenter), | |
438 | m_chart(chart), |
|
423 | m_chart(chart), | |
439 | m_markers(new QGraphicsItemGroup(q)), |
|
424 | m_markers(new QGraphicsItemGroup(q)), | |
440 | m_alignment(Qt::AlignTop), |
|
425 | m_alignment(Qt::AlignTop), | |
441 | m_brush(QBrush()), |
|
426 | m_brush(QBrush()), | |
442 | m_pen(QPen()), |
|
427 | m_pen(QPen()), | |
443 | m_labelPen(QPen(Qt::NoPen)), |
|
|||
444 | m_labelBrush(QBrush()), |
|
428 | m_labelBrush(QBrush()), | |
445 | m_offsetX(0), |
|
429 | m_offsetX(0), | |
446 | m_offsetY(0), |
|
430 | m_offsetY(0), | |
447 | m_minWidth(0), |
|
431 | m_minWidth(0), | |
448 | m_minHeight(0), |
|
432 | m_minHeight(0), | |
449 | m_width(0), |
|
433 | m_width(0), | |
450 | m_height(0), |
|
434 | m_height(0), | |
451 | m_diameter(5), |
|
435 | m_diameter(5), | |
452 | m_attachedToChart(true), |
|
436 | m_attachedToChart(true), | |
453 | m_backgroundVisible(false) |
|
437 | m_backgroundVisible(false) | |
454 | { |
|
438 | { | |
455 |
|
439 | |||
456 | } |
|
440 | } | |
457 |
|
441 | |||
458 | QLegendPrivate::~QLegendPrivate() |
|
442 | QLegendPrivate::~QLegendPrivate() | |
459 | { |
|
443 | { | |
460 |
|
444 | |||
461 | } |
|
445 | } | |
462 |
|
446 | |||
463 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
447 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
464 | { |
|
448 | { | |
465 | bool scrollHorizontal = true; |
|
449 | bool scrollHorizontal = true; | |
466 | switch(m_alignment) { |
|
450 | switch(m_alignment) { | |
467 | case Qt::AlignTop: |
|
451 | case Qt::AlignTop: | |
468 | case Qt::AlignBottom: { |
|
452 | case Qt::AlignBottom: { | |
469 | scrollHorizontal = true; |
|
453 | scrollHorizontal = true; | |
470 | break; |
|
454 | break; | |
471 | } |
|
455 | } | |
472 | case Qt::AlignLeft: |
|
456 | case Qt::AlignLeft: | |
473 | case Qt::AlignRight: { |
|
457 | case Qt::AlignRight: { | |
474 | scrollHorizontal = false; |
|
458 | scrollHorizontal = false; | |
475 | break; |
|
459 | break; | |
476 | } |
|
460 | } | |
477 | } |
|
461 | } | |
478 |
|
462 | |||
479 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. |
|
463 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. | |
480 | if (!m_attachedToChart) { |
|
464 | if (!m_attachedToChart) { | |
481 | scrollHorizontal = !scrollHorizontal; |
|
465 | scrollHorizontal = !scrollHorizontal; | |
482 | } |
|
466 | } | |
483 |
|
467 | |||
484 | // Limit offset between m_minOffset and m_maxOffset |
|
468 | // Limit offset between m_minOffset and m_maxOffset | |
485 | if (scrollHorizontal) { |
|
469 | if (scrollHorizontal) { | |
486 | if(m_width<=m_rect.width()) return; |
|
470 | if(m_width<=m_rect.width()) return; | |
487 |
|
471 | |||
488 | if (x != m_offsetX) { |
|
472 | if (x != m_offsetX) { | |
489 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); |
|
473 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); | |
490 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
474 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
491 | } |
|
475 | } | |
492 | } else { |
|
476 | } else { | |
493 | if(m_height<=m_rect.height()) return; |
|
477 | if(m_height<=m_rect.height()) return; | |
494 |
|
478 | |||
495 | if (y != m_offsetY) { |
|
479 | if (y != m_offsetY) { | |
496 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); |
|
480 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); | |
497 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
481 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
498 | } |
|
482 | } | |
499 | } |
|
483 | } | |
500 | } |
|
484 | } | |
501 |
|
485 | |||
502 | QPointF QLegendPrivate::offset() const |
|
486 | QPointF QLegendPrivate::offset() const | |
503 | { |
|
487 | { | |
504 | return QPointF(m_offsetX,m_offsetY); |
|
488 | return QPointF(m_offsetX,m_offsetY); | |
505 | } |
|
489 | } | |
506 |
|
490 | |||
507 | void QLegendPrivate::updateLayout() |
|
491 | void QLegendPrivate::updateLayout() | |
508 | { |
|
492 | { | |
509 | if (!m_attachedToChart) { |
|
493 | if (!m_attachedToChart) { | |
510 | updateDetachedLayout(); |
|
494 | updateDetachedLayout(); | |
511 | return; |
|
495 | return; | |
512 | } |
|
496 | } | |
513 |
|
497 | |||
514 | m_offsetX=0; |
|
498 | m_offsetX=0; | |
515 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
499 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
516 |
|
500 | |||
517 | if(items.isEmpty()) return; |
|
501 | if(items.isEmpty()) return; | |
518 |
|
502 | |||
519 | m_minWidth=0; |
|
503 | m_minWidth=0; | |
520 | m_minHeight=0; |
|
504 | m_minHeight=0; | |
521 |
|
505 | |||
522 | switch(m_alignment) { |
|
506 | switch(m_alignment) { | |
523 |
|
507 | |||
524 | case Qt::AlignTop: |
|
508 | case Qt::AlignTop: | |
525 | case Qt::AlignBottom: { |
|
509 | case Qt::AlignBottom: { | |
526 | QPointF point = m_rect.topLeft(); |
|
510 | QPointF point = m_rect.topLeft(); | |
527 | m_width = 0; |
|
511 | m_width = 0; | |
528 | foreach (QGraphicsItem *item, items) { |
|
512 | foreach (QGraphicsItem *item, items) { | |
529 | if (item->isVisible()) { |
|
513 | if (item->isVisible()) { | |
530 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
514 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
531 | const QRectF& rect = item->boundingRect(); |
|
515 | const QRectF& rect = item->boundingRect(); | |
532 | qreal w = rect.width(); |
|
516 | qreal w = rect.width(); | |
533 | m_minWidth=qMax(m_minWidth,w); |
|
517 | m_minWidth=qMax(m_minWidth,w); | |
534 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
518 | m_minHeight=qMax(m_minHeight,rect.height()); | |
535 | m_width+=w; |
|
519 | m_width+=w; | |
536 | point.setX(point.x() + w); |
|
520 | point.setX(point.x() + w); | |
537 | } |
|
521 | } | |
538 | } |
|
522 | } | |
539 | if(m_width<m_rect.width()) { |
|
523 | if(m_width<m_rect.width()) { | |
540 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
524 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
541 | } |
|
525 | } | |
542 | else { |
|
526 | else { | |
543 | m_markers->setPos(m_rect.topLeft()); |
|
527 | m_markers->setPos(m_rect.topLeft()); | |
544 | } |
|
528 | } | |
545 | m_height=m_minHeight; |
|
529 | m_height=m_minHeight; | |
546 | } |
|
530 | } | |
547 | break; |
|
531 | break; | |
548 | case Qt::AlignLeft: |
|
532 | case Qt::AlignLeft: | |
549 | case Qt::AlignRight: { |
|
533 | case Qt::AlignRight: { | |
550 | QPointF point = m_rect.topLeft(); |
|
534 | QPointF point = m_rect.topLeft(); | |
551 | m_height = 0; |
|
535 | m_height = 0; | |
552 | foreach (QGraphicsItem *item, items) { |
|
536 | foreach (QGraphicsItem *item, items) { | |
553 | if (item->isVisible()) { |
|
537 | if (item->isVisible()) { | |
554 | item->setPos(point); |
|
538 | item->setPos(point); | |
555 | const QRectF& rect = item->boundingRect(); |
|
539 | const QRectF& rect = item->boundingRect(); | |
556 | qreal h = rect.height(); |
|
540 | qreal h = rect.height(); | |
557 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
541 | m_minWidth=qMax(m_minWidth,rect.width()); | |
558 | m_minHeight=qMax(m_minHeight,h); |
|
542 | m_minHeight=qMax(m_minHeight,h); | |
559 | m_height+=h; |
|
543 | m_height+=h; | |
560 | point.setY(point.y() + h); |
|
544 | point.setY(point.y() + h); | |
561 | } |
|
545 | } | |
562 | } |
|
546 | } | |
563 | if(m_height<m_rect.height()) { |
|
547 | if(m_height<m_rect.height()) { | |
564 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
548 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
565 | } |
|
549 | } | |
566 | else { |
|
550 | else { | |
567 | m_markers->setPos(m_rect.topLeft()); |
|
551 | m_markers->setPos(m_rect.topLeft()); | |
568 | } |
|
552 | } | |
569 | m_width=m_minWidth; |
|
553 | m_width=m_minWidth; | |
570 | } |
|
554 | } | |
571 | break; |
|
555 | break; | |
572 | } |
|
556 | } | |
573 |
|
557 | |||
574 | m_minOffsetX = 0; |
|
558 | m_minOffsetX = 0; | |
575 | m_minOffsetY = 0; |
|
559 | m_minOffsetY = 0; | |
576 | m_maxOffsetX = m_width - m_rect.width(); |
|
560 | m_maxOffsetX = m_width - m_rect.width(); | |
577 | m_maxOffsetY = m_height - m_rect.height(); |
|
561 | m_maxOffsetY = m_height - m_rect.height(); | |
578 |
|
562 | |||
579 | m_presenter->updateLayout(); |
|
563 | m_presenter->updateLayout(); | |
580 | } |
|
564 | } | |
581 |
|
565 | |||
582 | void QLegendPrivate::updateDetachedLayout() |
|
566 | void QLegendPrivate::updateDetachedLayout() | |
583 | { |
|
567 | { | |
584 | // Detached layout is different. |
|
568 | // Detached layout is different. | |
585 | // In detached mode legend may have multiple rows and columns, so layout calculations |
|
569 | // In detached mode legend may have multiple rows and columns, so layout calculations | |
586 | // differ a log from attached mode. |
|
570 | // differ a log from attached mode. | |
587 | // Also the scrolling logic is bit different. |
|
571 | // Also the scrolling logic is bit different. | |
588 | m_offsetX=0; |
|
572 | m_offsetX=0; | |
589 | m_offsetY=0; |
|
573 | m_offsetY=0; | |
590 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
574 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
591 |
|
575 | |||
592 | if(items.isEmpty()) return; |
|
576 | if(items.isEmpty()) return; | |
593 |
|
577 | |||
594 | m_minWidth = 0; |
|
578 | m_minWidth = 0; | |
595 | m_minHeight = 0; |
|
579 | m_minHeight = 0; | |
596 |
|
580 | |||
597 | switch (m_alignment) { |
|
581 | switch (m_alignment) { | |
598 | case Qt::AlignTop: { |
|
582 | case Qt::AlignTop: { | |
599 | QPointF point = m_rect.topLeft(); |
|
583 | QPointF point = m_rect.topLeft(); | |
600 | m_width = 0; |
|
584 | m_width = 0; | |
601 | m_height = 0; |
|
585 | m_height = 0; | |
602 | for (int i=0; i<items.count(); i++) { |
|
586 | for (int i=0; i<items.count(); i++) { | |
603 | QGraphicsItem *item = items.at(i); |
|
587 | QGraphicsItem *item = items.at(i); | |
604 | if (item->isVisible()) { |
|
588 | if (item->isVisible()) { | |
605 | const QRectF& rect = item->boundingRect(); |
|
589 | const QRectF& rect = item->boundingRect(); | |
606 | qreal w = rect.width(); |
|
590 | qreal w = rect.width(); | |
607 | qreal h = rect.height(); |
|
591 | qreal h = rect.height(); | |
608 | m_minWidth = qMax(m_minWidth,w); |
|
592 | m_minWidth = qMax(m_minWidth,w); | |
609 | m_minHeight = qMax(m_minHeight,rect.height()); |
|
593 | m_minHeight = qMax(m_minHeight,rect.height()); | |
610 | m_height = qMax(m_height,h); |
|
594 | m_height = qMax(m_height,h); | |
611 | item->setPos(point.x(),point.y()); |
|
595 | item->setPos(point.x(),point.y()); | |
612 | point.setX(point.x() + w); |
|
596 | point.setX(point.x() + w); | |
613 | if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) { |
|
597 | if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) { | |
614 | // Next item would go off rect. |
|
598 | // Next item would go off rect. | |
615 | point.setX(m_rect.topLeft().x()); |
|
599 | point.setX(m_rect.topLeft().x()); | |
616 | point.setY(point.y() + h); |
|
600 | point.setY(point.y() + h); | |
617 | if (i+1 < items.count()) { |
|
601 | if (i+1 < items.count()) { | |
618 | m_height += h; |
|
602 | m_height += h; | |
619 | } |
|
603 | } | |
620 | } |
|
604 | } | |
621 | } |
|
605 | } | |
622 | } |
|
606 | } | |
623 | m_markers->setPos(m_rect.topLeft()); |
|
607 | m_markers->setPos(m_rect.topLeft()); | |
624 | m_width = m_minWidth; |
|
608 | m_width = m_minWidth; | |
625 |
|
609 | |||
626 | m_minOffsetX = 0; |
|
610 | m_minOffsetX = 0; | |
627 | m_minOffsetY = 0; |
|
611 | m_minOffsetY = 0; | |
628 | m_maxOffsetX = m_width - m_rect.width(); |
|
612 | m_maxOffsetX = m_width - m_rect.width(); | |
629 | m_maxOffsetY = m_height - m_rect.height(); |
|
613 | m_maxOffsetY = m_height - m_rect.height(); | |
630 | } |
|
614 | } | |
631 | break; |
|
615 | break; | |
632 | case Qt::AlignBottom: { |
|
616 | case Qt::AlignBottom: { | |
633 | QPointF point = m_rect.bottomLeft(); |
|
617 | QPointF point = m_rect.bottomLeft(); | |
634 | m_width = 0; |
|
618 | m_width = 0; | |
635 | m_height = 0; |
|
619 | m_height = 0; | |
636 | for (int i=0; i<items.count(); i++) { |
|
620 | for (int i=0; i<items.count(); i++) { | |
637 | QGraphicsItem *item = items.at(i); |
|
621 | QGraphicsItem *item = items.at(i); | |
638 | if (item->isVisible()) { |
|
622 | if (item->isVisible()) { | |
639 | const QRectF& rect = item->boundingRect(); |
|
623 | const QRectF& rect = item->boundingRect(); | |
640 | qreal w = rect.width(); |
|
624 | qreal w = rect.width(); | |
641 | qreal h = rect.height(); |
|
625 | qreal h = rect.height(); | |
642 | m_minWidth = qMax(m_minWidth,w); |
|
626 | m_minWidth = qMax(m_minWidth,w); | |
643 | m_minHeight = qMax(m_minHeight,rect.height()); |
|
627 | m_minHeight = qMax(m_minHeight,rect.height()); | |
644 | m_height = qMax(m_height,h); |
|
628 | m_height = qMax(m_height,h); | |
645 | item->setPos(point.x(),point.y() - h); |
|
629 | item->setPos(point.x(),point.y() - h); | |
646 | point.setX(point.x() + w); |
|
630 | point.setX(point.x() + w); | |
647 | if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) { |
|
631 | if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) { | |
648 | // Next item would go off rect. |
|
632 | // Next item would go off rect. | |
649 | point.setX(m_rect.bottomLeft().x()); |
|
633 | point.setX(m_rect.bottomLeft().x()); | |
650 | point.setY(point.y() - h); |
|
634 | point.setY(point.y() - h); | |
651 | if (i+1 < items.count()) { |
|
635 | if (i+1 < items.count()) { | |
652 | m_height += h; |
|
636 | m_height += h; | |
653 | } |
|
637 | } | |
654 | } |
|
638 | } | |
655 | } |
|
639 | } | |
656 | } |
|
640 | } | |
657 | m_markers->setPos(m_rect.topLeft()); |
|
641 | m_markers->setPos(m_rect.topLeft()); | |
658 | m_width = m_minWidth; |
|
642 | m_width = m_minWidth; | |
659 |
|
643 | |||
660 | m_minOffsetX = 0; |
|
644 | m_minOffsetX = 0; | |
661 | m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height()); |
|
645 | m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height()); | |
662 | m_maxOffsetX = m_width - m_rect.width(); |
|
646 | m_maxOffsetX = m_width - m_rect.width(); | |
663 | m_maxOffsetY = 0; |
|
647 | m_maxOffsetY = 0; | |
664 | } |
|
648 | } | |
665 | break; |
|
649 | break; | |
666 | case Qt::AlignLeft: { |
|
650 | case Qt::AlignLeft: { | |
667 | QPointF point = m_rect.topLeft(); |
|
651 | QPointF point = m_rect.topLeft(); | |
668 | m_width = 0; |
|
652 | m_width = 0; | |
669 | m_height = 0; |
|
653 | m_height = 0; | |
670 | qreal maxWidth = 0; |
|
654 | qreal maxWidth = 0; | |
671 | for (int i=0; i<items.count(); i++) { |
|
655 | for (int i=0; i<items.count(); i++) { | |
672 | QGraphicsItem *item = items.at(i); |
|
656 | QGraphicsItem *item = items.at(i); | |
673 | if (item->isVisible()) { |
|
657 | if (item->isVisible()) { | |
674 | const QRectF& rect = item->boundingRect(); |
|
658 | const QRectF& rect = item->boundingRect(); | |
675 | qreal w = rect.width(); |
|
659 | qreal w = rect.width(); | |
676 | qreal h = rect.height(); |
|
660 | qreal h = rect.height(); | |
677 | m_minWidth = qMax(m_minWidth,rect.width()); |
|
661 | m_minWidth = qMax(m_minWidth,rect.width()); | |
678 | m_minHeight = qMax(m_minHeight,h); |
|
662 | m_minHeight = qMax(m_minHeight,h); | |
679 | maxWidth = qMax(maxWidth,w); |
|
663 | maxWidth = qMax(maxWidth,w); | |
680 | item->setPos(point.x(),point.y()); |
|
664 | item->setPos(point.x(),point.y()); | |
681 | point.setY(point.y() + h); |
|
665 | point.setY(point.y() + h); | |
682 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { |
|
666 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { | |
683 | // Next item would go off rect. |
|
667 | // Next item would go off rect. | |
684 | point.setX(point.x() + maxWidth); |
|
668 | point.setX(point.x() + maxWidth); | |
685 | point.setY(m_rect.topLeft().y()); |
|
669 | point.setY(m_rect.topLeft().y()); | |
686 | if (i+1 < items.count()) { |
|
670 | if (i+1 < items.count()) { | |
687 | m_width += maxWidth; |
|
671 | m_width += maxWidth; | |
688 | maxWidth = 0; |
|
672 | maxWidth = 0; | |
689 | } |
|
673 | } | |
690 | } |
|
674 | } | |
691 | } |
|
675 | } | |
692 | } |
|
676 | } | |
693 | m_width += maxWidth; |
|
677 | m_width += maxWidth; | |
694 | m_markers->setPos(m_rect.topLeft()); |
|
678 | m_markers->setPos(m_rect.topLeft()); | |
695 | m_height = m_minHeight; |
|
679 | m_height = m_minHeight; | |
696 |
|
680 | |||
697 | m_minOffsetX = 0; |
|
681 | m_minOffsetX = 0; | |
698 | m_minOffsetY = 0; |
|
682 | m_minOffsetY = 0; | |
699 | m_maxOffsetX = m_width - m_rect.width(); |
|
683 | m_maxOffsetX = m_width - m_rect.width(); | |
700 | m_maxOffsetY = m_height - m_rect.height(); |
|
684 | m_maxOffsetY = m_height - m_rect.height(); | |
701 | } |
|
685 | } | |
702 | break; |
|
686 | break; | |
703 | case Qt::AlignRight: { |
|
687 | case Qt::AlignRight: { | |
704 | QPointF point = m_rect.topRight(); |
|
688 | QPointF point = m_rect.topRight(); | |
705 | m_width = 0; |
|
689 | m_width = 0; | |
706 | m_height = 0; |
|
690 | m_height = 0; | |
707 | qreal maxWidth = 0; |
|
691 | qreal maxWidth = 0; | |
708 | for (int i=0; i<items.count(); i++) { |
|
692 | for (int i=0; i<items.count(); i++) { | |
709 | QGraphicsItem *item = items.at(i); |
|
693 | QGraphicsItem *item = items.at(i); | |
710 | if (item->isVisible()) { |
|
694 | if (item->isVisible()) { | |
711 | const QRectF& rect = item->boundingRect(); |
|
695 | const QRectF& rect = item->boundingRect(); | |
712 | qreal w = rect.width(); |
|
696 | qreal w = rect.width(); | |
713 | qreal h = rect.height(); |
|
697 | qreal h = rect.height(); | |
714 | m_minWidth = qMax(m_minWidth,rect.width()); |
|
698 | m_minWidth = qMax(m_minWidth,rect.width()); | |
715 | m_minHeight = qMax(m_minHeight,h); |
|
699 | m_minHeight = qMax(m_minHeight,h); | |
716 | maxWidth = qMax(maxWidth,w); |
|
700 | maxWidth = qMax(maxWidth,w); | |
717 | item->setPos(point.x() - w,point.y()); |
|
701 | item->setPos(point.x() - w,point.y()); | |
718 | point.setY(point.y() + h); |
|
702 | point.setY(point.y() + h); | |
719 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { |
|
703 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { | |
720 | // Next item would go off rect. |
|
704 | // Next item would go off rect. | |
721 | point.setX(point.x() - maxWidth); |
|
705 | point.setX(point.x() - maxWidth); | |
722 | point.setY(m_rect.topLeft().y()); |
|
706 | point.setY(m_rect.topLeft().y()); | |
723 | if (i+1 < items.count()) { |
|
707 | if (i+1 < items.count()) { | |
724 | m_width += maxWidth; |
|
708 | m_width += maxWidth; | |
725 | maxWidth = 0; |
|
709 | maxWidth = 0; | |
726 | } |
|
710 | } | |
727 | } |
|
711 | } | |
728 | } |
|
712 | } | |
729 | } |
|
713 | } | |
730 | m_width += maxWidth; |
|
714 | m_width += maxWidth; | |
731 | m_markers->setPos(m_rect.topLeft()); |
|
715 | m_markers->setPos(m_rect.topLeft()); | |
732 | m_height = m_minHeight; |
|
716 | m_height = m_minHeight; | |
733 |
|
717 | |||
734 | m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width()); |
|
718 | m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width()); | |
735 | m_minOffsetY = 0; |
|
719 | m_minOffsetY = 0; | |
736 | m_maxOffsetX = 0; |
|
720 | m_maxOffsetX = 0; | |
737 | m_maxOffsetY = m_height - m_rect.height(); |
|
721 | m_maxOffsetY = m_height - m_rect.height(); | |
738 | } |
|
722 | } | |
739 | break; |
|
723 | break; | |
740 | default: |
|
724 | default: | |
741 | break; |
|
725 | break; | |
742 | } |
|
726 | } | |
743 | } |
|
727 | } | |
744 |
|
728 | |||
745 | void QLegendPrivate::attachToChart() |
|
729 | void QLegendPrivate::attachToChart() | |
746 | { |
|
730 | { | |
747 | m_attachedToChart = true; |
|
731 | m_attachedToChart = true; | |
748 | q_ptr->setParent(m_chart); |
|
732 | q_ptr->setParent(m_chart); | |
749 | } |
|
733 | } | |
750 |
|
734 | |||
751 | int QLegendPrivate::roundness(qreal size) |
|
735 | int QLegendPrivate::roundness(qreal size) | |
752 | { |
|
736 | { | |
753 | return 100*m_diameter/int(size); |
|
737 | return 100*m_diameter/int(size); | |
754 | } |
|
738 | } | |
755 |
|
739 | |||
756 | void QLegendPrivate::setFont(const QFont &font) |
|
740 | void QLegendPrivate::setFont(const QFont &font) | |
757 | { |
|
741 | { | |
758 | m_font = font; |
|
742 | m_font = font; | |
759 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
743 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
760 |
|
744 | |||
761 | foreach (QGraphicsItem *markers, items) { |
|
745 | foreach (QGraphicsItem *markers, items) { | |
762 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
746 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
763 | marker->setFont(m_font); |
|
747 | marker->setFont(m_font); | |
764 | } |
|
748 | } | |
765 | updateLayout(); |
|
749 | updateLayout(); | |
766 | } |
|
750 | } | |
767 |
|
751 | |||
768 | void QLegendPrivate::setLabelPen(const QPen &pen) |
|
|||
769 | { |
|
|||
770 | m_labelPen = pen; |
|
|||
771 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
|||
772 |
|
||||
773 | foreach (QGraphicsItem *markers, items) { |
|
|||
774 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
|||
775 | marker->setPen(m_labelPen); |
|
|||
776 | } |
|
|||
777 | updateLayout(); |
|
|||
778 | } |
|
|||
779 |
|
||||
780 | void QLegendPrivate::setLabelBrush(const QBrush &brush) |
|
752 | void QLegendPrivate::setLabelBrush(const QBrush &brush) | |
781 | { |
|
753 | { | |
782 | m_labelBrush = brush; |
|
754 | m_labelBrush = brush; | |
783 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
755 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
784 |
|
756 | |||
785 | foreach (QGraphicsItem *markers, items) { |
|
757 | foreach (QGraphicsItem *markers, items) { | |
786 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
758 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
787 | marker->setLabelBrush(m_labelBrush); |
|
759 | marker->setLabelBrush(m_labelBrush); | |
788 | } |
|
760 | } | |
789 | updateLayout(); |
|
761 | updateLayout(); | |
790 | } |
|
762 | } | |
791 |
|
763 | |||
792 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
764 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
793 | { |
|
765 | { | |
794 | Q_UNUSED(domain) |
|
766 | Q_UNUSED(domain) | |
795 |
|
767 | |||
796 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
768 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
797 | foreach(LegendMarker* marker, markers) { |
|
769 | foreach(LegendMarker* marker, markers) { | |
798 | marker->setFont(m_font); |
|
770 | marker->setFont(m_font); | |
799 | marker->setLabelPen(m_labelPen); |
|
|||
800 | marker->setLabelBrush(m_labelBrush); |
|
771 | marker->setLabelBrush(m_labelBrush); | |
801 | m_markers->addToGroup(marker); |
|
772 | m_markers->addToGroup(marker); | |
802 | } |
|
773 | } | |
803 |
|
774 | |||
804 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
775 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
805 |
|
776 | |||
806 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
777 | if(series->type() == QAbstractSeries::SeriesTypePie) { | |
807 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
778 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
808 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
779 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
809 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
780 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
810 | } |
|
781 | } | |
811 |
|
782 | |||
812 | updateLayout(); |
|
783 | updateLayout(); | |
813 | } |
|
784 | } | |
814 |
|
785 | |||
815 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
786 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
816 | { |
|
787 | { | |
817 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
788 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
818 |
|
789 | |||
819 | foreach (QGraphicsItem *markers, items) { |
|
790 | foreach (QGraphicsItem *markers, items) { | |
820 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
791 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
821 | if (marker->series() == series) { |
|
792 | if (marker->series() == series) { | |
822 | delete marker; |
|
793 | delete marker; | |
823 | } |
|
794 | } | |
824 | } |
|
795 | } | |
825 |
|
796 | |||
826 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
797 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
827 | { |
|
798 | { | |
828 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
799 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
829 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
800 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
830 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
801 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
831 | } |
|
802 | } | |
832 |
|
803 | |||
833 | updateLayout(); |
|
804 | updateLayout(); | |
834 | } |
|
805 | } | |
835 |
|
806 | |||
836 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
807 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) | |
837 | { |
|
808 | { | |
838 | // TODO: find out which markers are are added or removed. Update them |
|
809 | // TODO: find out which markers are are added or removed. Update them | |
839 | // TODO: better implementation |
|
810 | // TODO: better implementation | |
840 | handleSeriesRemoved(series); |
|
811 | handleSeriesRemoved(series); | |
841 | Domain domain; |
|
812 | Domain domain; | |
842 | handleSeriesAdded(series, &domain); |
|
813 | handleSeriesAdded(series, &domain); | |
843 | } |
|
814 | } | |
844 |
|
815 | |||
845 | void QLegendPrivate::handleUpdatePieSeries() |
|
816 | void QLegendPrivate::handleUpdatePieSeries() | |
846 | { |
|
817 | { | |
847 | //TODO: reimplement to be optimal |
|
818 | //TODO: reimplement to be optimal | |
848 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
819 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); | |
849 | Q_ASSERT(series); |
|
820 | Q_ASSERT(series); | |
850 | handleSeriesRemoved(series); |
|
821 | handleSeriesRemoved(series); | |
851 | handleSeriesAdded(series, 0); |
|
822 | handleSeriesAdded(series, 0); | |
852 | } |
|
823 | } | |
853 |
|
824 | |||
854 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
825 | void QLegendPrivate::handleSeriesVisibleChanged() | |
855 | { |
|
826 | { | |
856 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); |
|
827 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); | |
857 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
828 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
858 |
|
829 | |||
859 | foreach (QGraphicsItem *markers, items) { |
|
830 | foreach (QGraphicsItem *markers, items) { | |
860 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
831 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
861 | if (marker->series() == series) { |
|
832 | if (marker->series() == series) { | |
862 | marker->setVisible(!marker->isVisible()); |
|
833 | marker->setVisible(!marker->isVisible()); | |
863 | } |
|
834 | } | |
864 | } |
|
835 | } | |
865 |
|
836 | |||
866 | updateLayout(); |
|
837 | updateLayout(); | |
867 | } |
|
838 | } | |
868 |
|
839 | |||
869 |
|
840 | |||
870 | #include "moc_qlegend.cpp" |
|
841 | #include "moc_qlegend.cpp" | |
871 | #include "moc_qlegend_p.cpp" |
|
842 | #include "moc_qlegend_p.cpp" | |
872 |
|
843 | |||
873 | QTCOMMERCIALCHART_END_NAMESPACE |
|
844 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,121 +1,114 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Domain; |
|
31 | class Domain; | |
32 | class LegendMarker; |
|
32 | class LegendMarker; | |
33 | class QPieSlice; |
|
33 | class QPieSlice; | |
34 | class QXYSeries; |
|
34 | class QXYSeries; | |
35 | class QBarSet; |
|
35 | class QBarSet; | |
36 | class QBarSeries; |
|
36 | class QBarSeries; | |
37 | class QPieSeries; |
|
37 | class QPieSeries; | |
38 | class QAreaSeries; |
|
38 | class QAreaSeries; | |
39 | class LegendScrollButton; |
|
39 | class LegendScrollButton; | |
40 | class QChart; |
|
40 | class QChart; | |
41 | class QLegendPrivate; |
|
41 | class QLegendPrivate; | |
42 |
|
42 | |||
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) | |
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) | |
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) | |
51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
52 | // TODO? |
|
|||
53 | // Q_PROPERTY(QColor labelBorderColor READ labelBorderColor WRITE setLabelBorderColor NOTIFY labelBorderColorChanged) |
|
|||
54 |
|
52 | |||
55 | private: |
|
53 | private: | |
56 | explicit QLegend(QChart *chart); |
|
54 | explicit QLegend(QChart *chart); | |
57 |
|
55 | |||
58 | public: |
|
56 | public: | |
59 | ~QLegend(); |
|
57 | ~QLegend(); | |
60 |
|
58 | |||
61 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
59 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
62 | QRectF boundingRect() const; |
|
60 | QRectF boundingRect() const; | |
63 |
|
61 | |||
64 | void setBrush(const QBrush &brush); |
|
62 | void setBrush(const QBrush &brush); | |
65 | QBrush brush() const; |
|
63 | QBrush brush() const; | |
66 | void setColor(QColor color); |
|
64 | void setColor(QColor color); | |
67 | QColor color(); |
|
65 | QColor color(); | |
68 |
|
66 | |||
69 | void setPen(const QPen &pen); |
|
67 | void setPen(const QPen &pen); | |
70 | QPen pen() const; |
|
68 | QPen pen() const; | |
71 | void setBorderColor(QColor color); |
|
69 | void setBorderColor(QColor color); | |
72 | QColor borderColor(); |
|
70 | QColor borderColor(); | |
73 |
|
71 | |||
74 | void setFont(const QFont &font); |
|
72 | void setFont(const QFont &font); | |
75 | QFont font() const; |
|
73 | QFont font() const; | |
76 | void setLabelPen(const QPen &pen); |
|
|||
77 | QPen labelPen() const; |
|
|||
78 | void setLabelBrush(const QBrush &brush); |
|
74 | void setLabelBrush(const QBrush &brush); | |
79 | QBrush labelBrush() const; |
|
75 | QBrush labelBrush() const; | |
80 |
|
76 | |||
81 | void setLabelColor(QColor color); |
|
77 | void setLabelColor(QColor color); | |
82 | QColor labelColor() const; |
|
78 | QColor labelColor() const; | |
83 |
|
79 | |||
84 | void setAlignment(Qt::Alignment alignment); |
|
80 | void setAlignment(Qt::Alignment alignment); | |
85 | Qt::Alignment alignment() const; |
|
81 | Qt::Alignment alignment() const; | |
86 |
|
82 | |||
87 | void detachFromChart(); |
|
83 | void detachFromChart(); | |
88 | void attachToChart(); |
|
84 | void attachToChart(); | |
89 | bool isAttachedToChart(); |
|
85 | bool isAttachedToChart(); | |
90 |
|
86 | |||
91 | qreal minWidth() const; |
|
87 | qreal minWidth() const; | |
92 | qreal minHeight() const; |
|
88 | qreal minHeight() const; | |
93 |
|
89 | |||
94 | void setBackgroundVisible(bool visible = true); |
|
90 | void setBackgroundVisible(bool visible = true); | |
95 | bool isBackgroundVisible() const; |
|
91 | bool isBackgroundVisible() const; | |
96 |
|
92 | |||
97 | protected: |
|
93 | protected: | |
98 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
94 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
99 | void hideEvent(QHideEvent *event); |
|
95 | void hideEvent(QHideEvent *event); | |
100 | void showEvent(QShowEvent *event); |
|
96 | void showEvent(QShowEvent *event); | |
101 |
|
97 | |||
102 | Q_SIGNALS: |
|
98 | Q_SIGNALS: | |
103 | void backgroundVisibleChanged(bool visible); |
|
99 | void backgroundVisibleChanged(bool visible); | |
104 | void colorChanged(QColor color); |
|
100 | void colorChanged(QColor color); | |
105 | void borderColorChanged(QColor color); |
|
101 | void borderColorChanged(QColor color); | |
106 | void fontChanged(QFont font); |
|
102 | void fontChanged(QFont font); | |
107 | void labelPenChanged(QPen pen); |
|
|||
108 | void labelBrushChanged(QBrush brush); |
|
103 | void labelBrushChanged(QBrush brush); | |
109 | void labelColorChanged(QColor color); |
|
104 | void labelColorChanged(QColor color); | |
110 | // TODO? |
|
|||
111 | // void labelBorderColorChanged(QColor color); |
|
|||
112 |
|
105 | |||
113 | private: |
|
106 | private: | |
114 | QScopedPointer<QLegendPrivate> d_ptr; |
|
107 | QScopedPointer<QLegendPrivate> d_ptr; | |
115 | Q_DISABLE_COPY(QLegend) |
|
108 | Q_DISABLE_COPY(QLegend) | |
116 | friend class LegendScroller; |
|
109 | friend class LegendScroller; | |
117 | }; |
|
110 | }; | |
118 |
|
111 | |||
119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
112 | QTCOMMERCIALCHART_END_NAMESPACE | |
120 |
|
113 | |||
121 | #endif // QLEGEND_H |
|
114 | #endif // QLEGEND_H |
@@ -1,97 +1,95 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QLEGEND_P_H |
|
30 | #ifndef QLEGEND_P_H | |
31 | #define QLEGEND_P_H |
|
31 | #define QLEGEND_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QChart; |
|
37 | class QChart; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QAbstractSeries; |
|
39 | class QAbstractSeries; | |
40 |
|
40 | |||
41 | class QLegendPrivate : public QObject |
|
41 | class QLegendPrivate : public QObject | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
45 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); | |
46 | ~QLegendPrivate(); |
|
46 | ~QLegendPrivate(); | |
47 |
|
47 | |||
48 | void setOffset(qreal x, qreal y); |
|
48 | void setOffset(qreal x, qreal y); | |
49 | QPointF offset() const; |
|
49 | QPointF offset() const; | |
50 | void updateLayout(); |
|
50 | void updateLayout(); | |
51 | void updateDetachedLayout(); |
|
51 | void updateDetachedLayout(); | |
52 | void attachToChart(); |
|
52 | void attachToChart(); | |
53 | int roundness(qreal size); |
|
53 | int roundness(qreal size); | |
54 | void setFont(const QFont &font); |
|
54 | void setFont(const QFont &font); | |
55 | void setLabelPen(const QPen &pen); |
|
|||
56 | void setLabelBrush(const QBrush &brush); |
|
55 | void setLabelBrush(const QBrush &brush); | |
57 |
|
56 | |||
58 | public Q_SLOTS: |
|
57 | public Q_SLOTS: | |
59 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); |
|
58 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); | |
60 | void handleSeriesRemoved(QAbstractSeries *series); |
|
59 | void handleSeriesRemoved(QAbstractSeries *series); | |
61 | void handleSeriesUpdated(QAbstractSeries *series); |
|
60 | void handleSeriesUpdated(QAbstractSeries *series); | |
62 | void handleUpdatePieSeries(); //TODO remove this function |
|
61 | void handleUpdatePieSeries(); //TODO remove this function | |
63 | void handleSeriesVisibleChanged(); |
|
62 | void handleSeriesVisibleChanged(); | |
64 |
|
63 | |||
65 | private: |
|
64 | private: | |
66 | QLegend *q_ptr; |
|
65 | QLegend *q_ptr; | |
67 | ChartPresenter *m_presenter; |
|
66 | ChartPresenter *m_presenter; | |
68 | QChart* m_chart; |
|
67 | QChart* m_chart; | |
69 | QGraphicsItemGroup* m_markers; |
|
68 | QGraphicsItemGroup* m_markers; | |
70 | Qt::Alignment m_alignment; |
|
69 | Qt::Alignment m_alignment; | |
71 | QBrush m_brush; |
|
70 | QBrush m_brush; | |
72 | QPen m_pen; |
|
71 | QPen m_pen; | |
73 | QFont m_font; |
|
72 | QFont m_font; | |
74 | QPen m_labelPen; |
|
|||
75 | QBrush m_labelBrush; |
|
73 | QBrush m_labelBrush; | |
76 | QRectF m_rect; |
|
74 | QRectF m_rect; | |
77 | qreal m_offsetX; |
|
75 | qreal m_offsetX; | |
78 | qreal m_offsetY; |
|
76 | qreal m_offsetY; | |
79 | qreal m_minOffsetX; |
|
77 | qreal m_minOffsetX; | |
80 | qreal m_minOffsetY; |
|
78 | qreal m_minOffsetY; | |
81 | qreal m_maxOffsetX; |
|
79 | qreal m_maxOffsetX; | |
82 | qreal m_maxOffsetY; |
|
80 | qreal m_maxOffsetY; | |
83 | qreal m_minWidth; |
|
81 | qreal m_minWidth; | |
84 | qreal m_minHeight; |
|
82 | qreal m_minHeight; | |
85 | qreal m_width; |
|
83 | qreal m_width; | |
86 | qreal m_height; |
|
84 | qreal m_height; | |
87 | qreal m_diameter; |
|
85 | qreal m_diameter; | |
88 | bool m_attachedToChart; |
|
86 | bool m_attachedToChart; | |
89 | bool m_backgroundVisible; |
|
87 | bool m_backgroundVisible; | |
90 |
|
88 | |||
91 | friend class QLegend; |
|
89 | friend class QLegend; | |
92 |
|
90 | |||
93 | }; |
|
91 | }; | |
94 |
|
92 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
93 | QTCOMMERCIALCHART_END_NAMESPACE | |
96 |
|
94 | |||
97 | #endif |
|
95 | #endif |
@@ -1,70 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEBLUECERULEAN_P_H |
|
30 | #ifndef CHARTTHEMEBLUECERULEAN_P_H | |
31 | #define CHARTTHEMEBLUECERULEAN_P_H |
|
31 | #define CHARTTHEMEBLUECERULEAN_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeBlueCerulean: public ChartTheme |
|
37 | class ChartThemeBlueCerulean: public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) |
|
40 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0xc7e85b); |
|
43 | m_seriesColors << QRgb(0xc7e85b); | |
44 | m_seriesColors << QRgb(0x1cb54f); |
|
44 | m_seriesColors << QRgb(0x1cb54f); | |
45 | m_seriesColors << QRgb(0x5cbf9b); |
|
45 | m_seriesColors << QRgb(0x5cbf9b); | |
46 | m_seriesColors << QRgb(0x009fbf); |
|
46 | m_seriesColors << QRgb(0x009fbf); | |
47 | m_seriesColors << QRgb(0xee7392); |
|
47 | m_seriesColors << QRgb(0xee7392); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0x056189)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0x056189)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0x101a31)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0x101a31)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 |
|
56 | |||
57 | // Axes and other |
|
57 | // Axes and other | |
58 |
m_ |
|
58 | m_labelBrush = QBrush(QRgb(0xffffff)); | |
59 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); |
|
59 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |
60 | m_axisLinePen.setWidth(2); |
|
60 | m_axisLinePen.setWidth(2); | |
61 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); |
|
|||
62 | m_gridLinePen = QPen(QRgb(0x84a2b0)); |
|
61 | m_gridLinePen = QPen(QRgb(0x84a2b0)); | |
63 | m_gridLinePen.setWidth(1); |
|
62 | m_gridLinePen.setWidth(1); | |
64 | m_backgroundShades = BackgroundShadesNone; |
|
63 | m_backgroundShades = BackgroundShadesNone; | |
65 | } |
|
64 | } | |
66 | }; |
|
65 | }; | |
67 |
|
66 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
68 | |||
70 | #endif |
|
69 | #endif |
@@ -1,71 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEBLUEICY_P_H |
|
30 | #ifndef CHARTTHEMEBLUEICY_P_H | |
31 | #define CHARTTHEMEBLUEICY_P_H |
|
31 | #define CHARTTHEMEBLUEICY_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeBlueIcy: public ChartTheme |
|
37 | class ChartThemeBlueIcy: public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeBlueIcy() : ChartTheme(QChart::ChartThemeBlueIcy) |
|
40 | ChartThemeBlueIcy() : ChartTheme(QChart::ChartThemeBlueIcy) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0x3daeda); |
|
43 | m_seriesColors << QRgb(0x3daeda); | |
44 | m_seriesColors << QRgb(0x2685bf); |
|
44 | m_seriesColors << QRgb(0x2685bf); | |
45 | m_seriesColors << QRgb(0x0c2673); |
|
45 | m_seriesColors << QRgb(0x0c2673); | |
46 | m_seriesColors << QRgb(0x5f3dba); |
|
46 | m_seriesColors << QRgb(0x5f3dba); | |
47 | m_seriesColors << QRgb(0x2fa3b4); |
|
47 | m_seriesColors << QRgb(0x2fa3b4); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 | m_backgroundDropShadowEnabled = true; |
|
56 | m_backgroundDropShadowEnabled = true; | |
57 |
|
57 | |||
58 | // Axes and other |
|
58 | // Axes and other | |
59 |
m_ |
|
59 | m_labelBrush = QBrush(QRgb(0x404044)); | |
60 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); |
|
60 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |
61 | m_axisLinePen.setWidth(2); |
|
61 | m_axisLinePen.setWidth(2); | |
62 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
|||
63 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
62 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
64 | m_gridLinePen.setWidth(1); |
|
63 | m_gridLinePen.setWidth(1); | |
65 | m_backgroundShades = BackgroundShadesNone; |
|
64 | m_backgroundShades = BackgroundShadesNone; | |
66 | } |
|
65 | } | |
67 | }; |
|
66 | }; | |
68 |
|
67 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
69 | |||
71 | #endif |
|
70 | #endif |
@@ -1,70 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEBLUENCS_P_H |
|
30 | #ifndef CHARTTHEMEBLUENCS_P_H | |
31 | #define CHARTTHEMEBLUENCS_P_H |
|
31 | #define CHARTTHEMEBLUENCS_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeBlueNcs: public ChartTheme |
|
37 | class ChartThemeBlueNcs: public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeBlueNcs() : ChartTheme(QChart::ChartThemeBlueNcs) |
|
40 | ChartThemeBlueNcs() : ChartTheme(QChart::ChartThemeBlueNcs) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0x1db0da); |
|
43 | m_seriesColors << QRgb(0x1db0da); | |
44 | m_seriesColors << QRgb(0x1341a6); |
|
44 | m_seriesColors << QRgb(0x1341a6); | |
45 | m_seriesColors << QRgb(0x88d41e); |
|
45 | m_seriesColors << QRgb(0x88d41e); | |
46 | m_seriesColors << QRgb(0xff8e1a); |
|
46 | m_seriesColors << QRgb(0xff8e1a); | |
47 | m_seriesColors << QRgb(0x398ca3); |
|
47 | m_seriesColors << QRgb(0x398ca3); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 |
|
56 | |||
57 | // Axes and other |
|
57 | // Axes and other | |
58 |
m_ |
|
58 | m_labelBrush = QBrush(QRgb(0x404044)); | |
59 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); |
|
59 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |
60 | m_axisLinePen.setWidth(2); |
|
60 | m_axisLinePen.setWidth(2); | |
61 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
|||
62 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
61 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
63 | m_gridLinePen.setWidth(1); |
|
62 | m_gridLinePen.setWidth(1); | |
64 | m_backgroundShades = BackgroundShadesNone; |
|
63 | m_backgroundShades = BackgroundShadesNone; | |
65 | } |
|
64 | } | |
66 | }; |
|
65 | }; | |
67 |
|
66 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
68 | |||
70 | #endif |
|
69 | #endif |
@@ -1,70 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEBROWNSAND_P_H |
|
30 | #ifndef CHARTTHEMEBROWNSAND_P_H | |
31 | #define CHARTTHEMEBROWNSAND_P_H |
|
31 | #define CHARTTHEMEBROWNSAND_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeBrownSand: public ChartTheme |
|
37 | class ChartThemeBrownSand: public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeBrownSand() : ChartTheme(QChart::ChartThemeBrownSand) |
|
40 | ChartThemeBrownSand() : ChartTheme(QChart::ChartThemeBrownSand) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0xb39b72); |
|
43 | m_seriesColors << QRgb(0xb39b72); | |
44 | m_seriesColors << QRgb(0xb3b376); |
|
44 | m_seriesColors << QRgb(0xb3b376); | |
45 | m_seriesColors << QRgb(0xc35660); |
|
45 | m_seriesColors << QRgb(0xc35660); | |
46 | m_seriesColors << QRgb(0x536780); |
|
46 | m_seriesColors << QRgb(0x536780); | |
47 | m_seriesColors << QRgb(0x494345); |
|
47 | m_seriesColors << QRgb(0x494345); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0xf3ece0)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0xf3ece0)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0xf3ece0)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0xf3ece0)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 |
|
56 | |||
57 | // Axes and other |
|
57 | // Axes and other | |
58 |
m_ |
|
58 | m_labelBrush = QBrush(QRgb(0x404044)); | |
59 | m_axisLinePen = QPen(QRgb(0xb5b0a7)); |
|
59 | m_axisLinePen = QPen(QRgb(0xb5b0a7)); | |
60 | m_axisLinePen.setWidth(2); |
|
60 | m_axisLinePen.setWidth(2); | |
61 | m_axisLabelBrush = QBrush(QRgb(0x404044)); |
|
|||
62 | m_gridLinePen = QPen(QRgb(0xd4cec3)); |
|
61 | m_gridLinePen = QPen(QRgb(0xd4cec3)); | |
63 | m_gridLinePen.setWidth(1); |
|
62 | m_gridLinePen.setWidth(1); | |
64 | m_backgroundShades = BackgroundShadesNone; |
|
63 | m_backgroundShades = BackgroundShadesNone; | |
65 | } |
|
64 | } | |
66 | }; |
|
65 | }; | |
67 |
|
66 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
68 | |||
70 | #endif |
|
69 | #endif |
@@ -1,70 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEDARK_P_H |
|
30 | #ifndef CHARTTHEMEDARK_P_H | |
31 | #define CHARTTHEMEDARK_P_H |
|
31 | #define CHARTTHEMEDARK_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeDark : public ChartTheme |
|
37 | class ChartThemeDark : public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeDark() : ChartTheme(QChart::ChartThemeDark) |
|
40 | ChartThemeDark() : ChartTheme(QChart::ChartThemeDark) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0x38ad6b); |
|
43 | m_seriesColors << QRgb(0x38ad6b); | |
44 | m_seriesColors << QRgb(0x3c84a7); |
|
44 | m_seriesColors << QRgb(0x3c84a7); | |
45 | m_seriesColors << QRgb(0xeb8817); |
|
45 | m_seriesColors << QRgb(0xeb8817); | |
46 | m_seriesColors << QRgb(0x7b7f8c); |
|
46 | m_seriesColors << QRgb(0x7b7f8c); | |
47 | m_seriesColors << QRgb(0xbf593e); |
|
47 | m_seriesColors << QRgb(0xbf593e); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0x2e303a)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0x2e303a)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0x121218)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0x121218)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 |
|
56 | |||
57 | // Axes and other |
|
57 | // Axes and other | |
58 |
m_ |
|
58 | m_labelBrush = QBrush(QRgb(0xffffff)); | |
59 | m_axisLinePen = QPen(QRgb(0x86878c)); |
|
59 | m_axisLinePen = QPen(QRgb(0x86878c)); | |
60 | m_axisLinePen.setWidth(2); |
|
60 | m_axisLinePen.setWidth(2); | |
61 | m_axisLabelBrush = QBrush(QRgb(0xffffff)); |
|
|||
62 | m_gridLinePen = QPen(QRgb(0x86878c)); |
|
61 | m_gridLinePen = QPen(QRgb(0x86878c)); | |
63 | m_gridLinePen.setWidth(1); |
|
62 | m_gridLinePen.setWidth(1); | |
64 | m_backgroundShades = BackgroundShadesNone; |
|
63 | m_backgroundShades = BackgroundShadesNone; | |
65 | } |
|
64 | } | |
66 | }; |
|
65 | }; | |
67 |
|
66 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
68 | |||
70 | #endif |
|
69 | #endif |
@@ -1,72 +1,71 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMEHIGHCONTRAST_P_H |
|
30 | #ifndef CHARTTHEMEHIGHCONTRAST_P_H | |
31 | #define CHARTTHEMEHIGHCONTRAST_P_H |
|
31 | #define CHARTTHEMEHIGHCONTRAST_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeHighContrast : public ChartTheme |
|
37 | class ChartThemeHighContrast : public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeHighContrast() : ChartTheme(QChart::ChartThemeHighContrast) |
|
40 | ChartThemeHighContrast() : ChartTheme(QChart::ChartThemeHighContrast) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0x202020); |
|
43 | m_seriesColors << QRgb(0x202020); | |
44 | m_seriesColors << QRgb(0x596a74); |
|
44 | m_seriesColors << QRgb(0x596a74); | |
45 | m_seriesColors << QRgb(0xffab03); |
|
45 | m_seriesColors << QRgb(0xffab03); | |
46 | m_seriesColors << QRgb(0x038e9b); |
|
46 | m_seriesColors << QRgb(0x038e9b); | |
47 | m_seriesColors << QRgb(0xff4a41); |
|
47 | m_seriesColors << QRgb(0xff4a41); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); |
|
51 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 | m_backgroundDropShadowEnabled = true; |
|
56 | m_backgroundDropShadowEnabled = true; | |
57 |
|
57 | |||
58 | // Axes and other |
|
58 | // Axes and other | |
59 |
m_ |
|
59 | m_labelBrush = QBrush(QRgb(0x181818)); | |
60 | m_axisLinePen = QPen(QRgb(0x8c8c8c)); |
|
60 | m_axisLinePen = QPen(QRgb(0x8c8c8c)); | |
61 | m_axisLinePen.setWidth(2); |
|
61 | m_axisLinePen.setWidth(2); | |
62 | m_axisLabelBrush = QBrush(QRgb(0x181818)); |
|
|||
63 | m_gridLinePen = QPen(QRgb(0x8c8c8c)); |
|
62 | m_gridLinePen = QPen(QRgb(0x8c8c8c)); | |
64 | m_gridLinePen.setWidth(1); |
|
63 | m_gridLinePen.setWidth(1); | |
65 | m_backgroundShadesBrush = QBrush(QRgb(0xffeecd)); |
|
64 | m_backgroundShadesBrush = QBrush(QRgb(0xffeecd)); | |
66 | m_backgroundShades = BackgroundShadesHorizontal; |
|
65 | m_backgroundShades = BackgroundShadesHorizontal; | |
67 | } |
|
66 | } | |
68 | }; |
|
67 | }; | |
69 |
|
68 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
70 | |||
72 | #endif |
|
71 | #endif |
@@ -1,71 +1,71 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMELIGHT_P_H |
|
30 | #ifndef CHARTTHEMELIGHT_P_H | |
31 | #define CHARTTHEMELIGHT_P_H |
|
31 | #define CHARTTHEMELIGHT_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartThemeLight: public ChartTheme |
|
37 | class ChartThemeLight: public ChartTheme | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) |
|
40 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) | |
41 | { |
|
41 | { | |
42 | // Series colors |
|
42 | // Series colors | |
43 | m_seriesColors << QRgb(0x209fdf); |
|
43 | m_seriesColors << QRgb(0x209fdf); | |
44 | m_seriesColors << QRgb(0x99ca53); |
|
44 | m_seriesColors << QRgb(0x99ca53); | |
45 | m_seriesColors << QRgb(0xf6a625); |
|
45 | m_seriesColors << QRgb(0xf6a625); | |
46 | m_seriesColors << QRgb(0x6d5fd5); |
|
46 | m_seriesColors << QRgb(0x6d5fd5); | |
47 | m_seriesColors << QRgb(0xbf593e); |
|
47 | m_seriesColors << QRgb(0xbf593e); | |
48 | generateSeriesGradients(); |
|
48 | generateSeriesGradients(); | |
49 |
|
49 | |||
50 | // Background |
|
50 | // Background | |
51 | QLinearGradient backgroundGradient; |
|
51 | QLinearGradient backgroundGradient; | |
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
52 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
53 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
54 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
55 | m_chartBackgroundGradient = backgroundGradient; |
|
55 | m_chartBackgroundGradient = backgroundGradient; | |
56 | // There is a performance issue in the drop shadow implementation, so disabled for now |
|
56 | // There is a performance issue in the drop shadow implementation, so disabled for now | |
57 | // m_backgroundDropShadowEnabled = true; |
|
57 | // m_backgroundDropShadowEnabled = true; | |
58 |
|
58 | |||
59 | // Axes and other |
|
59 | // Axes and other | |
60 | m_axisLinePen = QPen(0xd6d6d6); |
|
60 | m_axisLinePen = QPen(0xd6d6d6); | |
61 | m_axisLinePen.setWidth(1); |
|
61 | m_axisLinePen.setWidth(1); | |
62 |
m_ |
|
62 | m_labelBrush = QBrush(QRgb(0x404044)); | |
63 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
63 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
64 | m_gridLinePen.setWidth(1); |
|
64 | m_gridLinePen.setWidth(1); | |
65 | m_backgroundShades = BackgroundShadesNone; |
|
65 | m_backgroundShades = BackgroundShadesNone; | |
66 | } |
|
66 | } | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
70 | |||
71 | #endif |
|
71 | #endif |
@@ -1,180 +1,180 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTTHEMESYSTEM_P_H |
|
30 | #ifndef CHARTTHEMESYSTEM_P_H | |
31 | #define CHARTTHEMESYSTEM_P_H |
|
31 | #define CHARTTHEMESYSTEM_P_H | |
32 |
|
32 | |||
33 | #include "charttheme_p.h" |
|
33 | #include "charttheme_p.h" | |
34 | #ifdef Q_OS_WIN |
|
34 | #ifdef Q_OS_WIN | |
35 | #include <windows.h> |
|
35 | #include <windows.h> | |
36 | #include <stdio.h> |
|
36 | #include <stdio.h> | |
37 | #endif |
|
37 | #endif | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class ChartThemeSystem: public ChartTheme |
|
41 | class ChartThemeSystem: public ChartTheme | |
42 | { |
|
42 | { | |
43 | public: |
|
43 | public: | |
44 | // System theme not used at the moment (the user is not able to select this theme) |
|
44 | // System theme not used at the moment (the user is not able to select this theme) | |
45 | ChartThemeSystem() : ChartTheme(QChart::ChartThemeLight /*QChart::ChartThemeSystem*/) |
|
45 | ChartThemeSystem() : ChartTheme(QChart::ChartThemeLight /*QChart::ChartThemeSystem*/) | |
46 | { |
|
46 | { | |
47 | #ifdef Q_OS_WIN |
|
47 | #ifdef Q_OS_WIN | |
48 | // TODO: use theme specific window frame color as a series base color (it would give more |
|
48 | // TODO: use theme specific window frame color as a series base color (it would give more | |
49 | // variation to the base colors in addition to the blue and black used now) |
|
49 | // variation to the base colors in addition to the blue and black used now) | |
50 | // TODO: COLOR_WINDOWTEXT for text color? |
|
50 | // TODO: COLOR_WINDOWTEXT for text color? | |
51 | // TODO: COLOR_INFOTEXT for tooltip text color? |
|
51 | // TODO: COLOR_INFOTEXT for tooltip text color? | |
52 | // TODO: COLOR_INFOBK for tooltip background color? |
|
52 | // TODO: COLOR_INFOBK for tooltip background color? | |
53 |
|
53 | |||
54 | // First series base color from COLOR_HIGHLIGHT |
|
54 | // First series base color from COLOR_HIGHLIGHT | |
55 | DWORD colorHighlight; |
|
55 | DWORD colorHighlight; | |
56 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
56 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); | |
57 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
57 | m_seriesColors.append(QColor(GetRValue(colorHighlight), | |
58 | GetGValue(colorHighlight), |
|
58 | GetGValue(colorHighlight), | |
59 | GetBValue(colorHighlight))); |
|
59 | GetBValue(colorHighlight))); | |
60 |
|
60 | |||
61 | // Second series base color from COLOR_WINDOWFRAME |
|
61 | // Second series base color from COLOR_WINDOWFRAME | |
62 | DWORD colorWindowFrame; |
|
62 | DWORD colorWindowFrame; | |
63 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
63 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); | |
64 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
64 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), | |
65 | GetGValue(colorWindowFrame), |
|
65 | GetGValue(colorWindowFrame), | |
66 | GetBValue(colorWindowFrame))); |
|
66 | GetBValue(colorWindowFrame))); | |
67 |
|
67 | |||
68 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
68 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / | |
69 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
69 | // COLOR_GRADIENTACTIVECAPTION gradient | |
70 | DWORD colorGradientActiveCaptionLeft; |
|
70 | DWORD colorGradientActiveCaptionLeft; | |
71 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
71 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); | |
72 | DWORD colorGradientActiveCaptionRight; |
|
72 | DWORD colorGradientActiveCaptionRight; | |
73 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
73 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); | |
74 | QLinearGradient g; |
|
74 | QLinearGradient g; | |
75 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
75 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), | |
76 | GetGValue(colorGradientActiveCaptionLeft), |
|
76 | GetGValue(colorGradientActiveCaptionLeft), | |
77 | GetBValue(colorGradientActiveCaptionLeft)); |
|
77 | GetBValue(colorGradientActiveCaptionLeft)); | |
78 | g.setColorAt(0.0, start); |
|
78 | g.setColorAt(0.0, start); | |
79 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
79 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), | |
80 | GetGValue(colorGradientActiveCaptionRight), |
|
80 | GetGValue(colorGradientActiveCaptionRight), | |
81 | GetBValue(colorGradientActiveCaptionRight)); |
|
81 | GetBValue(colorGradientActiveCaptionRight)); | |
82 | g.setColorAt(1.0, end); |
|
82 | g.setColorAt(1.0, end); | |
83 | m_seriesColors.append(colorAt(g, 0.5)); |
|
83 | m_seriesColors.append(colorAt(g, 0.5)); | |
84 |
|
84 | |||
85 | // Generate gradients from the base colors |
|
85 | // Generate gradients from the base colors | |
86 | generateSeriesGradients(); |
|
86 | generateSeriesGradients(); | |
87 |
|
87 | |||
88 | // Background fill color from COLOR_WINDOW |
|
88 | // Background fill color from COLOR_WINDOW | |
89 | QLinearGradient backgroundGradient; |
|
89 | QLinearGradient backgroundGradient; | |
90 | DWORD colorWindow; |
|
90 | DWORD colorWindow; | |
91 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
91 | colorWindow = GetSysColor(COLOR_WINDOW); | |
92 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
92 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), | |
93 | GetGValue(colorWindow), |
|
93 | GetGValue(colorWindow), | |
94 | GetBValue(colorWindow))); |
|
94 | GetBValue(colorWindow))); | |
95 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
95 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), | |
96 | GetGValue(colorWindow), |
|
96 | GetGValue(colorWindow), | |
97 | GetBValue(colorWindow))); |
|
97 | GetBValue(colorWindow))); | |
98 | // Axes and other |
|
98 | // Axes and other | |
99 | m_axisLinePen = QPen(0xd6d6d6); |
|
99 | m_axisLinePen = QPen(0xd6d6d6); | |
100 | m_axisLinePen.setWidth(1); |
|
100 | m_axisLinePen.setWidth(1); | |
101 |
m_ |
|
101 | m_labelBrush = QBrush(QRgb(0x404044)); | |
102 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
102 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
103 | m_gridLinePen.setWidth(1); |
|
103 | m_gridLinePen.setWidth(1); | |
104 | m_backgroundShades = BackgroundShadesNone; |
|
104 | m_backgroundShades = BackgroundShadesNone; | |
105 |
|
105 | |||
106 | #elif defined(Q_OS_LINUX) |
|
106 | #elif defined(Q_OS_LINUX) | |
107 | // TODO: replace this dummy theme with linux specific theme |
|
107 | // TODO: replace this dummy theme with linux specific theme | |
108 | m_seriesColors << QRgb(0x60a6e6); |
|
108 | m_seriesColors << QRgb(0x60a6e6); | |
109 | m_seriesColors << QRgb(0x92ca66); |
|
109 | m_seriesColors << QRgb(0x92ca66); | |
110 | m_seriesColors << QRgb(0xeba85f); |
|
110 | m_seriesColors << QRgb(0xeba85f); | |
111 | m_seriesColors << QRgb(0xfc5751); |
|
111 | m_seriesColors << QRgb(0xfc5751); | |
112 | generateSeriesGradients(); |
|
112 | generateSeriesGradients(); | |
113 |
|
113 | |||
114 | // Background |
|
114 | // Background | |
115 | QLinearGradient backgroundGradient; |
|
115 | QLinearGradient backgroundGradient; | |
116 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
116 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
117 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
117 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
118 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
118 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
119 | m_chartBackgroundGradient = backgroundGradient; |
|
119 | m_chartBackgroundGradient = backgroundGradient; | |
120 |
|
120 | |||
121 | // Axes and other |
|
121 | // Axes and other | |
122 | m_axisLinePen = QPen(0xd6d6d6); |
|
122 | m_axisLinePen = QPen(0xd6d6d6); | |
123 | m_axisLinePen.setWidth(1); |
|
123 | m_axisLinePen.setWidth(1); | |
124 |
m_ |
|
124 | m_labelBrush = QBrush(QRgb(0x404044)); | |
125 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
125 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
126 | m_gridLinePen.setWidth(1); |
|
126 | m_gridLinePen.setWidth(1); | |
127 | m_backgroundShades = BackgroundShadesNone; |
|
127 | m_backgroundShades = BackgroundShadesNone; | |
128 |
|
128 | |||
129 | #elif defined(Q_OS_MAC) |
|
129 | #elif defined(Q_OS_MAC) | |
130 | // TODO: replace this dummy theme with OSX specific theme |
|
130 | // TODO: replace this dummy theme with OSX specific theme | |
131 | m_seriesColors << QRgb(0x60a6e6); |
|
131 | m_seriesColors << QRgb(0x60a6e6); | |
132 | m_seriesColors << QRgb(0x92ca66); |
|
132 | m_seriesColors << QRgb(0x92ca66); | |
133 | m_seriesColors << QRgb(0xeba85f); |
|
133 | m_seriesColors << QRgb(0xeba85f); | |
134 | m_seriesColors << QRgb(0xfc5751); |
|
134 | m_seriesColors << QRgb(0xfc5751); | |
135 | generateSeriesGradients(); |
|
135 | generateSeriesGradients(); | |
136 |
|
136 | |||
137 | // Background |
|
137 | // Background | |
138 | QLinearGradient backgroundGradient; |
|
138 | QLinearGradient backgroundGradient; | |
139 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
139 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
140 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
140 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
141 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
141 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
142 | m_chartBackgroundGradient = backgroundGradient; |
|
142 | m_chartBackgroundGradient = backgroundGradient; | |
143 |
|
143 | |||
144 | // Axes and other |
|
144 | // Axes and other | |
145 | m_axisLinePen = QPen(0xd6d6d6); |
|
145 | m_axisLinePen = QPen(0xd6d6d6); | |
146 | m_axisLinePen.setWidth(1); |
|
146 | m_axisLinePen.setWidth(1); | |
147 |
m_ |
|
147 | m_labelBrush = QBrush(QRgb(0x404044)); | |
148 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
148 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
149 | m_gridLinePen.setWidth(1); |
|
149 | m_gridLinePen.setWidth(1); | |
150 | m_backgroundShades = BackgroundShadesNone; |
|
150 | m_backgroundShades = BackgroundShadesNone; | |
151 |
|
151 | |||
152 | #else |
|
152 | #else | |
153 | // TODO: replace this dummy theme with generic (not OS specific) theme |
|
153 | // TODO: replace this dummy theme with generic (not OS specific) theme | |
154 | m_seriesColors << QRgb(0x60a6e6); |
|
154 | m_seriesColors << QRgb(0x60a6e6); | |
155 | m_seriesColors << QRgb(0x92ca66); |
|
155 | m_seriesColors << QRgb(0x92ca66); | |
156 | m_seriesColors << QRgb(0xeba85f); |
|
156 | m_seriesColors << QRgb(0xeba85f); | |
157 | m_seriesColors << QRgb(0xfc5751); |
|
157 | m_seriesColors << QRgb(0xfc5751); | |
158 | generateSeriesGradients(); |
|
158 | generateSeriesGradients(); | |
159 |
|
159 | |||
160 | // Background |
|
160 | // Background | |
161 | QLinearGradient backgroundGradient; |
|
161 | QLinearGradient backgroundGradient; | |
162 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
162 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
163 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
163 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
164 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
164 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
165 | m_chartBackgroundGradient = backgroundGradient; |
|
165 | m_chartBackgroundGradient = backgroundGradient; | |
166 |
|
166 | |||
167 | // Axes and other |
|
167 | // Axes and other | |
168 | m_axisLinePen = QPen(0xd6d6d6); |
|
168 | m_axisLinePen = QPen(0xd6d6d6); | |
169 | m_axisLinePen.setWidth(1); |
|
169 | m_axisLinePen.setWidth(1); | |
170 |
m_ |
|
170 | m_labelBrush = QBrush(QRgb(0x404044)); | |
171 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
171 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
172 | m_gridLinePen.setWidth(1); |
|
172 | m_gridLinePen.setWidth(1); | |
173 | m_backgroundShades = BackgroundShadesNone; |
|
173 | m_backgroundShades = BackgroundShadesNone; | |
174 | #endif |
|
174 | #endif | |
175 | } |
|
175 | } | |
176 | }; |
|
176 | }; | |
177 |
|
177 | |||
178 | QTCOMMERCIALCHART_END_NAMESPACE |
|
178 | QTCOMMERCIALCHART_END_NAMESPACE | |
179 |
|
179 | |||
180 | #endif // CHARTTHEMESYSTEM_P_H |
|
180 | #endif // CHARTTHEMESYSTEM_P_H |
@@ -1,105 +1,107 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | id: chartView |
|
25 | id: chartView | |
26 | title: "Chart Title" |
|
26 | title: "Chart Title" | |
27 | anchors.fill: parent |
|
27 | anchors.fill: parent | |
28 | property variant series: chartView |
|
28 | property variant series: chartView | |
29 |
|
29 | |||
30 | LineSeries { |
|
30 | LineSeries { | |
31 | name: "line" |
|
31 | name: "line" | |
32 | XyPoint { x: 0; y: 0 } |
|
32 | XyPoint { x: 0; y: 0 } | |
33 | XyPoint { x: 1.1; y: 2.1 } |
|
33 | XyPoint { x: 1.1; y: 2.1 } | |
34 | XyPoint { x: 1.9; y: 3.3 } |
|
34 | XyPoint { x: 1.9; y: 3.3 } | |
35 | XyPoint { x: 2.1; y: 2.1 } |
|
35 | XyPoint { x: 2.1; y: 2.1 } | |
36 | XyPoint { x: 2.9; y: 4.9 } |
|
36 | XyPoint { x: 2.9; y: 4.9 } | |
37 | XyPoint { x: 3.4; y: 3.0 } |
|
37 | XyPoint { x: 3.4; y: 3.0 } | |
38 | XyPoint { x: 4.1; y: 3.3 } |
|
38 | XyPoint { x: 4.1; y: 3.3 } | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); | |
42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); | |
43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); |
|
43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor); | |
44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); | |
45 | onTopMarginChanged: { |
|
45 | onTopMarginChanged: { | |
46 | console.log("chart.onTopMarginChanged: " + margin); |
|
46 | console.log("chart.onTopMarginChanged: " + margin); | |
47 | marginVisualizer.opacity = 1.0; |
|
47 | marginVisualizer.opacity = 1.0; | |
48 | } |
|
48 | } | |
49 | onBottomMarginChanged: { |
|
49 | onBottomMarginChanged: { | |
50 | console.log("chart.onBottomMarginChanged: " + margin); |
|
50 | console.log("chart.onBottomMarginChanged: " + margin); | |
51 | marginVisualizer.opacity = 1.0; |
|
51 | marginVisualizer.opacity = 1.0; | |
52 | } |
|
52 | } | |
53 | onLeftMarginChanged: { |
|
53 | onLeftMarginChanged: { | |
54 | console.log("chart.onLeftMarginChanged: " + margin); |
|
54 | console.log("chart.onLeftMarginChanged: " + margin); | |
55 | marginVisualizer.opacity = 1.0; |
|
55 | marginVisualizer.opacity = 1.0; | |
56 | } |
|
56 | } | |
57 | onRightMarginChanged: { |
|
57 | onRightMarginChanged: { | |
58 | console.log("chart.onRightMarginChanged: " + margin); |
|
58 | console.log("chart.onRightMarginChanged: " + margin); | |
59 | marginVisualizer.opacity = 1.0; |
|
59 | marginVisualizer.opacity = 1.0; | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); |
|
62 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible); | |
63 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
63 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); | |
64 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
64 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); | |
65 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
65 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); | |
|
66 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); | |||
|
67 | legend.onLabelBrushChanged: console.log("legend.onLabelBrushChanged: " + brush); | |||
66 |
|
68 | |||
67 | axisX.onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
69 | axisX.onColorChanged: console.log("axisX.onColorChanged: " + color); | |
68 | axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
70 | axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); | |
69 | axisX.onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
71 | axisX.onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); | |
70 | axisX.onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
72 | axisX.onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); | |
71 | axisX.onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
73 | axisX.onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); | |
72 | axisX.onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
74 | axisX.onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); | |
73 | axisX.onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
75 | axisX.onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); | |
74 | axisX.onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
76 | axisX.onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); | |
75 | axisX.onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
77 | axisX.onMinChanged: console.log("axisX.onMinChanged: " + min); | |
76 | axisX.onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
78 | axisX.onMaxChanged: console.log("axisX.onMaxChanged: " + max); | |
77 |
|
79 | |||
78 | axisY.onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
80 | axisY.onColorChanged: console.log("axisY.onColorChanged: " + color); | |
79 | axisY.onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
81 | axisY.onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); | |
80 | axisY.onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
82 | axisY.onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); | |
81 | axisY.onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
83 | axisY.onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); | |
82 | axisY.onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
84 | axisY.onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); | |
83 | axisY.onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
85 | axisY.onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); | |
84 | axisY.onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
86 | axisY.onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); | |
85 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
87 | axisY.onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); | |
86 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
88 | axisY.onMinChanged: console.log("axisY.onMinChanged: " + min); | |
87 | axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
89 | axisY.onMaxChanged: console.log("axisY.onMaxChanged: " + max); | |
88 |
|
90 | |||
89 |
|
91 | |||
90 | Rectangle { |
|
92 | Rectangle { | |
91 | id: marginVisualizer |
|
93 | id: marginVisualizer | |
92 | color: "transparent" |
|
94 | color: "transparent" | |
93 | border.color: "red" |
|
95 | border.color: "red" | |
94 | anchors.fill: parent |
|
96 | anchors.fill: parent | |
95 | anchors.topMargin: parent.topMargin |
|
97 | anchors.topMargin: parent.topMargin | |
96 | anchors.bottomMargin: parent.bottomMargin |
|
98 | anchors.bottomMargin: parent.bottomMargin | |
97 | anchors.leftMargin: parent.leftMargin |
|
99 | anchors.leftMargin: parent.leftMargin | |
98 | anchors.rightMargin: parent.rightMargin |
|
100 | anchors.rightMargin: parent.rightMargin | |
99 | opacity: 0.0 |
|
101 | opacity: 0.0 | |
100 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
102 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; | |
101 | Behavior on opacity { |
|
103 | Behavior on opacity { | |
102 | NumberAnimation { duration: 800 } |
|
104 | NumberAnimation { duration: 800 } | |
103 | } |
|
105 | } | |
104 | } |
|
106 | } | |
105 | } |
|
107 | } |
@@ -1,73 +1,77 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Row { |
|
24 | Row { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | property variant chartLegend |
|
27 | property variant chartLegend | |
28 |
|
28 | |||
29 | Flow { |
|
29 | Flow { | |
30 | spacing: 5 |
|
30 | spacing: 5 | |
31 | flow: Flow.TopToBottom |
|
31 | flow: Flow.TopToBottom | |
32 |
|
32 | |||
33 | Button { |
|
33 | Button { | |
34 | text: "legend visible" |
|
34 | text: "legend visible" | |
35 | onClicked: chartLegend.visible = !chartLegend.visible; |
|
35 | onClicked: chartLegend.visible = !chartLegend.visible; | |
36 | } |
|
36 | } | |
37 | Button { |
|
37 | Button { | |
38 | text: "legend bckgrd visible" |
|
38 | text: "legend bckgrd visible" | |
39 | onClicked: chartLegend.backgroundVisible = !chartLegend.backgroundVisible; |
|
39 | onClicked: chartLegend.backgroundVisible = !chartLegend.backgroundVisible; | |
40 | } |
|
40 | } | |
41 | Button { |
|
41 | Button { | |
42 | text: "legend color" |
|
42 | text: "legend color" | |
43 | onClicked: chartLegend.color = main.nextColor(); |
|
43 | onClicked: chartLegend.color = main.nextColor(); | |
44 | } |
|
44 | } | |
45 | Button { |
|
45 | Button { | |
46 | text: "legend border color" |
|
46 | text: "legend border color" | |
47 | onClicked: chartLegend.borderColor = main.nextColor(); |
|
47 | onClicked: chartLegend.borderColor = main.nextColor(); | |
48 | } |
|
48 | } | |
49 | Button { |
|
49 | Button { | |
|
50 | text: "legend label color" | |||
|
51 | onClicked: chartLegend.labelColor = main.nextColor(); | |||
|
52 | } | |||
|
53 | Button { | |||
50 | text: "legend top" |
|
54 | text: "legend top" | |
51 | onClicked: chartLegend.alignment ^= Qt.AlignTop; |
|
55 | onClicked: chartLegend.alignment ^= Qt.AlignTop; | |
52 | } |
|
56 | } | |
53 | Button { |
|
57 | Button { | |
54 | text: "legend bottom" |
|
58 | text: "legend bottom" | |
55 | onClicked: chartLegend.alignment ^= Qt.AlignBottom; |
|
59 | onClicked: chartLegend.alignment ^= Qt.AlignBottom; | |
56 | } |
|
60 | } | |
57 | Button { |
|
61 | Button { | |
58 | text: "legend left" |
|
62 | text: "legend left" | |
59 | onClicked: chartLegend.alignment ^= Qt.AlignLeft; |
|
63 | onClicked: chartLegend.alignment ^= Qt.AlignLeft; | |
60 | } |
|
64 | } | |
61 | Button { |
|
65 | Button { | |
62 | text: "legend right" |
|
66 | text: "legend right" | |
63 | onClicked: chartLegend.alignment ^= Qt.AlignRight; |
|
67 | onClicked: chartLegend.alignment ^= Qt.AlignRight; | |
64 | } |
|
68 | } | |
65 | } |
|
69 | } | |
66 |
|
70 | |||
67 | FontEditor { |
|
71 | FontEditor { | |
68 | fontDescription: "legend" |
|
72 | fontDescription: "legend" | |
69 | function editedFont() { |
|
73 | function editedFont() { | |
70 | return chartLegend.font; |
|
74 | return chartLegend.font; | |
71 | } |
|
75 | } | |
72 | } |
|
76 | } | |
73 | } |
|
77 | } |
General Comments 0
You need to be logged in to leave comments.
Login now