diff --git a/src/controls/templates/private/ScrollView.qml b/src/controls/templates/private/ScrollView.qml --- a/src/controls/templates/private/ScrollView.qml +++ b/src/controls/templates/private/ScrollView.qml @@ -7,7 +7,7 @@ import QtQuick.Controls 2.0 import org.kde.kirigami 2.9 as Kirigami -MouseArea { +Item { id: root default property Item contentItem property Flickable flickableItem @@ -83,6 +83,15 @@ id: wheelHandler target: root.flickableItem } + Kirigami.WheelHandler { + target: flickableParent + blockTargetWheel: false + scrollFlickableTarget: false + onWheel: { + wheelHandler.includeWheelEvent(wheel) + wheel.accepted = true + } + } Item { id: flickableParent clip: true diff --git a/src/wheelhandler.h b/src/wheelhandler.h --- a/src/wheelhandler.h +++ b/src/wheelhandler.h @@ -76,7 +76,7 @@ * inverted: bool * * Whether the delta values are inverted - * On some platformsthe returned delta are inverted, so positive values would mean bottom/left + * On some platforms the returned delta are inverted, so positive values would mean bottom/left */ Q_PROPERTY(bool inverted READ inverted CONSTANT) @@ -151,6 +151,7 @@ private: void manageWheel(QQuickItem *target, QWheelEvent *wheel); + friend class WheelHandler; QMultiHash m_handlersForItem; KirigamiWheelEvent m_wheelEvent; }; @@ -195,6 +196,8 @@ QQuickItem *target() const; void setTarget(QQuickItem *target); + Q_SCRIPTABLE void includeWheelEvent(KirigamiWheelEvent *wheel); + Q_SIGNALS: void targetChanged(); void blockTargetWheelChanged(); diff --git a/src/wheelhandler.cpp b/src/wheelhandler.cpp --- a/src/wheelhandler.cpp +++ b/src/wheelhandler.cpp @@ -286,5 +286,14 @@ emit targetChanged(); } +void WheelHandler::includeWheelEvent(KirigamiWheelEvent *wheel) +{ + const QPointF pos = {wheel->x(), wheel->y()}; + QWheelEvent qwheel(pos, pos, wheel->pixelDelta().toPoint(), wheel->angleDelta().toPoint(), + Qt::MouseButtons(wheel->buttons()), + Qt::KeyboardModifiers (wheel->modifiers()), + Qt::NoScrollPhase, wheel->inverted()); + GlobalWheelFilter::self()->manageWheel(target(), &qwheel); +} #include "moc_wheelhandler.cpp" diff --git a/tests/ScrollPaddingScrollable.qml b/tests/ScrollPaddingScrollable.qml new file mode 100644 --- /dev/null +++ b/tests/ScrollPaddingScrollable.qml @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Layouts 1.0 +import org.kde.kirigami 2.4 as Kirigami + +Kirigami.ApplicationWindow +{ + id: main + Component { + id: keyPage + Kirigami.ScrollablePage { + leftPadding: 200 + ColumnLayout { + Repeater { + model: 200 + delegate: Label { + text: "Potato" + } + } + } + } + } + + header: Text { + text: "focus:" + activeFocusItem + " current: " + main.pageStack.currentIndex + } + + Component.onCompleted: { + main.pageStack.push(keyPage) + } +}