DoubleSpinBox.qml 2.9 KB
Newer Older
1
import Qt 4.7
2 3
import Bauhaus 1.0

4
QWidget { //This is a special doubleSpinBox that does color coding for states
5

6
    id: doubleSpinBox;
7

8 9
    property variant backendValue;
    property variant baseStateFlag;
10 11 12
    property alias singleStep: box.singleStep
    property alias minimum: box.minimum
    property alias maximum: box.maximum
13
    property alias spacing: layoutH.spacing
14
    property alias text: label.text
15
    property bool alignRight: true
16
    property bool enabled: true
17 18 19 20 21 22 23 24 25 26 27

    minimumHeight: 22;

    onBaseStateFlagChanged: {
        evaluate();
    }

    onBackendValueChanged: {
        evaluate();
    }

28 29 30 31
    onEnabledChanged: {
        evaluate();
    }

32 33 34 35 36 37 38 39
    function evaluate() {
        if (backendValue === undefined)
            return;
        if (!enabled) {
            box.setStyleSheet("color: "+scheme.disabledColor);
        } else {
            if (baseStateFlag) {
                if (backendValue.isInModel)
40
                    box.setStyleSheet("color: "+scheme.changedBaseColor);
41
                else
42
                    box.setStyleSheet("color: "+scheme.defaultColor);
43 44
            } else {
                if (backendValue.isInSubState)
45
                    box.setStyleSheet("color: "+scheme.changedStateColor);
46
                else
47
                    box.setStyleSheet("color: "+scheme.defaultColor);
48
            }
49 50 51
        }
    }

52 53
    ColorScheme { id:scheme; }

54
    property bool isInModel: backendValue.isInModel;
55 56 57 58 59

    onIsInModelChanged: {
        evaluate();
    }

60
    property bool isInSubState: backendValue.isInSubState;
61 62 63 64 65

    onIsInSubStateChanged: {
        evaluate();
    }

66
    layout: HorizontalLayout {
67
        id: layoutH;
68
		spacing: 4
69 70 71

        QLabel {
            id: label;
72
            font.bold: true;
73
            alignment: doubleSpinBox.alignRight  ? "Qt::AlignRight | Qt::AlignVCenter" : "Qt::AlignLeft | Qt::AlignVCenter";
74
            maximumWidth: 40
75
            visible: doubleSpinBox.text != "";
76
        }
77 78 79

        QDoubleSpinBox {
            id: box;
80
            decimals: 1;
81
            keyboardTracking: false;
82
            enabled: !backendValue.isBound && doubleSpinBox.enabled;
83

84
            property bool readingFromBackend: false;
85
            property real valueFromBackend: doubleSpinBox.backendValue.value;
86

87 88 89 90
            onValueFromBackendChanged: {
                readingFromBackend = true;
                value = valueFromBackend
                readingFromBackend = false;
91
            }
92

93
            onValueChanged: {
94
                doubleSpinBox.backendValue.value = value;
95 96
            }

97
            onMouseOverChanged: {
98 99

            }
100 101 102

            onFocusChanged: {
                if (focus)
103
                transaction.start();
104
                else
105
                transaction.end();
106
            }
107
        }
108
    }
109

110
    ExtendedFunctionButton {
111
        backendValue: doubleSpinBox.backendValue;
112 113
        y: box.y + 4
        x: box.x + 2
114
        visible: doubleSpinBox.enabled
115 116
    }
}