@@ -0,0 +1,36 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeLight: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeLight() : ChartTheme(QChart::ChartThemeLight) | |||
|
9 | { | |||
|
10 | // Series colors | |||
|
11 | m_seriesColors << QRgb(0x1c9dde); | |||
|
12 | m_seriesColors << QRgb(0xf7a015); | |||
|
13 | m_seriesColors << QRgb(0x8dc444); | |||
|
14 | generateSeriesGradients(); | |||
|
15 | ||||
|
16 | // Background | |||
|
17 | QLinearGradient backgroundGradient; | |||
|
18 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |||
|
19 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |||
|
20 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |||
|
21 | m_chartBackgroundGradient = backgroundGradient; | |||
|
22 | ||||
|
23 | // Axes and other | |||
|
24 | m_masterFont = QFont(); | |||
|
25 | m_axisLinePen = QPen(QRgb(0x424242)); | |||
|
26 | m_axisLinePen.setWidth(1); | |||
|
27 | m_axisLabelBrush = QBrush(QRgb(0x424242)); | |||
|
28 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |||
|
29 | m_backgroundShadesPen = Qt::NoPen; | |||
|
30 | m_backgroundShades = BackgroundShadesNone; | |||
|
31 | m_gridLinePen = QPen(QRgb(0x424242)); | |||
|
32 | m_gridLinePen.setWidth(1); | |||
|
33 | } | |||
|
34 | }; | |||
|
35 | ||||
|
36 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,310 +1,314 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
|
3 | #include "qchartview.h" | |||
3 | #include "qlegend.h" |
|
4 | #include "qlegend.h" | |
4 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
5 | #include <QTime> |
|
6 | #include <QTime> | |
6 |
|
7 | |||
7 | //series |
|
8 | //series | |
8 | #include "qbarset.h" |
|
9 | #include "qbarset.h" | |
9 | #include "qbarseries.h" |
|
10 | #include "qbarseries.h" | |
10 | #include "qstackedbarseries.h" |
|
11 | #include "qstackedbarseries.h" | |
11 | #include "qpercentbarseries.h" |
|
12 | #include "qpercentbarseries.h" | |
12 | #include "qlineseries.h" |
|
13 | #include "qlineseries.h" | |
13 | #include "qareaseries.h" |
|
14 | #include "qareaseries.h" | |
14 | #include "qscatterseries.h" |
|
15 | #include "qscatterseries.h" | |
15 | #include "qpieseries.h" |
|
16 | #include "qpieseries.h" | |
16 | #include "qpieslice.h" |
|
17 | #include "qpieslice.h" | |
17 | #include "qsplineseries.h" |
|
18 | #include "qsplineseries.h" | |
18 |
|
19 | |||
19 | //items |
|
20 | //items | |
20 | #include "axisitem_p.h" |
|
21 | #include "axisitem_p.h" | |
21 | #include "barpresenter_p.h" |
|
22 | #include "barpresenter_p.h" | |
22 | #include "stackedbarpresenter_p.h" |
|
23 | #include "stackedbarpresenter_p.h" | |
23 | #include "percentbarpresenter_p.h" |
|
24 | #include "percentbarpresenter_p.h" | |
24 | #include "linechartitem_p.h" |
|
25 | #include "linechartitem_p.h" | |
25 | #include "areachartitem_p.h" |
|
26 | #include "areachartitem_p.h" | |
26 | #include "scatterchartitem_p.h" |
|
27 | #include "scatterchartitem_p.h" | |
27 | #include "piechartitem_p.h" |
|
28 | #include "piechartitem_p.h" | |
28 | #include "splinechartitem_p.h" |
|
29 | #include "splinechartitem_p.h" | |
29 |
|
30 | |||
30 | //themes |
|
31 | //themes | |
31 | #include "chartthemedefault_p.h" |
|
32 | #include "chartthemedefault_p.h" | |
32 | #include "chartthemevanilla_p.h" |
|
33 | #include "chartthemevanilla_p.h" | |
33 | #include "chartthemeicy_p.h" |
|
34 | #include "chartthemeicy_p.h" | |
34 | #include "chartthemegrayscale_p.h" |
|
35 | #include "chartthemegrayscale_p.h" | |
35 | #include "chartthemescientific_p.h" |
|
36 | #include "chartthemescientific_p.h" | |
36 | #include "chartthemebluecerulean_p.h" |
|
37 | #include "chartthemebluecerulean_p.h" | |
|
38 | #include "chartthemelight_p.h" | |||
37 |
|
39 | |||
38 |
|
40 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
42 | |||
41 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
43 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
42 | { |
|
44 | { | |
43 | m_id = id; |
|
45 | m_id = id; | |
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
46 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
45 | } |
|
47 | } | |
46 |
|
48 | |||
47 |
|
49 | |||
48 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
50 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
49 | { |
|
51 | { | |
50 | switch(theme) { |
|
52 | switch(theme) { | |
51 | case QChart::ChartThemeVanilla: |
|
53 | case QChart::ChartThemeVanilla: | |
52 | return new ChartThemeVanilla(); |
|
54 | return new ChartThemeVanilla(); | |
53 | case QChart::ChartThemeIcy: |
|
55 | case QChart::ChartThemeIcy: | |
54 | return new ChartThemeIcy(); |
|
56 | return new ChartThemeIcy(); | |
55 | case QChart::ChartThemeGrayscale: |
|
57 | case QChart::ChartThemeGrayscale: | |
56 | return new ChartThemeGrayscale(); |
|
58 | return new ChartThemeGrayscale(); | |
57 | case QChart::ChartThemeScientific: |
|
59 | case QChart::ChartThemeScientific: | |
58 | return new ChartThemeScientific(); |
|
60 | return new ChartThemeScientific(); | |
59 | case QChart::ChartThemeBlueCerulean: |
|
61 | case QChart::ChartThemeBlueCerulean: | |
60 | return new ChartThemeBlueCerulean(); |
|
62 | return new ChartThemeBlueCerulean(); | |
|
63 | case QChart::ChartThemeLight: | |||
|
64 | return new ChartThemeLight(); | |||
61 | default: |
|
65 | default: | |
62 | return new ChartThemeDefault(); |
|
66 | return new ChartThemeDefault(); | |
63 | } |
|
67 | } | |
64 | } |
|
68 | } | |
65 |
|
69 | |||
66 | void ChartTheme::decorate(QChart* chart) |
|
70 | void ChartTheme::decorate(QChart* chart) | |
67 | { |
|
71 | { | |
68 | if (m_backgroundShades == BackgroundShadesNone) |
|
72 | if (m_backgroundShades == BackgroundShadesNone) { | |
69 |
chart->setChartBackgroundBrush(m_ |
|
73 | chart->setChartBackgroundBrush(m_chartBackgroundGradient); | |
70 | else |
|
74 | } else { | |
71 | chart->setChartBackgroundBrush(Qt::NoBrush); |
|
75 | chart->setChartBackgroundBrush(Qt::NoBrush); | |
|
76 | } | |||
72 | chart->setChartTitleFont(m_masterFont); |
|
77 | chart->setChartTitleFont(m_masterFont); | |
73 | } |
|
78 | } | |
74 |
|
79 | |||
75 | void ChartTheme::decorate(QLegend* legend) |
|
80 | void ChartTheme::decorate(QLegend* legend) | |
76 | { |
|
81 | { | |
77 |
legend->setBackgroundBrush(m_ |
|
82 | legend->setBackgroundBrush(m_chartBackgroundGradient); | |
78 | } |
|
83 | } | |
79 |
|
84 | |||
80 | void ChartTheme::decorate(QAreaSeries* series, int index) |
|
85 | void ChartTheme::decorate(QAreaSeries* series, int index) | |
81 | { |
|
86 | { | |
82 | QPen pen; |
|
87 | QPen pen; | |
83 | QBrush brush; |
|
88 | QBrush brush; | |
84 |
|
89 | |||
85 | if (pen == series->pen()){ |
|
90 | if (pen == series->pen()){ | |
86 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
91 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
87 | pen.setWidthF(2); |
|
92 | pen.setWidthF(2); | |
88 | series->setPen(pen); |
|
93 | series->setPen(pen); | |
89 | } |
|
94 | } | |
90 |
|
95 | |||
91 | if (brush == series->brush()) { |
|
96 | if (brush == series->brush()) { | |
92 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
97 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
93 | series->setBrush(brush); |
|
98 | series->setBrush(brush); | |
94 | } |
|
99 | } | |
95 | } |
|
100 | } | |
96 |
|
101 | |||
97 |
|
102 | |||
98 | void ChartTheme::decorate(QLineSeries* series,int index) |
|
103 | void ChartTheme::decorate(QLineSeries* series,int index) | |
99 | { |
|
104 | { | |
100 | QPen pen; |
|
105 | QPen pen; | |
101 | if(pen == series->pen()){ |
|
106 | if(pen == series->pen()){ | |
102 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
107 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
103 | pen.setWidthF(2); |
|
108 | pen.setWidthF(2); | |
104 | series->setPen(pen); |
|
109 | series->setPen(pen); | |
105 | } |
|
110 | } | |
106 | } |
|
111 | } | |
107 |
|
112 | |||
108 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) |
|
113 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) | |
109 | { |
|
114 | { | |
110 | QList<QBarSet*> sets = series->barSets(); |
|
115 | QList<QBarSet*> sets = series->barSets(); | |
111 | for (int i=0; i<sets.count(); i++) { |
|
116 | for (int i=0; i<sets.count(); i++) { | |
112 | qreal pos = 0.5; |
|
117 | qreal pos = 0.5; | |
113 | if (sets.count() > 1) |
|
118 | if (sets.count() > 1) | |
114 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
119 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
115 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
120 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
116 | sets.at(i)->setBrush(QBrush(c)); |
|
121 | sets.at(i)->setBrush(QBrush(c)); | |
117 |
|
122 | |||
118 | // Pick label color as far as possible from bar color (within gradient). |
|
123 | // Pick label color as far as possible from bar color (within gradient). | |
119 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
124 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) | |
120 | // TODO: better picking of label color? |
|
125 | // TODO: better picking of label color? | |
121 | if (pos < 0.3) { |
|
126 | if (pos < 0.3) { | |
122 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
127 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
123 | } else { |
|
128 | } else { | |
124 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
129 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
125 | } |
|
130 | } | |
126 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
131 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
127 | } |
|
132 | } | |
128 | } |
|
133 | } | |
129 |
|
134 | |||
130 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) |
|
135 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) | |
131 | { |
|
136 | { | |
132 | QList<QBarSet*> sets = series->barSets(); |
|
137 | QList<QBarSet*> sets = series->barSets(); | |
133 | for (int i=0; i<sets.count(); i++) { |
|
138 | for (int i=0; i<sets.count(); i++) { | |
134 | qreal pos = 0.5; |
|
139 | qreal pos = 0.5; | |
135 | if (sets.count() > 1) |
|
140 | if (sets.count() > 1) | |
136 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
141 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
137 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
142 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
138 | sets.at(i)->setBrush(QBrush(c)); |
|
143 | sets.at(i)->setBrush(QBrush(c)); | |
139 |
|
144 | |||
140 | if (pos < 0.3) { |
|
145 | if (pos < 0.3) { | |
141 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
146 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
142 | } else { |
|
147 | } else { | |
143 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
148 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
144 | } |
|
149 | } | |
145 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
150 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
146 | } |
|
151 | } | |
147 | } |
|
152 | } | |
148 |
|
153 | |||
149 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) |
|
154 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) | |
150 | { |
|
155 | { | |
151 | QList<QBarSet*> sets = series->barSets(); |
|
156 | QList<QBarSet*> sets = series->barSets(); | |
152 | for (int i=0; i<sets.count(); i++) { |
|
157 | for (int i=0; i<sets.count(); i++) { | |
153 | qreal pos = 0.5; |
|
158 | qreal pos = 0.5; | |
154 | if (sets.count() > 1) |
|
159 | if (sets.count() > 1) | |
155 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
160 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
156 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
161 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
157 | sets.at(i)->setBrush(QBrush(c)); |
|
162 | sets.at(i)->setBrush(QBrush(c)); | |
158 |
|
163 | |||
159 | if (pos < 0.3) { |
|
164 | if (pos < 0.3) { | |
160 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
165 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
161 | } else { |
|
166 | } else { | |
162 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
167 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
163 | } |
|
168 | } | |
164 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
169 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
165 | } |
|
170 | } | |
166 | } |
|
171 | } | |
167 |
|
172 | |||
168 | void ChartTheme::decorate(QScatterSeries* series, int index) |
|
173 | void ChartTheme::decorate(QScatterSeries* series, int index) | |
169 | { |
|
174 | { | |
170 |
|
175 | |||
171 | QPen pen; |
|
176 | QPen pen; | |
172 | QBrush brush; |
|
177 | QBrush brush; | |
173 |
|
178 | |||
174 | if (pen == series->pen()) { |
|
179 | if (pen == series->pen()) { | |
175 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
180 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
176 | pen.setWidthF(2); |
|
181 | pen.setWidthF(2); | |
177 | series->setPen(pen); |
|
182 | series->setPen(pen); | |
178 | } |
|
183 | } | |
179 |
|
184 | |||
180 | if (brush == series->brush()) { |
|
185 | if (brush == series->brush()) { | |
181 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
186 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
182 | series->setBrush(brush); |
|
187 | series->setBrush(brush); | |
183 | } |
|
188 | } | |
184 | } |
|
189 | } | |
185 |
|
190 | |||
186 | void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index) |
|
191 | void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index) | |
187 | { |
|
192 | { | |
188 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
193 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
189 | for (int i(0); i < series->slices().count(); i++) { |
|
194 | for (int i(0); i < series->slices().count(); i++) { | |
190 | qreal pos = (qreal) i / (qreal) series->count(); |
|
195 | qreal pos = (qreal) i / (qreal) series->count(); | |
191 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
196 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); | |
192 | series->slices().at(i)->setSlicePen(penColor); |
|
197 | series->slices().at(i)->setSlicePen(penColor); | |
193 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
198 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
194 | series->slices().at(i)->setSliceBrush(brushColor); |
|
199 | series->slices().at(i)->setSliceBrush(brushColor); | |
195 | } |
|
200 | } | |
196 | } |
|
201 | } | |
197 |
|
202 | |||
198 | void ChartTheme::decorate(QSplineSeries* series, int index) |
|
203 | void ChartTheme::decorate(QSplineSeries* series, int index) | |
199 | { |
|
204 | { | |
200 | QPen pen; |
|
205 | QPen pen; | |
201 | if(pen == series->pen()){ |
|
206 | if(pen == series->pen()){ | |
202 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
207 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
203 | pen.setWidthF(2); |
|
208 | pen.setWidthF(2); | |
204 | series->setPen(pen); |
|
209 | series->setPen(pen); | |
205 | } |
|
210 | } | |
206 | } |
|
211 | } | |
207 |
|
212 | |||
208 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) |
|
213 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) | |
209 | { |
|
214 | { | |
210 | if (axis->isAxisVisible()) { |
|
215 | if (axis->isAxisVisible()) { | |
211 | axis->setLabelsBrush(m_axisLabelBrush); |
|
216 | axis->setLabelsBrush(m_axisLabelBrush); | |
212 | axis->setLabelsPen(m_axisLabelPen); |
|
217 | axis->setLabelsPen(m_axisLabelPen); | |
213 | // TODO: check the axis type (x or y) should define whether to show the shades or not |
|
|||
214 | if (m_backgroundShades == BackgroundShadesBoth |
|
218 | if (m_backgroundShades == BackgroundShadesBoth | |
215 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
219 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
216 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { |
|
220 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { | |
217 | axis->setShadesPen(m_backgroundShadesPen); |
|
221 | axis->setShadesPen(m_backgroundShadesPen); | |
218 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
222 | axis->setShadesBrush(m_backgroundShadesBrush); | |
219 | } else { |
|
223 | } else { | |
220 | // The shades not supposed to be shown for this axis, clear possible brush and pen |
|
224 | // The shades not supposed to be shown for this axis, clear possible brush and pen | |
221 | axis->setShadesPen(Qt::NoPen); |
|
225 | axis->setShadesPen(Qt::NoPen); | |
222 | axis->setShadesBrush(Qt::NoBrush); |
|
226 | axis->setShadesBrush(Qt::NoBrush); | |
223 | } |
|
227 | } | |
224 | axis->setAxisPen(m_axisLinePen); |
|
228 | axis->setAxisPen(m_axisLinePen); | |
225 | axis->setGridLinePen(m_gridLinePen); |
|
229 | axis->setGridLinePen(m_gridLinePen); | |
226 | axis->setLabelsFont(m_masterFont); |
|
230 | axis->setLabelsFont(m_masterFont); | |
227 | } |
|
231 | } | |
228 | } |
|
232 | } | |
229 |
|
233 | |||
230 | void ChartTheme::generateSeriesGradients() |
|
234 | void ChartTheme::generateSeriesGradients() | |
231 | { |
|
235 | { | |
232 | // Generate gradients in HSV color space |
|
236 | // Generate gradients in HSV color space | |
233 | foreach (QColor color, m_seriesColors) { |
|
237 | foreach (QColor color, m_seriesColors) { | |
234 | QLinearGradient g; |
|
238 | QLinearGradient g; | |
235 | qreal h = color.hsvHueF(); |
|
239 | qreal h = color.hsvHueF(); | |
236 | qreal s = color.hsvSaturationF(); |
|
240 | qreal s = color.hsvSaturationF(); | |
237 |
|
241 | |||
238 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
242 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
239 | // most themes. The rest of the gradients we can define manually in theme specific |
|
243 | // most themes. The rest of the gradients we can define manually in theme specific | |
240 | // implementation. |
|
244 | // implementation. | |
241 | QColor start = color; |
|
245 | QColor start = color; | |
242 | start.setHsvF(h, 0.05, 0.95); |
|
246 | start.setHsvF(h, 0.05, 0.95); | |
243 | g.setColorAt(0.0, start); |
|
247 | g.setColorAt(0.0, start); | |
244 |
|
248 | |||
245 | g.setColorAt(0.5, color); |
|
249 | g.setColorAt(0.5, color); | |
246 |
|
250 | |||
247 | QColor end = color; |
|
251 | QColor end = color; | |
248 | end.setHsvF(h, s, 0.25); |
|
252 | end.setHsvF(h, s, 0.25); | |
249 | g.setColorAt(1.0, end); |
|
253 | g.setColorAt(1.0, end); | |
250 |
|
254 | |||
251 | m_seriesGradients << g; |
|
255 | m_seriesGradients << g; | |
252 | } |
|
256 | } | |
253 | } |
|
257 | } | |
254 |
|
258 | |||
255 |
|
259 | |||
256 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
260 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
257 | { |
|
261 | { | |
258 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
262 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
259 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
263 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
260 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
264 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
261 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
265 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
262 | QColor c; |
|
266 | QColor c; | |
263 | c.setRgbF(r, g, b); |
|
267 | c.setRgbF(r, g, b); | |
264 | return c; |
|
268 | return c; | |
265 | } |
|
269 | } | |
266 |
|
270 | |||
267 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
271 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
268 | { |
|
272 | { | |
269 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
273 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
270 |
|
274 | |||
271 | // another possibility: |
|
275 | // another possibility: | |
272 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
276 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
273 |
|
277 | |||
274 | QGradientStops stops = gradient.stops(); |
|
278 | QGradientStops stops = gradient.stops(); | |
275 | int count = stops.count(); |
|
279 | int count = stops.count(); | |
276 |
|
280 | |||
277 | // find previous stop relative to position |
|
281 | // find previous stop relative to position | |
278 | QGradientStop prev = stops.first(); |
|
282 | QGradientStop prev = stops.first(); | |
279 | for (int i=0; i<count; i++) { |
|
283 | for (int i=0; i<count; i++) { | |
280 | QGradientStop stop = stops.at(i); |
|
284 | QGradientStop stop = stops.at(i); | |
281 | if (pos > stop.first) |
|
285 | if (pos > stop.first) | |
282 | prev = stop; |
|
286 | prev = stop; | |
283 |
|
287 | |||
284 | // given position is actually a stop position? |
|
288 | // given position is actually a stop position? | |
285 | if (pos == stop.first) { |
|
289 | if (pos == stop.first) { | |
286 | //qDebug() << "stop color" << pos; |
|
290 | //qDebug() << "stop color" << pos; | |
287 | return stop.second; |
|
291 | return stop.second; | |
288 | } |
|
292 | } | |
289 | } |
|
293 | } | |
290 |
|
294 | |||
291 | // find next stop relative to position |
|
295 | // find next stop relative to position | |
292 | QGradientStop next = stops.last(); |
|
296 | QGradientStop next = stops.last(); | |
293 | for (int i=count-1; i>=0; i--) { |
|
297 | for (int i=count-1; i>=0; i--) { | |
294 | QGradientStop stop = stops.at(i); |
|
298 | QGradientStop stop = stops.at(i); | |
295 | if (pos < stop.first) |
|
299 | if (pos < stop.first) | |
296 | next = stop; |
|
300 | next = stop; | |
297 | } |
|
301 | } | |
298 |
|
302 | |||
299 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
303 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
300 |
|
304 | |||
301 | qreal range = next.first - prev.first; |
|
305 | qreal range = next.first - prev.first; | |
302 | qreal posDelta = pos - prev.first; |
|
306 | qreal posDelta = pos - prev.first; | |
303 | qreal relativePos = posDelta / range; |
|
307 | qreal relativePos = posDelta / range; | |
304 |
|
308 | |||
305 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
309 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
306 |
|
310 | |||
307 | return colorAt(prev.second, next.second, relativePos); |
|
311 | return colorAt(prev.second, next.second, relativePos); | |
308 | } |
|
312 | } | |
309 |
|
313 | |||
310 | QTCOMMERCIALCHART_END_NAMESPACE |
|
314 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,81 | |||||
1 | #ifndef CHARTTHEME_H |
|
1 | #ifndef CHARTTHEME_H | |
2 | #define CHARTTHEME_H |
|
2 | #define CHARTTHEME_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include <QColor> |
|
6 | #include <QColor> | |
7 | #include <QGradientStops> |
|
7 | #include <QGradientStops> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 | class QSeries; |
|
12 | class QSeries; | |
13 | class LineChartItem; |
|
13 | class LineChartItem; | |
14 | class QLineSeries; |
|
14 | class QLineSeries; | |
15 | class BarPresenter; |
|
15 | class BarPresenter; | |
16 | class QBarSeries; |
|
16 | class QBarSeries; | |
17 | class StackedBarPresenter; |
|
17 | class StackedBarPresenter; | |
18 | class QStackedBarSeries; |
|
18 | class QStackedBarSeries; | |
19 | class QPercentBarSeries; |
|
19 | class QPercentBarSeries; | |
20 | class PercentBarPresenter; |
|
20 | class PercentBarPresenter; | |
21 | class QScatterSeries; |
|
21 | class QScatterSeries; | |
22 | class ScatterChartItem; |
|
22 | class ScatterChartItem; | |
23 | class PieChartItem; |
|
23 | class PieChartItem; | |
24 | class QPieSeries; |
|
24 | class QPieSeries; | |
25 | class SplineChartItem; |
|
25 | class SplineChartItem; | |
26 | class QSplineSeries; |
|
26 | class QSplineSeries; | |
27 | class AreaChartItem; |
|
27 | class AreaChartItem; | |
28 | class QAreaSeries; |
|
28 | class QAreaSeries; | |
29 |
|
29 | |||
30 | class ChartTheme |
|
30 | class ChartTheme | |
31 | { |
|
31 | { | |
32 | public: |
|
32 | public: | |
33 | enum BackgroundShadesMode { |
|
33 | enum BackgroundShadesMode { | |
34 | BackgroundShadesNone = 0, |
|
34 | BackgroundShadesNone = 0, | |
35 | BackgroundShadesVertical, |
|
35 | BackgroundShadesVertical, | |
36 | BackgroundShadesHorizontal, |
|
36 | BackgroundShadesHorizontal, | |
37 | BackgroundShadesBoth |
|
37 | BackgroundShadesBoth | |
38 | }; |
|
38 | }; | |
39 |
|
39 | |||
40 | protected: |
|
40 | protected: | |
41 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); |
|
41 | explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault); | |
42 | public: |
|
42 | public: | |
43 | static ChartTheme* createTheme(QChart::ChartTheme theme); |
|
43 | static ChartTheme* createTheme(QChart::ChartTheme theme); | |
44 | QChart::ChartTheme id() const {return m_id;} |
|
44 | QChart::ChartTheme id() const {return m_id;} | |
45 | void decorate(QChart* chart); |
|
45 | void decorate(QChart* chart); | |
46 | void decorate(QLegend* legend); |
|
46 | void decorate(QLegend* legend); | |
47 | //void decorate(ChartItem* item, QSeries* series,int index); |
|
47 | //void decorate(ChartItem* item, QSeries* series,int index); | |
48 | void decorate(BarPresenter* item, QBarSeries* series, int index); |
|
48 | void decorate(BarPresenter* item, QBarSeries* series, int index); | |
49 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); |
|
49 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series, int index); | |
50 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); |
|
50 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series, int index); | |
51 | void decorate(QLineSeries* series, int index); |
|
51 | void decorate(QLineSeries* series, int index); | |
52 | void decorate(QAreaSeries* series, int index); |
|
52 | void decorate(QAreaSeries* series, int index); | |
53 | void decorate(QScatterSeries* series, int index); |
|
53 | void decorate(QScatterSeries* series, int index); | |
54 | void decorate(PieChartItem* item, QPieSeries* series, int index); |
|
54 | void decorate(PieChartItem* item, QPieSeries* series, int index); | |
55 | void decorate(QSplineSeries* series, int index); |
|
55 | void decorate(QSplineSeries* series, int index); | |
56 | void decorate(QChartAxis* axis, bool axisX); |
|
56 | void decorate(QChartAxis* axis, bool axisX); | |
57 |
|
57 | |||
58 | public: // utils |
|
58 | public: // utils | |
59 | void generateSeriesGradients(); |
|
59 | void generateSeriesGradients(); | |
60 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); |
|
60 | static QColor colorAt(const QColor &start, const QColor &end, qreal pos); | |
61 | static QColor colorAt(const QGradient &gradient, qreal pos); |
|
61 | static QColor colorAt(const QGradient &gradient, qreal pos); | |
62 |
|
62 | |||
63 | protected: |
|
63 | protected: | |
64 | QChart::ChartTheme m_id; |
|
64 | QChart::ChartTheme m_id; | |
65 | QList<QColor> m_seriesColors; |
|
65 | QList<QColor> m_seriesColors; | |
66 | QList<QGradient> m_seriesGradients; |
|
66 | QList<QGradient> m_seriesGradients; | |
67 |
QLinearGradient m_ |
|
67 | QLinearGradient m_chartBackgroundGradient; | |
68 |
|
68 | |||
69 | QFont m_masterFont; |
|
69 | QFont m_masterFont; | |
70 | QPen m_axisLinePen; |
|
70 | QPen m_axisLinePen; | |
71 | QBrush m_axisLabelBrush; |
|
71 | QBrush m_axisLabelBrush; | |
72 | QPen m_axisLabelPen; |
|
72 | QPen m_axisLabelPen; | |
73 | QPen m_backgroundShadesPen; |
|
73 | QPen m_backgroundShadesPen; | |
74 | QBrush m_backgroundShadesBrush; |
|
74 | QBrush m_backgroundShadesBrush; | |
75 | BackgroundShadesMode m_backgroundShades; |
|
75 | BackgroundShadesMode m_backgroundShades; | |
76 | QPen m_gridLinePen; |
|
76 | QPen m_gridLinePen; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
80 |
|
80 | |||
81 | #endif // CHARTTHEME_H |
|
81 | #endif // CHARTTHEME_H |
@@ -1,355 +1,356 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
5 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
6 | #include <QGraphicsScene> |
|
6 | #include <QGraphicsScene> | |
7 | #include <QGraphicsSceneResizeEvent> |
|
7 | #include <QGraphicsSceneResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | /*! |
|
12 | /*! | |
13 | \enum QChart::ChartTheme |
|
13 | \enum QChart::ChartTheme | |
14 |
|
14 | |||
15 | This enum describes the theme used by the chart. |
|
15 | This enum describes the theme used by the chart. | |
16 |
|
16 | |||
17 | \value ChartThemeDefault Follows the GUI style of the Operating System |
|
17 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
18 | \value ChartThemeVanilla |
|
18 | \value ChartThemeVanilla | |
19 | \value ChartThemeIcy |
|
19 | \value ChartThemeIcy | |
20 | \value ChartThemeGrayscale |
|
20 | \value ChartThemeGrayscale | |
21 | \value ChartThemeScientific |
|
21 | \value ChartThemeScientific | |
22 | \value ChartThemeBlueCerulean |
|
22 | \value ChartThemeBlueCerulean | |
|
23 | \value ChartThemeLight | |||
23 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
24 | \value ChartThemeCount Not really a theme; the total count of themes. | |
24 | */ |
|
25 | */ | |
25 |
|
26 | |||
26 | /*! |
|
27 | /*! | |
27 | \enum QChart::AnimationOption |
|
28 | \enum QChart::AnimationOption | |
28 |
|
29 | |||
29 | For enabling/disabling animations. Defaults to NoAnimation. |
|
30 | For enabling/disabling animations. Defaults to NoAnimation. | |
30 |
|
31 | |||
31 | \value NoAnimation |
|
32 | \value NoAnimation | |
32 | \value GridAxisAnimations |
|
33 | \value GridAxisAnimations | |
33 | \value SeriesAnimations |
|
34 | \value SeriesAnimations | |
34 | \value AllAnimations |
|
35 | \value AllAnimations | |
35 | */ |
|
36 | */ | |
36 |
|
37 | |||
37 | /*! |
|
38 | /*! | |
38 | \class QChart |
|
39 | \class QChart | |
39 | \brief QtCommercial chart API. |
|
40 | \brief QtCommercial chart API. | |
40 |
|
41 | |||
41 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
42 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
42 | representation of different types of QChartSeries and other chart related objects like |
|
43 | representation of different types of QChartSeries and other chart related objects like | |
43 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
44 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
44 | convenience class QChartView instead of QChart. |
|
45 | convenience class QChartView instead of QChart. | |
45 | \sa QChartView |
|
46 | \sa QChartView | |
46 | */ |
|
47 | */ | |
47 |
|
48 | |||
48 | /*! |
|
49 | /*! | |
49 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
50 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
50 | */ |
|
51 | */ | |
51 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
52 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
52 | m_backgroundItem(0), |
|
53 | m_backgroundItem(0), | |
53 | m_titleItem(0), |
|
54 | m_titleItem(0), | |
54 | m_legend(new QLegend(this)), |
|
55 | m_legend(new QLegend(this)), | |
55 | m_dataset(new ChartDataSet(this)), |
|
56 | m_dataset(new ChartDataSet(this)), | |
56 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
57 | m_presenter(new ChartPresenter(this,m_dataset)) | |
57 | { |
|
58 | { | |
58 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
59 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
59 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
60 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | /*! |
|
63 | /*! | |
63 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
64 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
64 | */ |
|
65 | */ | |
65 | QChart::~QChart() |
|
66 | QChart::~QChart() | |
66 | { |
|
67 | { | |
67 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
68 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
68 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
69 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | /*! |
|
72 | /*! | |
72 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
73 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
74 | the y axis). |
|
75 | the y axis). | |
75 | */ |
|
76 | */ | |
76 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
77 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
77 | { |
|
78 | { | |
78 | m_dataset->addSeries(series, axisY); |
|
79 | m_dataset->addSeries(series, axisY); | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | /*! |
|
82 | /*! | |
82 | Removes the \a series specified in a perameter from the QChartView. |
|
83 | Removes the \a series specified in a perameter from the QChartView. | |
83 | It releses its ownership of the specified QChartSeries object. |
|
84 | It releses its ownership of the specified QChartSeries object. | |
84 | It does not delete the pointed QChartSeries data object |
|
85 | It does not delete the pointed QChartSeries data object | |
85 | \sa addSeries(), removeAllSeries() |
|
86 | \sa addSeries(), removeAllSeries() | |
86 | */ |
|
87 | */ | |
87 | void QChart::removeSeries(QSeries* series) |
|
88 | void QChart::removeSeries(QSeries* series) | |
88 | { |
|
89 | { | |
89 | m_dataset->removeSeries(series); |
|
90 | m_dataset->removeSeries(series); | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | /*! |
|
93 | /*! | |
93 | Removes all the QChartSeries that have been added to the QChartView |
|
94 | Removes all the QChartSeries that have been added to the QChartView | |
94 | It also deletes the pointed QChartSeries data objects |
|
95 | It also deletes the pointed QChartSeries data objects | |
95 | \sa addSeries(), removeSeries() |
|
96 | \sa addSeries(), removeSeries() | |
96 | */ |
|
97 | */ | |
97 | void QChart::removeAllSeries() |
|
98 | void QChart::removeAllSeries() | |
98 | { |
|
99 | { | |
99 | m_dataset->removeAllSeries(); |
|
100 | m_dataset->removeAllSeries(); | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
102 | /*! |
|
103 | /*! | |
103 | Sets the \a brush that is used for painting the background of the chart area. |
|
104 | Sets the \a brush that is used for painting the background of the chart area. | |
104 | */ |
|
105 | */ | |
105 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
106 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
106 | { |
|
107 | { | |
107 | createChartBackgroundItem(); |
|
108 | createChartBackgroundItem(); | |
108 | m_backgroundItem->setBrush(brush); |
|
109 | m_backgroundItem->setBrush(brush); | |
109 | m_backgroundItem->update(); |
|
110 | m_backgroundItem->update(); | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | /*! |
|
113 | /*! | |
113 | Sets the \a pen that is used for painting the background of the chart area. |
|
114 | Sets the \a pen that is used for painting the background of the chart area. | |
114 | */ |
|
115 | */ | |
115 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
116 | void QChart::setChartBackgroundPen(const QPen& pen) | |
116 | { |
|
117 | { | |
117 | createChartBackgroundItem(); |
|
118 | createChartBackgroundItem(); | |
118 | m_backgroundItem->setPen(pen); |
|
119 | m_backgroundItem->setPen(pen); | |
119 | m_backgroundItem->update(); |
|
120 | m_backgroundItem->update(); | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | /*! |
|
123 | /*! | |
123 | Sets the chart \a title. The description text that is drawn above the chart. |
|
124 | Sets the chart \a title. The description text that is drawn above the chart. | |
124 | */ |
|
125 | */ | |
125 | void QChart::setChartTitle(const QString& title) |
|
126 | void QChart::setChartTitle(const QString& title) | |
126 | { |
|
127 | { | |
127 | createChartTitleItem(); |
|
128 | createChartTitleItem(); | |
128 | m_titleItem->setText(title); |
|
129 | m_titleItem->setText(title); | |
129 | updateLayout(); |
|
130 | updateLayout(); | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | /*! |
|
133 | /*! | |
133 | Returns the chart title. The description text that is drawn above the chart. |
|
134 | Returns the chart title. The description text that is drawn above the chart. | |
134 | */ |
|
135 | */ | |
135 | QString QChart::chartTitle() const |
|
136 | QString QChart::chartTitle() const | |
136 | { |
|
137 | { | |
137 | if(m_titleItem) |
|
138 | if(m_titleItem) | |
138 | return m_titleItem->text(); |
|
139 | return m_titleItem->text(); | |
139 | else |
|
140 | else | |
140 | return QString(); |
|
141 | return QString(); | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | /*! |
|
144 | /*! | |
144 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
145 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
145 | */ |
|
146 | */ | |
146 | void QChart::setChartTitleFont(const QFont& font) |
|
147 | void QChart::setChartTitleFont(const QFont& font) | |
147 | { |
|
148 | { | |
148 | createChartTitleItem(); |
|
149 | createChartTitleItem(); | |
149 | m_titleItem->setFont(font); |
|
150 | m_titleItem->setFont(font); | |
150 | updateLayout(); |
|
151 | updateLayout(); | |
151 | } |
|
152 | } | |
152 |
|
153 | |||
153 | /*! |
|
154 | /*! | |
154 | Sets the \a brush used for rendering the title text. |
|
155 | Sets the \a brush used for rendering the title text. | |
155 | */ |
|
156 | */ | |
156 | void QChart::setChartTitleBrush(const QBrush &brush) |
|
157 | void QChart::setChartTitleBrush(const QBrush &brush) | |
157 | { |
|
158 | { | |
158 | createChartTitleItem(); |
|
159 | createChartTitleItem(); | |
159 | m_titleItem->setBrush(brush); |
|
160 | m_titleItem->setBrush(brush); | |
160 | updateLayout(); |
|
161 | updateLayout(); | |
161 | } |
|
162 | } | |
162 |
|
163 | |||
163 | /*! |
|
164 | /*! | |
164 | Returns the brush used for rendering the title text. |
|
165 | Returns the brush used for rendering the title text. | |
165 | */ |
|
166 | */ | |
166 | QBrush QChart::chartTitleBrush() |
|
167 | QBrush QChart::chartTitleBrush() | |
167 | { |
|
168 | { | |
168 | createChartTitleItem(); |
|
169 | createChartTitleItem(); | |
169 | return m_titleItem->brush(); |
|
170 | return m_titleItem->brush(); | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 | void QChart::createChartBackgroundItem() |
|
173 | void QChart::createChartBackgroundItem() | |
173 | { |
|
174 | { | |
174 | if(!m_backgroundItem) { |
|
175 | if(!m_backgroundItem) { | |
175 | m_backgroundItem = new QGraphicsRectItem(this); |
|
176 | m_backgroundItem = new QGraphicsRectItem(this); | |
176 | m_backgroundItem->setPen(Qt::NoPen); |
|
177 | m_backgroundItem->setPen(Qt::NoPen); | |
177 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
178 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
178 | } |
|
179 | } | |
179 | } |
|
180 | } | |
180 |
|
181 | |||
181 | void QChart::createChartTitleItem() |
|
182 | void QChart::createChartTitleItem() | |
182 | { |
|
183 | { | |
183 | if(!m_titleItem) { |
|
184 | if(!m_titleItem) { | |
184 | m_titleItem = new QGraphicsSimpleTextItem(this); |
|
185 | m_titleItem = new QGraphicsSimpleTextItem(this); | |
185 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
186 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
186 | } |
|
187 | } | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | /*! |
|
190 | /*! | |
190 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
191 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
191 | \sa setMargin() |
|
192 | \sa setMargin() | |
192 | */ |
|
193 | */ | |
193 | int QChart::margin() const |
|
194 | int QChart::margin() const | |
194 | { |
|
195 | { | |
195 | return m_presenter->margin(); |
|
196 | return m_presenter->margin(); | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | /*! |
|
199 | /*! | |
199 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
200 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
200 | \sa margin() |
|
201 | \sa margin() | |
201 | */ |
|
202 | */ | |
202 | void QChart::setMargin(int margin) |
|
203 | void QChart::setMargin(int margin) | |
203 | { |
|
204 | { | |
204 | m_presenter->setMargin(margin); |
|
205 | m_presenter->setMargin(margin); | |
205 | updateLayout(); |
|
206 | updateLayout(); | |
206 | } |
|
207 | } | |
207 |
|
208 | |||
208 | /*! |
|
209 | /*! | |
209 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
210 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
210 | \sa ChartTheme, chartTheme() |
|
211 | \sa ChartTheme, chartTheme() | |
211 | */ |
|
212 | */ | |
212 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
213 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
213 | { |
|
214 | { | |
214 | m_presenter->setChartTheme(theme); |
|
215 | m_presenter->setChartTheme(theme); | |
215 | } |
|
216 | } | |
216 |
|
217 | |||
217 | /*! |
|
218 | /*! | |
218 | Returns the theme enum used by the chart. |
|
219 | Returns the theme enum used by the chart. | |
219 | \sa ChartTheme, setChartTheme() |
|
220 | \sa ChartTheme, setChartTheme() | |
220 | */ |
|
221 | */ | |
221 | QChart::ChartTheme QChart::chartTheme() const |
|
222 | QChart::ChartTheme QChart::chartTheme() const | |
222 | { |
|
223 | { | |
223 | return m_presenter->chartTheme(); |
|
224 | return m_presenter->chartTheme(); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | /*! |
|
227 | /*! | |
227 | Zooms in the view by a factor of 2 |
|
228 | Zooms in the view by a factor of 2 | |
228 | */ |
|
229 | */ | |
229 | void QChart::zoomIn() |
|
230 | void QChart::zoomIn() | |
230 | { |
|
231 | { | |
231 | m_presenter->zoomIn(); |
|
232 | m_presenter->zoomIn(); | |
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 | /*! |
|
235 | /*! | |
235 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
236 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
236 | */ |
|
237 | */ | |
237 | void QChart::zoomIn(const QRectF& rect) |
|
238 | void QChart::zoomIn(const QRectF& rect) | |
238 | { |
|
239 | { | |
239 |
|
240 | |||
240 | if(!rect.isValid()) return; |
|
241 | if(!rect.isValid()) return; | |
241 | m_presenter->zoomIn(rect); |
|
242 | m_presenter->zoomIn(rect); | |
242 | } |
|
243 | } | |
243 |
|
244 | |||
244 | /*! |
|
245 | /*! | |
245 | Restores the view zoom level to the previous one. |
|
246 | Restores the view zoom level to the previous one. | |
246 | */ |
|
247 | */ | |
247 | void QChart::zoomOut() |
|
248 | void QChart::zoomOut() | |
248 | { |
|
249 | { | |
249 | m_presenter->zoomOut(); |
|
250 | m_presenter->zoomOut(); | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | /*! |
|
253 | /*! | |
253 | Resets to the default view. |
|
254 | Resets to the default view. | |
254 | */ |
|
255 | */ | |
255 | void QChart::zoomReset() |
|
256 | void QChart::zoomReset() | |
256 | { |
|
257 | { | |
257 | m_presenter->zoomReset(); |
|
258 | m_presenter->zoomReset(); | |
258 | } |
|
259 | } | |
259 |
|
260 | |||
260 | /*! |
|
261 | /*! | |
261 | Returns the pointer to the x axis object of the chart |
|
262 | Returns the pointer to the x axis object of the chart | |
262 | */ |
|
263 | */ | |
263 | QChartAxis* QChart::axisX() const |
|
264 | QChartAxis* QChart::axisX() const | |
264 | { |
|
265 | { | |
265 | return m_dataset->axisX(); |
|
266 | return m_dataset->axisX(); | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | /*! |
|
269 | /*! | |
269 | Returns the pointer to the y axis object of the chart |
|
270 | Returns the pointer to the y axis object of the chart | |
270 | */ |
|
271 | */ | |
271 | QChartAxis* QChart::axisY() const |
|
272 | QChartAxis* QChart::axisY() const | |
272 | { |
|
273 | { | |
273 | return m_dataset->axisY(); |
|
274 | return m_dataset->axisY(); | |
274 | } |
|
275 | } | |
275 |
|
276 | |||
276 | /*! |
|
277 | /*! | |
277 | Returns the legend object of the chart |
|
278 | Returns the legend object of the chart | |
278 | */ |
|
279 | */ | |
279 | QLegend* QChart::legend() |
|
280 | QLegend* QChart::legend() | |
280 | { |
|
281 | { | |
281 | return m_legend; |
|
282 | return m_legend; | |
282 | } |
|
283 | } | |
283 |
|
284 | |||
284 | /*! |
|
285 | /*! | |
285 | Resizes and updates the chart area using the \a event data |
|
286 | Resizes and updates the chart area using the \a event data | |
286 | */ |
|
287 | */ | |
287 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
288 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
288 | { |
|
289 | { | |
289 |
|
290 | |||
290 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
291 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
291 | updateLayout(); |
|
292 | updateLayout(); | |
292 | QGraphicsWidget::resizeEvent(event); |
|
293 | QGraphicsWidget::resizeEvent(event); | |
293 | update(); |
|
294 | update(); | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | /*! |
|
297 | /*! | |
297 | Sets animation \a options for the chart |
|
298 | Sets animation \a options for the chart | |
298 | */ |
|
299 | */ | |
299 | void QChart::setAnimationOptions(AnimationOptions options) |
|
300 | void QChart::setAnimationOptions(AnimationOptions options) | |
300 | { |
|
301 | { | |
301 | m_presenter->setAnimationOptions(options); |
|
302 | m_presenter->setAnimationOptions(options); | |
302 | } |
|
303 | } | |
303 |
|
304 | |||
304 | /*! |
|
305 | /*! | |
305 | Returns animation options for the chart |
|
306 | Returns animation options for the chart | |
306 | */ |
|
307 | */ | |
307 | QChart::AnimationOptions QChart::animationOptions() const |
|
308 | QChart::AnimationOptions QChart::animationOptions() const | |
308 | { |
|
309 | { | |
309 | return m_presenter->animationOptions(); |
|
310 | return m_presenter->animationOptions(); | |
310 | } |
|
311 | } | |
311 |
|
312 | |||
312 | void QChart::scroll(int dx,int dy) |
|
313 | void QChart::scroll(int dx,int dy) | |
313 | { |
|
314 | { | |
314 | //temporary |
|
315 | //temporary | |
315 | if(dx>0) |
|
316 | if(dx>0) | |
316 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
317 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
317 | if(dx<0) |
|
318 | if(dx<0) | |
318 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
319 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
319 | if(dy>0) |
|
320 | if(dy>0) | |
320 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
321 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
321 | if(dy<0) |
|
322 | if(dy<0) | |
322 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
323 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 | void QChart::updateLayout() |
|
326 | void QChart::updateLayout() | |
326 | { |
|
327 | { | |
327 | if(!m_rect.isValid()) return; |
|
328 | if(!m_rect.isValid()) return; | |
328 |
|
329 | |||
329 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
330 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
330 |
|
331 | |||
331 | // recalculate title position |
|
332 | // recalculate title position | |
332 | if (m_titleItem) { |
|
333 | if (m_titleItem) { | |
333 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
334 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
334 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
335 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
335 | } |
|
336 | } | |
336 |
|
337 | |||
337 | //recalculate background gradient |
|
338 | //recalculate background gradient | |
338 | if (m_backgroundItem) { |
|
339 | if (m_backgroundItem) { | |
339 | m_backgroundItem->setRect(rect); |
|
340 | m_backgroundItem->setRect(rect); | |
340 | } |
|
341 | } | |
341 |
|
342 | |||
342 | // recalculate legend position |
|
343 | // recalculate legend position | |
343 | // TODO: better layout |
|
344 | // TODO: better layout | |
344 | if (m_legend) { |
|
345 | if (m_legend) { | |
345 | QRectF boundingRect(m_rect.adjusted(margin(), |
|
346 | QRectF boundingRect(m_rect.adjusted(margin(), | |
346 | rect.height() + margin() + margin()/2 - m_legend->minimumSize().height()/2, |
|
347 | rect.height() + margin() + margin()/2 - m_legend->minimumSize().height()/2, | |
347 | -margin(), |
|
348 | -margin(), | |
348 | -margin()/2 + m_legend->minimumSize().height()/2)); |
|
349 | -margin()/2 + m_legend->minimumSize().height()/2)); | |
349 | m_legend->handleGeometryChanged(boundingRect); |
|
350 | m_legend->handleGeometryChanged(boundingRect); | |
350 | qDebug() << "legend rect:" << m_legend->boundingRect(); |
|
351 | qDebug() << "legend rect:" << m_legend->boundingRect(); | |
351 | } |
|
352 | } | |
352 | } |
|
353 | } | |
353 | #include "moc_qchart.cpp" |
|
354 | #include "moc_qchart.cpp" | |
354 |
|
355 | |||
355 | QTCOMMERCIALCHART_END_NAMESPACE |
|
356 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,104 +1,105 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qseries.h> |
|
5 | #include <qseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QSeries; |
|
15 | class QSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 | class QLegend; |
|
23 | class QLegend; | |
24 |
|
24 | |||
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 | public: |
|
28 | public: | |
29 | enum ChartTheme { |
|
29 | enum ChartTheme { | |
30 | ChartThemeDefault, |
|
30 | ChartThemeDefault, | |
31 | ChartThemeVanilla, |
|
31 | ChartThemeVanilla, | |
32 | ChartThemeIcy, |
|
32 | ChartThemeIcy, | |
33 | ChartThemeGrayscale, |
|
33 | ChartThemeGrayscale, | |
34 | ChartThemeScientific, |
|
34 | ChartThemeScientific, | |
35 | ChartThemeBlueCerulean, |
|
35 | ChartThemeBlueCerulean, | |
|
36 | ChartThemeLight, | |||
36 | ChartThemeCount |
|
37 | ChartThemeCount | |
37 | }; |
|
38 | }; | |
38 |
|
39 | |||
39 | enum AnimationOption { |
|
40 | enum AnimationOption { | |
40 | NoAnimation = 0x0, |
|
41 | NoAnimation = 0x0, | |
41 | GridAxisAnimations = 0x1, |
|
42 | GridAxisAnimations = 0x1, | |
42 | SeriesAnimations =0x2, |
|
43 | SeriesAnimations =0x2, | |
43 | AllAnimations = 0x3 |
|
44 | AllAnimations = 0x3 | |
44 | }; |
|
45 | }; | |
45 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
46 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
46 |
|
47 | |||
47 | public: |
|
48 | public: | |
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
49 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
49 | ~QChart(); |
|
50 | ~QChart(); | |
50 |
|
51 | |||
51 | void addSeries(QSeries* series, QChartAxis* axisY = 0); |
|
52 | void addSeries(QSeries* series, QChartAxis* axisY = 0); | |
52 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
53 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
53 | void removeAllSeries(); // deletes series and axis |
|
54 | void removeAllSeries(); // deletes series and axis | |
54 |
|
55 | |||
55 | void setMargin(int margin); |
|
56 | void setMargin(int margin); | |
56 | int margin() const; |
|
57 | int margin() const; | |
57 | void setChartTheme(QChart::ChartTheme theme); |
|
58 | void setChartTheme(QChart::ChartTheme theme); | |
58 | QChart::ChartTheme chartTheme() const; |
|
59 | QChart::ChartTheme chartTheme() const; | |
59 |
|
60 | |||
60 | void setChartTitle(const QString& title); |
|
61 | void setChartTitle(const QString& title); | |
61 | QString chartTitle() const; |
|
62 | QString chartTitle() const; | |
62 | void setChartTitleFont(const QFont& font); |
|
63 | void setChartTitleFont(const QFont& font); | |
63 | void setChartTitleBrush(const QBrush &brush); |
|
64 | void setChartTitleBrush(const QBrush &brush); | |
64 | QBrush chartTitleBrush(); |
|
65 | QBrush chartTitleBrush(); | |
65 | void setChartBackgroundBrush(const QBrush& brush); |
|
66 | void setChartBackgroundBrush(const QBrush& brush); | |
66 | void setChartBackgroundPen(const QPen& pen); |
|
67 | void setChartBackgroundPen(const QPen& pen); | |
67 |
|
68 | |||
68 | void setAnimationOptions(AnimationOptions options); |
|
69 | void setAnimationOptions(AnimationOptions options); | |
69 | AnimationOptions animationOptions() const; |
|
70 | AnimationOptions animationOptions() const; | |
70 |
|
71 | |||
71 | void zoomIn(); |
|
72 | void zoomIn(); | |
72 | void zoomIn(const QRectF& rect); |
|
73 | void zoomIn(const QRectF& rect); | |
73 | void zoomOut(); |
|
74 | void zoomOut(); | |
74 | void zoomReset(); |
|
75 | void zoomReset(); | |
75 | void scroll(int dx,int dy); |
|
76 | void scroll(int dx,int dy); | |
76 |
|
77 | |||
77 | QChartAxis* axisX() const; |
|
78 | QChartAxis* axisX() const; | |
78 | QChartAxis* axisY() const; |
|
79 | QChartAxis* axisY() const; | |
79 |
|
80 | |||
80 | QLegend* legend(); |
|
81 | QLegend* legend(); | |
81 |
|
82 | |||
82 | protected: |
|
83 | protected: | |
83 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
84 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
84 |
|
85 | |||
85 | private: |
|
86 | private: | |
86 | inline void createChartBackgroundItem(); |
|
87 | inline void createChartBackgroundItem(); | |
87 | inline void createChartTitleItem(); |
|
88 | inline void createChartTitleItem(); | |
88 | void updateLayout(); |
|
89 | void updateLayout(); | |
89 |
|
90 | |||
90 | private: |
|
91 | private: | |
91 | Q_DISABLE_COPY(QChart) |
|
92 | Q_DISABLE_COPY(QChart) | |
92 | QGraphicsRectItem* m_backgroundItem; |
|
93 | QGraphicsRectItem* m_backgroundItem; | |
93 | QGraphicsSimpleTextItem* m_titleItem; |
|
94 | QGraphicsSimpleTextItem* m_titleItem; | |
94 | QRectF m_rect; |
|
95 | QRectF m_rect; | |
95 | QLegend* m_legend; |
|
96 | QLegend* m_legend; | |
96 | ChartDataSet *m_dataset; |
|
97 | ChartDataSet *m_dataset; | |
97 | ChartPresenter *m_presenter; |
|
98 | ChartPresenter *m_presenter; | |
98 | }; |
|
99 | }; | |
99 |
|
100 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 |
|
102 | |||
102 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
103 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
103 |
|
104 | |||
104 | #endif |
|
105 | #endif |
@@ -1,388 +1,399 | |||||
1 | #include "qchartview.h" |
|
1 | #include "qchartview.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartaxis.h" |
|
3 | #include "qchartaxis.h" | |
4 | #include <QGraphicsView> |
|
4 | #include <QGraphicsView> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QRubberBand> |
|
6 | #include <QRubberBand> | |
7 | #include <QResizeEvent> |
|
7 | #include <QResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | /*! |
|
10 | /*! | |
11 | \enum QChartView::RubberBandPolicy |
|
11 | \enum QChartView::RubberBandPolicy | |
12 |
|
12 | |||
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
13 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
14 |
|
14 | |||
15 | \value NoRubberBand |
|
15 | \value NoRubberBand | |
16 | \value VerticalRubberBand |
|
16 | \value VerticalRubberBand | |
17 | \value HorizonalRubberBand |
|
17 | \value HorizonalRubberBand | |
18 | \value RectangleRubberBand |
|
18 | \value RectangleRubberBand | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \class QChartView |
|
22 | \class QChartView | |
23 | \brief Standalone charting widget. |
|
23 | \brief Standalone charting widget. | |
24 |
|
24 | |||
25 | QChartView is a standalone widget that can display charts. It does not require separate |
|
25 | QChartView is a standalone widget that can display charts. It does not require separate | |
26 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
26 | QGraphicsScene to work. It manages the graphical representation of different types of | |
27 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to |
|
27 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
28 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
28 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
29 |
|
29 | |||
30 | \sa QChart |
|
30 | \sa QChart | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | Constructs a chartView object which is a child of a\a parent. |
|
36 | Constructs a chartView object which is a child of a\a parent. | |
37 | */ |
|
37 | */ | |
38 | QChartView::QChartView(QWidget *parent) : |
|
38 | QChartView::QChartView(QWidget *parent) : | |
39 | QGraphicsView(parent), |
|
39 | QGraphicsView(parent), | |
40 | m_scene(new QGraphicsScene(this)), |
|
40 | m_scene(new QGraphicsScene(this)), | |
41 | m_chart(new QChart()), |
|
41 | m_chart(new QChart()), | |
42 | m_rubberBand(0), |
|
42 | m_rubberBand(0), | |
43 | m_verticalRubberBand(false), |
|
43 | m_verticalRubberBand(false), | |
44 | m_horizonalRubberBand(false) |
|
44 | m_horizonalRubberBand(false) | |
45 | { |
|
45 | { | |
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
46 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
47 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
48 | setScene(m_scene); |
|
48 | setScene(m_scene); | |
49 | m_chart->setMargin(50); |
|
49 | m_chart->setMargin(50); | |
50 | m_scene->addItem(m_chart); |
|
50 | m_scene->addItem(m_chart); | |
51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
51 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
56 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
57 | */ |
|
57 | */ | |
58 | QChartView::~QChartView() |
|
58 | QChartView::~QChartView() | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Resizes and updates the chart area using the \a event data |
|
63 | Resizes and updates the chart area using the \a event data | |
64 | */ |
|
64 | */ | |
65 | void QChartView::resizeEvent(QResizeEvent *event) |
|
65 | void QChartView::resizeEvent(QResizeEvent *event) | |
66 | { |
|
66 | { | |
67 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
67 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
68 | m_chart->resize(size()); |
|
68 | m_chart->resize(size()); | |
69 | QWidget::resizeEvent(event); |
|
69 | QWidget::resizeEvent(event); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
73 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
74 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
75 | the y axis). |
|
75 | the y axis). | |
76 | \sa removeSeries(), removeAllSeries() |
|
76 | \sa removeSeries(), removeAllSeries() | |
77 | */ |
|
77 | */ | |
78 | void QChartView::addSeries(QSeries* series,QChartAxis *axisY) |
|
78 | void QChartView::addSeries(QSeries* series,QChartAxis *axisY) | |
79 | { |
|
79 | { | |
80 | m_chart->addSeries(series,axisY); |
|
80 | m_chart->addSeries(series,axisY); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | Removes the \a series specified in a perameter from the QChartView. |
|
84 | Removes the \a series specified in a perameter from the QChartView. | |
85 | It releses its ownership of the specified QChartSeries object. |
|
85 | It releses its ownership of the specified QChartSeries object. | |
86 | It does not delete the pointed QChartSeries data object |
|
86 | It does not delete the pointed QChartSeries data object | |
87 | \sa addSeries(), removeAllSeries() |
|
87 | \sa addSeries(), removeAllSeries() | |
88 | */ |
|
88 | */ | |
89 | void QChartView::removeSeries(QSeries* series) |
|
89 | void QChartView::removeSeries(QSeries* series) | |
90 | { |
|
90 | { | |
91 | m_chart->removeSeries(series); |
|
91 | m_chart->removeSeries(series); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | Removes all the QChartSeries that have been added to the QChartView |
|
95 | Removes all the QChartSeries that have been added to the QChartView | |
96 | It also deletes the pointed QChartSeries data objects |
|
96 | It also deletes the pointed QChartSeries data objects | |
97 | \sa addSeries(), removeSeries() |
|
97 | \sa addSeries(), removeSeries() | |
98 | */ |
|
98 | */ | |
99 | void QChartView::removeAllSeries() |
|
99 | void QChartView::removeAllSeries() | |
100 | { |
|
100 | { | |
101 | m_chart->removeAllSeries(); |
|
101 | m_chart->removeAllSeries(); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | Zooms in the view by a factor of 2 |
|
105 | Zooms in the view by a factor of 2 | |
106 | */ |
|
106 | */ | |
107 | void QChartView::zoomIn() |
|
107 | void QChartView::zoomIn() | |
108 | { |
|
108 | { | |
109 | m_chart->zoomIn(); |
|
109 | m_chart->zoomIn(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
113 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
114 | */ |
|
114 | */ | |
115 | void QChartView::zoomIn(const QRect& rect) |
|
115 | void QChartView::zoomIn(const QRect& rect) | |
116 | { |
|
116 | { | |
117 | m_chart->zoomIn(rect); |
|
117 | m_chart->zoomIn(rect); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Restores the view zoom level to the previous one. |
|
121 | Restores the view zoom level to the previous one. | |
122 | */ |
|
122 | */ | |
123 | void QChartView::zoomOut() |
|
123 | void QChartView::zoomOut() | |
124 | { |
|
124 | { | |
125 | m_chart->zoomOut(); |
|
125 | m_chart->zoomOut(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
129 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
130 | */ |
|
130 | */ | |
131 | int QChartView::margin() const |
|
131 | int QChartView::margin() const | |
132 | { |
|
132 | { | |
133 | return m_chart->margin(); |
|
133 | return m_chart->margin(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Sets the chart \a title. A description text that is drawn above the chart. |
|
137 | Sets the chart \a title. A description text that is drawn above the chart. | |
138 | */ |
|
138 | */ | |
139 | void QChartView::setChartTitle(const QString& title) |
|
139 | void QChartView::setChartTitle(const QString& title) | |
140 | { |
|
140 | { | |
141 | m_chart->setChartTitle(title); |
|
141 | m_chart->setChartTitle(title); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | Returns the chart's title. A description text that is drawn above the chart. |
|
145 | Returns the chart's title. A description text that is drawn above the chart. | |
146 | */ |
|
146 | */ | |
147 | QString QChartView::chartTitle() const |
|
147 | QString QChartView::chartTitle() const | |
148 | { |
|
148 | { | |
149 | return m_chart->chartTitle(); |
|
149 | return m_chart->chartTitle(); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
153 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
154 | */ |
|
154 | */ | |
155 | void QChartView::setChartTitleFont(const QFont& font) |
|
155 | void QChartView::setChartTitleFont(const QFont& font) | |
156 | { |
|
156 | { | |
157 | m_chart->setChartTitleFont(font); |
|
157 | m_chart->setChartTitleFont(font); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Sets the \a brush used for rendering the title text. |
|
161 | Sets the \a brush used for rendering the title text. | |
162 | */ |
|
162 | */ | |
163 | void QChartView::setChartTitleBrush(const QBrush &brush) |
|
163 | void QChartView::setChartTitleBrush(const QBrush &brush) | |
164 | { |
|
164 | { | |
165 | m_chart->setChartTitleBrush(brush); |
|
165 | m_chart->setChartTitleBrush(brush); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | Returns the brush used for rendering the title text. |
|
169 | Returns the brush used for rendering the title text. | |
170 | */ |
|
170 | */ | |
171 | QBrush QChartView::chartTitleBrush() |
|
171 | QBrush QChartView::chartTitleBrush() | |
172 | { |
|
172 | { | |
173 | return m_chart->chartTitleBrush(); |
|
173 | return m_chart->chartTitleBrush(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. |
|
177 | Sets the \a brush that is used for painting the background of the chart area of the QChartView widget. | |
178 | */ |
|
178 | */ | |
179 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
179 | void QChartView::setChartBackgroundBrush(const QBrush& brush) | |
180 | { |
|
180 | { | |
181 | m_chart->setChartBackgroundBrush(brush); |
|
181 | m_chart->setChartBackgroundBrush(brush); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. |
|
185 | Sets the \a pen that is used for painting the background of the chart area of the QChartView widget. | |
186 | */ |
|
186 | */ | |
187 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
187 | void QChartView::setChartBackgroundPen(const QPen& pen) | |
188 | { |
|
188 | { | |
189 | m_chart->setChartBackgroundPen(pen); |
|
189 | m_chart->setChartBackgroundPen(pen); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
193 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. | |
194 | */ |
|
194 | */ | |
195 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
195 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) | |
196 | { |
|
196 | { | |
197 | switch(policy) { |
|
197 | switch(policy) { | |
198 | case VerticalRubberBand: |
|
198 | case VerticalRubberBand: | |
199 | m_verticalRubberBand = true; |
|
199 | m_verticalRubberBand = true; | |
200 | m_horizonalRubberBand = false; |
|
200 | m_horizonalRubberBand = false; | |
201 | break; |
|
201 | break; | |
202 | case HorizonalRubberBand: |
|
202 | case HorizonalRubberBand: | |
203 | m_verticalRubberBand = false; |
|
203 | m_verticalRubberBand = false; | |
204 | m_horizonalRubberBand = true; |
|
204 | m_horizonalRubberBand = true; | |
205 | break; |
|
205 | break; | |
206 | case RectangleRubberBand: |
|
206 | case RectangleRubberBand: | |
207 | m_verticalRubberBand = true; |
|
207 | m_verticalRubberBand = true; | |
208 | m_horizonalRubberBand = true; |
|
208 | m_horizonalRubberBand = true; | |
209 | break; |
|
209 | break; | |
210 | case NoRubberBand: |
|
210 | case NoRubberBand: | |
211 | default: |
|
211 | default: | |
212 | delete m_rubberBand; |
|
212 | delete m_rubberBand; | |
213 | m_rubberBand=0; |
|
213 | m_rubberBand=0; | |
214 | m_horizonalRubberBand = false; |
|
214 | m_horizonalRubberBand = false; | |
215 | m_verticalRubberBand = false; |
|
215 | m_verticalRubberBand = false; | |
216 | return; |
|
216 | return; | |
217 | } |
|
217 | } | |
218 | if(!m_rubberBand) { |
|
218 | if(!m_rubberBand) { | |
219 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
219 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
220 | m_rubberBand->setEnabled(true); |
|
220 | m_rubberBand->setEnabled(true); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | /*! |
|
224 | /*! | |
225 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
225 | Returns the RubberBandPolicy that is currently being used by the widget. | |
226 | */ |
|
226 | */ | |
227 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
227 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const | |
228 | { |
|
228 | { | |
229 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
229 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; | |
230 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
230 | if(m_horizonalRubberBand) return HorizonalRubberBand; | |
231 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
231 | if(m_verticalRubberBand) return VerticalRubberBand; | |
232 | return NoRubberBand; |
|
232 | return NoRubberBand; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | /*! |
|
235 | /*! | |
236 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
236 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
237 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. |
|
237 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
238 | */ |
|
238 | */ | |
239 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
239 | void QChartView::mousePressEvent(QMouseEvent *event) | |
240 | { |
|
240 | { | |
241 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
241 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
242 |
|
242 | |||
243 | int margin = m_chart->margin(); |
|
243 | int margin = m_chart->margin(); | |
244 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
244 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
245 |
|
245 | |||
246 | if (rect.contains(event->pos())) { |
|
246 | if (rect.contains(event->pos())) { | |
247 | m_rubberBandOrigin = event->pos(); |
|
247 | m_rubberBandOrigin = event->pos(); | |
248 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
248 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); | |
249 | m_rubberBand->show(); |
|
249 | m_rubberBand->show(); | |
250 | event->accept(); |
|
250 | event->accept(); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 | else { |
|
253 | else { | |
254 | QGraphicsView::mousePressEvent(event); |
|
254 | QGraphicsView::mousePressEvent(event); | |
255 | } |
|
255 | } | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
259 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
260 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
260 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
261 | */ |
|
261 | */ | |
262 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
262 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
263 | { |
|
263 | { | |
264 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
264 | if(m_rubberBand && m_rubberBand->isVisible()) { | |
265 | int margin = m_chart->margin(); |
|
265 | int margin = m_chart->margin(); | |
266 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
266 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
267 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
267 | int width = event->pos().x() - m_rubberBandOrigin.x(); | |
268 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
268 | int height = event->pos().y() - m_rubberBandOrigin.y(); | |
269 | if(!m_verticalRubberBand) { |
|
269 | if(!m_verticalRubberBand) { | |
270 | m_rubberBandOrigin.setY(rect.top()); |
|
270 | m_rubberBandOrigin.setY(rect.top()); | |
271 | height = rect.height(); |
|
271 | height = rect.height(); | |
272 | } |
|
272 | } | |
273 | if(!m_horizonalRubberBand) { |
|
273 | if(!m_horizonalRubberBand) { | |
274 | m_rubberBandOrigin.setX(rect.left()); |
|
274 | m_rubberBandOrigin.setX(rect.left()); | |
275 | width= rect.width(); |
|
275 | width= rect.width(); | |
276 | } |
|
276 | } | |
277 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
277 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); | |
278 | } |
|
278 | } | |
279 | else { |
|
279 | else { | |
280 | QGraphicsView::mouseMoveEvent(event); |
|
280 | QGraphicsView::mouseMoveEvent(event); | |
281 | } |
|
281 | } | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
285 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
286 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
286 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
287 | */ |
|
287 | */ | |
288 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
288 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
289 | { |
|
289 | { | |
290 | if(m_rubberBand) { |
|
290 | if(m_rubberBand) { | |
291 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
291 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { | |
292 | m_rubberBand->hide(); |
|
292 | m_rubberBand->hide(); | |
293 | QRect rect = m_rubberBand->geometry(); |
|
293 | QRect rect = m_rubberBand->geometry(); | |
294 | m_chart->zoomIn(rect); |
|
294 | m_chart->zoomIn(rect); | |
295 | event->accept(); |
|
295 | event->accept(); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | if(event->button()==Qt::RightButton) |
|
298 | if(event->button()==Qt::RightButton) | |
299 | m_chart->zoomReset(); |
|
299 | m_chart->zoomReset(); | |
300 | } |
|
300 | } | |
301 | else { |
|
301 | else { | |
302 | QGraphicsView::mouseReleaseEvent(event); |
|
302 | QGraphicsView::mouseReleaseEvent(event); | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
307 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
308 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
308 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
309 | */ |
|
309 | */ | |
310 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
310 | void QChartView::keyPressEvent(QKeyEvent *event) | |
311 | { |
|
311 | { | |
312 | switch (event->key()) { |
|
312 | switch (event->key()) { | |
313 | case Qt::Key_Plus: |
|
313 | case Qt::Key_Plus: | |
314 | zoomIn(); |
|
314 | zoomIn(); | |
315 | break; |
|
315 | break; | |
316 | case Qt::Key_Minus: |
|
316 | case Qt::Key_Minus: | |
317 | zoomOut(); |
|
317 | zoomOut(); | |
318 | break; |
|
318 | break; | |
319 | default: |
|
319 | default: | |
320 | QGraphicsView::keyPressEvent(event); |
|
320 | QGraphicsView::keyPressEvent(event); | |
321 | break; |
|
321 | break; | |
322 | } |
|
322 | } | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | /*! |
|
325 | /*! | |
326 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
326 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
327 | \sa QChart::ChartTheme, chartTheme() |
|
327 | \sa QChart::ChartTheme, chartTheme() | |
328 | */ |
|
328 | */ | |
329 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
329 | void QChartView::setChartTheme(QChart::ChartTheme theme) | |
330 | { |
|
330 | { | |
|
331 | if (theme == QChart::ChartThemeBlueCerulean) { | |||
|
332 | QLinearGradient backgroundGradient; | |||
|
333 | backgroundGradient.setColorAt(0.0, QRgb(0x056188)); | |||
|
334 | backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); | |||
|
335 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |||
|
336 | setBackgroundBrush(backgroundGradient); | |||
|
337 | } else { | |||
|
338 | setBackgroundBrush(Qt::NoBrush); | |||
|
339 | } | |||
331 | m_chart->setChartTheme(theme); |
|
340 | m_chart->setChartTheme(theme); | |
332 | } |
|
341 | } | |
333 |
|
342 | |||
334 | /*! |
|
343 | /*! | |
335 | Returns the theme enum used by the chart. |
|
344 | Returns the theme enum used by the chart. | |
336 | \sa setChartTheme() |
|
345 | \sa setChartTheme() | |
337 | */ |
|
346 | */ | |
338 | QChart::ChartTheme QChartView::chartTheme() const |
|
347 | QChart::ChartTheme QChartView::chartTheme() const | |
339 | { |
|
348 | { | |
340 | return m_chart->chartTheme(); |
|
349 | return m_chart->chartTheme(); | |
341 | } |
|
350 | } | |
342 |
|
351 | |||
343 | /*! |
|
352 | /*! | |
344 | Returns the pointer to the x axis object of the chart |
|
353 | Returns the pointer to the x axis object of the chart | |
345 | */ |
|
354 | */ | |
346 | QChartAxis* QChartView::axisX() const |
|
355 | QChartAxis* QChartView::axisX() const | |
347 | { |
|
356 | { | |
348 | return m_chart->axisX(); |
|
357 | return m_chart->axisX(); | |
349 | } |
|
358 | } | |
350 |
|
359 | |||
351 | /*! |
|
360 | /*! | |
352 | Returns the pointer to the y axis object of the chart |
|
361 | Returns the pointer to the y axis object of the chart | |
353 | */ |
|
362 | */ | |
354 | QChartAxis* QChartView::axisY() const |
|
363 | QChartAxis* QChartView::axisY() const | |
355 | { |
|
364 | { | |
356 | return m_chart->axisY(); |
|
365 | return m_chart->axisY(); | |
357 | } |
|
366 | } | |
358 |
|
367 | |||
359 | /*! |
|
368 | /*! | |
360 | Returns the pointer to legend object of the chart |
|
369 | Returns the pointer to legend object of the chart | |
361 | */ |
|
370 | */ | |
362 | QLegend* QChartView::legend() const |
|
371 | QLegend* QChartView::legend() const | |
363 | { |
|
372 | { | |
364 | return m_chart->legend(); |
|
373 | return m_chart->legend(); | |
365 | } |
|
374 | } | |
366 |
|
375 | |||
367 | /*! |
|
376 | /*! | |
368 | Sets animation \a options for the chart |
|
377 | Sets animation \a options for the chart | |
369 | */ |
|
378 | */ | |
370 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) |
|
379 | void QChartView::setAnimationOptions(QChart::AnimationOptions options) | |
371 | { |
|
380 | { | |
372 | m_chart->setAnimationOptions(options); |
|
381 | m_chart->setAnimationOptions(options); | |
373 | } |
|
382 | } | |
374 |
|
383 | |||
375 | /*! |
|
384 | /*! | |
376 | Returns animation options for the chart |
|
385 | Returns animation options for the chart | |
377 | */ |
|
386 | */ | |
378 | QChart::AnimationOptions QChartView::animationOptions() const |
|
387 | QChart::AnimationOptions QChartView::animationOptions() const | |
379 | { |
|
388 | { | |
380 | return m_chart->animationOptions(); |
|
389 | return m_chart->animationOptions(); | |
381 | } |
|
390 | } | |
382 |
|
391 | |||
383 | void QChartView::scroll(int dx,int dy) |
|
392 | void QChartView::scroll(int dx,int dy) | |
384 | { |
|
393 | { | |
385 | m_chart->scroll(dx,dy); |
|
394 | m_chart->scroll(dx,dy); | |
386 | } |
|
395 | } | |
387 |
|
396 | |||
|
397 | #include "moc_qchartview.cpp" | |||
|
398 | ||||
388 | QTCOMMERCIALCHART_END_NAMESPACE |
|
399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,82 +1,81 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include "qseries.h" |
|
6 | #include "qseries.h" | |
7 | #include "qchart.h" |
|
7 | #include "qchart.h" | |
8 | #include <QGraphicsView> |
|
8 | #include <QGraphicsView> | |
9 |
|
9 | |||
10 | class QGraphicsScene; |
|
10 | class QGraphicsScene; | |
11 | class QRubberBand; |
|
11 | class QRubberBand; | |
12 |
|
12 | |||
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
14 |
|
14 | |||
15 | class QChart; |
|
15 | class QChart; | |
16 |
|
16 | |||
17 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
17 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
18 | { |
|
18 | { | |
|
19 | Q_OBJECT | |||
|
20 | ||||
19 | public: |
|
21 | public: | |
20 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
22 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
21 |
|
23 | |||
22 | explicit QChartView(QWidget *parent = 0); |
|
24 | explicit QChartView(QWidget *parent = 0); | |
23 | ~QChartView(); |
|
25 | ~QChartView(); | |
24 |
|
26 | |||
25 | //implement from QWidget |
|
27 | //implement from QWidget | |
26 | void resizeEvent(QResizeEvent *event); |
|
28 | void resizeEvent(QResizeEvent *event); | |
27 |
|
29 | |||
28 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership |
|
30 | void addSeries(QSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership | |
29 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
31 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
30 | void removeAllSeries(); // deletes series and axis |
|
32 | void removeAllSeries(); // deletes series and axis | |
31 | int margin() const; |
|
33 | int margin() const; | |
32 |
|
34 | |||
33 | void setChartTitle(const QString& title); |
|
35 | void setChartTitle(const QString& title); | |
34 | QString chartTitle() const; |
|
36 | QString chartTitle() const; | |
35 | void setChartTitleFont(const QFont& font); |
|
37 | void setChartTitleFont(const QFont& font); | |
36 | void setChartTitleBrush(const QBrush &brush); |
|
38 | void setChartTitleBrush(const QBrush &brush); | |
37 | QBrush chartTitleBrush(); |
|
39 | QBrush chartTitleBrush(); | |
38 | void setChartBackgroundBrush(const QBrush& brush); |
|
40 | void setChartBackgroundBrush(const QBrush& brush); | |
39 | void setChartBackgroundPen(const QPen& pen); |
|
41 | void setChartBackgroundPen(const QPen& pen); | |
40 |
|
42 | |||
41 | void zoomIn(); |
|
43 | void zoomIn(); | |
42 | void zoomIn(const QRect& rect); |
|
44 | void zoomIn(const QRect& rect); | |
43 | void zoomOut(); |
|
45 | void zoomOut(); | |
44 |
|
46 | |||
45 | void scroll(int dx,int dy); |
|
47 | void scroll(int dx,int dy); | |
46 |
|
48 | |||
47 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
49 | void setRubberBandPolicy(const RubberBandPolicy ); | |
48 | RubberBandPolicy rubberBandPolicy() const; |
|
50 | RubberBandPolicy rubberBandPolicy() const; | |
49 |
|
51 | |||
50 | void setChartTheme(QChart::ChartTheme theme); |
|
52 | void setChartTheme(QChart::ChartTheme theme); | |
51 | QChart::ChartTheme chartTheme() const; |
|
53 | QChart::ChartTheme chartTheme() const; | |
52 |
|
54 | |||
53 | void setAnimationOptions(QChart::AnimationOptions options); |
|
55 | void setAnimationOptions(QChart::AnimationOptions options); | |
54 | QChart::AnimationOptions animationOptions() const; |
|
56 | QChart::AnimationOptions animationOptions() const; | |
55 |
|
57 | |||
56 | QChartAxis* axisX() const; |
|
58 | QChartAxis* axisX() const; | |
57 | QChartAxis* axisY() const; |
|
59 | QChartAxis* axisY() const; | |
58 |
|
60 | |||
59 | QLegend* legend() const; |
|
61 | QLegend* legend() const; | |
60 |
|
62 | |||
61 | protected: |
|
63 | protected: | |
62 | void mousePressEvent(QMouseEvent *event); |
|
64 | void mousePressEvent(QMouseEvent *event); | |
63 | void mouseMoveEvent(QMouseEvent *event); |
|
65 | void mouseMoveEvent(QMouseEvent *event); | |
64 | void mouseReleaseEvent(QMouseEvent *event); |
|
66 | void mouseReleaseEvent(QMouseEvent *event); | |
65 | void keyPressEvent(QKeyEvent *event); |
|
67 | void keyPressEvent(QKeyEvent *event); | |
66 |
|
68 | |||
67 |
|
||||
68 | private: |
|
69 | private: | |
69 | QGraphicsScene *m_scene; |
|
70 | QGraphicsScene *m_scene; | |
70 | QChart* m_chart; |
|
71 | QChart* m_chart; | |
71 | QPoint m_rubberBandOrigin; |
|
72 | QPoint m_rubberBandOrigin; | |
72 | QRubberBand* m_rubberBand; |
|
73 | QRubberBand* m_rubberBand; | |
73 | bool m_verticalRubberBand; |
|
74 | bool m_verticalRubberBand; | |
74 | bool m_horizonalRubberBand; |
|
75 | bool m_horizonalRubberBand; | |
75 | Q_DISABLE_COPY(QChartView) |
|
76 | Q_DISABLE_COPY(QChartView) | |
76 |
|
||||
77 |
|
||||
78 | }; |
|
77 | }; | |
79 |
|
78 | |||
80 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE | |
81 |
|
80 | |||
82 | #endif // QCHARTWIDGET_H |
|
81 | #endif // QCHARTWIDGET_H |
@@ -1,99 +1,101 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += \ |
|
9 | SOURCES += \ | |
10 | chartdataset.cpp \ |
|
10 | chartdataset.cpp \ | |
11 | chartpresenter.cpp \ |
|
11 | chartpresenter.cpp \ | |
12 | charttheme.cpp \ |
|
12 | charttheme.cpp \ | |
13 | domain.cpp \ |
|
13 | domain.cpp \ | |
14 | qchart.cpp \ |
|
14 | qchart.cpp \ | |
15 | qchartview.cpp \ |
|
15 | qchartview.cpp \ | |
16 | qseries.cpp \ |
|
16 | qseries.cpp \ | |
17 | qlegend.cpp \ |
|
17 | qlegend.cpp \ | |
18 | legendmarker.cpp |
|
18 | legendmarker.cpp | |
19 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += \ | |
20 | chartdataset_p.h \ |
|
20 | chartdataset_p.h \ | |
21 | chartitem_p.h \ |
|
21 | chartitem_p.h \ | |
22 | chartpresenter_p.h \ |
|
22 | chartpresenter_p.h \ | |
23 | charttheme_p.h \ |
|
23 | charttheme_p.h \ | |
24 | domain_p.h \ |
|
24 | domain_p.h \ | |
25 | legendmarker_p.h |
|
25 | legendmarker_p.h | |
26 | PUBLIC_HEADERS += \ |
|
26 | PUBLIC_HEADERS += \ | |
27 | qchart.h \ |
|
27 | qchart.h \ | |
28 | qchartglobal.h \ |
|
28 | qchartglobal.h \ | |
29 | qseries.h \ |
|
29 | qseries.h \ | |
30 | qchartview.h \ |
|
30 | qchartview.h \ | |
31 | qlegend.h |
|
31 | qlegend.h | |
32 |
|
32 | |||
33 | include(animations/animations.pri) |
|
33 | include(animations/animations.pri) | |
34 | include(axis/axis.pri) |
|
34 | include(axis/axis.pri) | |
35 | include(xychart/xychart.pri) |
|
35 | include(xychart/xychart.pri) | |
36 | include(linechart/linechart.pri) |
|
36 | include(linechart/linechart.pri) | |
37 | include(areachart/areachart.pri) |
|
37 | include(areachart/areachart.pri) | |
38 | include(barchart/barchart.pri) |
|
38 | include(barchart/barchart.pri) | |
39 | include(piechart/piechart.pri) |
|
39 | include(piechart/piechart.pri) | |
40 | include(scatterseries/scatter.pri) |
|
40 | include(scatterseries/scatter.pri) | |
41 | include(splinechart/splinechart.pri) |
|
41 | include(splinechart/splinechart.pri) | |
42 |
|
42 | |||
43 | THEMES += themes/chartthemedefault_p.h \ |
|
43 | THEMES += themes/chartthemedefault_p.h \ | |
44 | themes/chartthemeicy_p.h \ |
|
44 | themes/chartthemeicy_p.h \ | |
45 | themes/chartthemegrayscale_p.h \ |
|
45 | themes/chartthemegrayscale_p.h \ | |
46 | themes/chartthemescientific_p.h \ |
|
46 | themes/chartthemescientific_p.h \ | |
47 | themes/chartthemevanilla_p.h \ |
|
47 | themes/chartthemevanilla_p.h \ | |
48 | themes/chartthemebluecerulean_p.h |
|
48 | themes/chartthemebluecerulean_p.h \ | |
|
49 | themes/chartthemelight_p.h | |||
|
50 | ||||
49 | HEADERS += $$PUBLIC_HEADERS |
|
51 | HEADERS += $$PUBLIC_HEADERS | |
50 | HEADERS += $$PRIVATE_HEADERS |
|
52 | HEADERS += $$PRIVATE_HEADERS | |
51 | HEADERS += $$THEMES |
|
53 | HEADERS += $$THEMES | |
52 | INCLUDEPATH += linechart \ |
|
54 | INCLUDEPATH += linechart \ | |
53 | barchart \ |
|
55 | barchart \ | |
54 | themes \ |
|
56 | themes \ | |
55 | . |
|
57 | . | |
56 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
58 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
57 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
59 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
58 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
60 | UI_DIR = $$CHART_BUILD_DIR/lib | |
59 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
61 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
60 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
62 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
61 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
63 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
62 | public_headers.files = $$PUBLIC_HEADERS |
|
64 | public_headers.files = $$PUBLIC_HEADERS | |
63 | target.path = $$[QT_INSTALL_LIBS] |
|
65 | target.path = $$[QT_INSTALL_LIBS] | |
64 | INSTALLS += target \ |
|
66 | INSTALLS += target \ | |
65 | public_headers |
|
67 | public_headers | |
66 | install_build_public_headers.name = bild_public_headers |
|
68 | install_build_public_headers.name = bild_public_headers | |
67 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
69 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
68 | install_build_public_headers.input = PUBLIC_HEADERS |
|
70 | install_build_public_headers.input = PUBLIC_HEADERS | |
69 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
71 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
70 | ${QMAKE_FILE_NAME} \ |
|
72 | ${QMAKE_FILE_NAME} \ | |
71 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
73 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
72 | install_build_public_headers.CONFIG += target_predeps \ |
|
74 | install_build_public_headers.CONFIG += target_predeps \ | |
73 | no_link |
|
75 | no_link | |
74 | install_build_private_headers.name = bild_private_headers |
|
76 | install_build_private_headers.name = bild_private_headers | |
75 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
77 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
76 | install_build_private_headers.input = PRIVATE_HEADERS |
|
78 | install_build_private_headers.input = PRIVATE_HEADERS | |
77 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
79 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
78 | ${QMAKE_FILE_NAME} \ |
|
80 | ${QMAKE_FILE_NAME} \ | |
79 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
81 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
80 | install_build_private_headers.CONFIG += target_predeps \ |
|
82 | install_build_private_headers.CONFIG += target_predeps \ | |
81 | no_link |
|
83 | no_link | |
82 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
84 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
83 | install_build_private_headers |
|
85 | install_build_private_headers | |
84 | chartversion.target = qchartversion_p.h |
|
86 | chartversion.target = qchartversion_p.h | |
85 | chartversion.commands = @echo \ |
|
87 | chartversion.commands = @echo \ | |
86 | "build_time" \ |
|
88 | "build_time" \ | |
87 | > \ |
|
89 | > \ | |
88 | $$chartversion.target; |
|
90 | $$chartversion.target; | |
89 | chartversion.depends = $$HEADERS \ |
|
91 | chartversion.depends = $$HEADERS \ | |
90 | $$SOURCES |
|
92 | $$SOURCES | |
91 | PRE_TARGETDEPS += qchartversion_p.h |
|
93 | PRE_TARGETDEPS += qchartversion_p.h | |
92 | QMAKE_CLEAN += qchartversion_p.h |
|
94 | QMAKE_CLEAN += qchartversion_p.h | |
93 | QMAKE_EXTRA_TARGETS += chartversion |
|
95 | QMAKE_EXTRA_TARGETS += chartversion | |
94 | unix:QMAKE_DISTCLEAN += -r \ |
|
96 | unix:QMAKE_DISTCLEAN += -r \ | |
95 | $$CHART_BUILD_HEADER_DIR \ |
|
97 | $$CHART_BUILD_HEADER_DIR \ | |
96 | $$CHART_BUILD_LIB_DIR |
|
98 | $$CHART_BUILD_LIB_DIR | |
97 | win32:QMAKE_DISTCLEAN += /Q \ |
|
99 | win32:QMAKE_DISTCLEAN += /Q \ | |
98 | $$CHART_BUILD_HEADER_DIR \ |
|
100 | $$CHART_BUILD_HEADER_DIR \ | |
99 | $$CHART_BUILD_LIB_DIR |
|
101 | $$CHART_BUILD_LIB_DIR |
@@ -1,36 +1,32 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeBlueCerulean: public ChartTheme |
|
5 | class ChartThemeBlueCerulean: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) |
|
8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0xc7e85b); |
|
11 | m_seriesColors << QRgb(0xc7e85b); | |
12 | m_seriesColors << QRgb(0x5dbe9b); |
|
12 | m_seriesColors << QRgb(0x5dbe9b); | |
13 | m_seriesColors << QRgb(0x4fbef3); |
|
13 | m_seriesColors << QRgb(0x4fbef3); | |
14 | generateSeriesGradients(); |
|
14 | generateSeriesGradients(); | |
15 |
|
15 | |||
16 | // Background |
|
16 | // No chart background, chart view specifies a background | |
17 | QLinearGradient backgroundGradient; |
|
17 | // TODO: what if the chart is drawn on custom graphics scene instead of QChartView? | |
18 | backgroundGradient.setColorAt(0.0, QRgb(0x056188)); |
|
|||
19 | backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); |
|
|||
20 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
|||
21 | m_backgroundGradient = backgroundGradient; |
|
|||
22 |
|
18 | |||
23 | // Axes and other |
|
19 | // Axes and other | |
24 | m_masterFont = QFont(); |
|
20 | m_masterFont = QFont(); | |
25 |
m_axisLinePen = QPen(QRgb(0x |
|
21 | m_axisLinePen = QPen(QRgb(0xf7f7ff)); | |
26 | m_axisLinePen.setWidth(2); |
|
22 | m_axisLinePen.setWidth(2); | |
27 |
m_axisLabelBrush = QBrush(QRgb(0x |
|
23 | m_axisLabelBrush = QBrush(QRgb(0xf7f7ff)); | |
28 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
24 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
29 | m_backgroundShadesPen = Qt::NoPen; |
|
25 | m_backgroundShadesPen = Qt::NoPen; | |
30 | m_backgroundShades = BackgroundShadesNone; |
|
26 | m_backgroundShades = BackgroundShadesNone; | |
31 |
m_gridLinePen = QPen(QRgb(0x |
|
27 | m_gridLinePen = QPen(QRgb(0xf7f7ff)); | |
32 |
m_gridLinePen.setWidth( |
|
28 | m_gridLinePen.setWidth(1); | |
33 | } |
|
29 | } | |
34 | }; |
|
30 | }; | |
35 |
|
31 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
32 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,154 +1,154 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #ifdef Q_OS_WIN |
|
2 | #ifdef Q_OS_WIN | |
3 | #include <windows.h> |
|
3 | #include <windows.h> | |
4 | #include <stdio.h> |
|
4 | #include <stdio.h> | |
5 | #endif |
|
5 | #endif | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class ChartThemeDefault: public ChartTheme |
|
9 | class ChartThemeDefault: public ChartTheme | |
10 | { |
|
10 | { | |
11 | public: |
|
11 | public: | |
12 | ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault) |
|
12 | ChartThemeDefault():ChartTheme(QChart::ChartThemeDefault) | |
13 | { |
|
13 | { | |
14 | #ifdef Q_OS_WIN |
|
14 | #ifdef Q_OS_WIN | |
15 | // TODO: use theme specific window frame color as a series base color (it would give more |
|
15 | // TODO: use theme specific window frame color as a series base color (it would give more | |
16 | // variation to the base colors in addition to the blue and black used now) |
|
16 | // variation to the base colors in addition to the blue and black used now) | |
17 | // TODO: COLOR_WINDOWTEXT for text color? |
|
17 | // TODO: COLOR_WINDOWTEXT for text color? | |
18 | // TODO: COLOR_INFOTEXT for tooltip text color? |
|
18 | // TODO: COLOR_INFOTEXT for tooltip text color? | |
19 | // TODO: COLOR_INFOBK for tooltip background color? |
|
19 | // TODO: COLOR_INFOBK for tooltip background color? | |
20 |
|
20 | |||
21 | // First series base color from COLOR_HIGHLIGHT |
|
21 | // First series base color from COLOR_HIGHLIGHT | |
22 | DWORD colorHighlight; |
|
22 | DWORD colorHighlight; | |
23 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
23 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); | |
24 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
24 | m_seriesColors.append(QColor(GetRValue(colorHighlight), | |
25 | GetGValue(colorHighlight), |
|
25 | GetGValue(colorHighlight), | |
26 | GetBValue(colorHighlight))); |
|
26 | GetBValue(colorHighlight))); | |
27 |
|
27 | |||
28 | // Second series base color from COLOR_WINDOWFRAME |
|
28 | // Second series base color from COLOR_WINDOWFRAME | |
29 | DWORD colorWindowFrame; |
|
29 | DWORD colorWindowFrame; | |
30 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
30 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); | |
31 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
31 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), | |
32 | GetGValue(colorWindowFrame), |
|
32 | GetGValue(colorWindowFrame), | |
33 | GetBValue(colorWindowFrame))); |
|
33 | GetBValue(colorWindowFrame))); | |
34 |
|
34 | |||
35 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
35 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / | |
36 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
36 | // COLOR_GRADIENTACTIVECAPTION gradient | |
37 | DWORD colorGradientActiveCaptionLeft; |
|
37 | DWORD colorGradientActiveCaptionLeft; | |
38 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
38 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); | |
39 | DWORD colorGradientActiveCaptionRight; |
|
39 | DWORD colorGradientActiveCaptionRight; | |
40 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
40 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); | |
41 | QLinearGradient g; |
|
41 | QLinearGradient g; | |
42 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
42 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), | |
43 | GetGValue(colorGradientActiveCaptionLeft), |
|
43 | GetGValue(colorGradientActiveCaptionLeft), | |
44 | GetBValue(colorGradientActiveCaptionLeft)); |
|
44 | GetBValue(colorGradientActiveCaptionLeft)); | |
45 | g.setColorAt(0.0, start); |
|
45 | g.setColorAt(0.0, start); | |
46 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
46 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), | |
47 | GetGValue(colorGradientActiveCaptionRight), |
|
47 | GetGValue(colorGradientActiveCaptionRight), | |
48 | GetBValue(colorGradientActiveCaptionRight)); |
|
48 | GetBValue(colorGradientActiveCaptionRight)); | |
49 | g.setColorAt(1.0, end); |
|
49 | g.setColorAt(1.0, end); | |
50 | m_seriesColors.append(colorAt(g, 0.5)); |
|
50 | m_seriesColors.append(colorAt(g, 0.5)); | |
51 |
|
51 | |||
52 | // Generate gradients from the base colors |
|
52 | // Generate gradients from the base colors | |
53 | generateSeriesGradients(); |
|
53 | generateSeriesGradients(); | |
54 |
|
54 | |||
55 | // Background fill color from COLOR_WINDOW |
|
55 | // Background fill color from COLOR_WINDOW | |
56 | QLinearGradient backgroundGradient; |
|
56 | QLinearGradient backgroundGradient; | |
57 | DWORD colorWindow; |
|
57 | DWORD colorWindow; | |
58 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
58 | colorWindow = GetSysColor(COLOR_WINDOW); | |
59 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
59 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), | |
60 | GetGValue(colorWindow), |
|
60 | GetGValue(colorWindow), | |
61 | GetBValue(colorWindow))); |
|
61 | GetBValue(colorWindow))); | |
62 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
62 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), | |
63 | GetGValue(colorWindow), |
|
63 | GetGValue(colorWindow), | |
64 | GetBValue(colorWindow))); |
|
64 | GetBValue(colorWindow))); | |
65 | // Axes and other |
|
65 | // Axes and other | |
66 | m_masterFont = QFont(); |
|
66 | m_masterFont = QFont(); | |
67 | m_masterFont.setPointSizeF(10.0); |
|
67 | m_masterFont.setPointSizeF(10.0); | |
68 | m_axisLinePen = QPen(Qt::black); |
|
68 | m_axisLinePen = QPen(Qt::black); | |
69 | m_axisLinePen.setWidth(2); |
|
69 | m_axisLinePen.setWidth(2); | |
70 | m_axisLabelBrush = QBrush(Qt::black); |
|
70 | m_axisLabelBrush = QBrush(Qt::black); | |
71 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
71 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
72 | m_backgroundShadesPen = Qt::NoPen; |
|
72 | m_backgroundShadesPen = Qt::NoPen; | |
73 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
73 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); | |
74 | m_backgroundShades = BackgroundShadesVertical; |
|
74 | m_backgroundShades = BackgroundShadesVertical; | |
75 |
|
75 | |||
76 | #elif defined(Q_OS_LINUX) |
|
76 | #elif defined(Q_OS_LINUX) | |
77 | // TODO: replace this dummy theme with linux specific theme |
|
77 | // TODO: replace this dummy theme with linux specific theme | |
78 | m_seriesColors << QRgb(0x60a6e6); |
|
78 | m_seriesColors << QRgb(0x60a6e6); | |
79 | m_seriesColors << QRgb(0x92ca66); |
|
79 | m_seriesColors << QRgb(0x92ca66); | |
80 | m_seriesColors << QRgb(0xeba85f); |
|
80 | m_seriesColors << QRgb(0xeba85f); | |
81 | m_seriesColors << QRgb(0xfc5751); |
|
81 | m_seriesColors << QRgb(0xfc5751); | |
82 | generateSeriesGradients(); |
|
82 | generateSeriesGradients(); | |
83 |
|
83 | |||
84 | QLinearGradient backgroundGradient; |
|
84 | QLinearGradient backgroundGradient; | |
85 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
85 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
86 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); |
|
86 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); | |
87 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
87 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
88 | m_backgroundGradient = backgroundGradient; |
|
88 | m_backgroundGradient = backgroundGradient; | |
89 |
|
89 | |||
90 | // Axes and other |
|
90 | // Axes and other | |
91 | m_masterFont = QFont(); |
|
91 | m_masterFont = QFont(); | |
92 | m_masterFont.setPointSizeF(10.0); |
|
92 | m_masterFont.setPointSizeF(10.0); | |
93 | m_axisLinePen = QPen(Qt::black); |
|
93 | m_axisLinePen = QPen(Qt::black); | |
94 | m_axisLinePen.setWidth(2); |
|
94 | m_axisLinePen.setWidth(2); | |
95 | m_axisLabelBrush = QBrush(Qt::black); |
|
95 | m_axisLabelBrush = QBrush(Qt::black); | |
96 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
96 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
97 | m_backgroundShadesPen = Qt::NoPen; |
|
97 | m_backgroundShadesPen = Qt::NoPen; | |
98 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
98 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); | |
99 | m_backgroundShades = BackgroundShadesVertical; |
|
99 | m_backgroundShades = BackgroundShadesVertical; | |
100 |
|
100 | |||
101 | #elif defined(Q_OS_MAC) |
|
101 | #elif defined(Q_OS_MAC) | |
102 | // TODO: replace this dummy theme with OSX specific theme |
|
102 | // TODO: replace this dummy theme with OSX specific theme | |
103 | m_seriesColors << QRgb(0x60a6e6); |
|
103 | m_seriesColors << QRgb(0x60a6e6); | |
104 | m_seriesColors << QRgb(0x92ca66); |
|
104 | m_seriesColors << QRgb(0x92ca66); | |
105 | m_seriesColors << QRgb(0xeba85f); |
|
105 | m_seriesColors << QRgb(0xeba85f); | |
106 | m_seriesColors << QRgb(0xfc5751); |
|
106 | m_seriesColors << QRgb(0xfc5751); | |
107 | generateSeriesGradients(); |
|
107 | generateSeriesGradients(); | |
108 |
|
108 | |||
109 | QLinearGradient backgroundGradient; |
|
109 | QLinearGradient backgroundGradient; | |
110 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
110 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
111 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); |
|
111 | backgroundGradient.setColorAt(1.0, QRgb(0xe9e9e9)); | |
112 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
112 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
113 |
m_ |
|
113 | m_chartBackgroundGradient = backgroundGradient; | |
114 |
|
114 | |||
115 | // Axes and other |
|
115 | // Axes and other | |
116 | m_masterFont = QFont(); |
|
116 | m_masterFont = QFont(); | |
117 | m_masterFont.setPointSizeF(10.0); |
|
117 | m_masterFont.setPointSizeF(10.0); | |
118 | m_axisLinePen = QPen(Qt::black); |
|
118 | m_axisLinePen = QPen(Qt::black); | |
119 | m_axisLinePen.setWidth(2); |
|
119 | m_axisLinePen.setWidth(2); | |
120 | m_axisLabelBrush = QBrush(Qt::black); |
|
120 | m_axisLabelBrush = QBrush(Qt::black); | |
121 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
121 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
122 | m_backgroundShadesPen = Qt::NoPen; |
|
122 | m_backgroundShadesPen = Qt::NoPen; | |
123 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
123 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); | |
124 | m_backgroundShades = BackgroundShadesVertical; |
|
124 | m_backgroundShades = BackgroundShadesVertical; | |
125 |
|
125 | |||
126 | #else |
|
126 | #else | |
127 | // TODO: replace this dummy theme with generic (not OS specific) theme |
|
127 | // TODO: replace this dummy theme with generic (not OS specific) theme | |
128 | m_seriesColors << QRgb(0x60a6e6); |
|
128 | m_seriesColors << QRgb(0x60a6e6); | |
129 | m_seriesColors << QRgb(0x92ca66); |
|
129 | m_seriesColors << QRgb(0x92ca66); | |
130 | m_seriesColors << QRgb(0xeba85f); |
|
130 | m_seriesColors << QRgb(0xeba85f); | |
131 | m_seriesColors << QRgb(0xfc5751); |
|
131 | m_seriesColors << QRgb(0xfc5751); | |
132 | generateSeriesGradients(); |
|
132 | generateSeriesGradients(); | |
133 |
|
133 | |||
134 | QLinearGradient backgroundGradient; |
|
134 | QLinearGradient backgroundGradient; | |
135 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
135 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
136 | backgroundGradient.setColorAt(1.0, QRgb(0xafafaf)); |
|
136 | backgroundGradient.setColorAt(1.0, QRgb(0xafafaf)); | |
137 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
137 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
138 | m_backgroundGradient = backgroundGradient; |
|
138 | m_backgroundGradient = backgroundGradient; | |
139 |
|
139 | |||
140 | // Axes and other |
|
140 | // Axes and other | |
141 | m_masterFont = QFont(); |
|
141 | m_masterFont = QFont(); | |
142 | m_masterFont.setPointSizeF(10.0); |
|
142 | m_masterFont.setPointSizeF(10.0); | |
143 | m_axisLinePen = QPen(Qt::black); |
|
143 | m_axisLinePen = QPen(Qt::black); | |
144 | m_axisLinePen.setWidth(2); |
|
144 | m_axisLinePen.setWidth(2); | |
145 | m_axisLabelBrush = QBrush(Qt::black); |
|
145 | m_axisLabelBrush = QBrush(Qt::black); | |
146 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
146 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
147 | m_backgroundShadesPen = Qt::NoPen; |
|
147 | m_backgroundShadesPen = Qt::NoPen; | |
148 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); |
|
148 | m_backgroundShadesBrush = QBrush(QColor(0xaf, 0xaf, 0xaf, 0x50)); | |
149 | m_backgroundShades = BackgroundShadesVertical; |
|
149 | m_backgroundShades = BackgroundShadesVertical; | |
150 | #endif |
|
150 | #endif | |
151 | } |
|
151 | } | |
152 | }; |
|
152 | }; | |
153 |
|
153 | |||
154 | QTCOMMERCIALCHART_END_NAMESPACE |
|
154 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeGrayscale: public ChartTheme |
|
5 | class ChartThemeGrayscale: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeGrayscale():ChartTheme(QChart::ChartThemeGrayscale) |
|
8 | ChartThemeGrayscale():ChartTheme(QChart::ChartThemeGrayscale) | |
9 | { |
|
9 | { | |
10 | // Series colors |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0x869299); |
|
11 | m_seriesColors << QRgb(0x869299); | |
12 | m_seriesColors << QRgb(0xa5bdcc); |
|
12 | m_seriesColors << QRgb(0xa5bdcc); | |
13 | m_seriesColors << QRgb(0xe8fffc); |
|
13 | m_seriesColors << QRgb(0xe8fffc); | |
14 | m_seriesColors << QRgb(0xccc2c2); |
|
14 | m_seriesColors << QRgb(0xccc2c2); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xe0e3e5)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xe0e3e5)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 |
m_ |
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_masterFont = QFont(); |
|
25 | m_masterFont = QFont(); | |
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
27 | m_axisLinePen.setWidth(2); |
|
27 | m_axisLinePen.setWidth(2); | |
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
30 | m_backgroundShadesPen = Qt::NoPen; |
|
30 | m_backgroundShadesPen = Qt::NoPen; | |
|
31 | m_backgroundShades = BackgroundShadesNone; | |||
31 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
32 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
32 | m_gridLinePen.setWidth(2); |
|
33 | m_gridLinePen.setWidth(2); | |
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeIcy: public ChartTheme |
|
5 | class ChartThemeIcy: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeIcy():ChartTheme(QChart::ChartThemeIcy) |
|
8 | ChartThemeIcy():ChartTheme(QChart::ChartThemeIcy) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0x0d2673); |
|
11 | m_seriesColors << QRgb(0x0d2673); | |
12 | m_seriesColors << QRgb(0x2685bf); |
|
12 | m_seriesColors << QRgb(0x2685bf); | |
13 | m_seriesColors << QRgb(0x3dadd9); |
|
13 | m_seriesColors << QRgb(0x3dadd9); | |
14 | m_seriesColors << QRgb(0x62c3d9); |
|
14 | m_seriesColors << QRgb(0x62c3d9); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xebebeb)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xf8f9fb)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 |
m_ |
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_masterFont = QFont(); |
|
25 | m_masterFont = QFont(); | |
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
27 | m_axisLinePen.setWidth(2); |
|
27 | m_axisLinePen.setWidth(2); | |
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
30 | m_backgroundShadesPen = Qt::NoPen; |
|
30 | m_backgroundShadesPen = Qt::NoPen; | |
|
31 | m_backgroundShades = BackgroundShadesNone; | |||
31 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
32 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
32 | m_gridLinePen.setWidth(2); |
|
33 | m_gridLinePen.setWidth(2); | |
33 | } |
|
34 | } | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,39 +1,39 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeScientific: public ChartTheme |
|
5 | class ChartThemeScientific: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) |
|
8 | ChartThemeScientific():ChartTheme(QChart::ChartThemeScientific) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0xFFAD00); |
|
11 | m_seriesColors << QRgb(0xFFAD00); | |
12 | m_seriesColors << QRgb(0x596A75); |
|
12 | m_seriesColors << QRgb(0x596A75); | |
13 | m_seriesColors << QRgb(0x202020); |
|
13 | m_seriesColors << QRgb(0x202020); | |
14 | m_seriesColors << QRgb(0x474747); |
|
14 | m_seriesColors << QRgb(0x474747); | |
15 | generateSeriesGradients(); |
|
15 | generateSeriesGradients(); | |
16 |
|
16 | |||
17 | // Background |
|
17 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
18 | QLinearGradient backgroundGradient; | |
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); |
|
19 | backgroundGradient.setColorAt(0.0, QRgb(0xfffefc)); | |
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); |
|
20 | backgroundGradient.setColorAt(1.0, QRgb(0xfffefc)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 |
m_ |
|
22 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
23 | |||
24 | // Axes and other |
|
24 | // Axes and other | |
25 | m_masterFont = QFont(); |
|
25 | m_masterFont = QFont(); | |
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
26 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
27 | m_axisLinePen.setWidth(2); |
|
27 | m_axisLinePen.setWidth(2); | |
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); |
|
28 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
29 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
30 | m_backgroundShadesPen = Qt::NoPen; |
|
30 | m_backgroundShadesPen = Qt::NoPen; | |
31 | // m_backgroundShadesBrush = QBrush(QColor(0x0f, 0x0f, 0x0f, 0x80)); |
|
31 | // m_backgroundShadesBrush = QBrush(QColor(0x0f, 0x0f, 0x0f, 0x80)); | |
32 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); |
|
32 | m_backgroundShadesBrush = QBrush(QColor(0xff, 0xad, 0x00, 0x50)); | |
33 | m_backgroundShades = BackgroundShadesHorizontal; |
|
33 | m_backgroundShades = BackgroundShadesHorizontal; | |
34 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
34 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
35 | m_gridLinePen.setWidth(2); |
|
35 | m_gridLinePen.setWidth(2); | |
36 | } |
|
36 | } | |
37 | }; |
|
37 | }; | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_END_NAMESPACE |
|
39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,38 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeVanilla: public ChartTheme |
|
5 | class ChartThemeVanilla: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeVanilla():ChartTheme(QChart::ChartThemeVanilla) |
|
8 | ChartThemeVanilla():ChartTheme(QChart::ChartThemeVanilla) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series | |
11 | m_seriesColors << QRgb(0xd9c574); |
|
11 | m_seriesColors << QRgb(0xd9c574); | |
12 | m_seriesColors << QRgb(0xd6a896); |
|
12 | m_seriesColors << QRgb(0xd6a896); | |
13 | m_seriesColors << QRgb(0xa0a071); |
|
13 | m_seriesColors << QRgb(0xa0a071); | |
14 | m_seriesColors << QRgb(0xd2d234); |
|
14 | m_seriesColors << QRgb(0xd2d234); | |
15 | m_seriesColors << QRgb(0x88723a); |
|
15 | m_seriesColors << QRgb(0x88723a); | |
16 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
17 |
|
17 | |||
18 | // Background |
|
18 | // Background | |
19 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient; | |
20 | backgroundGradient.setColorAt(0.0, QRgb(0xfbf9f1)); |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xfbf9f1)); | |
21 | backgroundGradient.setColorAt(1.0, QRgb(0xf5f0dc)); |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xf5f0dc)); | |
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
23 |
m_ |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
24 |
|
24 | |||
25 | // Axes and other |
|
25 | // Axes and other | |
26 | m_masterFont = QFont(); |
|
26 | m_masterFont = QFont(); | |
27 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
27 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |
28 | m_axisLinePen.setWidth(2); |
|
28 | m_axisLinePen.setWidth(2); | |
29 | m_axisLabelBrush = QBrush(QRgb(0xa0a071)); |
|
29 | m_axisLabelBrush = QBrush(QRgb(0xa0a071)); | |
30 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons |
|
30 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |
31 | m_backgroundShadesPen = Qt::NoPen; |
|
31 | m_backgroundShadesPen = Qt::NoPen; | |
|
32 | m_backgroundShades = BackgroundShadesNone; | |||
32 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); |
|
33 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |
33 | m_gridLinePen.setWidth(2); |
|
34 | m_gridLinePen.setWidth(2); | |
34 | } |
|
35 | } | |
35 | }; |
|
36 | }; | |
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_END_NAMESPACE |
|
38 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now