@@ -107,6 +107,7 void QChartView::setChart(QChart *chart) | |||||
107 | */ |
|
107 | */ | |
108 | void QChartView::setRubberBand(const RubberBands &rubberBand) |
|
108 | void QChartView::setRubberBand(const RubberBands &rubberBand) | |
109 | { |
|
109 | { | |
|
110 | #ifndef QT_NO_RUBBERBAND | |||
110 | d_ptr->m_rubberBandFlags = rubberBand; |
|
111 | d_ptr->m_rubberBandFlags = rubberBand; | |
111 |
|
112 | |||
112 | if (!d_ptr->m_rubberBandFlags) { |
|
113 | if (!d_ptr->m_rubberBandFlags) { | |
@@ -119,6 +120,10 void QChartView::setRubberBand(const RubberBands &rubberBand) | |||||
119 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
120 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
120 | d_ptr->m_rubberBand->setEnabled(true); |
|
121 | d_ptr->m_rubberBand->setEnabled(true); | |
121 | } |
|
122 | } | |
|
123 | #else | |||
|
124 | Q_UNUSED(rubberBand); | |||
|
125 | qWarning("Unable to set rubber band because Qt is configured without it."); | |||
|
126 | #endif | |||
122 | } |
|
127 | } | |
123 |
|
128 | |||
124 | /*! |
|
129 | /*! | |
@@ -135,6 +140,7 QChartView::RubberBands QChartView::rubberBand() const | |||||
135 | */ |
|
140 | */ | |
136 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
141 | void QChartView::mousePressEvent(QMouseEvent *event) | |
137 | { |
|
142 | { | |
|
143 | #ifndef QT_NO_RUBBERBAND | |||
138 | QRectF plotArea = d_ptr->m_chart->plotArea(); |
|
144 | QRectF plotArea = d_ptr->m_chart->plotArea(); | |
139 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() |
|
145 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() | |
140 | && event->button() == Qt::LeftButton && plotArea.contains(event->pos())) { |
|
146 | && event->button() == Qt::LeftButton && plotArea.contains(event->pos())) { | |
@@ -143,8 +149,11 void QChartView::mousePressEvent(QMouseEvent *event) | |||||
143 | d_ptr->m_rubberBand->show(); |
|
149 | d_ptr->m_rubberBand->show(); | |
144 | event->accept(); |
|
150 | event->accept(); | |
145 | } else { |
|
151 | } else { | |
|
152 | #endif | |||
146 | QGraphicsView::mousePressEvent(event); |
|
153 | QGraphicsView::mousePressEvent(event); | |
|
154 | #ifndef QT_NO_RUBBERBAND | |||
147 | } |
|
155 | } | |
|
156 | #endif | |||
148 | } |
|
157 | } | |
149 |
|
158 | |||
150 | /*! |
|
159 | /*! | |
@@ -153,6 +162,7 void QChartView::mousePressEvent(QMouseEvent *event) | |||||
153 | */ |
|
162 | */ | |
154 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
163 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
155 | { |
|
164 | { | |
|
165 | #ifndef QT_NO_RUBBERBAND | |||
156 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
166 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
157 | QRect rect = d_ptr->m_chart->plotArea().toRect(); |
|
167 | QRect rect = d_ptr->m_chart->plotArea().toRect(); | |
158 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
168 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
@@ -167,8 +177,11 void QChartView::mouseMoveEvent(QMouseEvent *event) | |||||
167 | } |
|
177 | } | |
168 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(), d_ptr->m_rubberBandOrigin.y(), width, height).normalized()); |
|
178 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(), d_ptr->m_rubberBandOrigin.y(), width, height).normalized()); | |
169 | } else { |
|
179 | } else { | |
|
180 | #endif | |||
170 | QGraphicsView::mouseMoveEvent(event); |
|
181 | QGraphicsView::mouseMoveEvent(event); | |
|
182 | #ifndef QT_NO_RUBBERBAND | |||
171 | } |
|
183 | } | |
|
184 | #endif | |||
172 | } |
|
185 | } | |
173 |
|
186 | |||
174 | /*! |
|
187 | /*! | |
@@ -178,6 +191,7 void QChartView::mouseMoveEvent(QMouseEvent *event) | |||||
178 | */ |
|
191 | */ | |
179 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
192 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
180 | { |
|
193 | { | |
|
194 | #ifndef QT_NO_RUBBERBAND | |||
181 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
195 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
182 | if (event->button() == Qt::LeftButton) { |
|
196 | if (event->button() == Qt::LeftButton) { | |
183 | d_ptr->m_rubberBand->hide(); |
|
197 | d_ptr->m_rubberBand->hide(); | |
@@ -217,8 +231,11 void QChartView::mouseReleaseEvent(QMouseEvent *event) | |||||
217 | event->accept(); |
|
231 | event->accept(); | |
218 | } |
|
232 | } | |
219 | } else { |
|
233 | } else { | |
|
234 | #endif | |||
220 | QGraphicsView::mouseReleaseEvent(event); |
|
235 | QGraphicsView::mouseReleaseEvent(event); | |
|
236 | #ifndef QT_NO_RUBBERBAND | |||
221 | } |
|
237 | } | |
|
238 | #endif | |||
222 | } |
|
239 | } | |
223 |
|
240 | |||
224 | /*! |
|
241 | /*! | |
@@ -236,7 +253,9 QChartViewPrivate::QChartViewPrivate(QChartView *q, QChart *chart) | |||||
236 | : q_ptr(q), |
|
253 | : q_ptr(q), | |
237 | m_scene(new QGraphicsScene(q)), |
|
254 | m_scene(new QGraphicsScene(q)), | |
238 | m_chart(chart), |
|
255 | m_chart(chart), | |
|
256 | #ifndef QT_NO_RUBBERBAND | |||
239 | m_rubberBand(0), |
|
257 | m_rubberBand(0), | |
|
258 | #endif | |||
240 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
259 | m_rubberBandFlags(QChartView::NoRubberBand) | |
241 | { |
|
260 | { | |
242 | q_ptr->setFrameShape(QFrame::NoFrame); |
|
261 | q_ptr->setFrameShape(QFrame::NoFrame); |
@@ -55,7 +55,9 public: | |||||
55 | QGraphicsScene *m_scene; |
|
55 | QGraphicsScene *m_scene; | |
56 | QChart *m_chart; |
|
56 | QChart *m_chart; | |
57 | QPoint m_rubberBandOrigin; |
|
57 | QPoint m_rubberBandOrigin; | |
|
58 | #ifndef QT_NO_RUBBERBAND | |||
58 | QRubberBand *m_rubberBand; |
|
59 | QRubberBand *m_rubberBand; | |
|
60 | #endif | |||
59 | QChartView::RubberBands m_rubberBandFlags; |
|
61 | QChartView::RubberBands m_rubberBandFlags; | |
60 | }; |
|
62 | }; | |
61 |
|
63 |
General Comments 0
You need to be logged in to leave comments.
Login now