| 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 |
Rectangle { |
| 32 |
id: root |
| 33 |
property real contentHeight: 100 |
| 34 |
property FakeFlickable flick: null |
| 35 |
property real position |
| 36 |
|
| 37 |
onPositionChanged: if (flick && (drag.active || tap.active)) { |
| 38 |
if (knob.state === "horizontal") |
| 39 |
flick.contentX = position * knob.scrollDistance |
| 40 |
else if (knob.state === "vertical") |
| 41 |
flick.contentY = position * knob.scrollDistance |
| 42 |
} |
| 43 |
|
| 44 |
SystemPalette { id: palette } |
| 45 |
|
| 46 |
color: palette.button |
| 47 |
border.color: Qt.darker(palette.button, 1.5) |
| 48 |
gradient: Gradient { |
| 49 |
GradientStop { position: 0; color: Qt.darker(palette.button, 1.3) } |
| 50 |
GradientStop { position: 1; color: palette.button } |
| 51 |
} |
| 52 |
antialiasing: true |
| 53 |
radius: Math.min(width, height) / 6 |
| 54 |
width: 20 |
| 55 |
height: 20 |
| 56 |
|
| 57 |
TapHandler { |
| 58 |
id: tap |
| 59 |
onTapped: { |
| 60 |
if (knob.state === "horizontal") |
| 61 |
knob.x = position.x - knob.width / 2 |
| 62 |
else if (knob.state === "vertical") |
| 63 |
knob.y = position.y - knob.height / 2 |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
Rectangle { |
| 68 |
id: knob |
| 69 |
border.color: "black" |
| 70 |
border.width: 1 |
| 71 |
gradient: Gradient { |
| 72 |
GradientStop { position: 0; color: palette.button } |
| 73 |
GradientStop { position: 1; color: Qt.darker(palette.button, 1.3) } |
| 74 |
} |
| 75 |
radius: 2 |
| 76 |
antialiasing: true |
| 77 |
state: root.height > root.width ? "vertical" : root.height < root.width ? "horizontal" : "" |
| 78 |
property real scrollDistance: 0 |
| 79 |
property real scrolledX: 0 |
| 80 |
property real scrolledY: 0 |
| 81 |
property real max: 0 |
| 82 |
|
| 83 |
Binding on x { |
| 84 |
value: knob.scrolledX |
| 85 |
when: !drag.active |
| 86 |
} |
| 87 |
|
| 88 |
Binding on y { |
| 89 |
value: knob.scrolledY |
| 90 |
when: !drag.active |
| 91 |
} |
| 92 |
|
| 93 |
states: [ |
| 94 |
// We will control the horizontal. We will control the vertical. |
| 95 |
State { |
| 96 |
name: "horizontal" |
| 97 |
PropertyChanges { |
| 98 |
target: knob |
| 99 |
max: root.width - knob.width |
| 100 |
scrolledX: Math.min(max, Math.max(0, max * flick.contentX / (flick.width - flick.contentWidth))) |
| 101 |
scrolledY: 1 |
| 102 |
scrollDistance: flick.width - flick.contentWidth |
| 103 |
width: flick.width * (flick.width / flick.contentWidth) - (height - anchors.margins) * 2 |
| 104 |
height: root.height - 2 |
| 105 |
} |
| 106 |
PropertyChanges { |
| 107 |
target: drag |
| 108 |
xAxis.minimum: 0 |
| 109 |
xAxis.maximum: knob.max |
| 110 |
yAxis.minimum: 1 |
| 111 |
yAxis.maximum: 1 |
| 112 |
} |
| 113 |
PropertyChanges { |
| 114 |
target: root |
| 115 |
position: knob.x / drag.xAxis.maximum |
| 116 |
} |
| 117 |
}, |
| 118 |
State { |
| 119 |
name: "vertical" |
| 120 |
PropertyChanges { |
| 121 |
target: knob |
| 122 |
max: root.height - knob.height |
| 123 |
scrolledX: 1 |
| 124 |
scrolledY: Math.min(max, Math.max(0, max * flick.contentY / (flick.height - flick.contentHeight))) |
| 125 |
scrollDistance: flick.height - flick.contentHeight |
| 126 |
width: root.width - 2 |
| 127 |
height: root.width - 2 |
| 128 |
} |
| 129 |
PropertyChanges { |
| 130 |
target: drag |
| 131 |
xAxis.minimum: 1 |
| 132 |
xAxis.maximum: 1 |
| 133 |
yAxis.minimum: 0 |
| 134 |
yAxis.maximum: knob.max |
| 135 |
} |
| 136 |
PropertyChanges { |
| 137 |
target: root |
| 138 |
position: knob.y / drag.yAxis.maximum |
| 139 |
} |
| 140 |
} |
| 141 |
] |
| 142 |
|
| 143 |
DragHandler { |
| 144 |
id: drag |
| 145 |
} |
| 146 |
} |
| 147 |
} |