Warning, /frameworks/kirigami/tests/wheelhandler/WheelHandlerFlickableTest.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 
0008 import org.kde.kirigami as Kirigami
0009 
0010 QQC2.ApplicationWindow {
0011     id: root
0012     width: flickable.implicitWidth
0013     height: flickable.implicitHeight
0014     visible: true
0015 
0016     Flickable {
0017         id: flickable
0018         anchors.fill: parent
0019         implicitWidth: wheelHandler.horizontalStepSize * 10 + leftMargin + rightMargin
0020         implicitHeight: wheelHandler.verticalStepSize * 10 + topMargin + bottomMargin
0021 
0022         leftMargin: QQC2.ScrollBar.vertical.visible && QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
0023         rightMargin: QQC2.ScrollBar.vertical.visible && !QQC2.ScrollBar.vertical.mirrored ? QQC2.ScrollBar.vertical.width : 0
0024         bottomMargin: QQC2.ScrollBar.horizontal.visible ? QQC2.ScrollBar.horizontal.height : 0
0025 
0026         contentWidth: contentItem.childrenRect.width
0027         contentHeight: contentItem.childrenRect.height
0028 
0029         Kirigami.WheelHandler {
0030             id: wheelHandler
0031             target: flickable
0032             filterMouseEvents: true
0033             keyNavigationEnabled: true
0034         }
0035 
0036         QQC2.ScrollBar.vertical: QQC2.ScrollBar {
0037             parent: flickable.parent
0038             height: flickable.height - flickable.topMargin - flickable.bottomMargin
0039             x: mirrored ? 0 : flickable.width - width
0040             y: flickable.topMargin
0041             active: flickable.QQC2.ScrollBar.horizontal.active
0042             stepSize: wheelHandler.verticalStepSize / flickable.contentHeight
0043         }
0044 
0045         QQC2.ScrollBar.horizontal: QQC2.ScrollBar {
0046             parent: flickable.parent
0047             width: flickable.width - flickable.leftMargin - flickable.rightMargin
0048             x: flickable.leftMargin
0049             y: flickable.height - height
0050             active: flickable.QQC2.ScrollBar.vertical.active
0051             stepSize: wheelHandler.horizontalStepSize / flickable.contentWidth
0052         }
0053 
0054         Grid {
0055             columns: Math.sqrt(visibleChildren.length)
0056             Repeater {
0057                 model: 500
0058                 delegate: Rectangle {
0059                     implicitWidth: wheelHandler.horizontalStepSize
0060                     implicitHeight: wheelHandler.verticalStepSize
0061                     gradient: Gradient {
0062                         orientation: index % 2 ? Gradient.Vertical : Gradient.Horizontal
0063                         GradientStop { position: 0; color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) }
0064                         GradientStop { position: 1; color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) }
0065                     }
0066                 }
0067             }
0068             QQC2.Button {
0069                 id: enableSliderButton
0070                 width: wheelHandler.horizontalStepSize
0071                 height: wheelHandler.verticalStepSize
0072                 contentItem: QQC2.Label {
0073                     horizontalAlignment: Text.AlignHCenter
0074                     verticalAlignment: Text.AlignVCenter
0075                     text: "Enable Slider"
0076                     wrapMode: Text.Wrap
0077                 }
0078                 checked: true
0079             }
0080             QQC2.Slider {
0081                 id: slider
0082                 enabled: enableSliderButton.checked
0083                 width: wheelHandler.horizontalStepSize
0084                 height: wheelHandler.verticalStepSize
0085             }
0086             Repeater {
0087                 model: 500
0088                 delegate: Rectangle {
0089                     implicitWidth: wheelHandler.horizontalStepSize
0090                     implicitHeight: wheelHandler.verticalStepSize
0091                     gradient: Gradient {
0092                         orientation: index % 2 ? Gradient.Vertical : Gradient.Horizontal
0093                         GradientStop { position: 0; color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) }
0094                         GradientStop { position: 1; color: Qt.rgba(Math.random(),Math.random(),Math.random(),1) }
0095                     }
0096                 }
0097             }
0098         }
0099     }
0100 }