From 6a2185228207dabb8e8c826ab8651db27ab3cde7 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 5 Aug 2013 00:27:40 +0200 Subject: ScrollView: handle QWheelEvent::phase Change-Id: I5642e8dc5f62b48aaf086820699cf41f689cec1a Reviewed-by: Gabriel de Dietrich --- src/controls/Private/ScrollViewHelper.qml | 9 +++++---- src/controls/Private/qquickwheelarea.cpp | 21 ++++++++++++++++++++- src/controls/Private/qquickwheelarea_p.h | 6 ++++++ src/controls/ScrollView.qml | 1 + 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/controls/Private/ScrollViewHelper.qml b/src/controls/Private/ScrollViewHelper.qml index 791c5e02..ccad20b2 100644 --- a/src/controls/Private/ScrollViewHelper.qml +++ b/src/controls/Private/ScrollViewHelper.qml @@ -59,6 +59,7 @@ Item { property int contentWidth property real originX property real originY + property bool active property int leftMargin: outerFrame ? root.__style.padding.left : 0 property int rightMargin: outerFrame ? root.__style.padding.right : 0 @@ -143,14 +144,14 @@ Item { Binding { target: hscrollbar.__panel property: "raised" - value: vscrollbar.active + value: vscrollbar.active || wheelarea.active when: hscrollbar.isTransient } Binding { target: hscrollbar.__panel property: "visible" value: true - when: !hscrollbar.isTransient + when: !hscrollbar.isTransient || wheelarea.active } function flash() { if (hscrollbar.isTransient) { @@ -184,14 +185,14 @@ Item { Binding { target: vscrollbar.__panel property: "raised" - value: hscrollbar.active + value: hscrollbar.active || wheelarea.active when: vscrollbar.isTransient } Binding { target: vscrollbar.__panel property: "visible" value: true - when: !vscrollbar.isTransient + when: !vscrollbar.isTransient || wheelarea.active } function flash() { if (vscrollbar.isTransient) { diff --git a/src/controls/Private/qquickwheelarea.cpp b/src/controls/Private/qquickwheelarea.cpp index 101e22bf..e276247b 100644 --- a/src/controls/Private/qquickwheelarea.cpp +++ b/src/controls/Private/qquickwheelarea.cpp @@ -66,7 +66,8 @@ QQuickWheelArea::QQuickWheelArea(QQuickItem *parent) m_verticalValue(0), m_verticalDelta(0), m_horizontalDelta(0), - m_scrollSpeed(defaultScrollSpeed) + m_scrollSpeed(defaultScrollSpeed), + m_active(false) { } @@ -78,6 +79,11 @@ QQuickWheelArea::~QQuickWheelArea() void QQuickWheelArea::wheelEvent(QWheelEvent *we) { + if (we->phase() == Qt::ScrollBegin) + setActive(true); + else if (we->phase() == Qt::ScrollEnd) + setActive(false); + QPoint numPixels = we->pixelDelta(); QPoint numDegrees = we->angleDelta() / 8; @@ -201,4 +207,17 @@ qreal QQuickWheelArea::scrollSpeed() const return m_scrollSpeed; } +bool QQuickWheelArea::isActive() const +{ + return m_active; +} + +void QQuickWheelArea::setActive(bool active) +{ + if (active != m_active) { + m_active = active; + emit activeChanged(); + } +} + QT_END_NAMESPACE diff --git a/src/controls/Private/qquickwheelarea_p.h b/src/controls/Private/qquickwheelarea_p.h index 057ad56d..ebaa1453 100644 --- a/src/controls/Private/qquickwheelarea_p.h +++ b/src/controls/Private/qquickwheelarea_p.h @@ -59,6 +59,7 @@ class QQuickWheelArea : public QQuickItem Q_PROPERTY(qreal horizontalValue READ horizontalValue WRITE setHorizontalValue) Q_PROPERTY(qreal verticalValue READ verticalValue WRITE setVerticalValue) Q_PROPERTY(qreal scrollSpeed READ scrollSpeed WRITE setScrollSpeed NOTIFY scrollSpeedChanged) + Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) public: QQuickWheelArea(QQuickItem *parent = 0); @@ -91,6 +92,9 @@ public: void setScrollSpeed(qreal value); qreal scrollSpeed() const; + bool isActive() const; + void setActive(bool active); + void wheelEvent(QWheelEvent *event); Q_SIGNALS: @@ -99,6 +103,7 @@ Q_SIGNALS: void verticalWheelMoved(); void horizontalWheelMoved(); void scrollSpeedChanged(); + void activeChanged(); private: qreal m_horizontalMinimumValue; @@ -110,6 +115,7 @@ private: qreal m_verticalDelta; qreal m_horizontalDelta; qreal m_scrollSpeed; + bool m_active; Q_DISABLE_COPY(QQuickWheelArea) }; diff --git a/src/controls/ScrollView.qml b/src/controls/ScrollView.qml index aa980ddd..7d3d1d9d 100644 --- a/src/controls/ScrollView.qml +++ b/src/controls/ScrollView.qml @@ -280,6 +280,7 @@ FocusScope { ScrollViewHelper { id: scroller anchors.fill: parent + active: wheelArea.active property bool outerFrame: !frameVisible || !(__style ? __style.__externalScrollBars : 0) property int scrollBarSpacing: outerFrame ? 0 : (__style ? __style.__scrollBarSpacing : 0) property int verticalScrollbarOffset: verticalScrollBar.visible && !verticalScrollBar.isTransient ? -- cgit v1.2.1