Debian Codegraph @

tests/manual/pointer/content/MouseAreaSlider.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 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.12
30
31 Item {
32 id: root
33 property int value: 50
34 property int maximumValue: 99
35 property alias label: label.text
36
37 Rectangle {
38 id: slot
39 anchors.top: parent.top
40 anchors.bottom: parent.bottom
41 anchors.margins: 10
42 anchors.topMargin: 30
43 anchors.bottomMargin: 30
44 anchors.horizontalCenter: parent.horizontalCenter
45 width: 10
46 color: "black"
47 radius: width / 2
48 smooth: true
49 }
50
51 Rectangle {
52 // RectangularGlow is better, but that's a different module
53 id: glow
54 anchors.fill: knob
55 anchors.margins: -5
56 anchors.leftMargin: -2
57 anchors.horizontalCenterOffset: 1
58 radius: 5
59 color: "#4400FFFF"
60 opacity: ma.pressed ? 1 : 0
61 }
62 Image {
63 id: knob
64 source: "../resources/mixer-knob.png"
65 antialiasing: true
66 x: slot.x - width / 2 + slot.width / 2
67 height: root.width / 2
68 width: implicitWidth / implicitHeight * height
69 property bool programmatic: false
70 property real multiplier: root.maximumValue / (ma.drag.maximumY - ma.drag.minimumY)
71 onYChanged: if (!programmatic) root.value = root.maximumValue - (knob.y - ma.drag.minimumY) * multiplier
72 transformOrigin: Item.Center
73 function setValue(value) { knob.y = ma.drag.maximumY - value / knob.multiplier }
74 MouseArea {
75 id: ma
76 anchors.fill: parent
77 drag.target: parent
78 drag.minimumX: knob.x
79 drag.maximumX: knob.x
80 drag.minimumY: slot.y
81 drag.maximumY: slot.height + slot.y - knob.height
82 }
83 }
84
85 Text {
86 font.pointSize: 16
87 color: "red"
88 anchors.bottom: parent.bottom
89 anchors.horizontalCenter: parent.horizontalCenter
90 text: root.value
91 }
92
93 Text {
94 id: label
95 font.pointSize: 12
96 color: "red"
97 anchors.top: parent.top
98 anchors.topMargin: 5
99 anchors.horizontalCenter: parent.horizontalCenter
100 }
101
102 onHeightChanged: {
103 knob.programmatic = true
104 knob.setValue(root.value)
105 knob.programmatic = false
106 }
107 }