aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/macos/RangeSlider.qml
blob: da3fe83cf2ee877c4aa7fd2d699772b2bf8dbd20 (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
// 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

import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
import QtQuick.Controls.macOS.impl

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

    first.handle: SwitchHandle {
        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
        down: control.first.pressed

        readonly property bool __ignoreNotCustomizable: true
    }

    second.handle: SwitchHandle {
        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
        down: control.second.pressed

        readonly property bool __ignoreNotCustomizable: true
    }

    background: Item {
        implicitWidth: control.horizontal ? 124 : 24
        implicitHeight: control.horizontal ? 24 : 124

        readonly property bool __ignoreNotCustomizable: true
        readonly property int barThickness: 4

        // Groove background.
        Rectangle {
            x: control.horizontal ? 0 : (parent.width - width) / 2
            y: control.horizontal ? (parent.height - height) / 2 : 0
            width: control.horizontal ? parent.width : parent.barThickness
            height: control.horizontal ? parent.barThickness : parent.height
            radius: height / 2
            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"

                Rectangle {
                    x: 1
                    y: 1
                    width: parent.width - 2
                    height: parent.height - 2
                    radius: parent.radius
                    color: "transparent"
                    border.color: Qt.darker(control.palette.window, 1.05)
                    visible: Qt.styleHints.colorScheme === Qt.Light
                }
            }
        }

        // Progress bar.
        Rectangle {
            x: control.horizontal ? control.first.position * parent.width + 3 : (parent.width - width) / 2
            y: control.horizontal ? (parent.height - height) / 2 : control.second.visualPosition * parent.height + 3
            width: control.horizontal
                ? control.second.position * parent.width - control.first.position * parent.width - parent.barThickness
                : parent.barThickness
            height: control.horizontal
                ? parent.barThickness
                : control.second.position * parent.height - control.first.position * parent.height - parent.barThickness
            color: control.palette.accent
        }
    }
}