@@ -1,72 +1,70 | |||||
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 |
|
30 | |||
31 | #ifndef LEGENDSCROLLER_P_H |
|
31 | #ifndef LEGENDSCROLLER_P_H | |
32 | #define LEGENDSCROLLER_P_H |
|
32 | #define LEGENDSCROLLER_P_H | |
33 |
|
33 | |||
34 | #include "qlegend.h" |
|
34 | #include "qlegend.h" | |
|
35 | #include "qlegend_p.h" | |||
35 | #include "scroller_p.h" |
|
36 | #include "scroller_p.h" | |
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
39 | |||
39 | class LegendScroller: public QLegend, public Scroller |
|
40 | class LegendScroller: public QLegend, public Scroller | |
40 | { |
|
41 | { | |
41 |
|
42 | |||
42 | public: |
|
43 | public: | |
43 | LegendScroller(QChart *chart):QLegend(chart) |
|
44 | LegendScroller(QChart *chart):QLegend(chart) | |
44 | { |
|
45 | { | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | void setOffset(const QPointF& point) |
|
48 | void setOffset(const QPointF& point) | |
48 | { |
|
49 | { | |
49 |
|
|
50 | d_ptr->setOffset(point.x(), point.y()); | |
50 | } |
|
51 | } | |
51 | QPointF offset() const |
|
52 | QPointF offset() const | |
52 | { |
|
53 | { | |
53 |
return |
|
54 | return d_ptr->offset(); | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ |
|
57 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ | |
57 | Scroller::mousePressEvent(event); |
|
58 | Scroller::mousePressEvent(event); | |
58 | //QLegend::mousePressEvent(event); |
|
|||
59 | } |
|
59 | } | |
60 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ |
|
60 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | |
61 | Scroller::mouseMoveEvent(event); |
|
61 | Scroller::mouseMoveEvent(event); | |
62 | //QLegend::mouseMoveEvent(event); |
|
|||
63 | } |
|
62 | } | |
64 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ |
|
63 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | |
65 | Scroller::mouseReleaseEvent(event); |
|
64 | Scroller::mouseReleaseEvent(event); | |
66 | //QLegend::mouseReleaseEvent(event); |
|
|||
67 | } |
|
65 | } | |
68 | }; |
|
66 | }; | |
69 |
|
67 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
69 | |||
72 | #endif |
|
70 | #endif |
@@ -1,748 +1,737 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 |
|
26 | |||
27 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 |
|
44 | |||
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \class QLegend |
|
50 | \class QLegend | |
51 | \brief part of QtCommercial chart API. |
|
51 | \brief part of QtCommercial chart API. | |
52 | \mainclass |
|
52 | \mainclass | |
53 |
|
53 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
56 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
58 | |||
59 | \image examples_percentbarchart_legend.png |
|
59 | \image examples_percentbarchart_legend.png | |
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlclass Legend QLegend |
|
64 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
66 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is referenced via ChartView class. For example: |
|
68 | series have been changed. Legend is referenced via ChartView class. For example: | |
69 | \code |
|
69 | \code | |
70 | ChartView { |
|
70 | ChartView { | |
71 | legend.visible: true |
|
71 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
72 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 |
|
76 | |||
77 | \image examples_percentbarchart_legend.png |
|
77 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLegend::alignment |
|
81 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
82 | \brief The alignment of the legend. | |
83 |
|
83 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
89 | \brief The alignment of the legend. | |
90 |
|
90 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QLegend::backgroundVisible |
|
96 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
97 | Whether the legend background is visible or not. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
100 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QLegend::color |
|
105 | \property QLegend::color | |
106 | The color of the legend, i.e. the background color. |
|
106 | The color of the legend, i.e. the background color. | |
107 | */ |
|
107 | */ | |
108 | /*! |
|
108 | /*! | |
109 | \qmlproperty color Legend::color |
|
109 | \qmlproperty color Legend::color | |
110 | The color of the legend, i.e. the background color. |
|
110 | The color of the legend, i.e. the background color. | |
111 | */ |
|
111 | */ | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | \property QLegend::borderColor |
|
114 | \property QLegend::borderColor | |
115 | The border color of the legend, i.e. the line color. |
|
115 | The border color of the legend, i.e. the line color. | |
116 | */ |
|
116 | */ | |
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty color Legend::borderColor |
|
118 | \qmlproperty color Legend::borderColor | |
119 | The border color of the legend, i.e. the line color. |
|
119 | The border color of the legend, i.e. the line color. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QLegend::alignmentChanged(Qt::Alignment) |
|
123 | \fn void QLegend::alignmentChanged(Qt::Alignment) | |
124 | Emitted when the \a alignment of the legend changes. |
|
124 | Emitted when the \a alignment of the legend changes. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
128 | \fn void QLegend::backgroundVisibleChanged(bool) | |
129 | The visibility of the legend background changed to \a visible. |
|
129 | The visibility of the legend background changed to \a visible. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QLegend::colorChanged(QColor) |
|
133 | \fn void QLegend::colorChanged(QColor) | |
134 | The color of the legend background changed to \a color. |
|
134 | The color of the legend background changed to \a color. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QLegend::borderColorChanged(QColor) |
|
138 | \fn void QLegend::borderColorChanged(QColor) | |
139 | The border color of the legend background changed to \a color. |
|
139 | The border color of the legend background changed to \a color. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \fn qreal QLegend::minWidth() const |
|
143 | \fn qreal QLegend::minWidth() const | |
144 | Returns minimum width of the legend |
|
144 | Returns minimum width of the legend | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn qreal QLegend::minHeight() const |
|
148 | \fn qreal QLegend::minHeight() const | |
149 | Returns minimum height of the legend |
|
149 | Returns minimum height of the legend | |
150 | */ |
|
150 | */ | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Constructs the legend object and sets the parent to \a parent |
|
153 | Constructs the legend object and sets the parent to \a parent | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
156 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
157 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
157 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) | |
158 | { |
|
158 | { | |
159 | setZValue(ChartPresenter::LegendZValue); |
|
159 | setZValue(ChartPresenter::LegendZValue); | |
160 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
160 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
161 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
161 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
162 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
162 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
163 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
163 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
167 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
168 | */ |
|
168 | */ | |
169 | QLegend::~QLegend() |
|
169 | QLegend::~QLegend() | |
170 | { |
|
170 | { | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. |
|
174 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
177 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
178 | { |
|
178 | { | |
179 | Q_UNUSED(option) |
|
179 | Q_UNUSED(option) | |
180 | Q_UNUSED(widget) |
|
180 | Q_UNUSED(widget) | |
181 | if(!d_ptr->m_backgroundVisible) return; |
|
181 | if(!d_ptr->m_backgroundVisible) return; | |
182 |
|
182 | |||
183 | painter->setOpacity(opacity()); |
|
183 | painter->setOpacity(opacity()); | |
184 | painter->setPen(d_ptr->m_pen); |
|
184 | painter->setPen(d_ptr->m_pen); | |
185 | painter->setBrush(d_ptr->m_brush); |
|
185 | painter->setBrush(d_ptr->m_brush); | |
186 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
186 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Bounding rect of legend. |
|
190 | Bounding rect of legend. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | QRectF QLegend::boundingRect() const |
|
193 | QRectF QLegend::boundingRect() const | |
194 | { |
|
194 | { | |
195 | return d_ptr->m_rect; |
|
195 | return d_ptr->m_rect; | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Sets the \a brush of legend. Brush affects the background of legend. |
|
199 | Sets the \a brush of legend. Brush affects the background of legend. | |
200 | */ |
|
200 | */ | |
201 | void QLegend::setBrush(const QBrush &brush) |
|
201 | void QLegend::setBrush(const QBrush &brush) | |
202 | { |
|
202 | { | |
203 | if (d_ptr->m_brush != brush) { |
|
203 | if (d_ptr->m_brush != brush) { | |
204 | d_ptr->m_brush = brush; |
|
204 | d_ptr->m_brush = brush; | |
205 | update(); |
|
205 | update(); | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Returns the brush used by legend. |
|
210 | Returns the brush used by legend. | |
211 | */ |
|
211 | */ | |
212 | QBrush QLegend::brush() const |
|
212 | QBrush QLegend::brush() const | |
213 | { |
|
213 | { | |
214 | return d_ptr->m_brush; |
|
214 | return d_ptr->m_brush; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void QLegend::setColor(QColor color) |
|
217 | void QLegend::setColor(QColor color) | |
218 | { |
|
218 | { | |
219 | QBrush b = d_ptr->m_brush; |
|
219 | QBrush b = d_ptr->m_brush; | |
220 | if (b.color() != color) { |
|
220 | if (b.color() != color) { | |
221 | b.setColor(color); |
|
221 | b.setColor(color); | |
222 | setBrush(b); |
|
222 | setBrush(b); | |
223 | emit colorChanged(color); |
|
223 | emit colorChanged(color); | |
224 | } |
|
224 | } | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | QColor QLegend::color() |
|
227 | QColor QLegend::color() | |
228 | { |
|
228 | { | |
229 | return d_ptr->m_brush.color(); |
|
229 | return d_ptr->m_brush.color(); | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | Sets the \a pen of legend. Pen affects the legend borders. |
|
233 | Sets the \a pen of legend. Pen affects the legend borders. | |
234 | */ |
|
234 | */ | |
235 | void QLegend::setPen(const QPen &pen) |
|
235 | void QLegend::setPen(const QPen &pen) | |
236 | { |
|
236 | { | |
237 | if (d_ptr->m_pen != pen) { |
|
237 | if (d_ptr->m_pen != pen) { | |
238 | d_ptr->m_pen = pen; |
|
238 | d_ptr->m_pen = pen; | |
239 | update(); |
|
239 | update(); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns the pen used by legend |
|
244 | Returns the pen used by legend | |
245 | */ |
|
245 | */ | |
246 |
|
246 | |||
247 | QPen QLegend::pen() const |
|
247 | QPen QLegend::pen() const | |
248 | { |
|
248 | { | |
249 | return d_ptr->m_pen; |
|
249 | return d_ptr->m_pen; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void QLegend::setBorderColor(QColor color) |
|
252 | void QLegend::setBorderColor(QColor color) | |
253 | { |
|
253 | { | |
254 | QPen p = d_ptr->m_pen; |
|
254 | QPen p = d_ptr->m_pen; | |
255 | if (p.color() != color) { |
|
255 | if (p.color() != color) { | |
256 | p.setColor(color); |
|
256 | p.setColor(color); | |
257 | setPen(p); |
|
257 | setPen(p); | |
258 | emit borderColorChanged(color); |
|
258 | emit borderColorChanged(color); | |
259 | } |
|
259 | } | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | QColor QLegend::borderColor() |
|
262 | QColor QLegend::borderColor() | |
263 | { |
|
263 | { | |
264 | return d_ptr->m_pen.color(); |
|
264 | return d_ptr->m_pen.color(); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
267 | void QLegend::setAlignment(Qt::Alignment alignment) | |
268 | { |
|
268 | { | |
269 | if(d_ptr->m_alignment!=alignment) { |
|
269 | if(d_ptr->m_alignment!=alignment) { | |
270 | d_ptr->m_alignment = alignment; |
|
270 | d_ptr->m_alignment = alignment; | |
271 | d_ptr->updateLayout(); |
|
271 | d_ptr->updateLayout(); | |
272 | alignmentChanged(alignment); |
|
272 | alignmentChanged(alignment); | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | Qt::Alignment QLegend::alignment() const |
|
276 | Qt::Alignment QLegend::alignment() const | |
277 | { |
|
277 | { | |
278 | return d_ptr->m_alignment; |
|
278 | return d_ptr->m_alignment; | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | /*! |
|
281 | /*! | |
282 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
282 | Detaches the legend from chart. Chart won't change layout of the legend. | |
283 | */ |
|
283 | */ | |
284 | void QLegend::detachFromChart() |
|
284 | void QLegend::detachFromChart() | |
285 | { |
|
285 | { | |
286 | d_ptr->m_attachedToChart = false; |
|
286 | d_ptr->m_attachedToChart = false; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | Attaches the legend to chart. Chart may change layout of the legend. |
|
290 | Attaches the legend to chart. Chart may change layout of the legend. | |
291 | */ |
|
291 | */ | |
292 | void QLegend::attachToChart() |
|
292 | void QLegend::attachToChart() | |
293 | { |
|
293 | { | |
294 | d_ptr->attachToChart(); |
|
294 | d_ptr->attachToChart(); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Returns true, if legend is attached to chart. |
|
298 | Returns true, if legend is attached to chart. | |
299 | */ |
|
299 | */ | |
300 | bool QLegend::isAttachedToChart() |
|
300 | bool QLegend::isAttachedToChart() | |
301 | { |
|
301 | { | |
302 | return d_ptr->m_attachedToChart; |
|
302 | return d_ptr->m_attachedToChart; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Sets the legend's scrolling offset to value defined by \a point. |
|
|||
307 | */ |
|
|||
308 | void QLegend::setOffset(const QPointF& point) |
|
|||
309 | { |
|
|||
310 | d_ptr->setOffset(point.x(),point.y()); |
|
|||
311 | } |
|
|||
312 |
|
||||
313 | /*! |
|
|||
314 | Returns the legend's scrolling offset. |
|
|||
315 | */ |
|
|||
316 | QPointF QLegend::offset() const |
|
|||
317 | { |
|
|||
318 | return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY); |
|
|||
319 | } |
|
|||
320 |
|
||||
321 | /*! |
|
|||
322 | Sets the visibility of legend background to \a visible |
|
306 | Sets the visibility of legend background to \a visible | |
323 | */ |
|
307 | */ | |
324 | void QLegend::setBackgroundVisible(bool visible) |
|
308 | void QLegend::setBackgroundVisible(bool visible) | |
325 | { |
|
309 | { | |
326 | if(d_ptr->m_backgroundVisible != visible) { |
|
310 | if(d_ptr->m_backgroundVisible != visible) { | |
327 | d_ptr->m_backgroundVisible = visible; |
|
311 | d_ptr->m_backgroundVisible = visible; | |
328 | update(); |
|
312 | update(); | |
329 | emit backgroundVisibleChanged(visible); |
|
313 | emit backgroundVisibleChanged(visible); | |
330 | } |
|
314 | } | |
331 | } |
|
315 | } | |
332 |
|
316 | |||
333 | /*! |
|
317 | /*! | |
334 | Returns the visibility of legend background |
|
318 | Returns the visibility of legend background | |
335 | */ |
|
319 | */ | |
336 | bool QLegend::isBackgroundVisible() const |
|
320 | bool QLegend::isBackgroundVisible() const | |
337 | { |
|
321 | { | |
338 | return d_ptr->m_backgroundVisible; |
|
322 | return d_ptr->m_backgroundVisible; | |
339 | } |
|
323 | } | |
340 |
|
324 | |||
341 | /*! |
|
325 | /*! | |
342 | \internal \a event see QGraphicsWidget for details |
|
326 | \internal \a event see QGraphicsWidget for details | |
343 | */ |
|
327 | */ | |
344 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
328 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
345 | { |
|
329 | { | |
346 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
330 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
347 | QGraphicsWidget::resizeEvent(event); |
|
331 | QGraphicsWidget::resizeEvent(event); | |
348 | if(d_ptr->m_rect != rect) { |
|
332 | if(d_ptr->m_rect != rect) { | |
349 | d_ptr->m_rect = rect; |
|
333 | d_ptr->m_rect = rect; | |
350 | d_ptr->updateLayout(); |
|
334 | d_ptr->updateLayout(); | |
351 | } |
|
335 | } | |
352 | } |
|
336 | } | |
353 |
|
337 | |||
354 | /*! |
|
338 | /*! | |
355 | \internal \a event see QGraphicsWidget for details |
|
339 | \internal \a event see QGraphicsWidget for details | |
356 | */ |
|
340 | */ | |
357 | void QLegend::hideEvent(QHideEvent *event) |
|
341 | void QLegend::hideEvent(QHideEvent *event) | |
358 | { |
|
342 | { | |
359 | QGraphicsWidget::hideEvent(event); |
|
343 | QGraphicsWidget::hideEvent(event); | |
360 | setEnabled(false); |
|
344 | setEnabled(false); | |
361 | d_ptr->updateLayout(); |
|
345 | d_ptr->updateLayout(); | |
362 | } |
|
346 | } | |
363 |
|
347 | |||
364 | /*! |
|
348 | /*! | |
365 | \internal \a event see QGraphicsWidget for details |
|
349 | \internal \a event see QGraphicsWidget for details | |
366 | */ |
|
350 | */ | |
367 | void QLegend::showEvent(QShowEvent *event) |
|
351 | void QLegend::showEvent(QShowEvent *event) | |
368 | { |
|
352 | { | |
369 | QGraphicsWidget::showEvent(event); |
|
353 | QGraphicsWidget::showEvent(event); | |
370 | setEnabled(true); |
|
354 | setEnabled(true); | |
371 | d_ptr->updateLayout(); |
|
355 | d_ptr->updateLayout(); | |
372 | } |
|
356 | } | |
373 |
|
357 | |||
374 | qreal QLegend::minWidth() const |
|
358 | qreal QLegend::minWidth() const | |
375 | { |
|
359 | { | |
376 | return d_ptr->m_minWidth; |
|
360 | return d_ptr->m_minWidth; | |
377 | } |
|
361 | } | |
378 |
|
362 | |||
379 | qreal QLegend::minHeight() const |
|
363 | qreal QLegend::minHeight() const | |
380 | { |
|
364 | { | |
381 | return d_ptr->m_minHeight; |
|
365 | return d_ptr->m_minHeight; | |
382 | } |
|
366 | } | |
383 |
|
367 | |||
384 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
368 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
385 |
|
369 | |||
386 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
370 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): | |
387 | q_ptr(q), |
|
371 | q_ptr(q), | |
388 | m_presenter(presenter), |
|
372 | m_presenter(presenter), | |
389 | m_chart(chart), |
|
373 | m_chart(chart), | |
390 | m_markers(new QGraphicsItemGroup(q)), |
|
374 | m_markers(new QGraphicsItemGroup(q)), | |
391 | m_alignment(Qt::AlignTop), |
|
375 | m_alignment(Qt::AlignTop), | |
392 | m_brush(QBrush()), |
|
376 | m_brush(QBrush()), | |
393 | m_pen(QPen()), |
|
377 | m_pen(QPen()), | |
394 | m_offsetX(0), |
|
378 | m_offsetX(0), | |
395 | m_offsetY(0), |
|
379 | m_offsetY(0), | |
396 | m_minWidth(0), |
|
380 | m_minWidth(0), | |
397 | m_minHeight(0), |
|
381 | m_minHeight(0), | |
398 | m_width(0), |
|
382 | m_width(0), | |
399 | m_height(0), |
|
383 | m_height(0), | |
400 | m_diameter(5), |
|
384 | m_diameter(5), | |
401 | m_attachedToChart(true), |
|
385 | m_attachedToChart(true), | |
402 | m_backgroundVisible(false) |
|
386 | m_backgroundVisible(false) | |
403 | { |
|
387 | { | |
404 |
|
388 | |||
405 | } |
|
389 | } | |
406 |
|
390 | |||
407 | QLegendPrivate::~QLegendPrivate() |
|
391 | QLegendPrivate::~QLegendPrivate() | |
408 | { |
|
392 | { | |
409 |
|
393 | |||
410 | } |
|
394 | } | |
411 |
|
395 | |||
412 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
396 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
413 | { |
|
397 | { | |
414 | bool scrollHorizontal = true; |
|
398 | bool scrollHorizontal = true; | |
415 | switch(m_alignment) { |
|
399 | switch(m_alignment) { | |
416 | case Qt::AlignTop: |
|
400 | case Qt::AlignTop: | |
417 | case Qt::AlignBottom: { |
|
401 | case Qt::AlignBottom: { | |
418 | scrollHorizontal = true; |
|
402 | scrollHorizontal = true; | |
419 | break; |
|
403 | break; | |
420 | } |
|
404 | } | |
421 | case Qt::AlignLeft: |
|
405 | case Qt::AlignLeft: | |
422 | case Qt::AlignRight: { |
|
406 | case Qt::AlignRight: { | |
423 | scrollHorizontal = false; |
|
407 | scrollHorizontal = false; | |
424 | break; |
|
408 | break; | |
425 | } |
|
409 | } | |
426 | } |
|
410 | } | |
427 |
|
411 | |||
428 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. |
|
412 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. | |
429 | if (!m_attachedToChart) { |
|
413 | if (!m_attachedToChart) { | |
430 | scrollHorizontal = !scrollHorizontal; |
|
414 | scrollHorizontal = !scrollHorizontal; | |
431 | } |
|
415 | } | |
432 |
|
416 | |||
433 | // Limit offset between m_minOffset and m_maxOffset |
|
417 | // Limit offset between m_minOffset and m_maxOffset | |
434 | if (scrollHorizontal) { |
|
418 | if (scrollHorizontal) { | |
435 | if(m_width<=m_rect.width()) return; |
|
419 | if(m_width<=m_rect.width()) return; | |
436 |
|
420 | |||
437 | if (x != m_offsetX) { |
|
421 | if (x != m_offsetX) { | |
438 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); |
|
422 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); | |
439 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
423 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
440 | } |
|
424 | } | |
441 | } else { |
|
425 | } else { | |
442 | if(m_height<=m_rect.height()) return; |
|
426 | if(m_height<=m_rect.height()) return; | |
443 |
|
427 | |||
444 | if (y != m_offsetY) { |
|
428 | if (y != m_offsetY) { | |
445 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); |
|
429 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); | |
446 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
430 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
447 | } |
|
431 | } | |
448 | } |
|
432 | } | |
449 | } |
|
433 | } | |
450 |
|
434 | |||
|
435 | QPointF QLegendPrivate::offset() const | |||
|
436 | { | |||
|
437 | return QPointF(m_offsetX,m_offsetY); | |||
|
438 | } | |||
451 |
|
439 | |||
452 | void QLegendPrivate::updateLayout() |
|
440 | void QLegendPrivate::updateLayout() | |
453 | { |
|
441 | { | |
454 | if (!m_attachedToChart) { |
|
442 | if (!m_attachedToChart) { | |
455 | updateDetachedLayout(); |
|
443 | updateDetachedLayout(); | |
456 | return; |
|
444 | return; | |
457 | } |
|
445 | } | |
458 |
|
446 | |||
459 | m_offsetX=0; |
|
447 | m_offsetX=0; | |
460 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
448 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
461 |
|
449 | |||
462 | if(items.isEmpty()) return; |
|
450 | if(items.isEmpty()) return; | |
463 |
|
451 | |||
464 | m_minWidth=0; |
|
452 | m_minWidth=0; | |
465 | m_minHeight=0; |
|
453 | m_minHeight=0; | |
466 |
|
454 | |||
467 | switch(m_alignment) { |
|
455 | switch(m_alignment) { | |
468 |
|
456 | |||
469 | case Qt::AlignTop: |
|
457 | case Qt::AlignTop: | |
470 | case Qt::AlignBottom: { |
|
458 | case Qt::AlignBottom: { | |
471 | QPointF point = m_rect.topLeft(); |
|
459 | QPointF point = m_rect.topLeft(); | |
472 | m_width = 0; |
|
460 | m_width = 0; | |
473 | foreach (QGraphicsItem *item, items) { |
|
461 | foreach (QGraphicsItem *item, items) { | |
474 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
462 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
475 | const QRectF& rect = item->boundingRect(); |
|
463 | const QRectF& rect = item->boundingRect(); | |
476 | qreal w = rect.width(); |
|
464 | qreal w = rect.width(); | |
477 | m_minWidth=qMax(m_minWidth,w); |
|
465 | m_minWidth=qMax(m_minWidth,w); | |
478 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
466 | m_minHeight=qMax(m_minHeight,rect.height()); | |
479 | m_width+=w; |
|
467 | m_width+=w; | |
480 | point.setX(point.x() + w); |
|
468 | point.setX(point.x() + w); | |
481 | } |
|
469 | } | |
482 | if(m_width<m_rect.width()) { |
|
470 | if(m_width<m_rect.width()) { | |
483 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
471 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
484 | } |
|
472 | } | |
485 | else { |
|
473 | else { | |
486 | m_markers->setPos(m_rect.topLeft()); |
|
474 | m_markers->setPos(m_rect.topLeft()); | |
487 | } |
|
475 | } | |
488 | m_height=m_minHeight; |
|
476 | m_height=m_minHeight; | |
489 | } |
|
477 | } | |
490 | break; |
|
478 | break; | |
491 | case Qt::AlignLeft: |
|
479 | case Qt::AlignLeft: | |
492 | case Qt::AlignRight: { |
|
480 | case Qt::AlignRight: { | |
493 | QPointF point = m_rect.topLeft(); |
|
481 | QPointF point = m_rect.topLeft(); | |
494 | m_height = 0; |
|
482 | m_height = 0; | |
495 | foreach (QGraphicsItem *item, items) { |
|
483 | foreach (QGraphicsItem *item, items) { | |
496 | item->setPos(point); |
|
484 | item->setPos(point); | |
497 | const QRectF& rect = item->boundingRect(); |
|
485 | const QRectF& rect = item->boundingRect(); | |
498 | qreal h = rect.height(); |
|
486 | qreal h = rect.height(); | |
499 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
487 | m_minWidth=qMax(m_minWidth,rect.width()); | |
500 | m_minHeight=qMax(m_minHeight,h); |
|
488 | m_minHeight=qMax(m_minHeight,h); | |
501 | m_height+=h; |
|
489 | m_height+=h; | |
502 | point.setY(point.y() + h); |
|
490 | point.setY(point.y() + h); | |
503 | } |
|
491 | } | |
504 | if(m_height<m_rect.height()) { |
|
492 | if(m_height<m_rect.height()) { | |
505 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
493 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
506 | } |
|
494 | } | |
507 | else { |
|
495 | else { | |
508 | m_markers->setPos(m_rect.topLeft()); |
|
496 | m_markers->setPos(m_rect.topLeft()); | |
509 | } |
|
497 | } | |
510 | m_width=m_minWidth; |
|
498 | m_width=m_minWidth; | |
511 | } |
|
499 | } | |
512 | break; |
|
500 | break; | |
513 | } |
|
501 | } | |
514 |
|
502 | |||
515 | m_minOffsetX = 0; |
|
503 | m_minOffsetX = 0; | |
516 | m_minOffsetY = 0; |
|
504 | m_minOffsetY = 0; | |
517 | m_maxOffsetX = m_width - m_rect.width(); |
|
505 | m_maxOffsetX = m_width - m_rect.width(); | |
518 | m_maxOffsetY = m_height - m_rect.height(); |
|
506 | m_maxOffsetY = m_height - m_rect.height(); | |
519 |
|
507 | |||
520 | m_presenter->updateLayout(); |
|
508 | m_presenter->updateLayout(); | |
521 | } |
|
509 | } | |
522 |
|
510 | |||
523 | void QLegendPrivate::updateDetachedLayout() |
|
511 | void QLegendPrivate::updateDetachedLayout() | |
524 | { |
|
512 | { | |
525 | // Detached layout is different. |
|
513 | // Detached layout is different. | |
526 | // In detached mode legend may have multiple rows and columns, so layout calculations |
|
514 | // In detached mode legend may have multiple rows and columns, so layout calculations | |
527 | // differ a log from attached mode. |
|
515 | // differ a log from attached mode. | |
528 | // Also the scrolling logic is bit different. |
|
516 | // Also the scrolling logic is bit different. | |
529 | m_offsetX=0; |
|
517 | m_offsetX=0; | |
530 | m_offsetY=0; |
|
518 | m_offsetY=0; | |
531 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
519 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
532 |
|
520 | |||
533 | if(items.isEmpty()) return; |
|
521 | if(items.isEmpty()) return; | |
534 |
|
522 | |||
535 | m_minWidth = 0; |
|
523 | m_minWidth = 0; | |
536 | m_minHeight = 0; |
|
524 | m_minHeight = 0; | |
537 |
|
525 | |||
538 | switch (m_alignment) { |
|
526 | switch (m_alignment) { | |
539 | case Qt::AlignTop: { |
|
527 | case Qt::AlignTop: { | |
540 | QPointF point = m_rect.topLeft(); |
|
528 | QPointF point = m_rect.topLeft(); | |
541 | m_width = 0; |
|
529 | m_width = 0; | |
542 | m_height = 0; |
|
530 | m_height = 0; | |
543 | for (int i=0; i<items.count(); i++) { |
|
531 | for (int i=0; i<items.count(); i++) { | |
544 | QGraphicsItem *item = items.at(i); |
|
532 | QGraphicsItem *item = items.at(i); | |
545 | const QRectF& rect = item->boundingRect(); |
|
533 | const QRectF& rect = item->boundingRect(); | |
546 | qreal w = rect.width(); |
|
534 | qreal w = rect.width(); | |
547 | qreal h = rect.height(); |
|
535 | qreal h = rect.height(); | |
548 | m_minWidth = qMax(m_minWidth,w); |
|
536 | m_minWidth = qMax(m_minWidth,w); | |
549 | m_minHeight = qMax(m_minHeight,rect.height()); |
|
537 | m_minHeight = qMax(m_minHeight,rect.height()); | |
550 | m_height = qMax(m_height,h); |
|
538 | m_height = qMax(m_height,h); | |
551 | item->setPos(point.x(),point.y()); |
|
539 | item->setPos(point.x(),point.y()); | |
552 | point.setX(point.x() + w); |
|
540 | point.setX(point.x() + w); | |
553 | if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) { |
|
541 | if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) { | |
554 | // Next item would go off rect. |
|
542 | // Next item would go off rect. | |
555 | point.setX(m_rect.topLeft().x()); |
|
543 | point.setX(m_rect.topLeft().x()); | |
556 | point.setY(point.y() + h); |
|
544 | point.setY(point.y() + h); | |
557 | if (i+1 < items.count()) { |
|
545 | if (i+1 < items.count()) { | |
558 | m_height += h; |
|
546 | m_height += h; | |
559 | } |
|
547 | } | |
560 | } |
|
548 | } | |
561 | } |
|
549 | } | |
562 | m_markers->setPos(m_rect.topLeft()); |
|
550 | m_markers->setPos(m_rect.topLeft()); | |
563 | m_width = m_minWidth; |
|
551 | m_width = m_minWidth; | |
564 |
|
552 | |||
565 | m_minOffsetX = 0; |
|
553 | m_minOffsetX = 0; | |
566 | m_minOffsetY = 0; |
|
554 | m_minOffsetY = 0; | |
567 | m_maxOffsetX = m_width - m_rect.width(); |
|
555 | m_maxOffsetX = m_width - m_rect.width(); | |
568 | m_maxOffsetY = m_height - m_rect.height(); |
|
556 | m_maxOffsetY = m_height - m_rect.height(); | |
569 | } |
|
557 | } | |
570 | break; |
|
558 | break; | |
571 | case Qt::AlignBottom: { |
|
559 | case Qt::AlignBottom: { | |
572 | QPointF point = m_rect.bottomLeft(); |
|
560 | QPointF point = m_rect.bottomLeft(); | |
573 | m_width = 0; |
|
561 | m_width = 0; | |
574 | m_height = 0; |
|
562 | m_height = 0; | |
575 | for (int i=0; i<items.count(); i++) { |
|
563 | for (int i=0; i<items.count(); i++) { | |
576 | QGraphicsItem *item = items.at(i); |
|
564 | QGraphicsItem *item = items.at(i); | |
577 | const QRectF& rect = item->boundingRect(); |
|
565 | const QRectF& rect = item->boundingRect(); | |
578 | qreal w = rect.width(); |
|
566 | qreal w = rect.width(); | |
579 | qreal h = rect.height(); |
|
567 | qreal h = rect.height(); | |
580 | m_minWidth = qMax(m_minWidth,w); |
|
568 | m_minWidth = qMax(m_minWidth,w); | |
581 | m_minHeight = qMax(m_minHeight,rect.height()); |
|
569 | m_minHeight = qMax(m_minHeight,rect.height()); | |
582 | m_height = qMax(m_height,h); |
|
570 | m_height = qMax(m_height,h); | |
583 | item->setPos(point.x(),point.y() - h); |
|
571 | item->setPos(point.x(),point.y() - h); | |
584 | point.setX(point.x() + w); |
|
572 | point.setX(point.x() + w); | |
585 | if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) { |
|
573 | if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) { | |
586 | // Next item would go off rect. |
|
574 | // Next item would go off rect. | |
587 | point.setX(m_rect.bottomLeft().x()); |
|
575 | point.setX(m_rect.bottomLeft().x()); | |
588 | point.setY(point.y() - h); |
|
576 | point.setY(point.y() - h); | |
589 | if (i+1 < items.count()) { |
|
577 | if (i+1 < items.count()) { | |
590 | m_height += h; |
|
578 | m_height += h; | |
591 | } |
|
579 | } | |
592 | } |
|
580 | } | |
593 | } |
|
581 | } | |
594 | m_markers->setPos(m_rect.topLeft()); |
|
582 | m_markers->setPos(m_rect.topLeft()); | |
595 | m_width = m_minWidth; |
|
583 | m_width = m_minWidth; | |
596 |
|
584 | |||
597 | m_minOffsetX = 0; |
|
585 | m_minOffsetX = 0; | |
598 | m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height()); |
|
586 | m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height()); | |
599 | m_maxOffsetX = m_width - m_rect.width(); |
|
587 | m_maxOffsetX = m_width - m_rect.width(); | |
600 | m_maxOffsetY = 0; |
|
588 | m_maxOffsetY = 0; | |
601 | } |
|
589 | } | |
602 | break; |
|
590 | break; | |
603 | case Qt::AlignLeft: { |
|
591 | case Qt::AlignLeft: { | |
604 | QPointF point = m_rect.topLeft(); |
|
592 | QPointF point = m_rect.topLeft(); | |
605 | m_width = 0; |
|
593 | m_width = 0; | |
606 | m_height = 0; |
|
594 | m_height = 0; | |
607 | qreal maxWidth = 0; |
|
595 | qreal maxWidth = 0; | |
608 | for (int i=0; i<items.count(); i++) { |
|
596 | for (int i=0; i<items.count(); i++) { | |
609 | QGraphicsItem *item = items.at(i); |
|
597 | QGraphicsItem *item = items.at(i); | |
610 | const QRectF& rect = item->boundingRect(); |
|
598 | const QRectF& rect = item->boundingRect(); | |
611 | qreal w = rect.width(); |
|
599 | qreal w = rect.width(); | |
612 | qreal h = rect.height(); |
|
600 | qreal h = rect.height(); | |
613 | m_minWidth = qMax(m_minWidth,rect.width()); |
|
601 | m_minWidth = qMax(m_minWidth,rect.width()); | |
614 | m_minHeight = qMax(m_minHeight,h); |
|
602 | m_minHeight = qMax(m_minHeight,h); | |
615 | maxWidth = qMax(maxWidth,w); |
|
603 | maxWidth = qMax(maxWidth,w); | |
616 | item->setPos(point.x(),point.y()); |
|
604 | item->setPos(point.x(),point.y()); | |
617 | point.setY(point.y() + h); |
|
605 | point.setY(point.y() + h); | |
618 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { |
|
606 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { | |
619 | // Next item would go off rect. |
|
607 | // Next item would go off rect. | |
620 | point.setX(point.x() + maxWidth); |
|
608 | point.setX(point.x() + maxWidth); | |
621 | point.setY(m_rect.topLeft().y()); |
|
609 | point.setY(m_rect.topLeft().y()); | |
622 | if (i+1 < items.count()) { |
|
610 | if (i+1 < items.count()) { | |
623 | m_width += maxWidth; |
|
611 | m_width += maxWidth; | |
624 | maxWidth = 0; |
|
612 | maxWidth = 0; | |
625 | } |
|
613 | } | |
626 | } |
|
614 | } | |
627 | } |
|
615 | } | |
628 | m_width += maxWidth; |
|
616 | m_width += maxWidth; | |
629 | m_markers->setPos(m_rect.topLeft()); |
|
617 | m_markers->setPos(m_rect.topLeft()); | |
630 | m_height = m_minHeight; |
|
618 | m_height = m_minHeight; | |
631 |
|
619 | |||
632 | m_minOffsetX = 0; |
|
620 | m_minOffsetX = 0; | |
633 | m_minOffsetY = 0; |
|
621 | m_minOffsetY = 0; | |
634 | m_maxOffsetX = m_width - m_rect.width(); |
|
622 | m_maxOffsetX = m_width - m_rect.width(); | |
635 | m_maxOffsetY = m_height - m_rect.height(); |
|
623 | m_maxOffsetY = m_height - m_rect.height(); | |
636 | } |
|
624 | } | |
637 | break; |
|
625 | break; | |
638 | case Qt::AlignRight: { |
|
626 | case Qt::AlignRight: { | |
639 | QPointF point = m_rect.topRight(); |
|
627 | QPointF point = m_rect.topRight(); | |
640 | m_width = 0; |
|
628 | m_width = 0; | |
641 | m_height = 0; |
|
629 | m_height = 0; | |
642 | qreal maxWidth = 0; |
|
630 | qreal maxWidth = 0; | |
643 | for (int i=0; i<items.count(); i++) { |
|
631 | for (int i=0; i<items.count(); i++) { | |
644 | QGraphicsItem *item = items.at(i); |
|
632 | QGraphicsItem *item = items.at(i); | |
645 | const QRectF& rect = item->boundingRect(); |
|
633 | const QRectF& rect = item->boundingRect(); | |
646 | qreal w = rect.width(); |
|
634 | qreal w = rect.width(); | |
647 | qreal h = rect.height(); |
|
635 | qreal h = rect.height(); | |
648 | m_minWidth = qMax(m_minWidth,rect.width()); |
|
636 | m_minWidth = qMax(m_minWidth,rect.width()); | |
649 | m_minHeight = qMax(m_minHeight,h); |
|
637 | m_minHeight = qMax(m_minHeight,h); | |
650 | maxWidth = qMax(maxWidth,w); |
|
638 | maxWidth = qMax(maxWidth,w); | |
651 | item->setPos(point.x() - w,point.y()); |
|
639 | item->setPos(point.x() - w,point.y()); | |
652 | point.setY(point.y() + h); |
|
640 | point.setY(point.y() + h); | |
653 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { |
|
641 | if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) { | |
654 | // Next item would go off rect. |
|
642 | // Next item would go off rect. | |
655 | point.setX(point.x() - maxWidth); |
|
643 | point.setX(point.x() - maxWidth); | |
656 | point.setY(m_rect.topLeft().y()); |
|
644 | point.setY(m_rect.topLeft().y()); | |
657 | if (i+1 < items.count()) { |
|
645 | if (i+1 < items.count()) { | |
658 | m_width += maxWidth; |
|
646 | m_width += maxWidth; | |
659 | maxWidth = 0; |
|
647 | maxWidth = 0; | |
660 | } |
|
648 | } | |
661 | } |
|
649 | } | |
662 | } |
|
650 | } | |
663 | m_width += maxWidth; |
|
651 | m_width += maxWidth; | |
664 | m_markers->setPos(m_rect.topLeft()); |
|
652 | m_markers->setPos(m_rect.topLeft()); | |
665 | m_height = m_minHeight; |
|
653 | m_height = m_minHeight; | |
666 |
|
654 | |||
667 | m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width()); |
|
655 | m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width()); | |
668 | m_minOffsetY = 0; |
|
656 | m_minOffsetY = 0; | |
669 | m_maxOffsetX = 0; |
|
657 | m_maxOffsetX = 0; | |
670 | m_maxOffsetY = m_height - m_rect.height(); |
|
658 | m_maxOffsetY = m_height - m_rect.height(); | |
671 | } |
|
659 | } | |
672 | break; |
|
660 | break; | |
673 | default: |
|
661 | default: | |
674 | break; |
|
662 | break; | |
675 | } |
|
663 | } | |
676 | } |
|
664 | } | |
677 |
|
665 | |||
678 | void QLegendPrivate::attachToChart() |
|
666 | void QLegendPrivate::attachToChart() | |
679 | { |
|
667 | { | |
680 | m_attachedToChart = true; |
|
668 | m_attachedToChart = true; | |
681 | q_ptr->setParent(m_chart); |
|
669 | q_ptr->setParent(m_chart); | |
682 | } |
|
670 | } | |
683 |
|
671 | |||
684 | int QLegendPrivate::roundness(qreal size) |
|
672 | int QLegendPrivate::roundness(qreal size) | |
685 | { |
|
673 | { | |
686 | return 100*m_diameter/int(size); |
|
674 | return 100*m_diameter/int(size); | |
687 | } |
|
675 | } | |
688 |
|
676 | |||
689 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
677 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
690 | { |
|
678 | { | |
691 | Q_UNUSED(domain) |
|
679 | Q_UNUSED(domain) | |
692 |
|
680 | |||
693 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
681 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
694 | foreach(LegendMarker* marker, markers) |
|
682 | foreach(LegendMarker* marker, markers) | |
695 | m_markers->addToGroup(marker); |
|
683 | m_markers->addToGroup(marker); | |
696 |
|
684 | |||
697 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
685 | if(series->type() == QAbstractSeries::SeriesTypePie) { | |
698 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
686 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
699 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
687 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
700 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
688 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
701 | } |
|
689 | } | |
702 |
|
690 | |||
703 | updateLayout(); |
|
691 | updateLayout(); | |
704 | } |
|
692 | } | |
705 |
|
693 | |||
706 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
694 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
707 | { |
|
695 | { | |
708 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
696 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
709 |
|
697 | |||
710 | foreach (QGraphicsItem *markers, items) { |
|
698 | foreach (QGraphicsItem *markers, items) { | |
711 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
699 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
712 | if (marker->series() == series) { |
|
700 | if (marker->series() == series) { | |
713 | delete marker; |
|
701 | delete marker; | |
714 | } |
|
702 | } | |
715 | } |
|
703 | } | |
716 |
|
704 | |||
717 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
705 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
718 | { |
|
706 | { | |
719 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
707 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
720 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
708 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
721 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
709 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
722 | } |
|
710 | } | |
723 |
|
711 | |||
724 | updateLayout(); |
|
712 | updateLayout(); | |
725 | } |
|
713 | } | |
726 |
|
714 | |||
727 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
715 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) | |
728 | { |
|
716 | { | |
729 | // TODO: find out which markers are are added or removed. Update them |
|
717 | // TODO: find out which markers are are added or removed. Update them | |
730 | // TODO: better implementation |
|
718 | // TODO: better implementation | |
731 | handleSeriesRemoved(series); |
|
719 | handleSeriesRemoved(series); | |
732 | Domain domain; |
|
720 | Domain domain; | |
733 | handleSeriesAdded(series, &domain); |
|
721 | handleSeriesAdded(series, &domain); | |
734 | } |
|
722 | } | |
735 |
|
723 | |||
736 | void QLegendPrivate::handleUpdatePieSeries() |
|
724 | void QLegendPrivate::handleUpdatePieSeries() | |
737 | { |
|
725 | { | |
738 | //TODO: reimplement to be optimal |
|
726 | //TODO: reimplement to be optimal | |
739 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
727 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); | |
740 | Q_ASSERT(series); |
|
728 | Q_ASSERT(series); | |
741 | handleSeriesRemoved(series); |
|
729 | handleSeriesRemoved(series); | |
742 | handleSeriesAdded(series, 0); |
|
730 | handleSeriesAdded(series, 0); | |
743 | } |
|
731 | } | |
744 |
|
732 | |||
|
733 | ||||
745 | #include "moc_qlegend.cpp" |
|
734 | #include "moc_qlegend.cpp" | |
746 | #include "moc_qlegend_p.cpp" |
|
735 | #include "moc_qlegend_p.cpp" | |
747 |
|
736 | |||
748 | QTCOMMERCIALCHART_END_NAMESPACE |
|
737 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,105 +1,102 | |||||
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 | #ifndef QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Domain; |
|
31 | class Domain; | |
32 | class LegendMarker; |
|
32 | class LegendMarker; | |
33 | class QPieSlice; |
|
33 | class QPieSlice; | |
34 | class QXYSeries; |
|
34 | class QXYSeries; | |
35 | class QBarSet; |
|
35 | class QBarSet; | |
36 | class QBarSeries; |
|
36 | class QBarSeries; | |
37 | class QPieSeries; |
|
37 | class QPieSeries; | |
38 | class QAreaSeries; |
|
38 | class QAreaSeries; | |
39 | class LegendScrollButton; |
|
39 | class LegendScrollButton; | |
40 | class QChart; |
|
40 | class QChart; | |
41 | class QLegendPrivate; |
|
41 | class QLegendPrivate; | |
42 |
|
42 | |||
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) |
|
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) | |
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) | |
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | explicit QLegend(QChart *chart); |
|
52 | explicit QLegend(QChart *chart); | |
53 |
|
53 | |||
54 | public: |
|
54 | public: | |
55 | ~QLegend(); |
|
55 | ~QLegend(); | |
56 |
|
56 | |||
57 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
57 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
58 | QRectF boundingRect() const; |
|
58 | QRectF boundingRect() const; | |
59 |
|
59 | |||
60 | void setBrush(const QBrush &brush); |
|
60 | void setBrush(const QBrush &brush); | |
61 | QBrush brush() const; |
|
61 | QBrush brush() const; | |
62 | void setColor(QColor color); |
|
62 | void setColor(QColor color); | |
63 | QColor color(); |
|
63 | QColor color(); | |
64 |
|
64 | |||
65 | void setPen(const QPen &pen); |
|
65 | void setPen(const QPen &pen); | |
66 | QPen pen() const; |
|
66 | QPen pen() const; | |
67 | void setBorderColor(QColor color); |
|
67 | void setBorderColor(QColor color); | |
68 | QColor borderColor(); |
|
68 | QColor borderColor(); | |
69 |
|
69 | |||
70 | void setAlignment(Qt::Alignment alignment); |
|
70 | void setAlignment(Qt::Alignment alignment); | |
71 | Qt::Alignment alignment() const; |
|
71 | Qt::Alignment alignment() const; | |
72 |
|
72 | |||
73 | void detachFromChart(); |
|
73 | void detachFromChart(); | |
74 | void attachToChart(); |
|
74 | void attachToChart(); | |
75 | bool isAttachedToChart(); |
|
75 | bool isAttachedToChart(); | |
76 |
|
76 | |||
77 | qreal minWidth() const; |
|
77 | qreal minWidth() const; | |
78 | qreal minHeight() const; |
|
78 | qreal minHeight() const; | |
79 |
|
79 | |||
80 | void setBackgroundVisible(bool visible = true); |
|
80 | void setBackgroundVisible(bool visible = true); | |
81 | bool isBackgroundVisible() const; |
|
81 | bool isBackgroundVisible() const; | |
82 |
|
82 | |||
83 | void setOffset(const QPointF& point); |
|
|||
84 | QPointF offset() const; |
|
|||
85 |
|
||||
86 | protected: |
|
83 | protected: | |
87 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
84 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
88 | void hideEvent(QHideEvent *event); |
|
85 | void hideEvent(QHideEvent *event); | |
89 | void showEvent(QShowEvent *event); |
|
86 | void showEvent(QShowEvent *event); | |
90 |
|
87 | |||
91 | Q_SIGNALS: |
|
88 | Q_SIGNALS: | |
92 | void alignmentChanged(Qt::Alignment alignment); |
|
89 | void alignmentChanged(Qt::Alignment alignment); | |
93 | void backgroundVisibleChanged(bool visible); |
|
90 | void backgroundVisibleChanged(bool visible); | |
94 | void colorChanged(QColor color); |
|
91 | void colorChanged(QColor color); | |
95 | void borderColorChanged(QColor color); |
|
92 | void borderColorChanged(QColor color); | |
96 |
|
93 | |||
97 | private: |
|
94 | private: | |
98 | QScopedPointer<QLegendPrivate> d_ptr; |
|
95 | QScopedPointer<QLegendPrivate> d_ptr; | |
99 | Q_DISABLE_COPY(QLegend) |
|
96 | Q_DISABLE_COPY(QLegend) | |
100 | friend class LegendScroller; |
|
97 | friend class LegendScroller; | |
101 | }; |
|
98 | }; | |
102 |
|
99 | |||
103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
104 |
|
101 | |||
105 | #endif // QLEGEND_H |
|
102 | #endif // QLEGEND_H |
@@ -1,89 +1,90 | |||||
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 QLEGEND_P_H |
|
30 | #ifndef QLEGEND_P_H | |
31 | #define QLEGEND_P_H |
|
31 | #define QLEGEND_P_H | |
32 |
|
32 | |||
33 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QChart; |
|
37 | class QChart; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class QAbstractSeries; |
|
39 | class QAbstractSeries; | |
40 |
|
40 | |||
41 | class QLegendPrivate : public QObject |
|
41 | class QLegendPrivate : public QObject | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
45 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); | |
46 | ~QLegendPrivate(); |
|
46 | ~QLegendPrivate(); | |
47 |
|
47 | |||
48 | void setOffset(qreal x, qreal y); |
|
48 | void setOffset(qreal x, qreal y); | |
|
49 | QPointF offset() const; | |||
49 | void updateLayout(); |
|
50 | void updateLayout(); | |
50 | void updateDetachedLayout(); |
|
51 | void updateDetachedLayout(); | |
51 | void attachToChart(); |
|
52 | void attachToChart(); | |
52 | int roundness(qreal size); |
|
53 | int roundness(qreal size); | |
53 |
|
54 | |||
54 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
55 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); |
|
56 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); | |
56 | void handleSeriesRemoved(QAbstractSeries *series); |
|
57 | void handleSeriesRemoved(QAbstractSeries *series); | |
57 | void handleSeriesUpdated(QAbstractSeries *series); |
|
58 | void handleSeriesUpdated(QAbstractSeries *series); | |
58 | void handleUpdatePieSeries(); //TODO remove this function |
|
59 | void handleUpdatePieSeries(); //TODO remove this function | |
59 |
|
60 | |||
60 | private: |
|
61 | private: | |
61 | QLegend *q_ptr; |
|
62 | QLegend *q_ptr; | |
62 | ChartPresenter *m_presenter; |
|
63 | ChartPresenter *m_presenter; | |
63 | QChart* m_chart; |
|
64 | QChart* m_chart; | |
64 | QGraphicsItemGroup* m_markers; |
|
65 | QGraphicsItemGroup* m_markers; | |
65 | Qt::Alignment m_alignment; |
|
66 | Qt::Alignment m_alignment; | |
66 | QBrush m_brush; |
|
67 | QBrush m_brush; | |
67 | QPen m_pen; |
|
68 | QPen m_pen; | |
68 | QRectF m_rect; |
|
69 | QRectF m_rect; | |
69 | qreal m_offsetX; |
|
70 | qreal m_offsetX; | |
70 | qreal m_offsetY; |
|
71 | qreal m_offsetY; | |
71 | qreal m_minOffsetX; |
|
72 | qreal m_minOffsetX; | |
72 | qreal m_minOffsetY; |
|
73 | qreal m_minOffsetY; | |
73 | qreal m_maxOffsetX; |
|
74 | qreal m_maxOffsetX; | |
74 | qreal m_maxOffsetY; |
|
75 | qreal m_maxOffsetY; | |
75 | qreal m_minWidth; |
|
76 | qreal m_minWidth; | |
76 | qreal m_minHeight; |
|
77 | qreal m_minHeight; | |
77 | qreal m_width; |
|
78 | qreal m_width; | |
78 | qreal m_height; |
|
79 | qreal m_height; | |
79 | qreal m_diameter; |
|
80 | qreal m_diameter; | |
80 | bool m_attachedToChart; |
|
81 | bool m_attachedToChart; | |
81 | bool m_backgroundVisible; |
|
82 | bool m_backgroundVisible; | |
82 |
|
83 | |||
83 | friend class QLegend; |
|
84 | friend class QLegend; | |
84 |
|
85 | |||
85 | }; |
|
86 | }; | |
86 |
|
87 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
88 |
|
89 | |||
89 | #endif |
|
90 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now