Search
SailfishOS Open Build Service
>
Projects
>
home:kaltsi
:
tnhlbug
>
qt
> 0011-Backport-Flickable-dragging-properties.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File 0011-Backport-Flickable-dragging-properties.patch of Package qt
From b32350782539738d8cc2b51b63eafa398575f083 Mon Sep 17 00:00:00 2001 From: Martin Jones <martin.jones@qinetic.com.au> Date: Thu, 18 Oct 2012 16:50:10 +1000 Subject: [PATCH 11/29] Backport Flickable dragging properties. dragging, draggingVertically and draggingHorizontally were added in QtQuick 2.0. Backporting to QtQuick 1.2 --- .../graphicsitems/qdeclarativeflickable.cpp | 88 +++++++++++++++++++- .../graphicsitems/qdeclarativeflickable_p.h | 11 +++ .../graphicsitems/qdeclarativeflickable_p_p.h | 6 +- .../graphicsitems/qdeclarativeitemsmodule.cpp | 3 + 4 files changed, 105 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp index f8e58e7..8982c6d 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp +++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp @@ -505,6 +505,22 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd() */ /*! + \qmlsignal Flickable::onDragStarted() + + This handler is called when the view starts to be dragged due to user + interaction. +*/ + +/*! + \qmlsignal Flickable::onDragEnded() + + This handler is called when the user stops dragging the view. + + If the velocity of the drag is suffient at the time the + touch/mouse button is released then a flick will start. +*/ + +/*! \qmlproperty real Flickable::visibleArea.xPosition \qmlproperty real Flickable::visibleArea.widthRatio \qmlproperty real Flickable::visibleArea.yPosition @@ -865,6 +881,7 @@ void QDeclarativeFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent } if (hMoved || vMoved) { + draggingStarting(); q->movementStarting(); q->viewportMoved(); } @@ -891,14 +908,18 @@ void QDeclarativeFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEv stealMouse = false; q->setKeepMouseGrab(false); pressed = false; - if (!lastPosTime.isValid()) - return; // if we drag then pause before release we should not cause a flick. qint64 elapsed = QDeclarativeItemPrivate::elapsed(lastPosTime); vData.updateVelocity(); hData.updateVelocity(); + + draggingEnding(); + + if (!lastPosTime.isValid()) + return; + vTime = timeline.time(); qreal velocity = elapsed < 100 ? vData.velocity : 0; @@ -1496,6 +1517,7 @@ bool QDeclarativeFlickable::sceneEvent(QEvent *event) // if our mouse grab has been removed (probably by another Flickable), // fix our state d->pressed = false; + d->draggingEnding(); d->stealMouse = false; setKeepMouseGrab(false); } @@ -1665,6 +1687,68 @@ bool QDeclarativeFlickable::isFlickingVertically() const } /*! + \qmlproperty bool Flickable::dragging + \qmlproperty bool Flickable::draggingHorizontally + \qmlproperty bool Flickable::draggingVertically + + These properties describe whether the view is currently moving horizontally, + vertically or in either direction, due to the user dragging the view. +*/ +bool QDeclarativeFlickable::isDragging() const +{ + Q_D(const QDeclarativeFlickable); + return d->hData.dragging || d->vData.dragging; +} + +bool QDeclarativeFlickable::isDraggingHorizontally() const +{ + Q_D(const QDeclarativeFlickable); + return d->hData.dragging; +} + +bool QDeclarativeFlickable::isDraggingVertically() const +{ + Q_D(const QDeclarativeFlickable); + return d->vData.dragging; +} + +void QDeclarativeFlickablePrivate::draggingStarting() +{ + Q_Q(QDeclarativeFlickable); + bool wasDragging = hData.dragging || vData.dragging; + if (hMoved && !hData.dragging) { + hData.dragging = true; + emit q->draggingHorizontallyChanged(); + } + if (vMoved && !vData.dragging) { + vData.dragging = true; + emit q->draggingVerticallyChanged(); + } + if (!wasDragging && (hData.dragging || vData.dragging)) { + emit q->draggingChanged(); + emit q->dragStarted(); + } +} + +void QDeclarativeFlickablePrivate::draggingEnding() +{ + Q_Q(QDeclarativeFlickable); + bool wasDragging = hData.dragging || vData.dragging; + if (hData.dragging) { + hData.dragging = false; + emit q->draggingHorizontallyChanged(); + } + if (vData.dragging) { + vData.dragging = false; + emit q->draggingVerticallyChanged(); + } + if (wasDragging && !hData.dragging && !vData.dragging) { + emit q->draggingChanged(); + emit q->dragEnded(); + } +} + +/*! \qmlproperty int Flickable::pressDelay This property holds the time to delay (ms) delivering a press to diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h index e74249f..c5561b3 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h @@ -74,6 +74,9 @@ class Q_AUTOTEST_EXPORT QDeclarativeFlickable : public QDeclarativeItem Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged) Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged) + Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged REVISION 2) + Q_PROPERTY(bool draggingHorizontally READ isDraggingHorizontally NOTIFY draggingHorizontallyChanged REVISION 2) + Q_PROPERTY(bool draggingVertically READ isDraggingVertically NOTIFY draggingVerticallyChanged REVISION 2) Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged) @@ -122,6 +125,9 @@ public: bool isFlicking() const; bool isFlickingHorizontally() const; bool isFlickingVertically() const; + bool isDragging() const; + bool isDraggingHorizontally() const; + bool isDraggingVertically() const; int pressDelay() const; void setPressDelay(int delay); @@ -163,6 +169,9 @@ Q_SIGNALS: void flickingChanged(); void flickingHorizontallyChanged(); void flickingVerticallyChanged(); + Q_REVISION(2) void draggingChanged(); + Q_REVISION(2) void draggingHorizontallyChanged(); + Q_REVISION(2) void draggingVerticallyChanged(); void horizontalVelocityChanged(); void verticalVelocityChanged(); void isAtBoundaryChanged(); @@ -176,6 +185,8 @@ Q_SIGNALS: void movementEnded(); void flickStarted(); void flickEnded(); + void dragStarted(); + void dragEnded(); protected: virtual bool sceneEventFilter(QGraphicsItem *, QEvent *); diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h index 44e9c24..941ed3f 100644 --- a/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h @@ -99,7 +99,7 @@ public: struct AxisData { AxisData(QDeclarativeFlickablePrivate *fp, void (QDeclarativeFlickablePrivate::*func)(qreal)) : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true) - , fixingUp(false), inOvershoot(false), moving(false), flicking(false) + , fixingUp(false), inOvershoot(false), moving(false), flicking(false), dragging(false) {} void reset() { @@ -128,6 +128,7 @@ public: bool inOvershoot : 1; bool moving : 1; bool flicking : 1; + bool dragging : 1; }; void flickX(qreal velocity); @@ -152,6 +153,9 @@ public: void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &); + void draggingStarting(); + void draggingEnding(); + public: QDeclarativeItem *contentItem; diff --git a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp index 665320d..e5254a0 100644 --- a/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitemsmodule.cpp @@ -200,6 +200,9 @@ void QDeclarativeItemModule::defineModule() qmlRegisterRevision<QDeclarativeImplicitSizePaintedItem,1>("QtQuick",1,1); qmlRegisterUncreatableType<QDeclarativeLayoutMirroringAttached>("QtQuick",1,1,"LayoutMirroring", QDeclarativeLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties")); + // QtQuick 1.2 items + qmlRegisterType<QDeclarativeFlickable,2>("QtQuick",1,2,"Flickable"); + #ifndef QT_NO_IMPORT_QT47_QML #ifdef QT_NO_MOVIE qmlRegisterTypeNotAvailable("Qt",4,7,"AnimatedImage", -- 1.7.10.3