From: Shawn Rutledge Date: Fri, 5 Dec 2014 09:28:20 +0000 (+0100) Subject: MouseArea: add scrollGestureEnabled property X-Git-Tag: v5.5.90+alpha1~466 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44ab79012f1662a4efa7c506b6ebc4466c50b3e9;p=platform%2Fupstream%2Fqtdeclarative.git MouseArea: add scrollGestureEnabled property If true, scroll gestures coming from the operating system can cause wheel to be emitted; if false, only an actual mouse wheel will do that. The photosurface example demostrates the use case. 1) the flick gesture on a trackpad should flick the underlying Flickable, not zoom an individual image 2) mouse wheel should zoom an individual image if the cursor is pointing to it 3) dragging an image on a touchscreen should be possible, independently of flicking the Flickable. This means multiPointTouchEnabled should be true, so we cannot interpret multiPointTouchEnabled to mean that multipoint touch scroll gestures should be disabled. Change-Id: Ie063556866f07b3fbadc53990b110edeed532710 Reviewed-by: Morten Johan Sørvig --- diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index dc7ba96c3..d6aa30835 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING) QQuickMouseAreaPrivate::QQuickMouseAreaPrivate() -: enabled(true), hovered(false), longPress(false), +: enabled(true), scrollGestureEnabled(true), hovered(false), longPress(false), moved(false), stealMouse(false), doubleClick(false), preventStealing(false), propagateComposedEvents(false), pressed(0) #ifndef QT_NO_DRAGANDDROP @@ -496,6 +496,36 @@ void QQuickMouseArea::setEnabled(bool a) } } +/*! + \qmlproperty bool QtQuick::MouseArea::scrollGestureEnabled + + This property controls whether this MouseArea responds to scroll gestures + from non-mouse devices, such as the 2-finger flick gesture on a trackpad. + If set to false, the \l wheel signal be emitted only when the wheel event + comes from an actual mouse with a wheel, while scroll gesture events will + pass through to any other Item that will handle them. For example, the user + might perform a flick gesture while the cursor is over an item containing a + MouseArea, intending to interact with a Flickable which is underneath. + Setting this property to false will allow the PinchArea to handle the mouse + wheel or the pinch gesture, while the Flickable handles the flick gesture. + + By default, this property is true. +*/ +bool QQuickMouseArea::isScrollGestureEnabled() const +{ + Q_D(const QQuickMouseArea); + return d->scrollGestureEnabled; +} + +void QQuickMouseArea::setScrollGestureEnabled(bool e) +{ + Q_D(QQuickMouseArea); + if (e != d->scrollGestureEnabled) { + d->scrollGestureEnabled = e; + emit scrollGestureEnabledChanged(); + } +} + /*! \qmlproperty bool QtQuick::MouseArea::preventStealing This property holds whether the mouse events may be stolen from this @@ -821,7 +851,7 @@ void QQuickMouseArea::hoverLeaveEvent(QHoverEvent *event) void QQuickMouseArea::wheelEvent(QWheelEvent *event) { Q_D(QQuickMouseArea); - if (!d->enabled) { + if (!d->enabled || (!isScrollGestureEnabled() && event->source() != Qt::MouseEventNotSynthesized)) { QQuickItem::wheelEvent(event); return; } diff --git a/src/quick/items/qquickmousearea_p.h b/src/quick/items/qquickmousearea_p.h index 8348a255d..e6bed1a72 100644 --- a/src/quick/items/qquickmousearea_p.h +++ b/src/quick/items/qquickmousearea_p.h @@ -54,6 +54,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickMouseArea : public QQuickItem Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) Q_PROPERTY(bool pressed READ pressed NOTIFY pressedChanged) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(bool scrollGestureEnabled READ isScrollGestureEnabled WRITE setScrollGestureEnabled NOTIFY scrollGestureEnabledChanged) Q_PROPERTY(Qt::MouseButtons pressedButtons READ pressedButtons NOTIFY pressedButtonsChanged) Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged) @@ -77,6 +78,9 @@ public: bool isEnabled() const; void setEnabled(bool); + bool isScrollGestureEnabled() const; + void setScrollGestureEnabled(bool); + bool hovered() const; bool pressed() const; bool containsPress() const; @@ -108,6 +112,7 @@ Q_SIGNALS: void hoveredChanged(); void pressedChanged(); void enabledChanged(); + void scrollGestureEnabledChanged(); void pressedButtonsChanged(); void acceptedButtonsChanged(); void hoverEnabledChanged(); diff --git a/src/quick/items/qquickmousearea_p_p.h b/src/quick/items/qquickmousearea_p_p.h index 73db6ea36..630b60f1b 100644 --- a/src/quick/items/qquickmousearea_p_p.h +++ b/src/quick/items/qquickmousearea_p_p.h @@ -78,6 +78,7 @@ public: bool isWheelConnected(); bool enabled : 1; + bool scrollGestureEnabled : 1; bool hovered : 1; bool longPress : 1; bool moved : 1; diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index a387046d4..ab6829f92 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1742,7 +1742,7 @@ bool QQuickWindowPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event if (item->contains(p)) { QWheelEvent wheel(p, p, event->pixelDelta(), event->angleDelta(), event->delta(), - event->orientation(), event->buttons(), event->modifiers(), event->phase()); + event->orientation(), event->buttons(), event->modifiers(), event->phase(), event->source()); wheel.accept(); q->sendEvent(item, &wheel); if (wheel.isAccepted()) {