aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/windows/RangeSlider.qml
blob: a124163e7be7b8afc6bacd223e79ae7e9c2fe306 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Templates as T

T.RangeSlider {
    id: control

    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
        Math.max(first.implicitHandleWidth, second.implicitHandleWidth) + leftPadding + rightPadding)
    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
        Math.max(first.implicitHandleHeight, second.implicitHandleHeight) + topPadding + bottomPadding)

    readonly property bool __notCustomizable: true
    readonly property Item __focusFrameTarget: control

    component SliderHandle: Rectangle {
        implicitWidth: control.horizontal ? 11 : 21
        implicitHeight: control.horizontal ? 21 : 11
        color: control.palette.highlight

        required property bool pressed
    }

    first.handle: SliderHandle {
        x: control.leftPadding + Math.round(control.horizontal
            ? control.first.visualPosition * (control.availableWidth - width)
            : (control.availableWidth - width) / 2)
        y: control.topPadding + Math.round(control.horizontal
            ? (control.availableHeight - height) / 2
            : control.first.visualPosition * (control.availableHeight - height))
        palette: control.palette
        pressed: control.first.pressed

        // We are the ones that get focus, but we want the control to
        // be used for the visual focus frame.
        readonly property Item __focusFrameControl: control
        readonly property bool __ignoreNotCustomizable: true
    }

    second.handle: SliderHandle {
        x: control.leftPadding + Math.round(control.horizontal
            ? control.second.visualPosition * (control.availableWidth - width)
            : (control.availableWidth - width) / 2)
        y: control.topPadding + Math.round(control.horizontal
            ? (control.availableHeight - height) / 2
            : control.second.visualPosition * (control.availableHeight - height))
        palette: control.palette
        pressed: control.second.pressed

        readonly property Item __focusFrameControl: control
        readonly property bool __ignoreNotCustomizable: true
    }

    background: Item {
        implicitWidth: control.horizontal ? 90 : 21
        implicitHeight: control.horizontal ? 21 : 90

        readonly property real __focusFrameRadius: 1
        readonly property bool __ignoreNotCustomizable: true
        readonly property int barThickness: 4

        // Groove background.
        Rectangle {
            x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2)
            y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0)
            width: control.horizontal ? control.availableWidth : parent.barThickness
            height: control.horizontal ? parent.barThickness : control.availableHeight
            color: control.palette.window

            Rectangle {
                width: parent.width
                height: parent.height
                radius: parent.radius
                // No border in dark mode, instead we fill.
                color: Qt.styleHints.colorScheme === Qt.Light
                    ? "transparent" : Qt.lighter(control.palette.window, 1.6)
                border.color: Qt.styleHints.colorScheme === Qt.Light
                    ? Qt.darker(control.palette.window, 1.1)
                    : "transparent"
            }
        }

        // Progress bar.
        Rectangle {
            x: control.leftPadding + (control.horizontal
                ? control.first.position * control.availableWidth
                : (control.availableWidth - width) / 2)
            y: control.topPadding + (control.horizontal
                ? (control.availableHeight - height) / 2
                : control.second.visualPosition * control.availableHeight)

            width: control.horizontal
                ? control.second.position * control.availableWidth - control.first.position * control.availableWidth
                : parent.barThickness
            height: control.horizontal
                ? parent.barThickness
                : control.second.position * control.availableHeight - control.first.position * control.availableHeight
            color: Qt.rgba(control.palette.highlight.r, control.palette.highlight.g, control.palette.highlight.b, 0.3)
        }
    }
}