##// END OF EJS Templates
Adds force option to chartTheme...
Michal Klocek -
r645:9b55fd85f9c4
parent child
Show More
@@ -63,6 +63,7 int main(int argc, char *argv[])
63 QChartAxis* axisY = chartView->axisY();
63 QChartAxis* axisY = chartView->axisY();
64 axisY->setLabelsAngle(45);
64 axisY->setLabelsAngle(45);
65 axisY->setShadesBrush(Qt::yellow);
65 axisY->setShadesBrush(Qt::yellow);
66 axisY->setShadesVisible(true);
66 axisY->setGridLineVisible(false);
67 axisY->setGridLineVisible(false);
67
68
68 QChartAxisCategories* categoriesY = axisY->categories();
69 QChartAxisCategories* categoriesY = axisY->categories();
@@ -33,10 +33,11 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char
33 m_chartTheme(0),
33 m_chartTheme(0),
34 m_zoomIndex(0),
34 m_zoomIndex(0),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
36 m_options(QChart::NoAnimation)
36 m_options(QChart::NoAnimation),
37 m_themeForce(false)
37 {
38 {
38 createConnections();
39 createConnections();
39 setChartTheme(QChart::ChartThemeDefault);
40 setChartTheme(QChart::ChartThemeDefault,false);
40 }
41 }
41
42
42 ChartPresenter::~ChartPresenter()
43 ChartPresenter::~ChartPresenter()
@@ -94,14 +95,14 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
94 }
95 }
95
96
96 if(axis==m_dataset->axisX()){
97 if(axis==m_dataset->axisX()){
97 m_chartTheme->decorate(axis,true);
98 m_chartTheme->decorate(axis,true,m_themeForce);
98 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
99 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
99 //initialize
100 //initialize
100 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
101 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
101
102
102 }
103 }
103 else{
104 else{
104 m_chartTheme->decorate(axis,false);
105 m_chartTheme->decorate(axis,false,m_themeForce);
105 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
106 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
106 //initialize
107 //initialize
107 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
108 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
@@ -135,7 +136,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
135 if(m_options.testFlag(QChart::SeriesAnimations)) {
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
136 m_animator->addAnimation(line);
137 m_animator->addAnimation(line);
137 }
138 }
138 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series));
139 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
139 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
140 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
140 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
141 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
141 item = line;
142 item = line;
@@ -150,7 +151,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
150 m_animator->addAnimation(area->upperLineItem());
151 m_animator->addAnimation(area->upperLineItem());
151 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
152 }
153 }
153 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series));
154 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
154 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
155 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
156 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
156 item=area;
157 item=area;
@@ -163,7 +164,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
163 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 // m_animator->addAnimation(bar);
165 // m_animator->addAnimation(bar);
165 }
166 }
166 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries));
167 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
167 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
168 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 item=bar;
170 item=bar;
@@ -176,7 +177,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
176 if(m_options.testFlag(QChart::SeriesAnimations)) {
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
177 // m_animator->addAnimation(bar);
178 // m_animator->addAnimation(bar);
178 }
179 }
179 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries));
180 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
180 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
181 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
181 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
182 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
182 item=bar;
183 item=bar;
@@ -189,7 +190,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
189 if(m_options.testFlag(QChart::SeriesAnimations)) {
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
190 // m_animator->addAnimation(bar);
191 // m_animator->addAnimation(bar);
191 }
192 }
192 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries));
193 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
193 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
194 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
194 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
195 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
195 item=bar;
196 item=bar;
@@ -202,7 +203,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
202 if(m_options.testFlag(QChart::SeriesAnimations)) {
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
203 m_animator->addAnimation(scatter);
204 m_animator->addAnimation(scatter);
204 }
205 }
205 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series));
206 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
206 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
207 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
207 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
208 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
208 item = scatter;
209 item = scatter;
@@ -215,7 +216,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
215 if(m_options.testFlag(QChart::SeriesAnimations)) {
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
216 m_animator->addAnimation(pie);
217 m_animator->addAnimation(pie);
217 }
218 }
218 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series));
219 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
219 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
220 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
220 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
221 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
221 // Hide all from background when there is only piechart
222 // Hide all from background when there is only piechart
@@ -223,7 +224,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
223 if (m_chartItems.count() == 0) {
224 if (m_chartItems.count() == 0) {
224 m_chart->axisX()->hide();
225 m_chart->axisX()->hide();
225 m_chart->axisY()->hide();
226 m_chart->axisY()->hide();
226 m_chart->setChartBackgroundBrush(Qt::transparent);
227 m_chart->setBackgroundVisible(false);
227 }
228 }
228 item=pie;
229 item=pie;
229 break;
230 break;
@@ -235,7 +236,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
235 if(m_options.testFlag(QChart::SeriesAnimations)) {
236 if(m_options.testFlag(QChart::SeriesAnimations)) {
236 m_animator->addAnimation(spline);
237 m_animator->addAnimation(spline);
237 }
238 }
238 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series));
239 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
239 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
240 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
240 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
241 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
241 item=spline;
242 item=spline;
@@ -271,13 +272,14 void ChartPresenter::handleSeriesRemoved(QSeries* series)
271 delete item;
272 delete item;
272 }
273 }
273
274
274 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
275 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
275 {
276 {
276 if(m_chartTheme && m_chartTheme->id() == theme) return;
277 if(m_chartTheme && m_chartTheme->id() == theme) return;
277 delete m_chartTheme;
278 delete m_chartTheme;
279 m_themeForce = force;
278 m_chartTheme = ChartTheme::createTheme(theme);
280 m_chartTheme = ChartTheme::createTheme(theme);
279 m_chartTheme->decorate(m_chart);
281 m_chartTheme->decorate(m_chart,m_themeForce);
280 m_chartTheme->decorate(m_chart->legend());
282 m_chartTheme->decorate(m_chart->legend(),m_themeForce);
281 resetAllElements();
283 resetAllElements();
282 }
284 }
283
285
@@ -41,7 +41,7 public:
41 QRectF geometry() const;
41 QRectF geometry() const;
42 ChartAnimator* animator() const {return m_animator;};
42 ChartAnimator* animator() const {return m_animator;};
43
43
44 void setChartTheme(QChart::ChartTheme theme);
44 void setChartTheme(QChart::ChartTheme theme,bool force = true);
45 QChart::ChartTheme chartTheme();
45 QChart::ChartTheme chartTheme();
46
46
47 void setAnimationOptions(QChart::AnimationOptions options);
47 void setAnimationOptions(QChart::AnimationOptions options);
@@ -77,6 +77,7 private:
77 QVector<QRectF> m_zoomStack;
77 QVector<QRectF> m_zoomStack;
78 QRectF m_rect;
78 QRectF m_rect;
79 QChart::AnimationOptions m_options;
79 QChart::AnimationOptions m_options;
80 bool m_themeForce;
80
81
81 };
82 };
82
83
@@ -75,82 +75,110 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
75 }
75 }
76 }
76 }
77
77
78 void ChartTheme::decorate(QChart* chart)
78 void ChartTheme::decorate(QChart* chart,bool force)
79 {
79 {
80 if (m_backgroundShades == BackgroundShadesNone) {
80 QPen pen;
81 chart->setChartBackgroundBrush(m_chartBackgroundGradient);
81 QBrush brush;
82 } else {
82
83 chart->setChartBackgroundBrush(Qt::NoBrush);
83 if(brush == chart->backgroundBrush() || force)
84 {
85 if (m_backgroundShades == BackgroundShadesNone) {
86 chart->setBackgroundBrush(m_chartBackgroundGradient);
87 }
88 else {
89 chart->setBackgroundBrush(Qt::NoBrush);
90 }
84 }
91 }
85 chart->setChartTitleFont(m_masterFont);
92 chart->setTitleFont(m_masterFont);
86 chart->setChartTitleBrush(m_titleBrush);
93 chart->setTitleBrush(m_titleBrush);
87 }
94 }
88
95
89 void ChartTheme::decorate(QLegend* legend)
96 void ChartTheme::decorate(QLegend* legend,bool force)
90 {
97 {
91 legend->setBackgroundBrush(m_chartBackgroundGradient);
98 QPen pen;
99 QBrush brush;
100
101 if (pen == legend->pen() || force){
102 //TODO:: legend->setPen();
103 }
104
105
106 if (brush == legend->brush() || force) {
107 legend->setBrush(m_chartBackgroundGradient);
108 }
92 }
109 }
93
110
94 void ChartTheme::decorate(QAreaSeries* series, int index)
111 void ChartTheme::decorate(QAreaSeries* series, int index,bool force)
95 {
112 {
96 QPen pen;
113 QPen pen;
97 QBrush brush;
114 QBrush brush;
98
115
99 if (pen == series->pen()){
116 if (pen == series->pen() || force){
100 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
117 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
101 pen.setWidthF(2);
118 pen.setWidthF(2);
102 series->setPen(pen);
119 series->setPen(pen);
103 }
120 }
104
121
105 if (brush == series->brush()) {
122 if (brush == series->brush() || force) {
106 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
123 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
107 series->setBrush(brush);
124 series->setBrush(brush);
108 }
125 }
109 }
126 }
110
127
111
128
112 void ChartTheme::decorate(QLineSeries* series,int index)
129 void ChartTheme::decorate(QLineSeries* series,int index,bool force)
113 {
130 {
114 QPen pen;
131 QPen pen;
115 if(pen == series->pen()){
132 if(pen == series->pen() || force ){
116 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
133 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
117 pen.setWidthF(2);
134 pen.setWidthF(2);
118 series->setPen(pen);
135 series->setPen(pen);
119 }
136 }
120 }
137 }
121
138
122 void ChartTheme::decorate(QBarSeries* series,int index)
139 void ChartTheme::decorate(QBarSeries* series,int index,bool force)
123 {
140 {
141 QBrush brush;
124 QList<QBarSet*> sets = series->barSets();
142 QList<QBarSet*> sets = series->barSets();
143
125 for (int i=0; i<sets.count(); i++) {
144 for (int i=0; i<sets.count(); i++) {
126 qreal pos = 0.5;
145 qreal pos = 0.5;
127 if (sets.count() > 1)
146 if (sets.count() > 1)
128 pos = (qreal) i / (qreal) (sets.count() - 1);
147 pos = (qreal) i / (qreal) (sets.count() - 1);
148
149 if(brush == sets.at(i)->brush() || force ){
129 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
150 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
130 sets.at(i)->setBrush(QBrush(c));
151 sets.at(i)->setBrush(QBrush(c));
131
152 }
132 // Pick label color as far as possible from bar color (within gradient).
153 // Pick label color as far as possible from bar color (within gradient).
133 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
154 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
134 // TODO: better picking of label color?
155 // TODO: better picking of label color?
156 QColor c;
157
135 if (pos < 0.3) {
158 if (pos < 0.3) {
136 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
159 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
137 } else {
160 } else {
138 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0);
161 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0);
139 }
162 }
140 sets.at(i)->setFloatingValuePen(QPen(c));
163 sets.at(i)->setFloatingValuePen(QPen(c));
164
141 }
165 }
142 }
166 }
143
167
144 void ChartTheme::decorate(QStackedBarSeries* series,int index)
168 void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force)
145 {
169 {
170 QBrush brush;
146 QList<QBarSet*> sets = series->barSets();
171 QList<QBarSet*> sets = series->barSets();
172
147 for (int i=0; i<sets.count(); i++) {
173 for (int i=0; i<sets.count(); i++) {
148 qreal pos = 0.5;
174 qreal pos = 0.5;
149 if (sets.count() > 1)
175 if (sets.count() > 1)
150 pos = (qreal) i / (qreal) (sets.count() - 1);
176 pos = (qreal) i / (qreal) (sets.count() - 1);
177 if(brush == sets.at(i)->brush() || force){
151 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
178 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
152 sets.at(i)->setBrush(QBrush(c));
179 sets.at(i)->setBrush(QBrush(c));
153
180 }
181 QColor c;
154 if (pos < 0.3) {
182 if (pos < 0.3) {
155 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
183 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
156 } else {
184 } else {
@@ -160,16 +188,21 void ChartTheme::decorate(QStackedBarSeries* series,int index)
160 }
188 }
161 }
189 }
162
190
163 void ChartTheme::decorate(QPercentBarSeries* series,int index)
191 void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force)
164 {
192 {
193 QBrush brush;
165 QList<QBarSet*> sets = series->barSets();
194 QList<QBarSet*> sets = series->barSets();
195
166 for (int i=0; i<sets.count(); i++) {
196 for (int i=0; i<sets.count(); i++) {
167 qreal pos = 0.5;
197 qreal pos = 0.5;
168 if (sets.count() > 1)
198 if (sets.count() > 1)
169 pos = (qreal) i / (qreal) (sets.count() - 1);
199 pos = (qreal) i / (qreal) (sets.count() - 1);
200
201 if(brush == sets.at(i)->brush() || force){
170 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
202 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
171 sets.at(i)->setBrush(QBrush(c));
203 sets.at(i)->setBrush(QBrush(c));
172
204 }
205 QColor c;
173 if (pos < 0.3) {
206 if (pos < 0.3) {
174 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
207 c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1);
175 } else {
208 } else {
@@ -179,64 +212,99 void ChartTheme::decorate(QPercentBarSeries* series,int index)
179 }
212 }
180 }
213 }
181
214
182 void ChartTheme::decorate(QScatterSeries* series, int index)
215 void ChartTheme::decorate(QScatterSeries* series, int index,bool force)
183 {
216 {
184
217
185 QPen pen;
218 QPen pen;
186 QBrush brush;
219 QBrush brush;
187
220
188 if (pen == series->pen()) {
221 if (pen == series->pen() || force) {
189 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
222 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
190 pen.setWidthF(2);
223 pen.setWidthF(2);
191 series->setPen(pen);
224 series->setPen(pen);
192 }
225 }
193
226
194 if (brush == series->brush()) {
227 if (brush == series->brush() || force) {
195 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
228 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
196 series->setBrush(brush);
229 series->setBrush(brush);
197 }
230 }
198 }
231 }
199
232
200 void ChartTheme::decorate(QPieSeries* series, int index)
233 void ChartTheme::decorate(QPieSeries* series, int index, bool force)
201 {
234 {
202 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
235 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
236
237 QPen pen;
238 QBrush brush;
239
203 for (int i(0); i < series->slices().count(); i++) {
240 for (int i(0); i < series->slices().count(); i++) {
204 qreal pos = (qreal) i / (qreal) series->count();
241 qreal pos = (qreal) i / (qreal) series->count();
242 if( pen == series->slices().at(i)->slicePen() || force){
205 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1);
243 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1);
206 series->slices().at(i)->setSlicePen(penColor);
244 series->slices().at(i)->setSlicePen(penColor);
245 }
246 if( brush == series->slices().at(i)->sliceBrush() || force){
207 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
247 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
208 series->slices().at(i)->setSliceBrush(brushColor);
248 series->slices().at(i)->setSliceBrush(brushColor);
249 }
209 }
250 }
210 }
251 }
211
252
212 void ChartTheme::decorate(QSplineSeries* series, int index)
253 void ChartTheme::decorate(QSplineSeries* series, int index, bool force)
213 {
254 {
214 QPen pen;
255 QPen pen;
215 if(pen == series->pen()){
256 if(pen == series->pen() || force){
216 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
257 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
217 pen.setWidthF(2);
258 pen.setWidthF(2);
218 series->setPen(pen);
259 series->setPen(pen);
219 }
260 }
220 }
261 }
221
262
222 void ChartTheme::decorate(QChartAxis* axis,bool axisX)
263 void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force)
223 {
264 {
265 QPen pen;
266 QBrush brush;
267 QFont font;
268
224 if (axis->isAxisVisible()) {
269 if (axis->isAxisVisible()) {
225 axis->setLabelsBrush(m_axisLabelBrush);
270
226 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
271 if(brush == axis->labelsBrush() || force){
227 if (m_backgroundShades == BackgroundShadesBoth
272 axis->setLabelsBrush(m_axisLabelBrush);
228 || (m_backgroundShades == BackgroundShadesVertical && axisX)
273 }
229 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) {
274 if(pen == axis->labelsPen() || force){
230 axis->setShadesPen(m_backgroundShadesPen);
275 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
231 axis->setShadesBrush(m_backgroundShadesBrush);
276 }
232 } else {
277
233 // The shades not supposed to be shown for this axis, clear possible brush and pen
278
234 axis->setShadesPen(Qt::NoPen);
279 if (axis->shadesVisible() || force) {
235 axis->setShadesBrush(Qt::NoBrush);
280
281 if(brush == axis->shadesBrush() || force){
282 axis->setShadesBrush(m_backgroundShadesBrush);
283 }
284
285 if(pen == axis->shadesPen() || force){
286 axis->setShadesPen(m_backgroundShadesPen);
287 }
288
289 if(force && (m_backgroundShades == BackgroundShadesBoth
290 || (m_backgroundShades == BackgroundShadesVertical && axisX)
291 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
292 axis->setShadesVisible(true);
293
294 }
295 }
296
297 if(pen == axis->axisPen() || force){
298 axis->setAxisPen(m_axisLinePen);
299 }
300
301 if(pen == axis->gridLinePen() || force){
302 axis->setGridLinePen(m_gridLinePen);
303 }
304
305 if(font == axis->labelsFont() || force){
306 axis->setLabelsFont(m_masterFont);
236 }
307 }
237 axis->setAxisPen(m_axisLinePen);
238 axis->setGridLinePen(m_gridLinePen);
239 axis->setLabelsFont(m_masterFont);
240 }
308 }
241 }
309 }
242
310
@@ -42,18 +42,18 protected:
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,bool force = true);
46 void decorate(QLegend* legend);
46 void decorate(QLegend* legend,bool force = true);
47 //void decorate(ChartItem* item, QSeries* series,int index);
47 //void decorate(ChartItem* item, QSeries* series,int index);
48 void decorate(QBarSeries* series, int index);
48 void decorate(QBarSeries* series, int index,bool force = true);
49 void decorate(QStackedBarSeries* series, int index);
49 void decorate(QStackedBarSeries* series, int index,bool force = true);
50 void decorate(QPercentBarSeries* series, int index);
50 void decorate(QPercentBarSeries* series, int index,bool force = true);
51 void decorate(QLineSeries* series, int index);
51 void decorate(QLineSeries* series, int index,bool force = true);
52 void decorate(QAreaSeries* series, int index);
52 void decorate(QAreaSeries* series, int index,bool force = true);
53 void decorate(QScatterSeries* series, int index);
53 void decorate(QScatterSeries* series, int index,bool force = true);
54 void decorate(QPieSeries* series, int index);
54 void decorate(QPieSeries* series, int index,bool force = true);
55 void decorate(QSplineSeries* series, int index);
55 void decorate(QSplineSeries* series, int index,bool force = true);
56 void decorate(QChartAxis* axis, bool axisX);
56 void decorate(QChartAxis* axis, bool axisX,bool force = true);
57
57
58 public: // utils
58 public: // utils
59 void generateSeriesGradients();
59 void generateSeriesGradients();
@@ -104,27 +104,39 void QChart::removeAllSeries()
104 /*!
104 /*!
105 Sets the \a brush that is used for painting the background of the chart area.
105 Sets the \a brush that is used for painting the background of the chart area.
106 */
106 */
107 void QChart::setChartBackgroundBrush(const QBrush& brush)
107 void QChart::setBackgroundBrush(const QBrush& brush)
108 {
108 {
109 createChartBackgroundItem();
109 createChartBackgroundItem();
110 m_backgroundItem->setBrush(brush);
110 m_backgroundItem->setBrush(brush);
111 m_backgroundItem->update();
111 m_backgroundItem->update();
112 }
112 }
113
113
114 QBrush QChart::backgroundBrush() const
115 {
116 if(!m_backgroundItem) return QBrush();
117 return m_backgroundItem->brush();
118 }
119
114 /*!
120 /*!
115 Sets the \a pen that is used for painting the background of the chart area.
121 Sets the \a pen that is used for painting the background of the chart area.
116 */
122 */
117 void QChart::setChartBackgroundPen(const QPen& pen)
123 void QChart::setBackgroundPen(const QPen& pen)
118 {
124 {
119 createChartBackgroundItem();
125 createChartBackgroundItem();
120 m_backgroundItem->setPen(pen);
126 m_backgroundItem->setPen(pen);
121 m_backgroundItem->update();
127 m_backgroundItem->update();
122 }
128 }
123
129
130 QPen QChart::backgroundPen() const
131 {
132 if(!m_backgroundItem) return QPen();
133 return m_backgroundItem->pen();
134 }
135
124 /*!
136 /*!
125 Sets the chart \a title. The description text that is drawn above the chart.
137 Sets the chart \a title. The description text that is drawn above the chart.
126 */
138 */
127 void QChart::setChartTitle(const QString& title)
139 void QChart::setTitle(const QString& title)
128 {
140 {
129 createChartTitleItem();
141 createChartTitleItem();
130 m_titleItem->setText(title);
142 m_titleItem->setText(title);
@@ -134,7 +146,7 void QChart::setChartTitle(const QString& title)
134 /*!
146 /*!
135 Returns the chart title. The description text that is drawn above the chart.
147 Returns the chart title. The description text that is drawn above the chart.
136 */
148 */
137 QString QChart::chartTitle() const
149 QString QChart::title() const
138 {
150 {
139 if(m_titleItem)
151 if(m_titleItem)
140 return m_titleItem->text();
152 return m_titleItem->text();
@@ -145,7 +157,7 QString QChart::chartTitle() const
145 /*!
157 /*!
146 Sets the \a font that is used for rendering the description text that is rendered above the chart.
158 Sets the \a font that is used for rendering the description text that is rendered above the chart.
147 */
159 */
148 void QChart::setChartTitleFont(const QFont& font)
160 void QChart::setTitleFont(const QFont& font)
149 {
161 {
150 createChartTitleItem();
162 createChartTitleItem();
151 m_titleItem->setFont(font);
163 m_titleItem->setFont(font);
@@ -155,7 +167,7 void QChart::setChartTitleFont(const QFont& font)
155 /*!
167 /*!
156 Sets the \a brush used for rendering the title text.
168 Sets the \a brush used for rendering the title text.
157 */
169 */
158 void QChart::setChartTitleBrush(const QBrush &brush)
170 void QChart::setTitleBrush(const QBrush &brush)
159 {
171 {
160 createChartTitleItem();
172 createChartTitleItem();
161 m_titleItem->setBrush(brush);
173 m_titleItem->setBrush(brush);
@@ -165,9 +177,9 void QChart::setChartTitleBrush(const QBrush &brush)
165 /*!
177 /*!
166 Returns the brush used for rendering the title text.
178 Returns the brush used for rendering the title text.
167 */
179 */
168 QBrush QChart::chartTitleBrush()
180 QBrush QChart::titleBrush() const
169 {
181 {
170 createChartTitleItem();
182 if(!m_titleItem) return QBrush();
171 return m_titleItem->brush();
183 return m_titleItem->brush();
172 }
184 }
173
185
@@ -365,6 +377,19 void QChart::setBackgroundDiameter(int diameter)
365 m_backgroundItem->update();
377 m_backgroundItem->update();
366 }
378 }
367
379
380 void QChart::setBackgroundVisible(bool visible)
381 {
382 createChartBackgroundItem();
383 m_backgroundItem->setVisible(visible);
384 }
385
386 bool QChart::isBackgroundVisible() const
387 {
388 if(!m_backgroundItem) return false;
389 return m_backgroundItem->isVisible();
390 }
391
392
368 #include "moc_qchart.cpp"
393 #include "moc_qchart.cpp"
369
394
370 QTCOMMERCIALCHART_END_NAMESPACE
395 QTCOMMERCIALCHART_END_NAMESPACE
@@ -58,13 +58,19 public:
58 void setChartTheme(QChart::ChartTheme theme);
58 void setChartTheme(QChart::ChartTheme theme);
59 QChart::ChartTheme chartTheme() const;
59 QChart::ChartTheme chartTheme() const;
60
60
61 void setChartTitle(const QString& title);
61 void setTitle(const QString& title);
62 QString chartTitle() const;
62 QString title() const;
63 void setChartTitleFont(const QFont& font);
63 void setTitleFont(const QFont& font);
64 void setChartTitleBrush(const QBrush &brush);
64 QFont titleFont() const;
65 QBrush chartTitleBrush();
65 void setTitleBrush(const QBrush &brush);
66 void setChartBackgroundBrush(const QBrush& brush);
66 QBrush titleBrush() const;
67 void setChartBackgroundPen(const QPen& pen);
67 void setBackgroundBrush(const QBrush& brush);
68 QBrush backgroundBrush() const;
69 void setBackgroundPen(const QPen& pen);
70 QPen backgroundPen() const;
71
72 void setBackgroundVisible(bool visible);
73 bool isBackgroundVisible() const;
68
74
69 void setAnimationOptions(AnimationOptions options);
75 void setAnimationOptions(AnimationOptions options);
70 AnimationOptions animationOptions() const;
76 AnimationOptions animationOptions() const;
@@ -129,7 +129,7 void QChartView::zoomOut()
129 */
129 */
130 void QChartView::setChartTitle(const QString& title)
130 void QChartView::setChartTitle(const QString& title)
131 {
131 {
132 m_chart->setChartTitle(title);
132 m_chart->setTitle(title);
133 }
133 }
134
134
135 /*!
135 /*!
@@ -137,7 +137,7 void QChartView::setChartTitle(const QString& title)
137 */
137 */
138 QString QChartView::chartTitle() const
138 QString QChartView::chartTitle() const
139 {
139 {
140 return m_chart->chartTitle();
140 return m_chart->title();
141 }
141 }
142
142
143 /*!
143 /*!
@@ -145,7 +145,7 QString QChartView::chartTitle() const
145 */
145 */
146 void QChartView::setChartTitleFont(const QFont& font)
146 void QChartView::setChartTitleFont(const QFont& font)
147 {
147 {
148 m_chart->setChartTitleFont(font);
148 m_chart->setTitleFont(font);
149 }
149 }
150
150
151 /*!
151 /*!
@@ -153,7 +153,7 void QChartView::setChartTitleFont(const QFont& font)
153 */
153 */
154 void QChartView::setChartTitleBrush(const QBrush &brush)
154 void QChartView::setChartTitleBrush(const QBrush &brush)
155 {
155 {
156 m_chart->setChartTitleBrush(brush);
156 m_chart->setTitleBrush(brush);
157 }
157 }
158
158
159 /*!
159 /*!
@@ -161,7 +161,7 void QChartView::setChartTitleBrush(const QBrush &brush)
161 */
161 */
162 QBrush QChartView::chartTitleBrush()
162 QBrush QChartView::chartTitleBrush()
163 {
163 {
164 return m_chart->chartTitleBrush();
164 return m_chart->titleBrush();
165 }
165 }
166
166
167 /*!
167 /*!
@@ -169,7 +169,7 QBrush QChartView::chartTitleBrush()
169 */
169 */
170 void QChartView::setChartBackgroundBrush(const QBrush& brush)
170 void QChartView::setChartBackgroundBrush(const QBrush& brush)
171 {
171 {
172 m_chart->setChartBackgroundBrush(brush);
172 m_chart->setBackgroundBrush(brush);
173 }
173 }
174
174
175 /*!
175 /*!
@@ -177,7 +177,7 void QChartView::setChartBackgroundBrush(const QBrush& brush)
177 */
177 */
178 void QChartView::setChartBackgroundPen(const QPen& pen)
178 void QChartView::setChartBackgroundPen(const QPen& pen)
179 {
179 {
180 m_chart->setChartBackgroundPen(pen);
180 m_chart->setBackgroundPen(pen);
181 }
181 }
182
182
183 /*!
183 /*!
@@ -27,7 +27,7 QLegend::QLegend(QGraphicsItem *parent)
27 ,mSize(0,0)
27 ,mSize(0,0)
28 ,mMinimumSize(50,20) // TODO: magic numbers
28 ,mMinimumSize(50,20) // TODO: magic numbers
29 ,mMaximumSize(150,100)
29 ,mMaximumSize(150,100)
30 ,mBackgroundBrush(Qt::darkGray) // TODO: from theme?
30 ,m_brush(Qt::darkGray) // TODO: from theme?
31 ,mPreferredLayout(QLegend::PreferredLayoutVertical)
31 ,mPreferredLayout(QLegend::PreferredLayoutVertical)
32 {
32 {
33 // setVisible(false);
33 // setVisible(false);
@@ -40,7 +40,8 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
40 Q_UNUSED(widget)
40 Q_UNUSED(widget)
41
41
42 painter->setOpacity(0.5);
42 painter->setOpacity(0.5);
43 painter->setBrush(mBackgroundBrush);
43 painter->setPen(m_pen);
44 painter->setBrush(m_brush);
44 painter->drawRect(boundingRect());
45 painter->drawRect(boundingRect());
45 }
46 }
46
47
@@ -49,14 +50,30 QRectF QLegend::boundingRect() const
49 return QRectF(mPos,mSize);
50 return QRectF(mPos,mSize);
50 }
51 }
51
52
52 void QLegend::setBackgroundBrush(const QBrush& brush)
53 void QLegend::setBrush(const QBrush& brush)
53 {
54 {
54 mBackgroundBrush = brush;
55 if(m_brush!=brush){
56 m_brush = brush;
57 update();
58 }
59 }
60
61 QBrush QLegend::brush() const
62 {
63 return m_brush;
64 }
65
66 void QLegend::setPen(const QPen& pen)
67 {
68 if(m_pen!=pen){
69 m_pen = pen;
70 update();
71 }
55 }
72 }
56
73
57 QBrush QLegend::backgroundBrush() const
74 QPen QLegend::pen() const
58 {
75 {
59 return mBackgroundBrush;
76 return m_pen;
60 }
77 }
61
78
62 void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred)
79 void QLegend::setPreferredLayout(QLegend::PreferredLayout preferred)
@@ -30,8 +30,11 public:
30 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
30 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
31 QRectF boundingRect() const;
31 QRectF boundingRect() const;
32
32
33 void setBackgroundBrush(const QBrush& brush);
33 void setBrush(const QBrush& brush);
34 QBrush backgroundBrush() const;
34 QBrush brush() const;
35
36 void setPen(const QPen& pen);
37 QPen pen() const;
35
38
36 void setPreferredLayout(QLegend::PreferredLayout preferred);
39 void setPreferredLayout(QLegend::PreferredLayout preferred);
37
40
@@ -74,7 +77,8 private:
74 // QList<QSeries*> mSeriesList;
77 // QList<QSeries*> mSeriesList;
75 QList<LegendMarker*> mMarkers;
78 QList<LegendMarker*> mMarkers;
76
79
77 QBrush mBackgroundBrush;
80 QBrush m_brush;
81 QPen m_pen;
78 QLegend::PreferredLayout mPreferredLayout;
82 QLegend::PreferredLayout mPreferredLayout;
79 };
83 };
80
84
General Comments 0
You need to be logged in to leave comments. Login now