Debian Codegraph @

app/qml/Settings/ColorComponentSlider.qml

raw
1 /*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored-by: Florian Boucault <[email protected]>
17 */
18
19 import QtQuick 2.4
20 import QtQuick.Layouts 1.3
21 import Lomiri.Components 1.3
22
23 MouseArea {
24 id: colorComponentSlider
25
26 property string label
27 property alias value: slider.value
28 property int minimumValue: 0
29 property int maximumValue: 255
30
31 function setValue(newValue) {
32 value = Math.min(maximumValue, Math.max(newValue, minimumValue));
33 }
34
35 height: row.height
36
37 onWheel: {
38 if (wheel.angleDelta.y >= 0) {
39 setValue(value+1);
40 } else {
41 setValue(value-1);
42 }
43 }
44
45 RowLayout {
46 id: row
47 spacing: units.gu(2)
48 anchors {
49 left: parent.left
50 right: parent.right
51 }
52
53 Label {
54 text: colorComponentSlider.label
55 textSize: Label.Large
56 }
57
58 Slider {
59 id: slider
60 Layout.fillWidth: true
61 minimumValue: colorComponentSlider.minimumValue
62 maximumValue: colorComponentSlider.maximumValue
63 stepSize: 1
64 live: true
65 function formatValue(v) {
66 return "";
67 }
68 }
69
70 TextFieldStyled {
71 id: textField
72 implicitWidth: units.gu(6)
73 hasClearButton: false
74 horizontalAlignment: TextInput.AlignHCenter
75 validator: IntValidator {
76 bottom: colorComponentSlider.minimumValue
77 top: colorComponentSlider.maximumValue
78 }
79 inputMethodHints: Qt.ImhDigitsOnly
80 Keys.onUpPressed: setValue(value+1)
81 Keys.onDownPressed: setValue(value-1)
82 }
83
84
85 DoubleBinding {
86 source: slider
87 target: textField
88 sourceProperty: "value"
89 targetProperty: "text"
90 function sourceToTarget(sourceValue) {
91 return Math.round(sourceValue);
92 }
93 }
94
95 }
96 }