Debian Codegraph @

tests/manual/pointer/content/Slider.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2019 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the manual tests of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 import QtQuick 2.14
30 import Qt.labs.animation 1.0
31
32 Item {
33 id: root
34 property int value: 50
35 property int maximumValue: 99
36 property alias label: label.text
37 property alias tapEnabled: tap.enabled
38 property alias pressed: tap.pressed
39 signal tapped
40
41 DragHandler {
42 id: dragHandler
43 objectName: label.text + " DragHandler"
44 target: knob
45 xAxis.enabled: false
46 }
47
48 WheelHandler {
49 id: wheelHandler
50 objectName: label.text + " WheelHandler"
51 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
52 invertible: false // Don't let the system "natural scrolling" setting affect this
53 rotationScale: -0.5 // But make it go consistently in the same direction as the fingers or wheel, a bit slow
54 target: knob
55 property: "y"
56 }
57
58 Rectangle {
59 id: slot
60 anchors.top: parent.top
61 anchors.bottom: parent.bottom
62 anchors.margins: 10
63 anchors.topMargin: label.height + 6
64 anchors.bottomMargin: valueLabel.height + 4
65 anchors.horizontalCenter: parent.horizontalCenter
66 width: 10
67 color: "black"
68 radius: width / 2
69 smooth: true
70 }
71
72 Rectangle {
73 // RectangularGlow is better, but that's a different module
74 id: glow
75 anchors.fill: knob
76 anchors.margins: -5
77 anchors.leftMargin: -2
78 anchors.horizontalCenterOffset: 1
79 radius: 5
80 color: "#4400FFFF"
81 opacity: tap.pressed || tapFlash.running ? 1 : 0
82 FlashAnimation on visible {
83 id: tapFlash
84 }
85 }
86 Image {
87 id: knob
88 source: "../resources/mixer-knob.png"
89 antialiasing: true
90 x: slot.x - width / 2 + slot.width / 2
91 height: root.width / 2
92 width: implicitWidth / implicitHeight * height
93 property bool programmatic: false
94 property real multiplier: root.maximumValue / (ybr.maximum - ybr.minimum)
95 onYChanged: if (!programmatic) root.value = root.maximumValue - (knob.y - ybr.minimum) * multiplier
96 transformOrigin: Item.Center
97 function setValue(value) { knob.y = ybr.maximum - value / knob.multiplier }
98 TapHandler {
99 id: tap
100 objectName: label.text + " TapHandler"
101 gesturePolicy: TapHandler.DragThreshold
102 onTapped: {
103 tapFlash.start()
104 root.tapped
105 }
106 }
107 BoundaryRule on y {
108 id: ybr
109 minimum: slot.y
110 maximum: slot.height + slot.y - knob.height
111 }
112 }
113
114 Text {
115 id: valueLabel
116 font.pointSize: 16
117 color: "red"
118 anchors.bottom: parent.bottom
119 anchors.horizontalCenter: parent.horizontalCenter
120 text: root.value
121 }
122
123 Text {
124 id: label
125 font.pointSize: 12
126 color: "red"
127 anchors.top: parent.top
128 anchors.topMargin: 5
129 anchors.horizontalCenter: parent.horizontalCenter
130 }
131
132 onHeightChanged: {
133 knob.programmatic = true
134 knob.setValue(root.value)
135 knob.programmatic = false
136 }
137 }