aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/HelperWidgets/SpinBox.qml
blob: 425a845119900f2d13591cccd6f3f37981008c06 (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0

import QtQuick 2.15
import StudioControls 1.0 as StudioControls
import StudioTheme 1.0 as StudioTheme

Item {
    id: wrapper

    property alias decimals: spinBox.decimals
    property alias hasSlider: spinBox.hasSlider

    property alias minimumValue: spinBox.realFrom
    property alias maximumValue: spinBox.realTo
    property alias stepSize: spinBox.realStepSize

    property alias backendValue: spinBox.backendValue
    property alias sliderIndicatorVisible: spinBox.sliderIndicatorVisible

    property alias realDragRange: spinBox.realDragRange
    property alias pixelsPerUnit: spinBox.pixelsPerUnit

    width: 96
    implicitHeight: spinBox.height

    onFocusChanged: {
        restoreCursor()
        transaction.end()
    }

    Component.onCompleted: {
        spinBox.enabled = backendValue === undefined ? false : !isBlocked(backendValue.name)
    }

    Connections {
        target: modelNodeBackend
        function onSelectionChanged() {
            spinBox.enabled = backendValue === undefined ? false : !isBlocked(backendValue.name)
        }
    }

    StudioControls.RealSpinBox {
        id: spinBox

        __devicePixelRatio: devicePixelRatio()

        onDragStarted: {
            hideCursor()
            transaction.start()
        }

        onDragEnded: {
            restoreCursor()
            transaction.end()
        }

        // Needs to be held in place due to screen size limits potentially being hit while dragging
        onDragging: holdCursorInPlace()

        onRealValueModified: {
            if (transaction.active())
                spinBox.commitValue()
        }

        function commitValue() {
            if (spinBox.backendValue.value !== spinBox.realValue)
                spinBox.backendValue.value = spinBox.realValue
        }

        property variant backendValue
        property bool hasSlider: wrapper.sliderIndicatorVisible

        width: wrapper.width

        ExtendedFunctionLogic {
            id: extFuncLogic
            backendValue: spinBox.backendValue
        }

        actionIndicator.icon.color: extFuncLogic.color
        actionIndicator.icon.text: extFuncLogic.glyph
        actionIndicator.onClicked: extFuncLogic.show()
        actionIndicator.forceVisible: extFuncLogic.menuVisible

        ColorLogic {
            id: colorLogic
            backendValue: spinBox.backendValue
            onValueFromBackendChanged: {
                if (colorLogic.valueFromBackend !== undefined)
                    spinBox.realValue = colorLogic.valueFromBackend
            }
        }

        labelColor: spinBox.edit ? StudioTheme.Values.themeTextColor : colorLogic.textColor

        onCompressedRealValueModified: spinBox.commitValue()
    }
}