Warning, /frameworks/kirigami/autotests/wheelhandler/tst_scrolling.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 readonly property real hstep: wheelHandler.horizontalStepSize 0013 readonly property real vstep: wheelHandler.verticalStepSize 0014 readonly property real pageWidth: flickable.width - flickable.leftMargin - flickable.rightMargin 0015 readonly property real pageHeight: flickable.height - flickable.topMargin - flickable.bottomMargin 0016 readonly property real contentWidth: flickable.contentWidth 0017 readonly property real contentHeight: flickable.contentHeight 0018 property alias wheelHandler: wheelHandler 0019 property alias flickable: flickable 0020 0021 name: "WheelHandler scrolling" 0022 visible: true 0023 when: windowShown 0024 width: flickable.implicitWidth 0025 height: flickable.implicitHeight 0026 0027 function wheelScrolling(angleDelta = wheelHandler.verticalStepSize) { 0028 let x = flickable.contentX 0029 let y = flickable.contentY 0030 const angleDeltaFactor = angleDelta / 120 0031 mouseWheel(flickable, flickable.leftMargin, 0, -angleDelta, -angleDelta, Qt.NoButton) 0032 if (angleDelta === wheelHandler.verticalStepSize) { 0033 tryCompare(flickable, "contentX", Math.round(x + hstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+xTick") 0034 } else { 0035 compare(flickable.contentX, Math.round(x + hstep * angleDeltaFactor), "+xTick") 0036 } 0037 x = flickable.contentX 0038 if (angleDelta === wheelHandler.verticalStepSize) { 0039 tryCompare(flickable, "contentY", Math.round(y + vstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+yTick") 0040 } else { 0041 compare(flickable.contentY, Math.round(y + vstep * angleDeltaFactor), "+yTick") 0042 } 0043 y = flickable.contentY 0044 0045 mouseWheel(flickable, flickable.leftMargin, 0, angleDelta, angleDelta, Qt.NoButton) 0046 if (angleDelta === wheelHandler.verticalStepSize) { 0047 tryCompare(flickable, "contentX", Math.round(x - hstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-xTick") 0048 } else { 0049 compare(flickable.contentX, Math.round(x - hstep * angleDeltaFactor), "-xTick") 0050 } 0051 x = flickable.contentX 0052 if (angleDelta === wheelHandler.verticalStepSize) { 0053 tryCompare(flickable, "contentY", Math.round(y - vstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-yTick") 0054 } else { 0055 compare(flickable.contentY, Math.round(y - vstep * angleDeltaFactor), "-yTick") 0056 } 0057 y = flickable.contentY 0058 0059 if (Qt.platform.pluginName !== "xcb") { 0060 mouseWheel(flickable, flickable.leftMargin, 0, 0, -angleDelta, Qt.NoButton, Qt.AltModifier) 0061 tryCompare(flickable, "contentX", Math.round(x + hstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+h_yTick") 0062 x = flickable.contentX 0063 tryCompare(flickable, "contentY", y, Kirigami.Units.longDuration * 2, "no +yTick") 0064 0065 mouseWheel(flickable, flickable.leftMargin, 0, 0, angleDelta, Qt.NoButton, Qt.AltModifier) 0066 tryCompare(flickable, "contentX", Math.round(x - hstep * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-h_yTick") 0067 x = flickable.contentX 0068 tryCompare(flickable, "contentY", y, Kirigami.Units.longDuration * 2, "no -yTick") 0069 } 0070 0071 mouseWheel(flickable, flickable.leftMargin, 0, -angleDelta, -angleDelta, Qt.NoButton, wheelHandler.pageScrollModifiers) 0072 if (angleDelta === wheelHandler.verticalStepSize) { 0073 tryCompare(flickable, "contentX", Math.round(x + pageWidth * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+xPage") 0074 } else { 0075 compare(flickable.contentX, Math.round(x + pageWidth * angleDeltaFactor), "+xPage") 0076 } 0077 x = flickable.contentX 0078 if (angleDelta === wheelHandler.verticalStepSize) { 0079 tryCompare(flickable, "contentY", Math.round(y + pageHeight * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+yPage") 0080 } else { 0081 compare(flickable.contentY, Math.round(y + pageHeight * angleDeltaFactor), "+yPage") 0082 } 0083 y = flickable.contentY 0084 0085 mouseWheel(flickable, flickable.leftMargin, 0, angleDelta, angleDelta, Qt.NoButton, wheelHandler.pageScrollModifiers) 0086 if (angleDelta === wheelHandler.verticalStepSize) { 0087 tryCompare(flickable, "contentX", Math.round(x - pageWidth * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-xPage") 0088 } else { 0089 compare(flickable.contentX, Math.round(x - pageWidth * angleDeltaFactor), "-xPage") 0090 } 0091 x = flickable.contentX 0092 if (angleDelta === wheelHandler.verticalStepSize) { 0093 tryCompare(flickable, "contentY", Math.round(y - pageHeight * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-yPage") 0094 } else { 0095 compare(flickable.contentY, Math.round(y - pageHeight * angleDeltaFactor), "-yPage") 0096 } 0097 y = flickable.contentY 0098 0099 if (Qt.platform.pluginName !== "xcb") { 0100 mouseWheel(flickable, flickable.leftMargin, 0, 0, -angleDelta, Qt.NoButton, 0101 Qt.AltModifier | wheelHandler.pageScrollModifiers) 0102 tryCompare(flickable, "contentX", Math.round(x + pageWidth * angleDeltaFactor), Kirigami.Units.longDuration * 2, "+h_yPage") 0103 x = flickable.contentX 0104 tryCompare(flickable, "contentY", y, Kirigami.Units.longDuration * 2, "no +yPage") 0105 0106 mouseWheel(flickable, flickable.leftMargin, 0, 0, angleDelta, Qt.NoButton, 0107 Qt.AltModifier | wheelHandler.pageScrollModifiers) 0108 tryCompare(flickable, "contentX", Math.round(x - pageWidth * angleDeltaFactor), Kirigami.Units.longDuration * 2, "-h_yPage") 0109 x = flickable.contentX 0110 tryCompare(flickable, "contentY", y, Kirigami.Units.longDuration * 2, "no -yPage") 0111 } 0112 } 0113 0114 function test_WheelScrolling() { 0115 // HID 1bcf:08a0 Mouse 0116 // Angle delta is 120, like most mice. 0117 wheelScrolling() 0118 } 0119 0120 function test_HiResWheelScrolling() { 0121 // Logitech MX Master 3 0122 // Main wheel angle delta is at least 16, plus multiples of 8 when scrolling faster. 0123 wheelScrolling(16) 0124 } 0125 0126 function test_TouchpadScrolling() { 0127 // UNIW0001:00 093A:0255 Touchpad 0128 // 2 finger scroll angle delta is at least 3, but larger increments are used when scrolling faster. 0129 wheelScrolling(3) 0130 } 0131 0132 function keyboardScrolling() { 0133 const originalX = flickable.contentX 0134 const originalY = flickable.contentY 0135 let x = originalX 0136 let y = originalY 0137 keyClick(Qt.Key_Right) 0138 tryCompare(flickable, "contentX", x + hstep, Kirigami.Units.longDuration * 2, "Key_Right") 0139 x = flickable.contentX 0140 0141 keyClick(Qt.Key_Left) 0142 tryCompare(flickable, "contentX", x - hstep, Kirigami.Units.longDuration * 2, "Key_Left") 0143 x = flickable.contentX 0144 0145 keyClick(Qt.Key_Down) 0146 tryCompare(flickable, "contentY", y + vstep, Kirigami.Units.longDuration * 2, "Key_Down") 0147 y = flickable.contentY 0148 0149 keyClick(Qt.Key_Up) 0150 tryCompare(flickable, "contentY", y - vstep, Kirigami.Units.longDuration * 2, "Key_Up") 0151 y = flickable.contentY 0152 0153 keyClick(Qt.Key_PageDown) 0154 tryCompare(flickable, "contentY", y + pageHeight, Kirigami.Units.longDuration * 2, "Key_PageDown") 0155 y = flickable.contentY 0156 0157 keyClick(Qt.Key_PageUp) 0158 tryCompare(flickable, "contentY", y - pageHeight, Kirigami.Units.longDuration * 2, "Key_PageUp") 0159 y = flickable.contentY 0160 0161 keyClick(Qt.Key_End) 0162 tryCompare(flickable, "contentY", contentHeight - pageHeight, Kirigami.Units.longDuration * 2, "Key_End") 0163 y = flickable.contentY 0164 0165 keyClick(Qt.Key_Home) 0166 tryCompare(flickable, "contentY", originalY, Kirigami.Units.longDuration * 2, "Key_Home") 0167 y = flickable.contentY 0168 0169 keyClick(Qt.Key_PageDown, Qt.AltModifier) 0170 tryCompare(flickable, "contentX", x + pageWidth, Kirigami.Units.longDuration * 2, "h_Key_PageDown") 0171 x = flickable.contentX 0172 0173 keyClick(Qt.Key_PageUp, Qt.AltModifier) 0174 tryCompare(flickable, "contentX", x - pageWidth, Kirigami.Units.longDuration * 2, "h_Key_PageUp") 0175 x = flickable.contentX 0176 0177 keyClick(Qt.Key_End, Qt.AltModifier) 0178 tryCompare(flickable, "contentX", contentWidth - pageWidth, Kirigami.Units.longDuration * 2, "h_Key_End") 0179 x = flickable.contentX 0180 0181 keyClick(Qt.Key_Home, Qt.AltModifier) 0182 tryCompare(flickable, "contentX", originalX, Kirigami.Units.longDuration * 2, "h_Key_Home") 0183 } 0184 0185 function test_KeyboardScrolling() { 0186 keyboardScrolling() 0187 } 0188 0189 function test_StepSize() { 0190 // 101 is a value unlikely to be used by any user's combination of settings and hardware 0191 wheelHandler.verticalStepSize = 101 0192 wheelHandler.horizontalStepSize = 101 0193 wheelScrolling() 0194 keyboardScrolling() 0195 // reset to default 0196 wheelHandler.verticalStepSize = undefined 0197 wheelHandler.horizontalStepSize = undefined 0198 verify(wheelHandler.verticalStepSize == 20 * Qt.styleHints.wheelScrollLines, "default verticalStepSize") 0199 verify(wheelHandler.horizontalStepSize == 20 * Qt.styleHints.wheelScrollLines, "default horizontalStepSize") 0200 } 0201 0202 ScrollableFlickable { 0203 id: flickable 0204 focus: true 0205 anchors.fill: parent 0206 Kirigami.WheelHandler { 0207 id: wheelHandler 0208 target: flickable 0209 keyNavigationEnabled: true 0210 } 0211 } 0212 }