CheckBox.qml 1.87 KB
Newer Older
1
import Qt 4.7
2
import Bauhaus 1.0
3

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

6
    id: checkBox;
7

8
    property variant backendValue;
9

10
    property variant baseStateFlag;
11 12
    property alias checkable: localCheckBox.checkable
    property alias text: localLabel.text
13

14
    onBaseStateFlagChanged: {
15 16 17
        evaluate();
    }

18 19 20
    onBackendValueChanged: {
        evaluate();
    }
21

22
    property bool isInModel: backendValue.isInModel;
23 24 25 26 27

    onIsInModelChanged: {
        evaluate();
    }

28
    property bool isInSubState: backendValue.isInSubState;
29 30 31 32 33

    onIsInSubStateChanged: {
        evaluate();
    }

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

    ColorScheme { id:scheme; }
53 54 55 56 57 58


    layout: HorizontalLayout {
        spacing: 4

        QCheckBox {
59
            id: localCheckBox
60
            checkable: true;
61
            checked: backendValue.value;
62 63 64
            onToggled: {
                backendValue.value = checked;
            }
65
            maximumWidth: 30
66 67 68
        }

        QLabel {
69
            id: localLabel
70
            font.bold: true;
71
            alignment: "Qt::AlignLeft | Qt::AlignVCenter"
72 73 74 75 76 77
        }

    }


    ExtendedFunctionButton {
78
        backendValue: checkBox.backendValue
79
        y: 3
80
        x: localCheckBox.x + 18;
81
    }
82
}
83