Mercurial > hg > easyhg
comparison src/panner.cpp @ 400:07eaf4e6003a
Merge from branch "item_appearance_adjustments"
author | Chris Cannam |
---|---|
date | Wed, 25 May 2011 14:59:09 +0100 |
parents | 496f2042155a |
children | 533519ebc0cb |
comparison
equal
deleted
inserted
replaced
385:5cc0d897eb26 | 400:07eaf4e6003a |
---|---|
30 public: | 30 public: |
31 friend class Panner; | 31 friend class Panner; |
32 }; | 32 }; |
33 | 33 |
34 Panner::Panner() : | 34 Panner::Panner() : |
35 m_clicked(false) | 35 m_clicked(false), |
36 m_moved(false) | |
36 { | 37 { |
37 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 38 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
38 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 39 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
39 setOptimizationFlags(QGraphicsView::DontSavePainterState | | 40 setOptimizationFlags(QGraphicsView::DontSavePainterState | |
40 QGraphicsView::IndirectPainting); | 41 QGraphicsView::IndirectPainting); |
207 if (e->button() != Qt::LeftButton) { | 208 if (e->button() != Qt::LeftButton) { |
208 QGraphicsView::mouseDoubleClickEvent(e); | 209 QGraphicsView::mouseDoubleClickEvent(e); |
209 return; | 210 return; |
210 } | 211 } |
211 m_clicked = true; | 212 m_clicked = true; |
213 m_moved = false; | |
212 m_clickedRect = m_pannedRect; | 214 m_clickedRect = m_pannedRect; |
213 m_clickedPoint = e->pos(); | 215 m_clickedPoint = e->pos(); |
214 } | 216 } |
215 | 217 |
216 void | 218 void |
229 { | 231 { |
230 if (!m_clicked) return; | 232 if (!m_clicked) return; |
231 QPointF cp = mapToScene(m_clickedPoint); | 233 QPointF cp = mapToScene(m_clickedPoint); |
232 QPointF mp = mapToScene(e->pos()); | 234 QPointF mp = mapToScene(e->pos()); |
233 QPointF delta = mp - cp; | 235 QPointF delta = mp - cp; |
236 if (!m_moved) { | |
237 if ((m_clickedPoint - e->pos()).manhattanLength() > 2) { | |
238 m_moved = true; | |
239 } else { | |
240 return; | |
241 } | |
242 } | |
234 QRectF nr = m_clickedRect; | 243 QRectF nr = m_clickedRect; |
235 nr.translate(delta); | 244 nr.translate(delta); |
236 m_pannedRect = nr; | 245 m_pannedRect = nr; |
237 emit pannedRectChanged(m_pannedRect); | 246 emit pannedRectChanged(m_pannedRect); |
238 viewport()->update(); | 247 viewport()->update(); |
245 QGraphicsView::mouseDoubleClickEvent(e); | 254 QGraphicsView::mouseDoubleClickEvent(e); |
246 return; | 255 return; |
247 } | 256 } |
248 | 257 |
249 if (m_clicked) { | 258 if (m_clicked) { |
250 mouseMoveEvent(e); | 259 if (m_moved) { |
260 mouseMoveEvent(e); | |
261 } else { | |
262 moveTo(e->pos()); | |
263 } | |
251 } | 264 } |
252 | 265 |
253 m_clicked = false; | 266 m_clicked = false; |
254 viewport()->update(); | 267 viewport()->update(); |
255 } | 268 } |
274 void | 287 void |
275 Panner::moveTo(QPoint p) | 288 Panner::moveTo(QPoint p) |
276 { | 289 { |
277 QPointF sp = mapToScene(p); | 290 QPointF sp = mapToScene(p); |
278 QRectF nr = m_pannedRect; | 291 QRectF nr = m_pannedRect; |
279 double d = sp.x() - nr.center().x(); | 292 double dx = sp.x() - nr.center().x(); |
280 nr.translate(d, 0); | 293 double dy = sp.y() - nr.center().y(); |
294 nr.translate(dx, dy); | |
281 slotSetPannedRect(nr); | 295 slotSetPannedRect(nr); |
282 emit pannedRectChanged(m_pannedRect); | 296 emit pannedRectChanged(m_pannedRect); |
283 viewport()->update(); | 297 viewport()->update(); |
284 } | 298 } |
285 | 299 |