##// END OF EJS Templates
Improved ChartView.minimuMargins implementation
Tero Ahola -
r1946:82bf43b42362
parent child
Show More
@@ -208,27 +208,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
208 */
208 */
209
209
210 /*!
210 /*!
211 \qmlsignal ChartView::onTopMarginChanged(real margin)
211 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
212 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
212 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
213 related properties of the legend or chart title.
213 or if you resize the chart, or if you modify font size related properties of the legend or chart
214 */
214 title.
215
216 /*!
217 \qmlsignal ChartView::onBottomMarginChanged(real margin)
218 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
219 related properties of the legend or chart title.
220 */
221
222 /*!
223 \qmlsignal ChartView::onLeftMarginChanged(real margin)
224 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
225 related properties of the legend or chart title.
226 */
227
228 /*!
229 \qmlsignal ChartView::onRightMarginChanged(real margin)
230 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
231 related properties of the legend or chart title.
232 */
215 */
233
216
234 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
217 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
@@ -241,13 +224,13 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
241 connect(m_minMargins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
224 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
242 connect(m_minMargins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
225 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
243 connect(m_minMargins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
226 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
244 // TODO: connect to plotAreaChanged signal from m_chart
245 }
227 }
246
228
247 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
229 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
248 {
230 {
249 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
231 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
250 plotAreaChanged(m_chart->plotArea());
232 emit minimumMarginsChanged();
233 emit plotAreaChanged(m_chart->plotArea());
251 }
234 }
252
235
253 DeclarativeChart::~DeclarativeChart()
236 DeclarativeChart::~DeclarativeChart()
@@ -370,6 +353,11 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &
370 }
353 }
371 }
354 }
372 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
355 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
356
357 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
358 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
359 // to implement it here for the QML API purposes.
360 emit plotAreaChanged(m_chart->plotArea());
373 }
361 }
374
362
375 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
363 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
@@ -41,11 +41,11 class DeclarativeChart : public QDeclarativeItem
41 Q_PROPERTY(int count READ count)
41 Q_PROPERTY(int count READ count)
42 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
42 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
43 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
43 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
44 Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged)
44 Q_PROPERTY(qreal topMargin READ topMargin)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
46 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
46 Q_PROPERTY(qreal leftMargin READ leftMargin)
47 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
47 Q_PROPERTY(qreal rightMargin READ rightMargin)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins REVISION 1)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
49 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
49 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
50 Q_ENUMS(Animation)
50 Q_ENUMS(Animation)
51 Q_ENUMS(Theme)
51 Q_ENUMS(Theme)
@@ -139,14 +139,10 Q_SIGNALS:
139 void titleColorChanged(QColor color);
139 void titleColorChanged(QColor color);
140 void backgroundColorChanged();
140 void backgroundColorChanged();
141 void dropShadowEnabledChanged(bool enabled);
141 void dropShadowEnabledChanged(bool enabled);
142 void topMarginChanged(qreal margin);
142 void minimumMarginsChanged();
143 void bottomMarginChanged(qreal margin);
144 void leftMarginChanged(qreal margin);
145 void rightMarginChanged(qreal margin);
146 void plotAreaChanged(QRectF plotArea);
143 void plotAreaChanged(QRectF plotArea);
147
144
148 public Q_SLOTS:
145 public Q_SLOTS:
149 // void handleMarginsChanged(QRectF newMargins);
150 void changeMinimumMargins(int top, int bottom, int left, int right);
146 void changeMinimumMargins(int top, int bottom, int left, int right);
151 void handleAxisXSet(QAbstractAxis *axis);
147 void handleAxisXSet(QAbstractAxis *axis);
152 void handleAxisYSet(QAbstractAxis *axis);
148 void handleAxisYSet(QAbstractAxis *axis);
@@ -42,22 +42,6 ChartView {
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onTopMarginChanged: {
46 console.log("chart.onTopMarginChanged: " + margin);
47 marginVisualizer.opacity = 1.0;
48 }
49 onBottomMarginChanged: {
50 console.log("chart.onBottomMarginChanged: " + margin);
51 marginVisualizer.opacity = 1.0;
52 }
53 onLeftMarginChanged: {
54 console.log("chart.onLeftMarginChanged: " + margin);
55 marginVisualizer.opacity = 1.0;
56 }
57 onRightMarginChanged: {
58 console.log("chart.onRightMarginChanged: " + margin);
59 marginVisualizer.opacity = 1.0;
60 }
61
45
62 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
46 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
63 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
47 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
@@ -65,10 +49,16 ChartView {
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
49 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
66 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
50 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
67 minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top );
51 minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top );
68 minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom + " " + chartView.plotArea.height);
52 minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom);
69 minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left + " " + chartView.plotArea.left);
53 minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left);
70 minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right + " " + chartView.plotArea.right);
54 minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right);
71 onPlotAreaChanged: console.log("chart.onPlotAreaChanged, width:" + chartView.plotArea.width + " height: " + chartView.plotArea.height + " y: " + chartView.plotArea.y + " x: " + chartView.plotArea.x);
55 onPlotAreaChanged: {
56 console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width
57 + " height: " + chartView.plotArea.height
58 + " y: " + chartView.plotArea.y
59 + " x: " + chartView.plotArea.x);
60 marginVisualizer.opacity = 1.0;
61 }
72
62
73 ValueAxis{
63 ValueAxis{
74 onColorChanged: console.log("axisX.onColorChanged: " + color);
64 onColorChanged: console.log("axisX.onColorChanged: " + color);
@@ -101,10 +91,10 ChartView {
101 color: "transparent"
91 color: "transparent"
102 border.color: "red"
92 border.color: "red"
103 anchors.fill: parent
93 anchors.fill: parent
104 anchors.topMargin: parent.topMargin
94 anchors.topMargin: chartView.minimumMargins.top
105 anchors.bottomMargin: parent.bottomMargin
95 anchors.bottomMargin: chartView.minimumMargins.bottom
106 anchors.leftMargin: parent.leftMargin
96 anchors.leftMargin: chartView.minimumMargins.left
107 anchors.rightMargin: parent.rightMargin
97 anchors.rightMargin: chartView.minimumMargins.right
108 opacity: 0.0
98 opacity: 0.0
109 onOpacityChanged: if (opacity > 0.9) opacity = 0.0;
99 onOpacityChanged: if (opacity > 0.9) opacity = 0.0;
110 Behavior on opacity {
100 Behavior on opacity {
General Comments 0
You need to be logged in to leave comments. Login now