Qt 4.8
qdeclarativeflickable.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativeflickable_p.h"
43 #include "private/qdeclarativeflickable_p_p.h"
44 #include <qdeclarativeinfo.h>
45 #include <QGraphicsSceneMouseEvent>
46 #include <QPointer>
47 #include <QTimer>
48 #include "qplatformdefs.h"
49 
51 
52 // The maximum number of pixels a flick can overshoot
53 #ifndef QML_FLICK_OVERSHOOT
54 #define QML_FLICK_OVERSHOOT 200
55 #endif
56 
57 // The number of samples to use in calculating the velocity of a flick
58 #ifndef QML_FLICK_SAMPLEBUFFER
59 #define QML_FLICK_SAMPLEBUFFER 3
60 #endif
61 
62 // The number of samples to discard when calculating the flick velocity.
63 // Touch panels often produce inaccurate results as the finger is lifted.
64 #ifndef QML_FLICK_DISCARDSAMPLES
65 #define QML_FLICK_DISCARDSAMPLES 1
66 #endif
67 
68 // The default maximum velocity of a flick.
69 #ifndef QML_FLICK_DEFAULTMAXVELOCITY
70 #define QML_FLICK_DEFAULTMAXVELOCITY 2500
71 #endif
72 
73 // The default deceleration of a flick.
74 #ifndef QML_FLICK_DEFAULTDECELERATION
75 #define QML_FLICK_DEFAULTDECELERATION 1750
76 #endif
77 
78 // How much faster to decelerate when overshooting
79 #ifndef QML_FLICK_OVERSHOOTFRICTION
80 #define QML_FLICK_OVERSHOOTFRICTION 8
81 #endif
82 
83 // FlickThreshold determines how far the "mouse" must have moved
84 // before we perform a flick.
85 static const int FlickThreshold = 20;
86 
87 // RetainGrabVelocity is the maxmimum instantaneous velocity that
88 // will ensure the Flickable retains the grab on consecutive flicks.
89 static const int RetainGrabVelocity = 15;
90 
92  : QObject(parent), flickable(parent), m_xPosition(0.), m_widthRatio(0.)
93  , m_yPosition(0.), m_heightRatio(0.)
94 {
95 }
96 
98 {
99  return m_widthRatio;
100 }
101 
103 {
104  return m_xPosition;
105 }
106 
108 {
109  return m_heightRatio;
110 }
111 
113 {
114  return m_yPosition;
115 }
116 
118 {
120 
121  bool changeX = false;
122  bool changeY = false;
123  bool changeWidth = false;
124  bool changeHeight = false;
125 
126  // Vertical
127  const qreal viewheight = flickable->height();
128  const qreal maxyextent = -flickable->maxYExtent() + flickable->minYExtent();
129  qreal pagePos = (-p->vData.move.value() + flickable->minYExtent()) / (maxyextent + viewheight);
130  qreal pageSize = viewheight / (maxyextent + viewheight);
131 
132  if (pageSize != m_heightRatio) {
133  m_heightRatio = pageSize;
134  changeHeight = true;
135  }
136  if (pagePos != m_yPosition) {
137  m_yPosition = pagePos;
138  changeY = true;
139  }
140 
141  // Horizontal
142  const qreal viewwidth = flickable->width();
143  const qreal maxxextent = -flickable->maxXExtent() + flickable->minXExtent();
144  pagePos = (-p->hData.move.value() + flickable->minXExtent()) / (maxxextent + viewwidth);
145  pageSize = viewwidth / (maxxextent + viewwidth);
146 
147  if (pageSize != m_widthRatio) {
148  m_widthRatio = pageSize;
149  changeWidth = true;
150  }
151  if (pagePos != m_xPosition) {
152  m_xPosition = pagePos;
153  changeX = true;
154  }
155 
156  if (changeX)
158  if (changeY)
160  if (changeWidth)
162  if (changeHeight)
164 }
165 
166 
168  : contentItem(new QDeclarativeItem)
169  , hData(this, &QDeclarativeFlickablePrivate::setRoundedViewportX)
170  , vData(this, &QDeclarativeFlickablePrivate::setRoundedViewportY)
171  , hMoved(false), vMoved(false)
172  , stealMouse(false), pressed(false), interactive(true), calcVelocity(false)
173  , deceleration(QML_FLICK_DEFAULTDECELERATION)
174  , maxVelocity(QML_FLICK_DEFAULTMAXVELOCITY), reportedVelocitySmoothing(100)
175  , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0), fixupDuration(400)
176  , fixupMode(Normal), vTime(0), visibleArea(0)
177  , flickableDirection(QDeclarativeFlickable::AutoFlickDirection)
178  , boundsBehavior(QDeclarativeFlickable::DragAndOvershootBounds)
179 {
180 }
181 
183 {
187  static int timelineUpdatedIdx = -1;
188  static int timelineCompletedIdx = -1;
189  static int flickableTickedIdx = -1;
190  static int flickableMovementEndingIdx = -1;
191  if (timelineUpdatedIdx == -1) {
192  timelineUpdatedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("updated()");
193  timelineCompletedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("completed()");
194  flickableTickedIdx = QDeclarativeFlickable::staticMetaObject.indexOfSlot("ticked()");
195  flickableMovementEndingIdx = QDeclarativeFlickable::staticMetaObject.indexOfSlot("movementEnding()");
196  }
197  QMetaObject::connect(&timeline, timelineUpdatedIdx,
198  q, flickableTickedIdx, Qt::DirectConnection);
199  QMetaObject::connect(&timeline, timelineCompletedIdx,
200  q, flickableMovementEndingIdx, Qt::DirectConnection);
201  q->setAcceptedMouseButtons(Qt::LeftButton);
202  q->setFiltersChildEvents(true);
206 }
207 
208 /*
209  Returns the amount to overshoot by given a view size.
210  Will be up to the lesser of 1/3 of the view size or QML_FLICK_OVERSHOOT
211 */
213 {
214  if (maxVelocity <= 0)
215  return 0.0;
216 
217  return qMin(qreal(QML_FLICK_OVERSHOOT), size/3);
218 }
219 
221 {
222  if (v > maxVelocity)
223  v = maxVelocity;
224  else if (v < -maxVelocity)
225  v = -maxVelocity;
226  velocityBuffer.append(v);
227  if (velocityBuffer.count() > QML_FLICK_SAMPLEBUFFER)
228  velocityBuffer.remove(0);
229 }
230 
232 {
233  velocity = 0;
234  if (velocityBuffer.count() > QML_FLICK_DISCARDSAMPLES) {
235  int count = velocityBuffer.count()-QML_FLICK_DISCARDSAMPLES;
236  for (int i = 0; i < count; ++i) {
237  qreal v = velocityBuffer.at(i);
238  velocity += v;
239  }
240  velocity /= count;
241  }
242 }
243 
245 {
247  if (item == contentItem) {
248  if (newGeom.x() != oldGeom.x())
249  emit q->contentXChanged();
250  if (newGeom.y() != oldGeom.y())
251  emit q->contentYChanged();
252  }
253 }
254 
256 {
258  flick(hData, q->minXExtent(), q->maxXExtent(), q->width(), fixupX_callback, velocity);
259 }
260 
262 {
264  flick(vData, q->minYExtent(), q->maxYExtent(), q->height(), fixupY_callback, velocity);
265 }
266 
268  QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
269 {
271  qreal maxDistance = -1;
272  data.fixingUp = false;
273  // -ve velocity means list is moving up
274  if (velocity > 0) {
275  maxDistance = qAbs(minExtent - data.move.value());
276  data.flickTarget = minExtent;
277  } else {
278  maxDistance = qAbs(maxExtent - data.move.value());
279  data.flickTarget = maxExtent;
280  }
281  if (maxDistance > 0) {
282  qreal v = velocity;
283  if (maxVelocity != -1 && maxVelocity < qAbs(v)) {
284  if (v < 0)
285  v = -maxVelocity;
286  else
287  v = maxVelocity;
288  }
289  timeline.reset(data.move);
291  timeline.accel(data.move, v, deceleration);
292  else
293  timeline.accel(data.move, v, deceleration, maxDistance);
294  timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
295  if (!hData.flicking && q->xflick()) {
296  hData.flicking = true;
297  emit q->flickingChanged();
298  emit q->flickingHorizontallyChanged();
299  if (!vData.flicking)
300  emit q->flickStarted();
301  }
302  if (!vData.flicking && q->yflick()) {
303  vData.flicking = true;
304  emit q->flickingChanged();
305  emit q->flickingVerticallyChanged();
306  if (!hData.flicking)
307  emit q->flickStarted();
308  }
309  } else {
310  timeline.reset(data.move);
311  fixup(data, minExtent, maxExtent);
312  }
313 }
314 
316 {
317  ((QDeclarativeFlickablePrivate *)data)->fixupY();
318 }
319 
321 {
322  ((QDeclarativeFlickablePrivate *)data)->fixupX();
323 }
324 
326 {
328  fixup(hData, q->minXExtent(), q->maxXExtent());
329 }
330 
332 {
334  fixup(vData, q->minYExtent(), q->maxYExtent());
335 }
336 
338 {
339  if (data.move.value() > minExtent || maxExtent > minExtent) {
340  timeline.reset(data.move);
341  if (data.move.value() != minExtent) {
342  switch (fixupMode) {
343  case Immediate:
344  timeline.set(data.move, minExtent);
345  break;
346  case ExtentChanged:
347  // The target has changed. Don't start from the beginning; just complete the
348  // second half of the animation using the new extent.
350  data.fixingUp = true;
351  break;
352  default: {
353  qreal dist = minExtent - data.move;
354  timeline.move(data.move, minExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4);
356  data.fixingUp = true;
357  }
358  }
359  }
360  } else if (data.move.value() < maxExtent) {
361  timeline.reset(data.move);
362  switch (fixupMode) {
363  case Immediate:
364  timeline.set(data.move, maxExtent);
365  break;
366  case ExtentChanged:
367  // The target has changed. Don't start from the beginning; just complete the
368  // second half of the animation using the new extent.
370  data.fixingUp = true;
371  break;
372  default: {
373  qreal dist = maxExtent - data.move;
374  timeline.move(data.move, maxExtent - dist/2, QEasingCurve(QEasingCurve::InQuad), fixupDuration/4);
376  data.fixingUp = true;
377  }
378  }
379  }
380  data.inOvershoot = false;
381  fixupMode = Normal;
382  vTime = timeline.time();
383 }
384 
386 {
388  bool atBoundaryChange = false;
389 
390  // Vertical
391  const int maxyextent = int(-q->maxYExtent());
392  const qreal ypos = -vData.move.value();
393  bool atBeginning = (ypos <= -q->minYExtent());
394  bool atEnd = (maxyextent <= ypos);
395 
396  if (atBeginning != vData.atBeginning) {
397  vData.atBeginning = atBeginning;
398  atBoundaryChange = true;
399  }
400  if (atEnd != vData.atEnd) {
401  vData.atEnd = atEnd;
402  atBoundaryChange = true;
403  }
404 
405  // Horizontal
406  const int maxxextent = int(-q->maxXExtent());
407  const qreal xpos = -hData.move.value();
408  atBeginning = (xpos <= -q->minXExtent());
409  atEnd = (maxxextent <= xpos);
410 
411  if (atBeginning != hData.atBeginning) {
412  hData.atBeginning = atBeginning;
413  atBoundaryChange = true;
414  }
415  if (atEnd != hData.atEnd) {
416  hData.atEnd = atEnd;
417  atBoundaryChange = true;
418  }
419 
420  if (atBoundaryChange)
421  emit q->isAtBoundaryChanged();
422 
423  if (visibleArea)
425 }
426 
549 {
551  d->init();
552 }
553 
555  : QDeclarativeItem(dd, parent)
556 {
558  d->init();
559 }
560 
562 {
563 }
564 
577 {
578  Q_D(const QDeclarativeFlickable);
579  return -d->contentItem->x();
580 }
581 
583 {
585  d->timeline.reset(d->hData.move);
586  d->vTime = d->timeline.time();
587  movementXEnding();
588  if (-pos != d->hData.move.value()) {
589  d->hData.move.setValue(-pos);
590  viewportMoved();
591  }
592 }
593 
595 {
596  Q_D(const QDeclarativeFlickable);
597  return -d->contentItem->y();
598 }
599 
601 {
603  d->timeline.reset(d->vData.move);
604  d->vTime = d->timeline.time();
605  movementYEnding();
606  if (-pos != d->vData.move.value()) {
607  d->vData.move.setValue(-pos);
608  viewportMoved();
609  }
610 }
611 
629 {
630  Q_D(const QDeclarativeFlickable);
631  return d->interactive;
632 }
633 
635 {
637  if (interactive != d->interactive) {
638  d->interactive = interactive;
639  if (!interactive && (d->hData.flicking || d->vData.flicking)) {
640  d->timeline.clear();
641  d->vTime = d->timeline.time();
642  d->hData.flicking = false;
643  d->vData.flicking = false;
647  emit flickEnded();
648  }
650  }
651 }
652 
665 {
666  Q_D(const QDeclarativeFlickable);
667  return d->hData.smoothVelocity.value();
668 }
669 
671 {
672  Q_D(const QDeclarativeFlickable);
673  return d->vData.smoothVelocity.value();
674 }
675 
689 {
690  Q_D(const QDeclarativeFlickable);
691  return d->hData.atEnd;
692 }
693 
695 {
696  Q_D(const QDeclarativeFlickable);
697  return d->hData.atBeginning;
698 }
699 
701 {
702  Q_D(const QDeclarativeFlickable);
703  return d->vData.atEnd;
704 }
705 
707 {
708  Q_D(const QDeclarativeFlickable);
709  return d->vData.atBeginning;
710 }
711 
713 {
714  viewportMoved();
715 }
716 
739 {
741  return d->contentItem;
742 }
743 
745 {
747  if (!d->visibleArea)
748  d->visibleArea = new QDeclarativeFlickableVisibleArea(this);
749  return d->visibleArea;
750 }
751 
771 {
772  Q_D(const QDeclarativeFlickable);
773  return d->flickableDirection;
774 }
775 
777 {
779  if (direction != d->flickableDirection) {
780  d->flickableDirection = direction;
782  }
783 }
784 
786 {
788  if (interactive && timeline.isActive()
789  && (qAbs(hData.smoothVelocity.value()) > RetainGrabVelocity || qAbs(vData.smoothVelocity.value()) > RetainGrabVelocity))
790  stealMouse = true; // If we've been flicked then steal the click.
791  else
792  stealMouse = false;
793  q->setKeepMouseGrab(stealMouse);
794  pressed = true;
795  timeline.clear();
796  hData.reset();
797  vData.reset();
798  hData.dragMinBound = q->minXExtent();
799  vData.dragMinBound = q->minYExtent();
800  hData.dragMaxBound = q->maxXExtent();
801  vData.dragMaxBound = q->maxYExtent();
802  fixupMode = Normal;
803  lastPos = QPoint();
804  QDeclarativeItemPrivate::start(lastPosTime);
805  pressPos = event->pos();
806  hData.pressPos = hData.move.value();
807  vData.pressPos = vData.move.value();
808  hData.flicking = false;
809  vData.flicking = false;
811  QDeclarativeItemPrivate::start(velocityTime);
812 }
813 
815 {
817  if (!interactive || !lastPosTime.isValid())
818  return;
819  bool rejectY = false;
820  bool rejectX = false;
821 
822  bool stealY = stealMouse;
823  bool stealX = stealMouse;
824 
825  if (q->yflick()) {
826  int dy = int(event->pos().y() - pressPos.y());
828  if (!vMoved)
829  vData.dragStartOffset = dy;
830  qreal newY = dy + vData.pressPos - vData.dragStartOffset;
831  const qreal minY = vData.dragMinBound;
832  const qreal maxY = vData.dragMaxBound;
833  if (newY > minY)
834  newY = minY + (newY - minY) / 2;
835  if (newY < maxY && maxY - minY <= 0)
836  newY = maxY + (newY - maxY) / 2;
837  if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newY <= maxY) {
838  newY = maxY;
839  rejectY = vData.pressPos == maxY && dy < 0;
840  }
841  if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newY >= minY) {
842  newY = minY;
843  rejectY = vData.pressPos == minY && dy > 0;
844  }
845  if (!rejectY && stealMouse && dy != 0) {
846  vData.move.setValue(qRound(newY));
847  vMoved = true;
848  }
849  if (!rejectY && qAbs(dy) > QApplication::startDragDistance())
850  stealY = true;
851  }
852  }
853 
854  if (q->xflick()) {
855  int dx = int(event->pos().x() - pressPos.x());
857  if (!hMoved)
858  hData.dragStartOffset = dx;
859  qreal newX = dx + hData.pressPos - hData.dragStartOffset;
860  const qreal minX = hData.dragMinBound;
861  const qreal maxX = hData.dragMaxBound;
862  if (newX > minX)
863  newX = minX + (newX - minX) / 2;
864  if (newX < maxX && maxX - minX <= 0)
865  newX = maxX + (newX - maxX) / 2;
866  if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newX <= maxX) {
867  newX = maxX;
868  rejectX = hData.pressPos == maxX && dx < 0;
869  }
870  if (boundsBehavior == QDeclarativeFlickable::StopAtBounds && newX >= minX) {
871  newX = minX;
872  rejectX = hData.pressPos == minX && dx > 0;
873  }
874  if (!rejectX && stealMouse && dx != 0) {
875  hData.move.setValue(qRound(newX));
876  hMoved = true;
877  }
878 
879  if (!rejectX && qAbs(dx) > QApplication::startDragDistance())
880  stealX = true;
881  }
882  }
883 
884  stealMouse = stealX || stealY;
885  if (stealMouse)
886  q->setKeepMouseGrab(true);
887 
888  if (rejectY) {
889  vData.velocityBuffer.clear();
890  vData.velocity = 0;
891  }
892  if (rejectX) {
893  hData.velocityBuffer.clear();
894  hData.velocity = 0;
895  }
896 
897  if (hMoved || vMoved) {
898  q->movementStarting();
899  q->viewportMoved();
900  }
901 
902  if (!lastPos.isNull()) {
903  qreal elapsed = qreal(QDeclarativeItemPrivate::elapsed(lastPosTime)) / 1000.;
904  if (elapsed <= 0)
905  return;
907  qreal dy = event->pos().y()-lastPos.y();
908  if (q->yflick() && !rejectY)
909  vData.addVelocitySample(dy/elapsed, maxVelocity);
910  qreal dx = event->pos().x()-lastPos.x();
911  if (q->xflick() && !rejectX)
912  hData.addVelocitySample(dx/elapsed, maxVelocity);
913  }
914 
915  lastPos = event->pos();
916 }
917 
919 {
921  stealMouse = false;
922  q->setKeepMouseGrab(false);
923  pressed = false;
924  if (!lastPosTime.isValid())
925  return;
926 
927  // if we drag then pause before release we should not cause a flick.
929 
930  vData.updateVelocity();
931  hData.updateVelocity();
932  vTime = timeline.time();
933 
934  qreal velocity = elapsed < 100 ? vData.velocity : 0;
935  if (vData.atBeginning || vData.atEnd)
936  velocity /= 2;
937  if (q->yflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) {
938  velocityTimeline.reset(vData.smoothVelocity);
939  vData.smoothVelocity.setValue(-velocity);
940  flickY(velocity);
941  } else {
942  fixupY();
943  }
944 
945  velocity = elapsed < 100 ? hData.velocity : 0;
946  if (hData.atBeginning || hData.atEnd)
947  velocity /= 2;
948  if (q->xflick() && qAbs(velocity) > MinimumFlickVelocity && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) {
949  velocityTimeline.reset(hData.smoothVelocity);
950  hData.smoothVelocity.setValue(-velocity);
951  flickX(velocity);
952  } else {
953  fixupX();
954  }
955 
956  if (!timeline.isActive())
957  q->movementEnding();
958 }
959 
961 {
963  if (d->interactive) {
964  if (!d->pressed)
965  d->handleMousePressEvent(event);
966  event->accept();
967  } else {
969  }
970 }
971 
973 {
975  if (d->interactive) {
976  d->handleMouseMoveEvent(event);
977  event->accept();
978  } else {
980  }
981 }
982 
984 {
986  if (d->interactive) {
987  d->clearDelayedPress();
988  d->handleMouseReleaseEvent(event);
989  event->accept();
990  ungrabMouse();
991  } else {
993  }
994 }
995 
997 {
999  if (!d->interactive) {
1001  } else if (yflick() && event->orientation() == Qt::Vertical) {
1002  bool valid = false;
1003  if (event->delta() > 0 && contentY() > -minYExtent()) {
1004  d->vData.velocity = qMax(event->delta()*2 - d->vData.smoothVelocity.value(), qreal(d->maxVelocity/4));
1005  valid = true;
1006  } else if (event->delta() < 0 && contentY() < -maxYExtent()) {
1007  d->vData.velocity = qMin(event->delta()*2 - d->vData.smoothVelocity.value(), qreal(-d->maxVelocity/4));
1008  valid = true;
1009  }
1010  if (valid) {
1011  d->vData.flicking = false;
1012  d->flickY(d->vData.velocity);
1013  if (d->vData.flicking) {
1014  d->vMoved = true;
1015  movementStarting();
1016  }
1017  event->accept();
1018  }
1019  } else if (xflick() && event->orientation() == Qt::Horizontal) {
1020  bool valid = false;
1021  if (event->delta() > 0 && contentX() > -minXExtent()) {
1022  d->hData.velocity = qMax(event->delta()*2 - d->hData.smoothVelocity.value(), qreal(d->maxVelocity/4));
1023  valid = true;
1024  } else if (event->delta() < 0 && contentX() < -maxXExtent()) {
1025  d->hData.velocity = qMin(event->delta()*2 - d->hData.smoothVelocity.value(), qreal(-d->maxVelocity/4));
1026  valid = true;
1027  }
1028  if (valid) {
1029  d->hData.flicking = false;
1030  d->flickX(d->hData.velocity);
1031  if (d->hData.flicking) {
1032  d->hMoved = true;
1033  movementStarting();
1034  }
1035  event->accept();
1036  }
1037  } else {
1039  }
1040 }
1041 
1043 {
1044  Q_Q(const QDeclarativeFlickable);
1045  QDeclarativeItem *item = q->parentItem();
1046  while (item) {
1048  if (flick && flick->pressDelay() > 0 && flick->isInteractive())
1049  return false;
1050  item = item->parentItem();
1051  }
1052 
1053  return true;
1054 }
1055 
1057 {
1059  if (!q->scene() || pressDelay <= 0)
1060  return;
1061  if (!isOutermostPressDelay())
1062  return;
1063  delayedPressTarget = q->scene()->mouseGrabberItem();
1064  delayedPressEvent = new QGraphicsSceneMouseEvent(event->type());
1065  delayedPressEvent->setAccepted(false);
1066  for (int i = 0x1; i <= 0x10; i <<= 1) {
1067  if (event->buttons() & i) {
1068  Qt::MouseButton button = Qt::MouseButton(i);
1069  delayedPressEvent->setButtonDownPos(button, event->buttonDownPos(button));
1070  delayedPressEvent->setButtonDownScenePos(button, event->buttonDownScenePos(button));
1071  delayedPressEvent->setButtonDownScreenPos(button, event->buttonDownScreenPos(button));
1072  }
1073  }
1074  delayedPressEvent->setButtons(event->buttons());
1075  delayedPressEvent->setButton(event->button());
1076  delayedPressEvent->setPos(event->pos());
1077  delayedPressEvent->setScenePos(event->scenePos());
1078  delayedPressEvent->setScreenPos(event->screenPos());
1079  delayedPressEvent->setLastPos(event->lastPos());
1080  delayedPressEvent->setLastScenePos(event->lastScenePos());
1081  delayedPressEvent->setLastScreenPos(event->lastScreenPos());
1082  delayedPressEvent->setModifiers(event->modifiers());
1083  delayedPressTimer.start(pressDelay, q);
1084 }
1085 
1087 {
1088  if (delayedPressEvent) {
1089  delayedPressTimer.stop();
1090  delete delayedPressEvent;
1091  delayedPressEvent = 0;
1092  }
1093 }
1094 
1096 {
1097  contentItem->setX(qRound(x));
1098 }
1099 
1101 {
1102  contentItem->setY(qRound(y));
1103 }
1104 
1106 {
1108  if (event->timerId() == d->delayedPressTimer.timerId()) {
1109  d->delayedPressTimer.stop();
1110  if (d->delayedPressEvent) {
1112  if (!grabber || grabber != this) {
1113  // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay)
1114  // so we reset the grabber
1115  if (scene()->mouseGrabberItem() == d->delayedPressTarget)
1116  d->delayedPressTarget->ungrabMouse();
1117  //Use the event handler that will take care of finding the proper item to propagate the event
1118  QApplication::postEvent(scene(), d->delayedPressEvent);
1119  } else {
1120  delete d->delayedPressEvent;
1121  }
1122  d->delayedPressEvent = 0;
1123  }
1124  }
1125 }
1126 
1128 {
1129  return 0.0;
1130 }
1131 
1133 {
1134  return 0.0;
1135 }
1136 
1137 /* returns -ve */
1139 {
1140  return width() - vWidth();
1141 }
1142 /* returns -ve */
1144 {
1145  return height() - vHeight();
1146 }
1147 
1149 {
1151 
1152  qreal prevX = d->lastFlickablePosition.x();
1153  qreal prevY = d->lastFlickablePosition.y();
1154  if (d->pressed || d->calcVelocity) {
1155  int elapsed = QDeclarativeItemPrivate::restart(d->velocityTime);
1156  if (elapsed > 0) {
1157  qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / elapsed;
1158  if (qAbs(horizontalVelocity) > 0) {
1159  d->velocityTimeline.reset(d->hData.smoothVelocity);
1160  d->velocityTimeline.move(d->hData.smoothVelocity, horizontalVelocity, d->reportedVelocitySmoothing);
1161  d->velocityTimeline.move(d->hData.smoothVelocity, 0, d->reportedVelocitySmoothing);
1162  }
1163  qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / elapsed;
1164  if (qAbs(verticalVelocity) > 0) {
1165  d->velocityTimeline.reset(d->vData.smoothVelocity);
1166  d->velocityTimeline.move(d->vData.smoothVelocity, verticalVelocity, d->reportedVelocitySmoothing);
1167  d->velocityTimeline.move(d->vData.smoothVelocity, 0, d->reportedVelocitySmoothing);
1168  }
1169  }
1170  } else {
1171  if (d->timeline.time() > d->vTime) {
1172  d->velocityTimeline.clear();
1173  qreal horizontalVelocity = (prevX - d->hData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
1174  qreal verticalVelocity = (prevY - d->vData.move.value()) * 1000 / (d->timeline.time() - d->vTime);
1175  d->hData.smoothVelocity.setValue(horizontalVelocity);
1176  d->vData.smoothVelocity.setValue(verticalVelocity);
1177  }
1178  }
1179 
1180  if (!d->vData.inOvershoot && !d->vData.fixingUp && d->vData.flicking
1181  && (d->vData.move.value() > minYExtent() || d->vData.move.value() < maxYExtent())
1182  && qAbs(d->vData.smoothVelocity.value()) > 100) {
1183  // Increase deceleration if we've passed a bound
1184  d->vData.inOvershoot = true;
1185  qreal maxDistance = d->overShootDistance(height());
1186  d->timeline.reset(d->vData.move);
1187  d->timeline.accel(d->vData.move, -d->vData.smoothVelocity.value(), d->deceleration*QML_FLICK_OVERSHOOTFRICTION, maxDistance);
1188  d->timeline.callback(QDeclarativeTimeLineCallback(&d->vData.move, d->fixupY_callback, d));
1189  }
1190  if (!d->hData.inOvershoot && !d->hData.fixingUp && d->hData.flicking
1191  && (d->hData.move.value() > minXExtent() || d->hData.move.value() < maxXExtent())
1192  && qAbs(d->hData.smoothVelocity.value()) > 100) {
1193  // Increase deceleration if we've passed a bound
1194  d->hData.inOvershoot = true;
1195  qreal maxDistance = d->overShootDistance(width());
1196  d->timeline.reset(d->hData.move);
1197  d->timeline.accel(d->hData.move, -d->hData.smoothVelocity.value(), d->deceleration*QML_FLICK_OVERSHOOTFRICTION, maxDistance);
1198  d->timeline.callback(QDeclarativeTimeLineCallback(&d->hData.move, d->fixupX_callback, d));
1199  }
1200 
1201  d->lastFlickablePosition = QPointF(d->hData.move.value(), d->vData.move.value());
1202 
1203  d->vTime = d->timeline.time();
1204  d->updateBeginningEnd();
1205 }
1206 
1208  const QRectF &oldGeometry)
1209 {
1211  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
1212 
1213  bool changed = false;
1214  if (newGeometry.width() != oldGeometry.width()) {
1215  if (xflick())
1216  changed = true;
1217  if (d->hData.viewSize < 0) {
1218  d->contentItem->setWidth(width());
1220  }
1221  // Make sure that we're entirely in view.
1222  if (!d->pressed && !d->hData.moving && !d->vData.moving) {
1224  d->fixupX();
1225  }
1226  }
1227  if (newGeometry.height() != oldGeometry.height()) {
1228  if (yflick())
1229  changed = true;
1230  if (d->vData.viewSize < 0) {
1231  d->contentItem->setHeight(height());
1233  }
1234  // Make sure that we're entirely in view.
1235  if (!d->pressed && !d->hData.moving && !d->vData.moving) {
1237  d->fixupY();
1238  }
1239  }
1240 
1241  if (changed)
1242  d->updateBeginningEnd();
1243 }
1244 
1246 {
1248  d->timeline.reset(d->hData.move);
1249  d->timeline.reset(d->vData.move);
1250  movementEnding();
1251 }
1252 
1254 {
1256  if (i) {
1258  if (static_cast<QDeclarativeItemPrivate*>(d)->componentComplete) {
1259  i->setParentItem(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem);
1260  } else {
1261  d->setParentItemHelper(static_cast<QDeclarativeFlickablePrivate*>(prop->data)->contentItem, 0, 0);
1262  }
1263  } else {
1264  o->setParent(prop->object);
1265  }
1266 }
1267 
1269 {
1270  QDeclarativeItem *contentItem= static_cast<QDeclarativeFlickablePrivate*>(property->data)->contentItem;
1271  return contentItem->childItems().count() + contentItem->children().count();
1272 }
1273 
1275 {
1276  QDeclarativeItem *contentItem = static_cast<QDeclarativeFlickablePrivate*>(property->data)->contentItem;
1277 
1278  int childItemCount = contentItem->childItems().count();
1279 
1280  if (index < 0)
1281  return 0;
1282 
1283  if (index < childItemCount) {
1284  return contentItem->childItems().at(index)->toGraphicsObject();
1285  } else {
1286  return contentItem->children().at(index - childItemCount);
1287  }
1288 
1289  return 0;
1290 }
1291 
1293 {
1294  QDeclarativeItem *contentItem = static_cast<QDeclarativeFlickablePrivate*>(property->data)->contentItem;
1295 
1296  const QList<QGraphicsItem*> graphicsItems = contentItem->childItems();
1297  for (int i = 0; i < graphicsItems.count(); i++)
1298  contentItem->scene()->removeItem(graphicsItems[i]);
1299 
1300  const QList<QObject*> objects = contentItem->children();
1301  for (int i = 0; i < objects.count(); i++)
1302  objects[i]->setParent(0);
1303 }
1304 
1306 {
1312 }
1313 
1315 {
1317  return QGraphicsItemPrivate::get(d->contentItem)->childrenList();
1318 }
1319 
1345 {
1346  Q_D(const QDeclarativeFlickable);
1347  return d->boundsBehavior;
1348 }
1349 
1351 {
1353  if (b == d->boundsBehavior)
1354  return;
1355  d->boundsBehavior = b;
1357 }
1358 
1380 {
1381  Q_D(const QDeclarativeFlickable);
1382  return d->hData.viewSize;
1383 }
1384 
1386 {
1388  if (d->hData.viewSize == w)
1389  return;
1390  d->hData.viewSize = w;
1391  if (w < 0)
1392  d->contentItem->setWidth(width());
1393  else
1394  d->contentItem->setWidth(w);
1395  // Make sure that we're entirely in view.
1396  if (!d->pressed && !d->hData.moving && !d->vData.moving) {
1398  d->fixupX();
1399  } else if (!d->pressed && d->hData.fixingUp) {
1401  d->fixupX();
1402  }
1404  d->updateBeginningEnd();
1405 }
1406 
1408 {
1409  Q_D(const QDeclarativeFlickable);
1410  return d->vData.viewSize;
1411 }
1412 
1414 {
1416  if (d->vData.viewSize == h)
1417  return;
1418  d->vData.viewSize = h;
1419  if (h < 0)
1420  d->contentItem->setHeight(height());
1421  else
1422  d->contentItem->setHeight(h);
1423  // Make sure that we're entirely in view.
1424  if (!d->pressed && !d->hData.moving && !d->vData.moving) {
1426  d->fixupY();
1427  } else if (!d->pressed && d->vData.fixingUp) {
1429  d->fixupY();
1430  }
1432  d->updateBeginningEnd();
1433 }
1434 
1453 {
1455  if (w != d->hData.viewSize) {
1456  qreal oldSize = d->hData.viewSize;
1457  d->hData.viewSize = w;
1458  d->contentItem->setWidth(w);
1460  if (center.x() != 0) {
1461  qreal pos = center.x() * w / oldSize;
1462  setContentX(contentX() + pos - center.x());
1463  }
1464  }
1465  if (h != d->vData.viewSize) {
1466  qreal oldSize = d->vData.viewSize;
1467  d->vData.viewSize = h;
1468  d->contentItem->setHeight(h);
1470  if (center.y() != 0) {
1471  qreal pos = center.y() * h / oldSize;
1472  setContentY(contentY() + pos - center.y());
1473  }
1474  }
1475  d->updateBeginningEnd();
1476 }
1477 
1492 {
1494  d->fixupX();
1495  d->fixupY();
1496 }
1497 
1499 {
1500  Q_D(const QDeclarativeFlickable);
1501  if (d->hData.viewSize < 0)
1502  return width();
1503  else
1504  return d->hData.viewSize;
1505 }
1506 
1508 {
1509  Q_D(const QDeclarativeFlickable);
1510  if (d->vData.viewSize < 0)
1511  return height();
1512  else
1513  return d->vData.viewSize;
1514 }
1515 
1517 {
1518  Q_D(const QDeclarativeFlickable);
1519  if (d->flickableDirection == QDeclarativeFlickable::AutoFlickDirection)
1520  return vWidth() != width();
1521  return d->flickableDirection & QDeclarativeFlickable::HorizontalFlick;
1522 }
1523 
1525 {
1526  Q_D(const QDeclarativeFlickable);
1527  if (d->flickableDirection == QDeclarativeFlickable::AutoFlickDirection)
1528  return vHeight() != height();
1529  return d->flickableDirection & QDeclarativeFlickable::VerticalFlick;
1530 }
1531 
1533 {
1534  bool rv = QDeclarativeItem::sceneEvent(event);
1535  if (event->type() == QEvent::UngrabMouse) {
1537  if (d->pressed) {
1538  // if our mouse grab has been removed (probably by another Flickable),
1539  // fix our state
1540  d->pressed = false;
1541  d->stealMouse = false;
1542  setKeepMouseGrab(false);
1543  }
1544  }
1545  return rv;
1546 }
1547 
1549 {
1552  QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect();
1553 
1554  QGraphicsScene *s = scene();
1556  QGraphicsItem *grabberItem = s ? s->mouseGrabberItem() : 0;
1557  bool disabledItem = grabberItem && !grabberItem->isEnabled();
1558  bool stealThisEvent = d->stealMouse;
1559  if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab() || disabledItem)) {
1560  mouseEvent.setAccepted(false);
1561  for (int i = 0x1; i <= 0x10; i <<= 1) {
1562  if (event->buttons() & i) {
1563  Qt::MouseButton button = Qt::MouseButton(i);
1564  mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button)));
1565  }
1566  }
1567  mouseEvent.setScenePos(event->scenePos());
1568  mouseEvent.setLastScenePos(event->lastScenePos());
1569  mouseEvent.setPos(mapFromScene(event->scenePos()));
1570  mouseEvent.setLastPos(mapFromScene(event->lastScenePos()));
1571 
1572  switch(mouseEvent.type()) {
1574  d->handleMouseMoveEvent(&mouseEvent);
1575  break;
1577  if (d->pressed && !event->spontaneous()) // we are already pressed - this is a delayed replay
1578  return false;
1579 
1580  d->handleMousePressEvent(&mouseEvent);
1581  d->captureDelayedPress(event);
1582  stealThisEvent = d->stealMouse; // Update stealThisEvent in case changed by function call above
1583  break;
1585  if (d->delayedPressEvent) {
1586  // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay)
1587  // so we reset the grabber
1588  if (s->mouseGrabberItem() == d->delayedPressTarget)
1589  d->delayedPressTarget->ungrabMouse();
1590  //Use the event handler that will take care of finding the proper item to propagate the event
1591  QApplication::sendEvent(scene(), d->delayedPressEvent);
1592  d->clearDelayedPress();
1593  // We send the release
1595  // And the event has been consumed
1596  d->stealMouse = false;
1597  d->pressed = false;
1598  return true;
1599  }
1600  d->handleMouseReleaseEvent(&mouseEvent);
1601  break;
1602  default:
1603  break;
1604  }
1606  if ((grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this) || disabledItem) {
1607  d->clearDelayedPress();
1608  grabMouse();
1609  }
1610 
1611  return stealThisEvent || d->delayedPressEvent || disabledItem;
1612  } else if (d->lastPosTime.isValid()) {
1613  d->lastPosTime.invalidate();
1614  }
1616  d->clearDelayedPress();
1617  d->stealMouse = false;
1618  d->pressed = false;
1619  }
1620 
1621  return false;
1622 }
1623 
1625 {
1627  if (!isVisible() || !d->interactive || !isEnabled())
1629  switch (e->type()) {
1633  return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e));
1634  default:
1635  break;
1636  }
1637 
1639 }
1640 
1651 {
1652  Q_D(const QDeclarativeFlickable);
1653  return d->maxVelocity;
1654 }
1655 
1657 {
1659  if (v == d->maxVelocity)
1660  return;
1661  d->maxVelocity = v;
1663 }
1664 
1675 {
1676  Q_D(const QDeclarativeFlickable);
1677  return d->deceleration;
1678 }
1679 
1681 {
1683  if (deceleration == d->deceleration)
1684  return;
1685  d->deceleration = deceleration;
1687 }
1688 
1690 {
1691  Q_D(const QDeclarativeFlickable);
1692  return d->hData.flicking || d->vData.flicking;
1693 }
1694 
1707 {
1708  Q_D(const QDeclarativeFlickable);
1709  return d->hData.flicking;
1710 }
1711 
1713 {
1714  Q_D(const QDeclarativeFlickable);
1715  return d->vData.flicking;
1716 }
1717 
1736 {
1737  Q_D(const QDeclarativeFlickable);
1738  return d->pressDelay;
1739 }
1740 
1742 {
1744  if (d->pressDelay == delay)
1745  return;
1746  d->pressDelay = delay;
1748 }
1749 
1750 
1752 {
1753  Q_D(const QDeclarativeFlickable);
1754  return d->hData.moving || d->vData.moving;
1755 }
1756 
1770 {
1771  Q_D(const QDeclarativeFlickable);
1772  return d->hData.moving;
1773 }
1774 
1776 {
1777  Q_D(const QDeclarativeFlickable);
1778  return d->vData.moving;
1779 }
1780 
1782 {
1784  if (d->hMoved && !d->hData.moving) {
1785  d->hData.moving = true;
1786  emit movingChanged();
1788  if (!d->vData.moving)
1790  }
1791  else if (d->vMoved && !d->vData.moving) {
1792  d->vData.moving = true;
1793  emit movingChanged();
1795  if (!d->hData.moving)
1797  }
1798 }
1799 
1801 {
1803  movementXEnding();
1804  movementYEnding();
1805  d->hData.smoothVelocity.setValue(0);
1806  d->vData.smoothVelocity.setValue(0);
1807 }
1808 
1810 {
1812  if (d->hData.flicking) {
1813  d->hData.flicking = false;
1816  if (!d->vData.flicking)
1817  emit flickEnded();
1818  }
1819  if (!d->pressed && !d->stealMouse) {
1820  if (d->hData.moving) {
1821  d->hData.moving = false;
1822  d->hMoved = false;
1823  emit movingChanged();
1825  if (!d->vData.moving)
1826  emit movementEnded();
1827  }
1828  }
1829  d->hData.fixingUp = false;
1830 }
1831 
1833 {
1835  if (d->vData.flicking) {
1836  d->vData.flicking = false;
1839  if (!d->hData.flicking)
1840  emit flickEnded();
1841  }
1842  if (!d->pressed && !d->stealMouse) {
1843  if (d->vData.moving) {
1844  d->vData.moving = false;
1845  d->vMoved = false;
1846  emit movingChanged();
1848  if (!d->hData.moving)
1849  emit movementEnded();
1850  }
1851  }
1852  d->vData.fixingUp = false;
1853 }
1854 
1856 {
1858  emit q->horizontalVelocityChanged();
1859  emit q->verticalVelocityChanged();
1860 }
1861 
void setFlickableDirection(FlickableDirection)
static QObject * data_at(QDeclarativeListProperty< QObject > *, int)
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant)
Make sure not to trigger any pure virtual function calls (e.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QGraphicsItem * parent
void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object...
BoundsBehavior boundsBehavior() const
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
static const int RetainGrabVelocity
double qreal
Definition: qglobal.h:1193
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static qint64 elapsed(QElapsedTimer &)
void xPositionChanged(qreal xPosition)
QDeclarativeParserStatus ** d
QList< QGraphicsItem * > childItems() const
Returns a list of this item&#39;s children.
virtual qreal maxYExtent() const
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
int accel(QDeclarativeTimeLineValue &, qreal velocity, qreal accel)
Decelerate timeLineValue from the starting velocity to zero at the given acceleration rate...
bool sceneEvent(QEvent *event)
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
#define QML_FLICK_OVERSHOOTFRICTION
void flickingHorizontallyChanged()
virtual bool event(QEvent *)
void flickingVerticallyChanged()
friend class QDeclarativeFlickableVisibleArea
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
void setAccepted(bool accepted)
Definition: qcoreevent.h:306
void move(QDeclarativeTimeLineValue &, qreal destination, int time=500)
Linearly change the timeLineValue from its current value to the given destination value over time mil...
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QDeclarativeFlickable(QDeclarativeItem *parent=0)
QDeclarativeItem * contentItem()
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
void handleMousePressEvent(QGraphicsSceneMouseEvent *)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
void captureDelayedPress(QGraphicsSceneMouseEvent *event)
void setBoundsBehavior(BoundsBehavior)
qreal contentY() const
qreal contentX() const
QPointF pos() const
Returns the position of the item in parent coordinates.
void reset(QDeclarativeTimeLineValue &)
Cancel (but don&#39;t complete) all scheduled actions for timeLineValue.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
qreal flickDeceleration() const
QDeclarativeListProperty< QObject > flickableData()
#define QML_FLICK_SAMPLEBUFFER
QDeclarativeListProperty< QGraphicsObject > flickableChildren()
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
virtual void wheelEvent(QGraphicsSceneWheelEvent *event)
This event handler, for event event, can be reimplemented to receive wheel events for this item...
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &)
virtual qreal minYExtent() const
void yPositionChanged(qreal yPosition)
bool sendEvent(QGraphicsItem *item, QEvent *event)
Sends event event to item item through possible event filters.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center)
#define Q_Q(Class)
Definition: qglobal.h:2483
QPointF buttonDownScenePos(Qt::MouseButton button) const
Returns the mouse cursor position in scene coordinates where the specified button was clicked...
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
void setParentItem(QDeclarativeItem *parent)
QPointF lastScenePos() const
Returns the last recorded mouse cursor position in scene coordinates.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
const qreal MinimumFlickVelocity
The QDeclarativeItem class provides the most basic of all visual items in QML.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
bool sendMouseEvent(QGraphicsSceneMouseEvent *event)
void addItemChangeListener(QDeclarativeItemChangeListener *listener, ChangeTypes types)
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
#define QML_FLICK_DISCARDSAMPLES
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
virtual qreal value() const
Return the current value.
#define QML_FLICK_OVERSHOOT
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
void flickableDirectionChanged()
QDeclarativeFlickableVisibleArea * visibleArea()
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent)
void handleMouseMoveEvent(QGraphicsSceneMouseEvent *)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void invalidate()
Marks this QElapsedTimer object as invalid.
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
static void data_append(QDeclarativeListProperty< QObject > *, QObject *)
static int startDragDistance()
__int64 qint64
Definition: qglobal.h:942
void setX(qreal x)
Set&#39;s the x coordinate of the item&#39;s position.
virtual qreal minXExtent() const
static int data_count(QDeclarativeListProperty< QObject > *)
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
void set(QDeclarativeTimeLineValue &, qreal)
Set the value of timeLineValue.
void widthRatioChanged(qreal widthRatio)
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent=0)
void addVelocitySample(qreal v, qreal maxVelocity)
static void start(QElapsedTimer &)
int delta() const
Returns the distance that the wheel is rotated, in eighths (1/8s) of a degree.
QDeclarativeTimeLineValueProxy< QDeclarativeFlickablePrivate > move
QDeclarativeListProperty< QGraphicsObject > childrenList()
Returns a list of this item&#39;s children.
qreal y() const
This convenience function is equivalent to calling pos().
#define QML_FLICK_DEFAULTDECELERATION
QDeclarativeItem * parentItem() const
Returns the QDeclarativeItem parent of this item.
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
QPoint lastScreenPos() const
Returns the last recorded mouse cursor position in screen coordinates.
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
static qint64 restart(QElapsedTimer &)
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
qreal contentHeight() const
qreal x() const
This convenience function is equivalent to calling pos().
void setY(qreal y)
Set&#39;s the y coordinate of the item&#39;s position.
static const int FlickThreshold
virtual void componentComplete()
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void wheelEvent(QGraphicsSceneWheelEvent *event)
This event handler, for event event, can be reimplemented to receive wheel events for this item...
QPoint buttonDownScreenPos(Qt::MouseButton button) const
Returns the mouse cursor position in screen coordinates where the specified button was clicked...
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
qreal contentWidth() const
virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize, QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
virtual bool sceneEvent(QEvent *)
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
FlickableDirection flickableDirection() const
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
bool keepMouseGrab() const
Returns a value indicating whether mouse input should remain with this item exclusively.
QPointF pos() const
Returns the mouse cursor position in item coordinates.
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifiers in use at the time the event was sent.
qreal verticalVelocity() const
QDeclarativeFlickableVisibleArea * visibleArea
static void data_clear(QDeclarativeListProperty< QObject > *)
void heightRatioChanged(qreal heightRatio)
qreal horizontalVelocity() const
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
void ungrabMouse()
Releases the mouse grab.
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
void movingHorizontallyChanged()
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
virtual void setContentX(qreal pos)
Q_INVOKABLE void returnToBounds()
Qt::Orientation orientation() const
Returns the wheel orientation.
The QGraphicsObject class provides a base class for all graphics items that require signals...
virtual qreal maxXExtent() const
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.
int pressDelay() const
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void maximumFlickVelocityChanged()
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...
#define QML_FLICK_DEFAULTMAXVELOCITY
void callback(const QDeclarativeTimeLineCallback &)
Execute the event.
qreal maximumFlickVelocity() const
QDeclarativeListProperty< QObject > data()
virtual void setContentY(qreal pos)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
virtual bool sceneEventFilter(QGraphicsItem *, QEvent *)
Filters events for the item watched.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *)
QPointF lastPos() const
Returns the last recorded mouse cursor position in item coordinates.
void grabMouse()
Grabs the mouse input.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
void setKeepMouseGrab(bool)
The flag indicating whether the mouse should remain with this item is set to keep.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Qt::LayoutDirection direction
MouseButton
Definition: qnamespace.h:150
QDeclarativeFlickable::BoundsBehavior boundsBehavior