Warning, /frameworks/kirigami/autotests/wheelhandler/tst_onWheel.qml is written in an unsupported language. File is not indexed.
0001 /* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
0002 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 */
0004
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import org.kde.kirigami as Kirigami
0008 import QtTest
0009
0010 TestCase {
0011 id: root
0012 name: "WheelHandler onWheel"
0013 visible: true
0014 when: windowShown
0015 width: 600
0016 height: 600
0017
0018 function test_onWheel() {
0019 let contentX = flickable.contentX
0020 let contentY = flickable.contentY
0021 let contentWidth = flickable.contentWidth
0022 let contentHeight = flickable.contentHeight
0023
0024 // grow
0025 mouseWheel(flickable, flickable.leftMargin, 0, -120, -120, Qt.NoButton, Qt.ControlModifier)
0026 verify(flickable.contentWidth === contentWidth - 120, "-xDelta")
0027 contentWidth = flickable.contentWidth
0028 verify(flickable.contentHeight === contentHeight - 120, "-yDelta")
0029 contentHeight = flickable.contentHeight
0030
0031 // check if accepting the event prevents scrolling
0032 verify(flickable.contentX === contentX && flickable.contentY === contentY, "not moved")
0033
0034 // shrink
0035 mouseWheel(flickable, flickable.leftMargin, 0, 120, 120, Qt.NoButton, Qt.ControlModifier)
0036 verify(flickable.contentWidth === contentWidth + 120, "+xDelta")
0037 verify(flickable.contentHeight === contentHeight + 120, "+yDelta")
0038
0039 // check if accepting the event prevents scrolling
0040 verify(flickable.contentX === contentX && flickable.contentY === contentY, "not moved")
0041 }
0042
0043 Rectangle {
0044 anchors.fill: parent
0045 color: "black"
0046 }
0047
0048 Flickable {
0049 id: flickable
0050 anchors.fill: parent
0051 Kirigami.WheelHandler {
0052 id: wheelHandler
0053 target: flickable
0054 onWheel: {
0055 if (wheel.modifiers & Qt.ControlModifier) {
0056 // Adding delta is the simplest way to change size without running into floating point number issues
0057 // NOTE: Not limiting minimum content size to a size greater than the Flickable size makes it so
0058 // wheel events stop coming to onWheel when the content size is the size of the flickable or smaller.
0059 // Maybe it's a Flickable issue? Koko had the same problem with Flickable.
0060 flickable.contentWidth = Math.max(720, flickable.contentWidth + wheel.angleDelta.x)
0061 flickable.contentHeight = Math.max(720, flickable.contentHeight + wheel.angleDelta.y)
0062 wheel.accepted = true
0063 }
0064 }
0065 }
0066 leftMargin: QQC2.ScrollBar.vertical && QQC2.ScrollBar.vertical.visible && QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
0067 rightMargin: QQC2.ScrollBar.vertical && QQC2.ScrollBar.vertical.visible && !QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
0068 bottomMargin: QQC2.ScrollBar.horizontal && QQC2.ScrollBar.horizontal.visible ? QQC2.ScrollBar.horizontal.height : 0
0069 QQC2.ScrollBar.vertical: QQC2.ScrollBar {
0070 parent: flickable.parent
0071 anchors.right: flickable.right
0072 anchors.top: flickable.top
0073 anchors.bottom: flickable.bottom
0074 anchors.bottomMargin: flickable.QQC2.ScrollBar.horizontal ? flickable.QQC2.ScrollBar.horizontal.height : anchors.margins
0075 active: flickable.QQC2.ScrollBar.vertical.active
0076 }
0077 QQC2.ScrollBar.horizontal: QQC2.ScrollBar {
0078 parent: flickable.parent
0079 anchors.left: flickable.left
0080 anchors.right: flickable.right
0081 anchors.bottom: flickable.bottom
0082 anchors.rightMargin: flickable.QQC2.ScrollBar.vertical ? flickable.QQC2.ScrollBar.vertical.width : anchors.margins
0083 active: flickable.QQC2.ScrollBar.horizontal.active
0084 }
0085 contentWidth: 1200
0086 contentHeight: 1200
0087 Rectangle {
0088 id: contentRect
0089 anchors.fill: parent
0090 gradient: Gradient.WideMatrix
0091 border.color: Qt.rgba(0,0,0,0.5)
0092 border.width: 2
0093 }
0094 }
0095
0096 QQC2.Label {
0097 anchors.centerIn: parent
0098 leftPadding: 4
0099 rightPadding: 4
0100 wrapMode: Text.Wrap
0101 color: "white"
0102 text: `Rectangle size: ${contentRect.width}x${contentRect.height}`
0103 background: Rectangle {
0104 color: "black"
0105 }
0106 }
0107 }