Warning, /frameworks/kirigami/autotests/wheelhandler/tst_filterMouseEvents.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 2.15
0006 import QtQuick.Controls 2.15 as QQC2
0007 import org.kde.kirigami 2.19 as Kirigami
0008 import QtTest 1.15
0009 
0010 TestCase {
0011     id: root
0012     name: "WheelHandler filterMouseEvents"
0013     visible: true
0014     when: windowShown
0015     width: flickable.implicitWidth
0016     height: flickable.implicitHeight
0017 
0018     function test_MouseFlick() {
0019         const x = flickable.contentX
0020         const y = flickable.contentY
0021         mousePress(flickable, flickable.leftMargin + 10, 10)
0022         mouseMove(flickable)
0023         mouseRelease(flickable)
0024         verify(flickable.contentX === x && flickable.contentY === y, "not moved")
0025     }
0026 
0027     // NOTE: Unfortunately, this test can't work. Flickable does not handle touch events, only mouse events synthesized from touch events
0028     // TODO: Uncomment if Flickable is ever able to use touch events.
0029     /*function test_TouchFlick() {
0030         const x = flickable.contentX, y = flickable.contentY
0031         let touch = touchEvent(flickable)
0032         // Press on center.
0033         touch.press(0, flickable)
0034         touch.commit()
0035         // Move a bit towards top left.
0036         touch.move(0, flickable, flickable.width/2 - 50, flickable.height/2 - 50)
0037         touch.commit()
0038         // Release at the spot we moved to.
0039         touch.release(0, flickable, flickable.width/2 - 50, flickable.height/2 - 50)
0040         touch.commit()
0041         verify(flickable.contentX !== x || flickable.contentY !== y, "moved")
0042     }*/
0043 
0044     function test_MouseScrollBars() {
0045         const x = flickable.contentX, y = flickable.contentY
0046         mousePress(flickable, flickable.leftMargin + 10, 10)
0047         mouseMove(flickable)
0048         const interactive = flickable.QQC2.ScrollBar.vertical.interactive || flickable.QQC2.ScrollBar.horizontal.interactive
0049         mouseRelease(flickable)
0050         verify(interactive, "interactive scrollbars")
0051     }
0052 
0053     function test_TouchScrollBars() {
0054         const x = flickable.contentX, y = flickable.contentY
0055         let touch = touchEvent(flickable)
0056         touch.press(0, flickable, flickable.leftMargin + 10, 10)
0057         touch.commit()
0058         touch.move(0, flickable)
0059         touch.commit()
0060         const interactive = flickable.QQC2.ScrollBar.vertical.interactive || flickable.QQC2.ScrollBar.horizontal.interactive
0061         touch.release(0, flickable)
0062         touch.commit()
0063         verify(!interactive, "no interactive scrollbars")
0064     }
0065 
0066     ScrollableFlickable {
0067         id: flickable
0068         anchors.fill: parent
0069         Kirigami.WheelHandler {
0070             id: wheelHandler
0071             target: flickable
0072             filterMouseEvents: true
0073         }
0074     }
0075 }