@@ -1,122 +1,126 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charts.h" |
|
21 | #include "charts.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 |
|
24 | |||
25 | class FontChart: public Chart |
|
25 | class FontChart: public Chart | |
26 | { |
|
26 | { | |
27 | public: |
|
27 | public: | |
28 | FontChart(int fontSize): m_fontSize(fontSize) {}; |
|
28 | FontChart(int fontSize): m_fontSize(fontSize) {}; | |
29 | QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); } |
|
29 | QString name() { return QObject::tr("Font") + " " + QString::number(m_fontSize); } | |
30 | QString category() { return QObject::tr("Font"); } |
|
30 | QString category() { return QObject::tr("Font"); } | |
31 | QString subCategory() { return QString::null; } |
|
31 | QString subCategory() { return QString::null; } | |
32 |
|
32 | |||
33 | QChart *createChart(const DataTable &table) |
|
33 | QChart *createChart(const DataTable &table) | |
34 | { |
|
34 | { | |
35 | QChart *chart = new QChart(); |
|
35 | QChart *chart = new QChart(); | |
36 | chart->setTitle("Font size " + QString::number(m_fontSize)); |
|
36 | chart->setTitle("Font size " + QString::number(m_fontSize)); | |
37 | QString name("Series "); |
|
37 | QString name("Series "); | |
38 | int nameIndex = 0; |
|
38 | int nameIndex = 0; | |
39 | foreach (DataList list, table) { |
|
39 | foreach (DataList list, table) { | |
40 | QLineSeries *series = new QLineSeries(chart); |
|
40 | QLineSeries *series = new QLineSeries(chart); | |
41 | foreach (Data data, list) |
|
41 | foreach (Data data, list) | |
42 | series->append(data.first); |
|
42 | series->append(data.first); | |
43 | series->setName(name + QString::number(nameIndex)); |
|
43 | series->setName(name + QString::number(nameIndex)); | |
44 | nameIndex++; |
|
44 | nameIndex++; | |
45 | chart->addSeries(series); |
|
45 | chart->addSeries(series); | |
46 | } |
|
46 | } | |
47 | chart->createDefaultAxes(); |
|
47 | chart->createDefaultAxes(); | |
48 | QFont font; |
|
48 | QFont font; | |
49 | font.setPixelSize(m_fontSize); |
|
49 | font.setPixelSize(m_fontSize); | |
50 | chart->setTitleFont(font); |
|
50 | chart->setTitleFont(font); | |
51 | chart->axisX()->setLabelsFont(font); |
|
51 | chart->axisX()->setLabelsFont(font); | |
52 | chart->axisY()->setLabelsFont(font); |
|
52 | chart->axisY()->setLabelsFont(font); | |
|
53 | chart->axisX()->setTitle("Axis X"); | |||
|
54 | chart->axisY()->setTitle("Axis Y"); | |||
|
55 | chart->axisX()->setTitleFont(font); | |||
|
56 | chart->axisY()->setTitleFont(font); | |||
53 | return chart; |
|
57 | return chart; | |
54 | } |
|
58 | } | |
55 |
|
59 | |||
56 | private: |
|
60 | private: | |
57 | int m_fontSize; |
|
61 | int m_fontSize; | |
58 | }; |
|
62 | }; | |
59 |
|
63 | |||
60 | class FontChart6: public FontChart |
|
64 | class FontChart6: public FontChart | |
61 | { |
|
65 | { | |
62 | public: |
|
66 | public: | |
63 | FontChart6(): FontChart(6) {}; |
|
67 | FontChart6(): FontChart(6) {}; | |
64 | }; |
|
68 | }; | |
65 |
|
69 | |||
66 | class FontChart8: public FontChart |
|
70 | class FontChart8: public FontChart | |
67 | { |
|
71 | { | |
68 | public: |
|
72 | public: | |
69 | FontChart8(): FontChart(8) {}; |
|
73 | FontChart8(): FontChart(8) {}; | |
70 | }; |
|
74 | }; | |
71 |
|
75 | |||
72 | class FontChart10: public FontChart |
|
76 | class FontChart10: public FontChart | |
73 | { |
|
77 | { | |
74 | public: |
|
78 | public: | |
75 | FontChart10(): FontChart(10) {}; |
|
79 | FontChart10(): FontChart(10) {}; | |
76 | }; |
|
80 | }; | |
77 |
|
81 | |||
78 | class FontChart14: public FontChart |
|
82 | class FontChart14: public FontChart | |
79 | { |
|
83 | { | |
80 | public: |
|
84 | public: | |
81 | FontChart14(): FontChart(14) {}; |
|
85 | FontChart14(): FontChart(14) {}; | |
82 | }; |
|
86 | }; | |
83 |
|
87 | |||
84 | class FontChart18: public FontChart |
|
88 | class FontChart18: public FontChart | |
85 | { |
|
89 | { | |
86 | public: |
|
90 | public: | |
87 | FontChart18(): FontChart(18) {}; |
|
91 | FontChart18(): FontChart(18) {}; | |
88 | }; |
|
92 | }; | |
89 |
|
93 | |||
90 | class FontChart20: public FontChart |
|
94 | class FontChart20: public FontChart | |
91 | { |
|
95 | { | |
92 | public: |
|
96 | public: | |
93 | FontChart20(): FontChart(20) {}; |
|
97 | FontChart20(): FontChart(20) {}; | |
94 | }; |
|
98 | }; | |
95 |
|
99 | |||
96 | class FontChart24: public FontChart |
|
100 | class FontChart24: public FontChart | |
97 | { |
|
101 | { | |
98 | public: |
|
102 | public: | |
99 | FontChart24(): FontChart(24) {}; |
|
103 | FontChart24(): FontChart(24) {}; | |
100 | }; |
|
104 | }; | |
101 |
|
105 | |||
102 | class FontChart28: public FontChart |
|
106 | class FontChart28: public FontChart | |
103 | { |
|
107 | { | |
104 | public: |
|
108 | public: | |
105 | FontChart28(): FontChart(28) {}; |
|
109 | FontChart28(): FontChart(28) {}; | |
106 | }; |
|
110 | }; | |
107 |
|
111 | |||
108 | class FontChart32: public FontChart |
|
112 | class FontChart32: public FontChart | |
109 | { |
|
113 | { | |
110 | public: |
|
114 | public: | |
111 | FontChart32(): FontChart(32) {}; |
|
115 | FontChart32(): FontChart(32) {}; | |
112 | }; |
|
116 | }; | |
113 |
|
117 | |||
114 | DECLARE_CHART(FontChart6); |
|
118 | DECLARE_CHART(FontChart6); | |
115 | DECLARE_CHART(FontChart8); |
|
119 | DECLARE_CHART(FontChart8); | |
116 | DECLARE_CHART(FontChart10); |
|
120 | DECLARE_CHART(FontChart10); | |
117 | DECLARE_CHART(FontChart14); |
|
121 | DECLARE_CHART(FontChart14); | |
118 | DECLARE_CHART(FontChart18); |
|
122 | DECLARE_CHART(FontChart18); | |
119 | DECLARE_CHART(FontChart20); |
|
123 | DECLARE_CHART(FontChart20); | |
120 | DECLARE_CHART(FontChart24); |
|
124 | DECLARE_CHART(FontChart24); | |
121 | DECLARE_CHART(FontChart28); |
|
125 | DECLARE_CHART(FontChart28); | |
122 | DECLARE_CHART(FontChart32); |
|
126 | DECLARE_CHART(FontChart32); |
@@ -1,449 +1,474 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartlayout_p.h" |
|
25 | #include "chartlayout_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QDateTime> |
|
28 | #include <QDateTime> | |
29 | #include <QValueAxis> |
|
29 | #include <QValueAxis> | |
30 | #include <QGraphicsLayout> |
|
30 | #include <QGraphicsLayout> | |
31 | #include <QFontMetrics> |
|
31 | #include <QFontMetrics> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) |
|
35 | ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis) | |
36 | : ChartElement(presenter), |
|
36 | : ChartElement(presenter), | |
37 | m_chartAxis(axis), |
|
37 | m_chartAxis(axis), | |
38 | m_labelsAngle(0), |
|
38 | m_labelsAngle(0), | |
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
40 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
41 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
42 | m_arrow(new QGraphicsItemGroup(presenter->rootItem())), |
|
42 | m_arrow(new QGraphicsItemGroup(presenter->rootItem())), | |
43 | m_title(new QGraphicsSimpleTextItem(presenter->rootItem())), |
|
43 | m_title(new QGraphicsSimpleTextItem(presenter->rootItem())), | |
44 | m_min(0), |
|
44 | m_min(0), | |
45 | m_max(0), |
|
45 | m_max(0), | |
46 | m_animation(0), |
|
46 | m_animation(0), | |
47 | m_labelPadding(5), |
|
47 | m_labelPadding(5), | |
48 | m_intervalAxis(intervalAxis) |
|
48 | m_intervalAxis(intervalAxis) | |
49 | { |
|
49 | { | |
50 | //initial initialization |
|
50 | //initial initialization | |
51 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
51 | m_arrow->setZValue(ChartPresenter::AxisZValue); | |
52 | m_arrow->setHandlesChildEvents(false); |
|
52 | m_arrow->setHandlesChildEvents(false); | |
53 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
53 | m_labels->setZValue(ChartPresenter::AxisZValue); | |
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
54 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
55 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
55 | m_grid->setZValue(ChartPresenter::GridZValue); | |
56 | m_title->setZValue(ChartPresenter::GridZValue); |
|
56 | m_title->setZValue(ChartPresenter::GridZValue); | |
57 |
|
57 | |||
58 | QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated())); |
|
58 | QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated())); | |
59 |
|
59 | |||
60 | QGraphicsSimpleTextItem item; |
|
60 | QGraphicsSimpleTextItem item; | |
61 | m_font = item.font(); |
|
61 | m_font = item.font(); | |
62 |
|
62 | |||
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | ChartAxis::~ChartAxis() |
|
65 | ChartAxis::~ChartAxis() | |
66 | { |
|
66 | { | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartAxis::setAnimation(AxisAnimation *animation) |
|
69 | void ChartAxis::setAnimation(AxisAnimation *animation) | |
70 | { |
|
70 | { | |
71 | m_animation = animation; |
|
71 | m_animation = animation; | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
74 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
75 | { |
|
75 | { | |
76 | m_layoutVector = layout; |
|
76 | m_layoutVector = layout; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void ChartAxis::createItems(int count) |
|
79 | void ChartAxis::createItems(int count) | |
80 | { |
|
80 | { | |
81 | if (m_arrow->children().size() == 0) |
|
81 | if (m_arrow->children().size() == 0) | |
82 | m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem())); |
|
82 | m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem())); | |
83 |
|
83 | |||
84 | if (m_intervalAxis && m_grid->children().size() == 0) { |
|
84 | if (m_intervalAxis && m_grid->children().size() == 0) { | |
85 | for (int i = 0 ; i < 2 ; i ++) |
|
85 | for (int i = 0 ; i < 2 ; i ++) | |
86 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
86 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | for (int i = 0; i < count; ++i) { |
|
89 | for (int i = 0; i < count; ++i) { | |
90 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
90 | m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
91 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); |
|
91 | m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem())); | |
92 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); |
|
92 | m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem())); | |
93 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2) |
|
93 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2) | |
94 | m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); |
|
94 | m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem())); | |
95 | } |
|
95 | } | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void ChartAxis::deleteItems(int count) |
|
98 | void ChartAxis::deleteItems(int count) | |
99 | { |
|
99 | { | |
100 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
100 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
101 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
101 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
102 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
102 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
103 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
103 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | |
104 |
|
104 | |||
105 | for (int i = 0; i < count; ++i) { |
|
105 | for (int i = 0; i < count; ++i) { | |
106 | if (lines.size() % 2 && lines.size() > 1) |
|
106 | if (lines.size() % 2 && lines.size() > 1) | |
107 | delete(shades.takeLast()); |
|
107 | delete(shades.takeLast()); | |
108 | delete(lines.takeLast()); |
|
108 | delete(lines.takeLast()); | |
109 | delete(labels.takeLast()); |
|
109 | delete(labels.takeLast()); | |
110 | delete(axis.takeLast()); |
|
110 | delete(axis.takeLast()); | |
111 | } |
|
111 | } | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
114 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
115 | { |
|
115 | { | |
116 | int diff = m_layoutVector.size() - layout.size(); |
|
116 | int diff = m_layoutVector.size() - layout.size(); | |
117 |
|
117 | |||
118 | if (diff > 0) |
|
118 | if (diff > 0) | |
119 | deleteItems(diff); |
|
119 | deleteItems(diff); | |
120 | else if (diff < 0) |
|
120 | else if (diff < 0) | |
121 | createItems(-diff); |
|
121 | createItems(-diff); | |
122 |
|
122 | |||
123 | if (diff < 0) handleAxisUpdated(); |
|
123 | if (diff < 0) handleAxisUpdated(); | |
124 |
|
124 | |||
125 | if (m_animation) { |
|
125 | if (m_animation) { | |
126 | switch (presenter()->state()) { |
|
126 | switch (presenter()->state()) { | |
127 | case ChartPresenter::ZoomInState: |
|
127 | case ChartPresenter::ZoomInState: | |
128 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
128 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
129 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
129 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
130 | break; |
|
130 | break; | |
131 | case ChartPresenter::ZoomOutState: |
|
131 | case ChartPresenter::ZoomOutState: | |
132 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
132 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
133 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
133 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
134 | break; |
|
134 | break; | |
135 | case ChartPresenter::ScrollUpState: |
|
135 | case ChartPresenter::ScrollUpState: | |
136 | case ChartPresenter::ScrollLeftState: |
|
136 | case ChartPresenter::ScrollLeftState: | |
137 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
137 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
138 | break; |
|
138 | break; | |
139 | case ChartPresenter::ScrollDownState: |
|
139 | case ChartPresenter::ScrollDownState: | |
140 | case ChartPresenter::ScrollRightState: |
|
140 | case ChartPresenter::ScrollRightState: | |
141 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
141 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
142 | break; |
|
142 | break; | |
143 | case ChartPresenter::ShowState: |
|
143 | case ChartPresenter::ShowState: | |
144 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
144 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
145 | break; |
|
145 | break; | |
146 | } |
|
146 | } | |
147 | m_animation->setValues(m_layoutVector, layout); |
|
147 | m_animation->setValues(m_layoutVector, layout); | |
148 | presenter()->startAnimation(m_animation); |
|
148 | presenter()->startAnimation(m_animation); | |
149 | } else { |
|
149 | } else { | |
150 | setLayout(layout); |
|
150 | setLayout(layout); | |
151 | updateGeometry(); |
|
151 | updateGeometry(); | |
152 | } |
|
152 | } | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void ChartAxis::setArrowOpacity(qreal opacity) |
|
155 | void ChartAxis::setArrowOpacity(qreal opacity) | |
156 | { |
|
156 | { | |
157 | m_arrow->setOpacity(opacity); |
|
157 | m_arrow->setOpacity(opacity); | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | qreal ChartAxis::arrowOpacity() const |
|
160 | qreal ChartAxis::arrowOpacity() const | |
161 | { |
|
161 | { | |
162 | return m_arrow->opacity(); |
|
162 | return m_arrow->opacity(); | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | void ChartAxis::setArrowVisibility(bool visible) |
|
165 | void ChartAxis::setArrowVisibility(bool visible) | |
166 | { |
|
166 | { | |
167 | m_arrow->setOpacity(visible); |
|
167 | m_arrow->setOpacity(visible); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void ChartAxis::setGridOpacity(qreal opacity) |
|
170 | void ChartAxis::setGridOpacity(qreal opacity) | |
171 | { |
|
171 | { | |
172 | m_grid->setOpacity(opacity); |
|
172 | m_grid->setOpacity(opacity); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | qreal ChartAxis::gridOpacity() const |
|
175 | qreal ChartAxis::gridOpacity() const | |
176 | { |
|
176 | { | |
177 | return m_grid->opacity(); |
|
177 | return m_grid->opacity(); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void ChartAxis::setGridVisibility(bool visible) |
|
180 | void ChartAxis::setGridVisibility(bool visible) | |
181 | { |
|
181 | { | |
182 | m_grid->setOpacity(visible); |
|
182 | m_grid->setOpacity(visible); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
185 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
186 | { |
|
186 | { | |
187 | m_labels->setOpacity(opacity); |
|
187 | m_labels->setOpacity(opacity); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | qreal ChartAxis::labelsOpacity() const |
|
190 | qreal ChartAxis::labelsOpacity() const | |
191 | { |
|
191 | { | |
192 | return m_labels->opacity(); |
|
192 | return m_labels->opacity(); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void ChartAxis::setLabelsVisibility(bool visible) |
|
195 | void ChartAxis::setLabelsVisibility(bool visible) | |
196 | { |
|
196 | { | |
197 | m_labels->setOpacity(visible); |
|
197 | m_labels->setOpacity(visible); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
200 | void ChartAxis::setShadesOpacity(qreal opacity) | |
201 | { |
|
201 | { | |
202 | m_shades->setOpacity(opacity); |
|
202 | m_shades->setOpacity(opacity); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | qreal ChartAxis::shadesOpacity() const |
|
205 | qreal ChartAxis::shadesOpacity() const | |
206 | { |
|
206 | { | |
207 | return m_shades->opacity(); |
|
207 | return m_shades->opacity(); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void ChartAxis::setShadesVisibility(bool visible) |
|
210 | void ChartAxis::setShadesVisibility(bool visible) | |
211 | { |
|
211 | { | |
212 | m_shades->setVisible(visible); |
|
212 | m_shades->setVisible(visible); | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | void ChartAxis::setLabelsAngle(int angle) |
|
215 | void ChartAxis::setLabelsAngle(int angle) | |
216 | { |
|
216 | { | |
217 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
217 | foreach (QGraphicsItem *item, m_labels->childItems()) | |
218 | item->setRotation(angle); |
|
218 | item->setRotation(angle); | |
219 |
|
219 | |||
220 | m_labelsAngle = angle; |
|
220 | m_labelsAngle = angle; | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
223 | void ChartAxis::setLabelsPen(const QPen &pen) | |
224 | { |
|
224 | { | |
225 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
225 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
226 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
226 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
229 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
230 | { |
|
230 | { | |
231 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
231 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
232 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
232 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void ChartAxis::setLabelsFont(const QFont &font) |
|
235 | void ChartAxis::setLabelsFont(const QFont &font) | |
236 | { |
|
236 | { | |
237 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
|||
238 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); |
|
|||
239 |
|
||||
240 | if (m_font != font) { |
|
237 | if (m_font != font) { | |
241 | m_font = font; |
|
238 | m_font = font; | |
242 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
239 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
243 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); |
|
240 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
244 | QGraphicsLayoutItem::updateGeometry(); |
|
241 | QGraphicsLayoutItem::updateGeometry(); | |
245 | presenter()->layout()->invalidate(); |
|
242 | presenter()->layout()->invalidate(); | |
246 | } |
|
243 | } | |
247 | } |
|
244 | } | |
248 |
|
245 | |||
249 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
246 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
250 | { |
|
247 | { | |
251 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
248 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
252 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
249 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | |
253 | } |
|
250 | } | |
254 |
|
251 | |||
255 | void ChartAxis::setShadesPen(const QPen &pen) |
|
252 | void ChartAxis::setShadesPen(const QPen &pen) | |
256 | { |
|
253 | { | |
257 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
254 | foreach (QGraphicsItem *item , m_shades->childItems()) | |
258 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
255 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); | |
259 | } |
|
256 | } | |
260 |
|
257 | |||
261 | void ChartAxis::setArrowPen(const QPen &pen) |
|
258 | void ChartAxis::setArrowPen(const QPen &pen) | |
262 | { |
|
259 | { | |
263 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
260 | foreach (QGraphicsItem *item , m_arrow->childItems()) | |
264 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
261 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
265 | } |
|
262 | } | |
266 |
|
263 | |||
267 | void ChartAxis::setGridPen(const QPen &pen) |
|
264 | void ChartAxis::setGridPen(const QPen &pen) | |
268 | { |
|
265 | { | |
269 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
266 | foreach (QGraphicsItem *item , m_grid->childItems()) | |
270 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
267 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); | |
271 | } |
|
268 | } | |
272 |
|
269 | |||
273 | void ChartAxis::setLabelPadding(int padding) |
|
270 | void ChartAxis::setLabelPadding(int padding) | |
274 | { |
|
271 | { | |
275 | m_labelPadding = padding; |
|
272 | m_labelPadding = padding; | |
276 | } |
|
273 | } | |
277 |
|
274 | |||
278 | bool ChartAxis::isEmpty() |
|
275 | bool ChartAxis::isEmpty() | |
279 | { |
|
276 | { | |
280 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyIsNull(m_min - m_max); |
|
277 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyIsNull(m_min - m_max); | |
281 | } |
|
278 | } | |
282 |
|
279 | |||
283 | void ChartAxis::handleDomainUpdated() |
|
280 | void ChartAxis::handleDomainUpdated() | |
284 | { |
|
281 | { | |
285 | Domain *domain = qobject_cast<Domain *>(sender()); |
|
282 | Domain *domain = qobject_cast<Domain *>(sender()); | |
286 | qreal min(0); |
|
283 | qreal min(0); | |
287 | qreal max(0); |
|
284 | qreal max(0); | |
288 |
|
285 | |||
289 | if (m_chartAxis->orientation() == Qt::Horizontal) { |
|
286 | if (m_chartAxis->orientation() == Qt::Horizontal) { | |
290 | min = domain->minX(); |
|
287 | min = domain->minX(); | |
291 | max = domain->maxX(); |
|
288 | max = domain->maxX(); | |
292 | } else if (m_chartAxis->orientation() == Qt::Vertical) { |
|
289 | } else if (m_chartAxis->orientation() == Qt::Vertical) { | |
293 | min = domain->minY(); |
|
290 | min = domain->minY(); | |
294 | max = domain->maxY(); |
|
291 | max = domain->maxY(); | |
295 | } |
|
292 | } | |
296 |
|
293 | |||
297 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) { |
|
294 | if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) { | |
298 | m_min = min; |
|
295 | m_min = min; | |
299 | m_max = max; |
|
296 | m_max = max; | |
300 |
|
297 | |||
301 | if (!isEmpty()) { |
|
298 | if (!isEmpty()) { | |
302 |
|
299 | |||
303 | QVector<qreal> layout = calculateLayout(); |
|
300 | QVector<qreal> layout = calculateLayout(); | |
304 | updateLayout(layout); |
|
301 | updateLayout(layout); | |
305 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); |
|
302 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
306 | QSizeF after = sizeHint(Qt::PreferredSize); |
|
303 | QSizeF after = sizeHint(Qt::PreferredSize); | |
307 |
|
304 | |||
308 | if (before != after) { |
|
305 | if (before != after) { | |
309 | QGraphicsLayoutItem::updateGeometry(); |
|
306 | QGraphicsLayoutItem::updateGeometry(); | |
310 | //we don't want to call invalidate on layout, since it will change minimum size of component, |
|
307 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
311 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, |
|
308 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
312 | //instead recalculate layout and use plotArea for extra space. |
|
309 | //instead recalculate layout and use plotArea for extra space. | |
313 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); |
|
310 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
314 | } |
|
311 | } | |
315 | } |
|
312 | } | |
316 | } |
|
313 | } | |
317 | } |
|
314 | } | |
318 |
|
315 | |||
319 | void ChartAxis::handleAxisUpdated() |
|
316 | void ChartAxis::handleAxisUpdated() | |
320 | { |
|
317 | { | |
321 | if (isEmpty()) |
|
318 | if (isEmpty()) | |
322 | return; |
|
319 | return; | |
323 |
|
320 | |||
324 | bool visible = m_chartAxis->isVisible(); |
|
321 | bool visible = m_chartAxis->isVisible(); | |
325 |
|
322 | |||
|
323 | //TODO: split this into separate signal/slots ? | |||
326 | setArrowVisibility(visible && m_chartAxis->isLineVisible()); |
|
324 | setArrowVisibility(visible && m_chartAxis->isLineVisible()); | |
327 | setGridVisibility(visible && m_chartAxis->isGridLineVisible()); |
|
325 | setGridVisibility(visible && m_chartAxis->isGridLineVisible()); | |
328 | setLabelsVisibility(visible && m_chartAxis->labelsVisible()); |
|
326 | setLabelsVisibility(visible && m_chartAxis->labelsVisible()); | |
329 | setShadesVisibility(visible && m_chartAxis->shadesVisible()); |
|
327 | setShadesVisibility(visible && m_chartAxis->shadesVisible()); | |
330 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
328 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
331 | setArrowPen(m_chartAxis->linePen()); |
|
329 | setArrowPen(m_chartAxis->linePen()); | |
332 | setLabelsPen(m_chartAxis->labelsPen()); |
|
330 | setLabelsPen(m_chartAxis->labelsPen()); | |
333 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
331 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
334 | setLabelsFont(m_chartAxis->labelsFont()); |
|
332 | setLabelsFont(m_chartAxis->labelsFont()); | |
335 | setGridPen(m_chartAxis->gridLinePen()); |
|
333 | setGridPen(m_chartAxis->gridLinePen()); | |
336 | setShadesPen(m_chartAxis->shadesPen()); |
|
334 | setShadesPen(m_chartAxis->shadesPen()); | |
337 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
335 | setShadesBrush(m_chartAxis->shadesBrush()); | |
338 | setTitleText(m_chartAxis->title()); |
|
336 | setTitleText(m_chartAxis->title()); | |
|
337 | setTitleFont(m_chartAxis->titleFont()); | |||
|
338 | setTitlePen(m_chartAxis->titlePen()); | |||
|
339 | setTitleBrush(m_chartAxis->titleBrush()); | |||
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | void ChartAxis::setTitleText(const QString &title) |
|
342 | void ChartAxis::setTitleText(const QString &title) | |
342 | { |
|
343 | { | |
343 | if (m_titleText != title) { |
|
344 | if (m_titleText != title) { | |
344 | m_titleText = title; |
|
345 | m_titleText = title; | |
345 | QGraphicsLayoutItem::updateGeometry(); |
|
346 | QGraphicsLayoutItem::updateGeometry(); | |
346 | presenter()->layout()->invalidate(); |
|
347 | presenter()->layout()->invalidate(); | |
347 | } |
|
348 | } | |
348 | } |
|
349 | } | |
349 |
|
350 | |||
|
351 | void ChartAxis::setTitlePen(const QPen &pen) | |||
|
352 | { | |||
|
353 | m_title->setPen(pen); | |||
|
354 | } | |||
|
355 | ||||
|
356 | void ChartAxis::setTitleBrush(const QBrush &brush) | |||
|
357 | { | |||
|
358 | m_title->setBrush(brush); | |||
|
359 | } | |||
|
360 | ||||
|
361 | void ChartAxis::setTitleFont(const QFont &font) | |||
|
362 | { | |||
|
363 | if(m_title->font() != font){ | |||
|
364 | m_title->setFont(font); | |||
|
365 | QGraphicsLayoutItem::updateGeometry(); | |||
|
366 | presenter()->layout()->invalidate(); | |||
|
367 | } | |||
|
368 | } | |||
|
369 | ||||
|
370 | QFont ChartAxis::titleFont() const | |||
|
371 | { | |||
|
372 | return m_title->font(); | |||
|
373 | } | |||
|
374 | ||||
350 | void ChartAxis::hide() |
|
375 | void ChartAxis::hide() | |
351 | { |
|
376 | { | |
352 | setArrowVisibility(false); |
|
377 | setArrowVisibility(false); | |
353 | setGridVisibility(false); |
|
378 | setGridVisibility(false); | |
354 | setLabelsVisibility(false); |
|
379 | setLabelsVisibility(false); | |
355 | setShadesVisibility(false); |
|
380 | setShadesVisibility(false); | |
356 | } |
|
381 | } | |
357 |
|
382 | |||
358 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
383 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | |
359 | { |
|
384 | { | |
360 | m_gridRect = grid; |
|
385 | m_gridRect = grid; | |
361 | m_axisRect = axis; |
|
386 | m_axisRect = axis; | |
362 |
|
387 | |||
363 | if (isEmpty()) |
|
388 | if (isEmpty()) | |
364 | return; |
|
389 | return; | |
365 |
|
390 | |||
366 | QVector<qreal> layout = calculateLayout(); |
|
391 | QVector<qreal> layout = calculateLayout(); | |
367 | updateLayout(layout); |
|
392 | updateLayout(layout); | |
368 |
|
393 | |||
369 | } |
|
394 | } | |
370 |
|
395 | |||
371 | void ChartAxis::axisSelected() |
|
396 | void ChartAxis::axisSelected() | |
372 | { |
|
397 | { | |
373 | //TODO: axis clicked; |
|
398 | //TODO: axis clicked; | |
374 | } |
|
399 | } | |
375 |
|
400 | |||
376 | Qt::Orientation ChartAxis::orientation() const |
|
401 | Qt::Orientation ChartAxis::orientation() const | |
377 | { |
|
402 | { | |
378 | return m_chartAxis->orientation(); |
|
403 | return m_chartAxis->orientation(); | |
379 | } |
|
404 | } | |
380 |
|
405 | |||
381 | Qt::Alignment ChartAxis::alignment() const |
|
406 | Qt::Alignment ChartAxis::alignment() const | |
382 | { |
|
407 | { | |
383 | return m_chartAxis->alignment(); |
|
408 | return m_chartAxis->alignment(); | |
384 | } |
|
409 | } | |
385 |
|
410 | |||
386 | bool ChartAxis::isVisible() |
|
411 | bool ChartAxis::isVisible() | |
387 | { |
|
412 | { | |
388 | return m_chartAxis->isVisible(); |
|
413 | return m_chartAxis->isVisible(); | |
389 | } |
|
414 | } | |
390 |
|
415 | |||
391 | void ChartAxis::setLabels(const QStringList &labels) |
|
416 | void ChartAxis::setLabels(const QStringList &labels) | |
392 | { |
|
417 | { | |
393 | m_labelsList = labels; |
|
418 | m_labelsList = labels; | |
394 | } |
|
419 | } | |
395 |
|
420 | |||
396 | QStringList ChartAxis::createValueLabels(int ticks) const |
|
421 | QStringList ChartAxis::createValueLabels(int ticks) const | |
397 | { |
|
422 | { | |
398 | Q_ASSERT(m_max > m_min); |
|
423 | Q_ASSERT(m_max > m_min); | |
399 | Q_ASSERT(ticks > 1); |
|
424 | Q_ASSERT(ticks > 1); | |
400 |
|
425 | |||
401 | QStringList labels; |
|
426 | QStringList labels; | |
402 |
|
427 | |||
403 | int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0); |
|
428 | int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0); | |
404 | n++; |
|
429 | n++; | |
405 |
|
430 | |||
406 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); |
|
431 | QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis); | |
407 |
|
432 | |||
408 | QString format = axis->labelFormat(); |
|
433 | QString format = axis->labelFormat(); | |
409 |
|
434 | |||
410 | if (format.isNull()) { |
|
435 | if (format.isNull()) { | |
411 | for (int i = 0; i < ticks; i++) { |
|
436 | for (int i = 0; i < ticks; i++) { | |
412 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); |
|
437 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
413 | labels << QString::number(value, 'f', n); |
|
438 | labels << QString::number(value, 'f', n); | |
414 | } |
|
439 | } | |
415 | } else { |
|
440 | } else { | |
416 | QByteArray array = format.toAscii(); |
|
441 | QByteArray array = format.toAscii(); | |
417 | for (int i = 0; i < ticks; i++) { |
|
442 | for (int i = 0; i < ticks; i++) { | |
418 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); |
|
443 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
419 | labels << QString().sprintf(array, value); |
|
444 | labels << QString().sprintf(array, value); | |
420 | } |
|
445 | } | |
421 | } |
|
446 | } | |
422 |
|
447 | |||
423 | return labels; |
|
448 | return labels; | |
424 | } |
|
449 | } | |
425 |
|
450 | |||
426 | QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const |
|
451 | QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const | |
427 | { |
|
452 | { | |
428 | Q_ASSERT(m_max > m_min); |
|
453 | Q_ASSERT(m_max > m_min); | |
429 | Q_ASSERT(ticks > 1); |
|
454 | Q_ASSERT(ticks > 1); | |
430 | QStringList labels; |
|
455 | QStringList labels; | |
431 | int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0); |
|
456 | int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0); | |
432 | n++; |
|
457 | n++; | |
433 | for (int i = 0; i < ticks; i++) { |
|
458 | for (int i = 0; i < ticks; i++) { | |
434 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); |
|
459 | qreal value = m_min + (i * (m_max - m_min) / (ticks - 1)); | |
435 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
460 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | |
436 | } |
|
461 | } | |
437 | return labels; |
|
462 | return labels; | |
438 | } |
|
463 | } | |
439 |
|
464 | |||
440 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
465 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | |
441 | { |
|
466 | { | |
442 | Q_UNUSED(which); |
|
467 | Q_UNUSED(which); | |
443 | Q_UNUSED(constraint); |
|
468 | Q_UNUSED(constraint); | |
444 | return QSizeF(); |
|
469 | return QSizeF(); | |
445 | } |
|
470 | } | |
446 |
|
471 | |||
447 | #include "moc_chartaxis_p.cpp" |
|
472 | #include "moc_chartaxis_p.cpp" | |
448 |
|
473 | |||
449 | QTCOMMERCIALCHART_END_NAMESPACE |
|
474 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,201 +1,200 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTAXIS_H |
|
30 | #ifndef CHARTAXIS_H | |
31 | #define CHARTAXIS_H |
|
31 | #define CHARTAXIS_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartelement_p.h" |
|
34 | #include "chartelement_p.h" | |
35 | #include "axisanimation_p.h" |
|
35 | #include "axisanimation_p.h" | |
36 | #include <QGraphicsItem> |
|
36 | #include <QGraphicsItem> | |
37 | #include <QGraphicsLayoutItem> |
|
37 | #include <QGraphicsLayoutItem> | |
38 | #include <QFont> |
|
38 | #include <QFont> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class QAbstractAxis; |
|
42 | class QAbstractAxis; | |
43 | class ChartPresenter; |
|
43 | class ChartPresenter; | |
44 |
|
44 | |||
45 | class ChartAxis : public ChartElement, public QGraphicsLayoutItem |
|
45 | class ChartAxis : public ChartElement, public QGraphicsLayoutItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | Q_INTERFACES(QGraphicsLayoutItem) |
|
48 | Q_INTERFACES(QGraphicsLayoutItem) | |
49 | public: |
|
49 | public: | |
50 |
|
50 | |||
51 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); |
|
51 | ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis = false); | |
52 | ~ChartAxis(); |
|
52 | ~ChartAxis(); | |
53 |
|
53 | |||
54 | QAbstractAxis* axis() const { return m_chartAxis; } |
|
54 | QAbstractAxis* axis() const { return m_chartAxis; } | |
55 |
|
55 | |||
56 | void setArrowOpacity(qreal opacity); |
|
56 | void setArrowOpacity(qreal opacity); | |
57 | qreal arrowOpacity() const; |
|
57 | qreal arrowOpacity() const; | |
58 | void setArrowVisibility(bool visible); |
|
58 | void setArrowVisibility(bool visible); | |
59 |
|
59 | |||
60 | void setGridOpacity(qreal opacity); |
|
60 | void setGridOpacity(qreal opacity); | |
61 | qreal gridOpacity() const; |
|
61 | qreal gridOpacity() const; | |
62 | void setGridVisibility(bool visible); |
|
62 | void setGridVisibility(bool visible); | |
63 |
|
63 | |||
64 | void setLabelsOpacity(qreal opacity); |
|
64 | void setLabelsOpacity(qreal opacity); | |
65 | qreal labelsOpacity() const; |
|
65 | qreal labelsOpacity() const; | |
66 | void setLabelsVisibility(bool visible); |
|
66 | void setLabelsVisibility(bool visible); | |
67 |
|
67 | |||
68 | void setShadesOpacity(qreal opacity); |
|
68 | void setShadesOpacity(qreal opacity); | |
69 | qreal shadesOpacity() const; |
|
69 | qreal shadesOpacity() const; | |
70 | void setShadesVisibility(bool visible); |
|
70 | void setShadesVisibility(bool visible); | |
71 |
|
71 | |||
72 | void setLabelsAngle(int angle); |
|
72 | void setLabelsAngle(int angle); | |
73 | int labelsAngle()const { return m_labelsAngle; } |
|
73 | int labelsAngle()const { return m_labelsAngle; } | |
74 |
|
74 | |||
75 | void setShadesBrush(const QBrush &brush); |
|
75 | void setShadesBrush(const QBrush &brush); | |
76 | void setShadesPen(const QPen &pen); |
|
76 | void setShadesPen(const QPen &pen); | |
77 |
|
77 | |||
78 | void setArrowPen(const QPen &pen); |
|
78 | void setArrowPen(const QPen &pen); | |
79 | void setGridPen(const QPen &pen); |
|
79 | void setGridPen(const QPen &pen); | |
80 |
|
80 | |||
81 | void setLabelsPen(const QPen &pen); |
|
81 | void setLabelsPen(const QPen &pen); | |
82 | void setLabelsBrush(const QBrush &brush); |
|
82 | void setLabelsBrush(const QBrush &brush); | |
83 | void setLabelsFont(const QFont &font); |
|
83 | void setLabelsFont(const QFont &font); | |
84 | void setLabelPadding(int padding); |
|
84 | void setLabelPadding(int padding); | |
85 | int labelPadding() const { return m_labelPadding;}; |
|
85 | int labelPadding() const { return m_labelPadding;}; | |
86 |
|
86 | |||
87 | void setTitlePen(const QPen &pen); |
|
87 | void setTitlePen(const QPen &pen); | |
88 | void setTitleBrush(const QBrush &brush); |
|
88 | void setTitleBrush(const QBrush &brush); | |
89 | void setTitleFont(const QFont &font); |
|
89 | void setTitleFont(const QFont &font); | |
90 |
QFont titleFont() const |
|
90 | QFont titleFont() const; | |
91 | void setTitleText(const QString &title); |
|
91 | void setTitleText(const QString &title); | |
92 | QString titleText() const {return m_titleText; }; |
|
92 | QString titleText() const {return m_titleText; }; | |
93 |
|
93 | |||
94 | void setLayout(QVector<qreal> &layout); |
|
94 | void setLayout(QVector<qreal> &layout); | |
95 | QVector<qreal> layout() const { return m_layoutVector; } |
|
95 | QVector<qreal> layout() const { return m_layoutVector; } | |
96 |
|
96 | |||
97 | void setAnimation(AxisAnimation *animation); |
|
97 | void setAnimation(AxisAnimation *animation); | |
98 | ChartAnimation *animation() const { return m_animation; }; |
|
98 | ChartAnimation *animation() const { return m_animation; }; | |
99 |
|
99 | |||
100 | Qt::Orientation orientation() const; |
|
100 | Qt::Orientation orientation() const; | |
101 | Qt::Alignment alignment() const; |
|
101 | Qt::Alignment alignment() const; | |
102 |
|
102 | |||
103 | bool isVisible(); |
|
103 | bool isVisible(); | |
104 | void hide(); |
|
104 | void hide(); | |
105 |
|
105 | |||
106 | void setGeometry(const QRectF &axis, const QRectF &grid); |
|
106 | void setGeometry(const QRectF &axis, const QRectF &grid); | |
107 | QRectF axisGeometry() const { return m_axisRect; } |
|
107 | QRectF axisGeometry() const { return m_axisRect; } | |
108 | QRectF gridGeometry() const { return m_gridRect; } |
|
108 | QRectF gridGeometry() const { return m_gridRect; } | |
109 |
|
109 | |||
110 | void setLabels(const QStringList &labels); |
|
110 | void setLabels(const QStringList &labels); | |
111 | QStringList labels() const { return m_labelsList; } |
|
111 | QStringList labels() const { return m_labelsList; } | |
112 |
|
112 | |||
113 | //this flag indicates that axis is used to show intervals it means labels are in between ticks |
|
113 | //this flag indicates that axis is used to show intervals it means labels are in between ticks | |
114 | bool intervalAxis() const { return m_intervalAxis; } |
|
114 | bool intervalAxis() const { return m_intervalAxis; } | |
115 |
|
115 | |||
116 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
116 | virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; | |
117 |
|
117 | |||
118 | protected: |
|
118 | protected: | |
119 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; |
|
119 | void setGeometry(const QRectF &size) { Q_UNUSED(size);}; | |
120 | virtual void updateGeometry() = 0; |
|
120 | virtual void updateGeometry() = 0; | |
121 | virtual QVector<qreal> calculateLayout() const = 0; |
|
121 | virtual QVector<qreal> calculateLayout() const = 0; | |
122 |
|
122 | |||
123 | QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); }; |
|
123 | QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); }; | |
124 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems();}; |
|
124 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems();}; | |
125 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();}; |
|
125 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();}; | |
126 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; |
|
126 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();}; | |
127 | QGraphicsSimpleTextItem* titleItem() const { return m_title.data();} |
|
127 | QGraphicsSimpleTextItem* titleItem() const { return m_title.data();} | |
128 |
|
128 | |||
129 | QFont font() const { return m_font; } |
|
129 | QFont font() const { return m_font; } | |
130 | qreal min() const {return m_min; } |
|
130 | qreal min() const {return m_min; } | |
131 | qreal max() const {return m_max; } |
|
131 | qreal max() const {return m_max; } | |
132 | QStringList createValueLabels(int ticks) const; |
|
132 | QStringList createValueLabels(int ticks) const; | |
133 | QStringList createDateTimeLabels(const QString &format, int ticks) const; |
|
133 | QStringList createDateTimeLabels(const QString &format, int ticks) const; | |
134 |
|
134 | |||
135 | public Q_SLOTS: |
|
135 | public Q_SLOTS: | |
136 | virtual void handleAxisUpdated(); |
|
136 | virtual void handleAxisUpdated(); | |
137 | virtual void handleDomainUpdated(); |
|
137 | virtual void handleDomainUpdated(); | |
138 |
|
138 | |||
139 | private: |
|
139 | private: | |
140 | inline bool isEmpty(); |
|
140 | inline bool isEmpty(); | |
141 | void createItems(int count); |
|
141 | void createItems(int count); | |
142 | void deleteItems(int count); |
|
142 | void deleteItems(int count); | |
143 | void updateLayout(QVector<qreal> &layout); |
|
143 | void updateLayout(QVector<qreal> &layout); | |
144 | void axisSelected(); |
|
144 | void axisSelected(); | |
145 |
|
145 | |||
146 | private: |
|
146 | private: | |
147 | QAbstractAxis *m_chartAxis; |
|
147 | QAbstractAxis *m_chartAxis; | |
148 | int m_labelsAngle; |
|
148 | int m_labelsAngle; | |
149 | QRectF m_axisRect; |
|
149 | QRectF m_axisRect; | |
150 | QRectF m_gridRect; |
|
150 | QRectF m_gridRect; | |
151 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
151 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
152 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
152 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
153 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
153 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
154 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
154 | QScopedPointer<QGraphicsItemGroup> m_arrow; | |
155 | QScopedPointer<QGraphicsSimpleTextItem> m_title; |
|
155 | QScopedPointer<QGraphicsSimpleTextItem> m_title; | |
156 | QVector<qreal> m_layoutVector; |
|
156 | QVector<qreal> m_layoutVector; | |
157 | qreal m_min; |
|
157 | qreal m_min; | |
158 | qreal m_max; |
|
158 | qreal m_max; | |
159 | AxisAnimation *m_animation; |
|
159 | AxisAnimation *m_animation; | |
160 | QFont m_font; |
|
160 | QFont m_font; | |
161 | QFont m_titleFont; |
|
|||
162 | QString m_titleText; |
|
161 | QString m_titleText; | |
163 | int m_labelPadding; |
|
162 | int m_labelPadding; | |
164 | QStringList m_labelsList; |
|
163 | QStringList m_labelsList; | |
165 | bool m_intervalAxis; |
|
164 | bool m_intervalAxis; | |
166 |
|
165 | |||
167 | friend class AxisAnimation; |
|
166 | friend class AxisAnimation; | |
168 | friend class AxisItem; |
|
167 | friend class AxisItem; | |
169 |
|
168 | |||
170 | }; |
|
169 | }; | |
171 |
|
170 | |||
172 | class AxisItem: public QGraphicsLineItem |
|
171 | class AxisItem: public QGraphicsLineItem | |
173 | { |
|
172 | { | |
174 |
|
173 | |||
175 | public: |
|
174 | public: | |
176 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
175 | explicit AxisItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | |
177 |
|
176 | |||
178 | protected: |
|
177 | protected: | |
179 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { |
|
178 | void mousePressEvent(QGraphicsSceneMouseEvent *event) { | |
180 | Q_UNUSED(event) |
|
179 | Q_UNUSED(event) | |
181 | m_axis->axisSelected(); |
|
180 | m_axis->axisSelected(); | |
182 | } |
|
181 | } | |
183 |
|
182 | |||
184 | QRectF boundingRect() const { |
|
183 | QRectF boundingRect() const { | |
185 | return shape().boundingRect(); |
|
184 | return shape().boundingRect(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | QPainterPath shape() const { |
|
187 | QPainterPath shape() const { | |
189 | QPainterPath path = QGraphicsLineItem::shape(); |
|
188 | QPainterPath path = QGraphicsLineItem::shape(); | |
190 | QRectF rect = path.boundingRect(); |
|
189 | QRectF rect = path.boundingRect(); | |
191 | path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0)); |
|
190 | path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0)); | |
192 | return path; |
|
191 | return path; | |
193 | } |
|
192 | } | |
194 |
|
193 | |||
195 | private: |
|
194 | private: | |
196 | ChartAxis *m_axis; |
|
195 | ChartAxis *m_axis; | |
197 | }; |
|
196 | }; | |
198 |
|
197 | |||
199 | QTCOMMERCIALCHART_END_NAMESPACE |
|
198 | QTCOMMERCIALCHART_END_NAMESPACE | |
200 |
|
199 | |||
201 | #endif /* CHARTAXI_H */ |
|
200 | #endif /* CHARTAXI_H */ |
@@ -1,385 +1,399 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qabstractbarseries.h" |
|
31 | #include "qabstractbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qpieslice_p.h" |
|
39 | #include "qpieslice_p.h" | |
40 | #include "qsplineseries.h" |
|
40 | #include "qsplineseries.h" | |
41 |
|
41 | |||
42 | //items |
|
42 | //items | |
43 | #include "chartaxis_p.h" |
|
43 | #include "chartaxis_p.h" | |
44 | #include "abstractbarchartitem_p.h" |
|
44 | #include "abstractbarchartitem_p.h" | |
45 | #include "stackedbarchartitem_p.h" |
|
45 | #include "stackedbarchartitem_p.h" | |
46 | #include "percentbarchartitem_p.h" |
|
46 | #include "percentbarchartitem_p.h" | |
47 | #include "linechartitem_p.h" |
|
47 | #include "linechartitem_p.h" | |
48 | #include "areachartitem_p.h" |
|
48 | #include "areachartitem_p.h" | |
49 | #include "scatterchartitem_p.h" |
|
49 | #include "scatterchartitem_p.h" | |
50 | #include "piechartitem_p.h" |
|
50 | #include "piechartitem_p.h" | |
51 | #include "splinechartitem_p.h" |
|
51 | #include "splinechartitem_p.h" | |
52 |
|
52 | |||
53 | //themes |
|
53 | //themes | |
54 | #include "chartthemesystem_p.h" |
|
54 | #include "chartthemesystem_p.h" | |
55 | #include "chartthemelight_p.h" |
|
55 | #include "chartthemelight_p.h" | |
56 | #include "chartthemebluecerulean_p.h" |
|
56 | #include "chartthemebluecerulean_p.h" | |
57 | #include "chartthemedark_p.h" |
|
57 | #include "chartthemedark_p.h" | |
58 | #include "chartthemebrownsand_p.h" |
|
58 | #include "chartthemebrownsand_p.h" | |
59 | #include "chartthemebluencs_p.h" |
|
59 | #include "chartthemebluencs_p.h" | |
60 | #include "chartthemehighcontrast_p.h" |
|
60 | #include "chartthemehighcontrast_p.h" | |
61 | #include "chartthemeblueicy_p.h" |
|
61 | #include "chartthemeblueicy_p.h" | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
64 |
|
64 | |||
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
66 | m_id(id), |
|
66 | m_id(id), | |
67 | m_masterFont(QFont("arial", 14)), |
|
67 | m_masterFont(QFont("arial", 14)), | |
68 | m_labelFont(QFont("arial", 10)), |
|
68 | m_labelFont(QFont("arial", 10)), | |
69 | m_labelBrush(QColor(QRgb(0x000000))), |
|
69 | m_labelBrush(QColor(QRgb(0x000000))), | |
70 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
70 | m_axisLinePen(QPen(QRgb(0x000000))), | |
71 | m_backgroundShadesPen(Qt::NoPen), |
|
71 | m_backgroundShadesPen(Qt::NoPen), | |
72 | m_backgroundShadesBrush(Qt::NoBrush), |
|
72 | m_backgroundShadesBrush(Qt::NoBrush), | |
73 | m_backgroundShades(BackgroundShadesNone), |
|
73 | m_backgroundShades(BackgroundShadesNone), | |
74 | m_backgroundDropShadowEnabled(false), |
|
74 | m_backgroundDropShadowEnabled(false), | |
75 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
75 | m_gridLinePen(QPen(QRgb(0x000000))), | |
76 | m_force(false) |
|
76 | m_force(false) | |
77 | { |
|
77 | { | |
78 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ChartTheme *ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme *ChartTheme::createTheme(QChart::ChartTheme theme) | |
83 | { |
|
83 | { | |
84 | switch (theme) { |
|
84 | switch (theme) { | |
85 | case QChart::ChartThemeLight: |
|
85 | case QChart::ChartThemeLight: | |
86 | return new ChartThemeLight(); |
|
86 | return new ChartThemeLight(); | |
87 | case QChart::ChartThemeBlueCerulean: |
|
87 | case QChart::ChartThemeBlueCerulean: | |
88 | return new ChartThemeBlueCerulean(); |
|
88 | return new ChartThemeBlueCerulean(); | |
89 | case QChart::ChartThemeDark: |
|
89 | case QChart::ChartThemeDark: | |
90 | return new ChartThemeDark(); |
|
90 | return new ChartThemeDark(); | |
91 | case QChart::ChartThemeBrownSand: |
|
91 | case QChart::ChartThemeBrownSand: | |
92 | return new ChartThemeBrownSand(); |
|
92 | return new ChartThemeBrownSand(); | |
93 | case QChart::ChartThemeBlueNcs: |
|
93 | case QChart::ChartThemeBlueNcs: | |
94 | return new ChartThemeBlueNcs(); |
|
94 | return new ChartThemeBlueNcs(); | |
95 | case QChart::ChartThemeHighContrast: |
|
95 | case QChart::ChartThemeHighContrast: | |
96 | return new ChartThemeHighContrast(); |
|
96 | return new ChartThemeHighContrast(); | |
97 | case QChart::ChartThemeBlueIcy: |
|
97 | case QChart::ChartThemeBlueIcy: | |
98 | return new ChartThemeBlueIcy(); |
|
98 | return new ChartThemeBlueIcy(); | |
99 | default: |
|
99 | default: | |
100 | return new ChartThemeSystem(); |
|
100 | return new ChartThemeSystem(); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
105 | { |
|
105 | { | |
106 | QBrush brush; |
|
106 | QBrush brush; | |
107 |
|
107 | |||
108 | if (m_force || brush == chart->backgroundBrush()) |
|
108 | if (m_force || brush == chart->backgroundBrush()) | |
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
110 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
111 | chart->setTitleBrush(m_labelBrush); |
|
111 | chart->setTitleBrush(m_labelBrush); | |
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
116 | { |
|
116 | { | |
117 | QPen pen; |
|
117 | QPen pen; | |
118 | QBrush brush; |
|
118 | QBrush brush; | |
119 | QFont font; |
|
119 | QFont font; | |
120 |
|
120 | |||
121 | if (m_force || pen == legend->pen()) |
|
121 | if (m_force || pen == legend->pen()) | |
122 | legend->setPen(m_axisLinePen); |
|
122 | legend->setPen(m_axisLinePen); | |
123 |
|
123 | |||
124 | if (m_force || brush == legend->brush()) |
|
124 | if (m_force || brush == legend->brush()) | |
125 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
126 |
|
126 | |||
127 | if (m_force || font == legend->font()) |
|
127 | if (m_force || font == legend->font()) | |
128 | legend->setFont(m_labelFont); |
|
128 | legend->setFont(m_labelFont); | |
129 |
|
129 | |||
130 | if (m_force || brush == legend->labelBrush()) |
|
130 | if (m_force || brush == legend->labelBrush()) | |
131 | legend->setLabelBrush(m_labelBrush); |
|
131 | legend->setLabelBrush(m_labelBrush); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
134 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
135 | { |
|
135 | { | |
136 | QPen pen; |
|
136 | QPen pen; | |
137 | QBrush brush; |
|
137 | QBrush brush; | |
138 |
|
138 | |||
139 | if (m_force || pen == series->pen()) { |
|
139 | if (m_force || pen == series->pen()) { | |
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
141 | pen.setWidthF(2); |
|
141 | pen.setWidthF(2); | |
142 | series->setPen(pen); |
|
142 | series->setPen(pen); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | if (m_force || brush == series->brush()) { |
|
145 | if (m_force || brush == series->brush()) { | |
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
147 | series->setBrush(brush); |
|
147 | series->setBrush(brush); | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 |
|
151 | |||
152 | void ChartTheme::decorate(QLineSeries *series, int index) |
|
152 | void ChartTheme::decorate(QLineSeries *series, int index) | |
153 | { |
|
153 | { | |
154 | QPen pen; |
|
154 | QPen pen; | |
155 | if (m_force || pen == series->pen()) { |
|
155 | if (m_force || pen == series->pen()) { | |
156 | pen.setColor(m_seriesColors.at(index % m_seriesColors.size())); |
|
156 | pen.setColor(m_seriesColors.at(index % m_seriesColors.size())); | |
157 | pen.setWidthF(2); |
|
157 | pen.setWidthF(2); | |
158 | series->setPen(pen); |
|
158 | series->setPen(pen); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) |
|
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) | |
163 | { |
|
163 | { | |
164 | QBrush brush; |
|
164 | QBrush brush; | |
165 | QPen pen; |
|
165 | QPen pen; | |
166 | QList<QBarSet *> sets = series->barSets(); |
|
166 | QList<QBarSet *> sets = series->barSets(); | |
167 |
|
167 | |||
168 | qreal takeAtPos = 0.5; |
|
168 | qreal takeAtPos = 0.5; | |
169 | qreal step = 0.2; |
|
169 | qreal step = 0.2; | |
170 | if (sets.count() > 1) { |
|
170 | if (sets.count() > 1) { | |
171 | step = 1.0 / (qreal) sets.count(); |
|
171 | step = 1.0 / (qreal) sets.count(); | |
172 | if (sets.count() % m_seriesGradients.count()) |
|
172 | if (sets.count() % m_seriesGradients.count()) | |
173 | step *= m_seriesGradients.count(); |
|
173 | step *= m_seriesGradients.count(); | |
174 | else |
|
174 | else | |
175 | step *= (m_seriesGradients.count() - 1); |
|
175 | step *= (m_seriesGradients.count() - 1); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | for (int i(0); i < sets.count(); i++) { |
|
178 | for (int i(0); i < sets.count(); i++) { | |
179 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
179 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
181 | // There is no dedicated base color for each sets, generate more colors |
|
181 | // There is no dedicated base color for each sets, generate more colors | |
182 | takeAtPos += step; |
|
182 | takeAtPos += step; | |
183 | if (takeAtPos == 1.0) |
|
183 | if (takeAtPos == 1.0) | |
184 | takeAtPos += step; |
|
184 | takeAtPos += step; | |
185 | takeAtPos -= (int) takeAtPos; |
|
185 | takeAtPos -= (int) takeAtPos; | |
186 | } |
|
186 | } | |
187 | if (m_force || brush == sets.at(i)->brush()) |
|
187 | if (m_force || brush == sets.at(i)->brush()) | |
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
189 |
|
189 | |||
190 | // Pick label color from the opposite end of the gradient. |
|
190 | // Pick label color from the opposite end of the gradient. | |
191 | // 0.3 as a boundary seems to work well. |
|
191 | // 0.3 as a boundary seems to work well. | |
192 | if (m_force || brush == sets.at(i)->labelBrush()) { |
|
192 | if (m_force || brush == sets.at(i)->labelBrush()) { | |
193 | if (takeAtPos < 0.3) |
|
193 | if (takeAtPos < 0.3) | |
194 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
194 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
195 | else |
|
195 | else | |
196 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
196 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | if (m_force || pen == sets.at(i)->pen()) { |
|
199 | if (m_force || pen == sets.at(i)->pen()) { | |
200 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
200 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
201 | sets.at(i)->setPen(c); |
|
201 | sets.at(i)->setPen(c); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
206 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
207 | { |
|
207 | { | |
208 | QPen pen; |
|
208 | QPen pen; | |
209 | QBrush brush; |
|
209 | QBrush brush; | |
210 |
|
210 | |||
211 | if (m_force || pen == series->pen()) { |
|
211 | if (m_force || pen == series->pen()) { | |
212 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
212 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
213 | pen.setWidthF(2); |
|
213 | pen.setWidthF(2); | |
214 | series->setPen(pen); |
|
214 | series->setPen(pen); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | if (m_force || brush == series->brush()) { |
|
217 | if (m_force || brush == series->brush()) { | |
218 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
218 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
219 | series->setBrush(brush); |
|
219 | series->setBrush(brush); | |
220 | } |
|
220 | } | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
223 | void ChartTheme::decorate(QPieSeries *series, int index) | |
224 | { |
|
224 | { | |
225 |
|
225 | |||
226 | for (int i(0); i < series->slices().count(); i++) { |
|
226 | for (int i(0); i < series->slices().count(); i++) { | |
227 |
|
227 | |||
228 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
228 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
229 |
|
229 | |||
230 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
230 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
231 | qreal pos = (qreal)(i + 1) / (qreal) series->count(); |
|
231 | qreal pos = (qreal)(i + 1) / (qreal) series->count(); | |
232 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
232 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
233 |
|
233 | |||
234 | QPieSlice *s = series->slices().at(i); |
|
234 | QPieSlice *s = series->slices().at(i); | |
235 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
235 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
236 |
|
236 | |||
237 | if (m_force || d->m_data.m_slicePen.isThemed()) |
|
237 | if (m_force || d->m_data.m_slicePen.isThemed()) | |
238 | d->setPen(penColor, true); |
|
238 | d->setPen(penColor, true); | |
239 |
|
239 | |||
240 | if (m_force || d->m_data.m_sliceBrush.isThemed()) |
|
240 | if (m_force || d->m_data.m_sliceBrush.isThemed()) | |
241 | d->setBrush(brushColor, true); |
|
241 | d->setBrush(brushColor, true); | |
242 |
|
242 | |||
243 | if (m_force || d->m_data.m_labelBrush.isThemed()) |
|
243 | if (m_force || d->m_data.m_labelBrush.isThemed()) | |
244 | d->setLabelBrush(m_labelBrush.color(), true); |
|
244 | d->setLabelBrush(m_labelBrush.color(), true); | |
245 |
|
245 | |||
246 | if (m_force || d->m_data.m_labelFont.isThemed()) |
|
246 | if (m_force || d->m_data.m_labelFont.isThemed()) | |
247 | d->setLabelFont(m_labelFont, true); |
|
247 | d->setLabelFont(m_labelFont, true); | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
251 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
252 | { |
|
252 | { | |
253 | QPen pen; |
|
253 | QPen pen; | |
254 | if (m_force || pen == series->pen()) { |
|
254 | if (m_force || pen == series->pen()) { | |
255 | pen.setColor(m_seriesColors.at(index % m_seriesColors.size())); |
|
255 | pen.setColor(m_seriesColors.at(index % m_seriesColors.size())); | |
256 | pen.setWidthF(2); |
|
256 | pen.setWidthF(2); | |
257 | series->setPen(pen); |
|
257 | series->setPen(pen); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void ChartTheme::decorate(QAbstractAxis *axis) |
|
261 | void ChartTheme::decorate(QAbstractAxis *axis) | |
262 | { |
|
262 | { | |
263 | QPen pen; |
|
263 | QPen pen; | |
264 | QBrush brush; |
|
264 | QBrush brush; | |
265 | QFont font; |
|
265 | QFont font; | |
266 |
|
266 | |||
267 | bool axisX = axis->orientation() == Qt::Horizontal; |
|
267 | bool axisX = axis->orientation() == Qt::Horizontal; | |
268 |
|
268 | |||
269 | if (axis->isLineVisible()) { |
|
269 | if (axis->isLineVisible()) { | |
270 |
|
270 | |||
271 | if (m_force || brush == axis->labelsBrush()) |
|
271 | if (m_force || brush == axis->labelsBrush()) | |
272 | axis->setLabelsBrush(m_labelBrush); |
|
272 | axis->setLabelsBrush(m_labelBrush); | |
273 |
|
273 | |||
|
274 | //TODO: introduce axis brush | |||
|
275 | if (m_force || brush == axis->titleBrush()) | |||
|
276 | axis->setTitleBrush(m_labelBrush); | |||
|
277 | ||||
274 | if (m_force || pen == axis->labelsPen()) |
|
278 | if (m_force || pen == axis->labelsPen()) | |
275 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
279 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
276 |
|
280 | |||
|
281 | if (m_force || pen == axis->titlePen()) | |||
|
282 | axis->setTitlePen(Qt::NoPen); // Noen for performance reasons | |||
|
283 | ||||
277 | if (m_force || axis->shadesVisible()) { |
|
284 | if (m_force || axis->shadesVisible()) { | |
278 |
|
285 | |||
279 | if (m_force || brush == axis->shadesBrush()) |
|
286 | if (m_force || brush == axis->shadesBrush()) | |
280 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
287 | axis->setShadesBrush(m_backgroundShadesBrush); | |
281 |
|
288 | |||
282 | if (m_force || pen == axis->shadesPen()) |
|
289 | if (m_force || pen == axis->shadesPen()) | |
283 | axis->setShadesPen(m_backgroundShadesPen); |
|
290 | axis->setShadesPen(m_backgroundShadesPen); | |
284 |
|
291 | |||
285 | if (m_force && (m_backgroundShades == BackgroundShadesBoth |
|
292 | if (m_force && (m_backgroundShades == BackgroundShadesBoth | |
286 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
293 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
287 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))) { |
|
294 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))) { | |
288 | axis->setShadesVisible(true); |
|
295 | axis->setShadesVisible(true); | |
289 | } |
|
296 | } | |
290 | } |
|
297 | } | |
291 |
|
298 | |||
292 | if (m_force || pen == axis->linePen()) |
|
299 | if (m_force || pen == axis->linePen()) | |
293 | axis->setLinePen(m_axisLinePen); |
|
300 | axis->setLinePen(m_axisLinePen); | |
294 |
|
301 | |||
295 | if (m_force || pen == axis->gridLinePen()) |
|
302 | if (m_force || pen == axis->gridLinePen()) | |
296 | axis->setGridLinePen(m_gridLinePen); |
|
303 | axis->setGridLinePen(m_gridLinePen); | |
297 |
|
304 | |||
298 | if (m_force || font == axis->labelsFont()) |
|
305 | if (m_force || font == axis->labelsFont()) | |
299 | axis->setLabelsFont(m_labelFont); |
|
306 | axis->setLabelsFont(m_labelFont); | |
|
307 | ||||
|
308 | //TODO: discuss with Tero | |||
|
309 | if (m_force || font == axis->titleFont()){ | |||
|
310 | QFont font(m_labelFont); | |||
|
311 | font.setBold(true); | |||
|
312 | axis->setTitleFont(font); | |||
|
313 | } | |||
300 | } |
|
314 | } | |
301 | } |
|
315 | } | |
302 |
|
316 | |||
303 | void ChartTheme::generateSeriesGradients() |
|
317 | void ChartTheme::generateSeriesGradients() | |
304 | { |
|
318 | { | |
305 | // Generate gradients in HSV color space |
|
319 | // Generate gradients in HSV color space | |
306 | foreach (const QColor &color, m_seriesColors) { |
|
320 | foreach (const QColor &color, m_seriesColors) { | |
307 | QLinearGradient g; |
|
321 | QLinearGradient g; | |
308 | qreal h = color.hsvHueF(); |
|
322 | qreal h = color.hsvHueF(); | |
309 | qreal s = color.hsvSaturationF(); |
|
323 | qreal s = color.hsvSaturationF(); | |
310 |
|
324 | |||
311 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
325 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
312 | // most themes. The rest of the gradients we can define manually in theme specific |
|
326 | // most themes. The rest of the gradients we can define manually in theme specific | |
313 | // implementation. |
|
327 | // implementation. | |
314 | QColor start = color; |
|
328 | QColor start = color; | |
315 | start.setHsvF(h, 0.0, 1.0); |
|
329 | start.setHsvF(h, 0.0, 1.0); | |
316 | g.setColorAt(0.0, start); |
|
330 | g.setColorAt(0.0, start); | |
317 |
|
331 | |||
318 | g.setColorAt(0.5, color); |
|
332 | g.setColorAt(0.5, color); | |
319 |
|
333 | |||
320 | QColor end = color; |
|
334 | QColor end = color; | |
321 | end.setHsvF(h, s, 0.25); |
|
335 | end.setHsvF(h, s, 0.25); | |
322 | g.setColorAt(1.0, end); |
|
336 | g.setColorAt(1.0, end); | |
323 |
|
337 | |||
324 | m_seriesGradients << g; |
|
338 | m_seriesGradients << g; | |
325 | } |
|
339 | } | |
326 | } |
|
340 | } | |
327 |
|
341 | |||
328 |
|
342 | |||
329 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
343 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
330 | { |
|
344 | { | |
331 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
345 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
332 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
346 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
333 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
347 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
334 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
348 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
335 | QColor c; |
|
349 | QColor c; | |
336 | c.setRgbF(r, g, b); |
|
350 | c.setRgbF(r, g, b); | |
337 | return c; |
|
351 | return c; | |
338 | } |
|
352 | } | |
339 |
|
353 | |||
340 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
354 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
341 | { |
|
355 | { | |
342 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
356 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
343 |
|
357 | |||
344 | QGradientStops stops = gradient.stops(); |
|
358 | QGradientStops stops = gradient.stops(); | |
345 | int count = stops.count(); |
|
359 | int count = stops.count(); | |
346 |
|
360 | |||
347 | // find previous stop relative to position |
|
361 | // find previous stop relative to position | |
348 | QGradientStop prev = stops.first(); |
|
362 | QGradientStop prev = stops.first(); | |
349 | for (int i = 0; i < count; i++) { |
|
363 | for (int i = 0; i < count; i++) { | |
350 | QGradientStop stop = stops.at(i); |
|
364 | QGradientStop stop = stops.at(i); | |
351 | if (pos > stop.first) |
|
365 | if (pos > stop.first) | |
352 | prev = stop; |
|
366 | prev = stop; | |
353 |
|
367 | |||
354 | // given position is actually a stop position? |
|
368 | // given position is actually a stop position? | |
355 | if (pos == stop.first) { |
|
369 | if (pos == stop.first) { | |
356 | //qDebug() << "stop color" << pos; |
|
370 | //qDebug() << "stop color" << pos; | |
357 | return stop.second; |
|
371 | return stop.second; | |
358 | } |
|
372 | } | |
359 | } |
|
373 | } | |
360 |
|
374 | |||
361 | // find next stop relative to position |
|
375 | // find next stop relative to position | |
362 | QGradientStop next = stops.last(); |
|
376 | QGradientStop next = stops.last(); | |
363 | for (int i = count - 1; i >= 0; i--) { |
|
377 | for (int i = count - 1; i >= 0; i--) { | |
364 | QGradientStop stop = stops.at(i); |
|
378 | QGradientStop stop = stops.at(i); | |
365 | if (pos < stop.first) |
|
379 | if (pos < stop.first) | |
366 | next = stop; |
|
380 | next = stop; | |
367 | } |
|
381 | } | |
368 |
|
382 | |||
369 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
383 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
370 |
|
384 | |||
371 | qreal range = next.first - prev.first; |
|
385 | qreal range = next.first - prev.first; | |
372 | qreal posDelta = pos - prev.first; |
|
386 | qreal posDelta = pos - prev.first; | |
373 | qreal relativePos = posDelta / range; |
|
387 | qreal relativePos = posDelta / range; | |
374 |
|
388 | |||
375 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
389 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
376 |
|
390 | |||
377 | return colorAt(prev.second, next.second, relativePos); |
|
391 | return colorAt(prev.second, next.second, relativePos); | |
378 | } |
|
392 | } | |
379 |
|
393 | |||
380 | void ChartTheme::setForced(bool enabled) |
|
394 | void ChartTheme::setForced(bool enabled) | |
381 | { |
|
395 | { | |
382 | m_force = enabled; |
|
396 | m_force = enabled; | |
383 | } |
|
397 | } | |
384 |
|
398 | |||
385 | QTCOMMERCIALCHART_END_NAMESPACE |
|
399 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now