##// END OF EJS Templates
Added API to set chart background roundness...
Miikka Heikkinen -
r2549:a58216ed7654
parent child
Show More
@@ -115,6 +115,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
115 115 */
116 116
117 117 /*!
118 \qmlproperty real ChartView::backgroundRoundness
119 The diameter of the rounding cirle at the corners of the chart background.
120 */
121
122 /*!
118 123 \qmlproperty color ChartView::plotAreaColor
119 124 The color of the background of the chart's plot area. By default plot area background uses chart's
120 125 background color.
@@ -706,6 +711,19 bool DeclarativeChart::dropShadowEnabled()
706 711 return m_chart->isDropShadowEnabled();
707 712 }
708 713
714 qreal DeclarativeChart::backgroundRoundness() const
715 {
716 return m_chart->backgroundRoundness();
717 }
718
719 void DeclarativeChart::setBackgroundRoundness(qreal diameter)
720 {
721 if (m_chart->backgroundRoundness() != diameter) {
722 m_chart->setBackgroundRoundness(diameter);
723 emit backgroundRoundnessChanged(diameter);
724 }
725 }
726
709 727 qreal DeclarativeChart::topMargin()
710 728 {
711 729 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
@@ -53,6 +53,7 class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM
53 53 Q_PROPERTY(int count READ count)
54 54 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
55 55 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
56 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness NOTIFY backgroundRoundnessChanged REVISION 3)
56 57 Q_PROPERTY(qreal topMargin READ topMargin)
57 58 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
58 59 Q_PROPERTY(qreal leftMargin READ leftMargin)
@@ -143,6 +144,8 public:
143 144 int count();
144 145 void setDropShadowEnabled(bool enabled);
145 146 bool dropShadowEnabled();
147 Q_REVISION(3) qreal backgroundRoundness() const;
148 Q_REVISION(3) void setBackgroundRoundness(qreal diameter);
146 149
147 150 // Margins & plotArea
148 151 qreal topMargin();
@@ -191,6 +194,7 Q_SIGNALS:
191 194 void seriesAdded(QAbstractSeries *series);
192 195 void seriesRemoved(QAbstractSeries *series);
193 196 Q_REVISION(3) void plotAreaColorChanged();
197 Q_REVISION(3) void backgroundRoundnessChanged(qreal diameter);
194 198
195 199 private Q_SLOTS:
196 200 void changeMinimumMargins(int top, int bottom, int left, int right);
@@ -29,7 +29,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 ChartBackground::ChartBackground(QGraphicsItem *parent)
31 31 : QGraphicsRectItem(parent),
32 m_diameter(15),
32 m_diameter(5),
33 33 m_dropShadow(0)
34 34 {
35 35 }
@@ -69,7 +69,7 void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
69 69 painter->save();
70 70 painter->setPen(pen());
71 71 painter->setBrush(brush());
72 painter->drawRoundRect(rect(), roundness(rect().width()), roundness(rect().height()));
72 painter->drawRoundedRect(rect(), m_diameter, m_diameter);
73 73 #ifndef QT_NO_DEBUG
74 74 painter->setPen(Qt::black);
75 75 QFont font;
@@ -81,21 +81,15 void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
81 81 painter->restore();
82 82 }
83 83
84 int ChartBackground::roundness(qreal size) const
85 {
86 if (qFuzzyCompare(size, 0))
87 return 0;
88 return 100 * m_diameter / int(size);
89 }
90
91 int ChartBackground::diameter() const
84 qreal ChartBackground::diameter() const
92 85 {
93 86 return m_diameter;
94 87 }
95 88
96 void ChartBackground::setDiameter(int diameter)
89 void ChartBackground::setDiameter(qreal diameter)
97 90 {
98 91 m_diameter = diameter;
92 update();
99 93 }
100 94
101 95 QTCOMMERCIALCHART_END_NAMESPACE
@@ -42,8 +42,8 public:
42 42 ChartBackground(QGraphicsItem *parent = 0);
43 43 ~ChartBackground();
44 44
45 void setDiameter(int diameter);
46 int diameter() const;
45 void setDiameter(qreal diameter);
46 qreal diameter() const;
47 47 void setDropShadowEnabled(bool enabled);
48 48 bool isDropShadowEnabled() { return m_dropShadow != 0; }
49 49
@@ -51,10 +51,7 protected:
51 51 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
52 52
53 53 private:
54 int roundness(qreal size) const;
55
56 private:
57 int m_diameter;
54 qreal m_diameter;
58 55 QGraphicsDropShadowEffect *m_dropShadow;
59 56 };
60 57
@@ -227,6 +227,20 QPen ChartPresenter::backgroundPen() const
227 227 return m_background->pen();
228 228 }
229 229
230 void ChartPresenter::setBackgroundRoundness(qreal diameter)
231 {
232 createBackgroundItem();
233 m_background->setDiameter(diameter);
234 m_layout->invalidate();
235 }
236
237 qreal ChartPresenter::backgroundRoundness() const
238 {
239 if (!m_background)
240 return 0;
241 return m_background->diameter();
242 }
243
230 244 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
231 245 {
232 246 createPlotAreaBackgroundItem();
@@ -102,6 +102,9 public:
102 102 void setBackgroundPen(const QPen &pen);
103 103 QPen backgroundPen() const;
104 104
105 void setBackgroundRoundness(qreal diameter);
106 qreal backgroundRoundness() const;
107
105 108 void setPlotAreaBackgroundBrush(const QBrush &brush);
106 109 QBrush plotAreaBackgroundBrush() const;
107 110
@@ -97,6 +97,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
97 97 */
98 98
99 99 /*!
100 \property QChart::backgroundRoundness
101 The diameter of the rounding cirle at the corners of the chart background.
102 */
103
104 /*!
100 105 \property QChart::minimumMargins
101 106 Minimum margins between the plot area (axes) and the edge of the chart widget.
102 107 This property is deprecated; use margins property instead.
@@ -594,6 +599,16 bool QChart::isDropShadowEnabled() const
594 599 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
595 600 }
596 601
602 void QChart::setBackgroundRoundness(qreal diameter)
603 {
604 d_ptr->m_presenter->setBackgroundRoundness(diameter);
605 }
606
607 qreal QChart::backgroundRoundness() const
608 {
609 return d_ptr->m_presenter->backgroundRoundness();
610 }
611
597 612 /*!
598 613 Returns all series that are added to the chart.
599 614
@@ -43,6 +43,7 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
43 43 Q_PROPERTY(QString title READ title WRITE setTitle)
44 44 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
45 45 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
46 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness)
46 47 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
47 48 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
48 49 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
@@ -119,6 +120,8 public:
119 120
120 121 void setDropShadowEnabled(bool enabled = true);
121 122 bool isDropShadowEnabled() const;
123 void setBackgroundRoundness(qreal diameter);
124 qreal backgroundRoundness() const;
122 125 void setAnimationOptions(AnimationOptions options);
123 126 AnimationOptions animationOptions() const;
124 127
@@ -109,6 +109,7 private slots:
109 109 void createDefaultAxesForLineSeries_data();
110 110 void createDefaultAxesForLineSeries();
111 111 void axisPolarOrientation();
112 void backgroundRoundness();
112 113 private:
113 114 void createTestData();
114 115
@@ -1028,6 +1029,14 void tst_QChart::axisPolarOrientation()
1028 1029 QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial);
1029 1030 }
1030 1031
1032 void tst_QChart::backgroundRoundness()
1033 {
1034 createTestData();
1035 m_chart->createDefaultAxes();
1036 m_chart->setBackgroundRoundness(100.0);
1037 QVERIFY(m_chart->backgroundRoundness() == 100.0);
1038 }
1039
1031 1040 QTEST_MAIN(tst_QChart)
1032 1041 #include "tst_qchart.moc"
1033 1042
@@ -42,6 +42,7 ChartView {
42 42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor);
44 44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter);
45 46 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
46 47 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
47 48 onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor);
@@ -58,6 +58,10 Flow {
58 58 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
59 59 }
60 60 Button {
61 text: "roundness"
62 onClicked: chart.backgroundRoundness++;
63 }
64 Button {
61 65 text: "zoom +"
62 66 onClicked: chart.zoom(2);
63 67 }
@@ -42,6 +42,7 ChartView {
42 42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor);
44 44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onBackgroundRoundnessChanged: console.log("chart.onBackgroundRoundnessChanged: " + diameter);
45 46 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
46 47 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
47 48 onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor);
@@ -58,6 +58,10 Flow {
58 58 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
59 59 }
60 60 Button {
61 text: "roundness"
62 onClicked: chart.backgroundRoundness++;
63 }
64 Button {
61 65 text: "zoom +"
62 66 onClicked: chart.zoom(2);
63 67 }
General Comments 0
You need to be logged in to leave comments. Login now