##// END OF EJS Templates
Adds to themes support to lineseries
Michal Klocek -
r152:a883350fc5d3
parent child
Show More
@@ -1,142 +1,149
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2 #include "qchart.h"
2 #include "qchart.h"
3
3
4
4
5 //series
5 //series
6 #include "barchartseries.h"
6 #include "barchartseries.h"
7 #include "stackedbarchartseries.h"
7 #include "stackedbarchartseries.h"
8 #include "percentbarchartseries.h"
8 #include "percentbarchartseries.h"
9 #include "qlinechartseries.h"
9 #include "qlinechartseries.h"
10 //items
10 //items
11 #include "axisitem_p.h"
11 #include "axisitem_p.h"
12 #include "bargroup.h"
12 #include "bargroup.h"
13 #include "stackedbargroup.h"
13 #include "stackedbargroup.h"
14 #include "linechartitem_p.h"
14 #include "linechartitem_p.h"
15 #include "percentbargroup.h"
15 #include "percentbargroup.h"
16
16
17 //themes
17 //themes
18 #include "chartthemevanilla_p.h"
18 #include "chartthemevanilla_p.h"
19 #include "chartthemeicy_p.h"
19 #include "chartthemeicy_p.h"
20 #include "chartthemegrayscale_p.h"
20 #include "chartthemegrayscale_p.h"
21 #include "chartthemescientific_p.h"
21 #include "chartthemescientific_p.h"
22
22
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /* TODO
26 /* TODO
27 case QChart::ChartThemeUnnamed1:
27 case QChart::ChartThemeUnnamed1:
28 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
28 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
29 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
29 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
30 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
30 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
31 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
31 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
32 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
32 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
33
33
34 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
34 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
35 m_gradientEndColor = QColor(QRgb(0xffafafaf));
35 m_gradientEndColor = QColor(QRgb(0xffafafaf));
36 */
36 */
37
37
38 ChartTheme::ChartTheme()
38 ChartTheme::ChartTheme()
39 {
39 {
40 m_seriesColor.append(QRgb(0xff000000));
40 m_seriesColor.append(QRgb(0xff000000));
41 m_seriesColor.append(QRgb(0xff707070));
41 m_seriesColor.append(QRgb(0xff707070));
42 m_gradientStartColor = QColor(QRgb(0xffffffff));
42 m_gradientStartColor = QColor(QRgb(0xffffffff));
43 m_gradientEndColor = QColor(QRgb(0xffafafaf));
43 m_gradientEndColor = QColor(QRgb(0xffafafaf));
44 }
44 }
45
45
46
46
47 ChartTheme* ChartTheme::createTheme(QChart::ChartThemeId theme)
47 ChartTheme* ChartTheme::createTheme(QChart::ChartThemeId theme)
48 {
48 {
49 switch(theme) {
49 switch(theme) {
50 case QChart::ChartThemeDefault:
50 case QChart::ChartThemeDefault:
51 return new ChartTheme();
51 return new ChartTheme();
52 case QChart::ChartThemeVanilla:
52 case QChart::ChartThemeVanilla:
53 return new ChartThemeVanilla();
53 return new ChartThemeVanilla();
54 case QChart::ChartThemeIcy:
54 case QChart::ChartThemeIcy:
55 return new ChartThemeIcy();
55 return new ChartThemeIcy();
56 case QChart::ChartThemeGrayscale:
56 case QChart::ChartThemeGrayscale:
57 return new ChartThemeGrayscale();
57 return new ChartThemeGrayscale();
58 case QChart::ChartThemeScientific:
58 case QChart::ChartThemeScientific:
59 return new ChartThemeScientific();
59 return new ChartThemeScientific();
60 }
60 }
61 }
61 }
62
62
63 void ChartTheme::decorate(QChart* chart)
63 void ChartTheme::decorate(QChart* chart)
64 {
64 {
65 QLinearGradient backgroundGradient;
65 QLinearGradient backgroundGradient;
66 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
66 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
67 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
67 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
68 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
68 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
69 chart->setChartBackgroundBrush(backgroundGradient);
69 chart->setChartBackgroundBrush(backgroundGradient);
70 }
70 }
71 //TODO helper to by removed later
71 //TODO helper to by removed later
72 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
72 void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count)
73 {
73 {
74 switch(series->type())
74 switch(series->type())
75 {
75 {
76 case QChartSeries::SeriesTypeLine: {
76 case QChartSeries::SeriesTypeLine: {
77 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
77 QLineChartSeries* s = static_cast<QLineChartSeries*>(series);
78 LineChartItem* i = static_cast<LineChartItem*>(item);
78 LineChartItem* i = static_cast<LineChartItem*>(item);
79 decorate(i,s,count);
79 decorate(i,s,count);
80 break;
80 break;
81 }
81 }
82 case QChartSeries::SeriesTypeBar: {
82 case QChartSeries::SeriesTypeBar: {
83 BarChartSeries* b = static_cast<BarChartSeries*>(series);
83 BarChartSeries* b = static_cast<BarChartSeries*>(series);
84 BarGroup* i = static_cast<BarGroup*>(item);
84 BarGroup* i = static_cast<BarGroup*>(item);
85 decorate(i,b,count);
85 decorate(i,b,count);
86 break;
86 break;
87 }
87 }
88 case QChartSeries::SeriesTypeStackedBar: {
88 case QChartSeries::SeriesTypeStackedBar: {
89 StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series);
89 StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series);
90 StackedBarGroup* i = static_cast<StackedBarGroup*>(item);
90 StackedBarGroup* i = static_cast<StackedBarGroup*>(item);
91 decorate(i,s,count);
91 decorate(i,s,count);
92 break;
92 break;
93 }
93 }
94 case QChartSeries::SeriesTypePercentBar: {
94 case QChartSeries::SeriesTypePercentBar: {
95 PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series);
95 PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series);
96 PercentBarGroup* i = static_cast<PercentBarGroup*>(item);
96 PercentBarGroup* i = static_cast<PercentBarGroup*>(item);
97 decorate(i,s,count);
97 decorate(i,s,count);
98 break;
98 break;
99 }
99 }
100 default:
100 default:
101 qDebug()<<"Wrong item to be decorated by theme";
101 qDebug()<<"Wrong item to be decorated by theme";
102 break;
102 break;
103 }
103 }
104
104
105 }
105 }
106
106
107 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count)
107 void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count)
108 {
108 {
109 item->setPen(series->pen());
109 QPen pen;
110 if(pen != series->pen()){
111 item->setPen(series->pen());
112 return;
113 }
114 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
115 pen.setWidthF(2);
116 item->setPen(pen);
110 }
117 }
111
118
112 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
119 void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count)
113 {
120 {
114 item->addColor(QColor(255,0,0,128));
121 item->addColor(QColor(255,0,0,128));
115 item->addColor(QColor(255,255,0,128));
122 item->addColor(QColor(255,255,0,128));
116 item->addColor(QColor(0,255,0,128));
123 item->addColor(QColor(0,255,0,128));
117 item->addColor(QColor(0,0,255,128));
124 item->addColor(QColor(0,0,255,128));
118 item->addColor(QColor(255,128,0,128));
125 item->addColor(QColor(255,128,0,128));
119 }
126 }
120
127
121 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
128 void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count)
122 {
129 {
123 // Add some fugly colors for 5 fist series...
130 // Add some fugly colors for 5 fist series...
124 item->addColor(QColor(255,0,0,128));
131 item->addColor(QColor(255,0,0,128));
125 item->addColor(QColor(255,255,0,128));
132 item->addColor(QColor(255,255,0,128));
126 item->addColor(QColor(0,255,0,128));
133 item->addColor(QColor(0,255,0,128));
127 item->addColor(QColor(0,0,255,128));
134 item->addColor(QColor(0,0,255,128));
128 item->addColor(QColor(255,128,0,128));
135 item->addColor(QColor(255,128,0,128));
129 }
136 }
130
137
131 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
138 void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count)
132 {
139 {
133 // Add some fugly colors for 5 fist series...
140 // Add some fugly colors for 5 fist series...
134 item->addColor(QColor(255,0,0,128));
141 item->addColor(QColor(255,0,0,128));
135 item->addColor(QColor(255,255,0,128));
142 item->addColor(QColor(255,255,0,128));
136 item->addColor(QColor(0,255,0,128));
143 item->addColor(QColor(0,255,0,128));
137 item->addColor(QColor(0,0,255,128));
144 item->addColor(QColor(0,0,255,128));
138 item->addColor(QColor(255,128,0,128));
145 item->addColor(QColor(255,128,0,128));
139 }
146 }
140
147
141
148
142 QTCOMMERCIALCHART_END_NAMESPACE
149 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now