summaryrefslogtreecommitdiff
path: root/retrace/daemon/ui/qml/StateControl.qml
blob: ff54c76d3d0533e85029c8157b21fa416524c5d2 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import ApiTrace 1.0

Item {
    property QStateModel stateModel

    ScrollView {
        anchors.fill: parent
        ListView {
            id: stateList
            model: stateModel.state
            anchors.fill: parent
            delegate: Component {
                Row {
                    visible: modelData.visible
                    height: modelData.visible ? combo.height : 0
                    spacing: 10
                    Rectangle {
                        id: indent
                        width: nameText.height * modelData.indent
                        height: 1
                        opacity: 0.0
                    }
                    Image {
                        id: collapse
                        anchors.verticalCenter: nameText.verticalCenter
                        width: nameText.height * 0.75
                        height: nameText.height * 0.75
                        source: "qrc:///qml/images/if_next_right_82215.png"
                        visible: (modelData.valueType == QStateValue.KglDirectory)
                        property var collapsed: false
                        transform: Rotation {
                            origin.x: collapse.width / 2
                            origin.y: collapse.width / 2
                            angle: collapse.collapsed ? 0 : 90
                        }

                        MouseArea {
                            anchors.fill: parent
                            onClicked: {
                                if (collapse.collapsed) {
                                    stateModel.expand(modelData.path);
                                    collapse.collapsed = false
                                } else {
                                    stateModel.collapse(modelData.path);
                                    collapse.collapsed = true
                                }
                            }
                        }
                    }
                    Text {
                        id: nameText
                        anchors.verticalCenter: parent.verticalCenter
                        text: modelData.name + " : "
                    }
                    TextInput {
                        anchors.margins: 3
                        anchors.verticalCenter: parent.verticalCenter
                        visible: (modelData.valueType == QStateValue.KglFloat)
                        validator: DoubleValidator{}
                        text: (modelData.valueType == QStateValue.KglFloat) ? modelData.value : ""
                        Keys.onReturnPressed: {
                            if (!acceptableInput) {
                                text = modelData.value;
                                return;
                            }
                            stateModel.setState(modelData.group,
                                                modelData.path,
                                                modelData.name,
                                                0,
                                                text);
                        }
                    }
                    Row {
                        anchors.verticalCenter: parent.verticalCenter
                        spacing: 10
                        visible: (modelData.valueType == QStateValue.KglColor)
                        Text{
                            text: "Red: "
                        }
                        TextInput {
                            anchors.margins: 3
                            validator: DoubleValidator{}
                            text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[0] : ""
                            Keys.onReturnPressed: {
                                if (!acceptableInput) {
                                    text = modelData.value[0];
                                    return;
                                }
                                stateModel.setState(modelData.group,
                                                    modelData.path,
                                                    modelData.name,
                                                    0,
                                                    text);
                            }
                        }
                        Text{
                            text: "Blue: "
                        }
                        TextInput {
                            anchors.margins: 3
                            validator: DoubleValidator{}
                            text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[1] : ""
                            Keys.onReturnPressed: {
                                if (!acceptableInput) {
                                    text = modelData.value[1];
                                    return;
                                }
                                stateModel.setState(modelData.group,
                                                    modelData.path,
                                                    modelData.name,
                                                    1,
                                                    text);
                            }
                        }
                        Text{
                            text: "Green: "
                        }
                        TextInput {
                            anchors.margins: 3
                            validator: DoubleValidator{}
                            text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[2] : ""
                            Keys.onReturnPressed: {
                                if (!acceptableInput) {
                                    text = modelData.value[2];
                                    return;
                                }
                                stateModel.setState(modelData.group,
                                                    modelData.path,
                                                    modelData.name,
                                                    2,
                                                    text);
                            }
                        }
                        Text{
                            text: "Alpha: "
                        }
                        TextInput {
                            validator: DoubleValidator{}
                            anchors.margins: 3
                            text: (modelData.valueType == QStateValue.KglColor) ? modelData.value[3] : ""
                            Keys.onReturnPressed: {
                                if (!acceptableInput) {
                                    text = modelData.value[3];
                                    return;
                                }
                                stateModel.setState(modelData.group,
                                                    modelData.path,
                                                    modelData.name,
                                                    3,
                                                    text);
                            }
                        }
                    }
                    ComboBoxFitContents {
                        id: combo
                        anchors.verticalCenter: parent.verticalCenter
                        model: modelData.choices
                        currentIndex: (modelData.valueType == QStateValue.KglEnum ? modelData.value : 0)
                        visible: (modelData.valueType == QStateValue.KglEnum)
                        onActivated: {
                            stateModel.setState(modelData.group,
                                                modelData.path,
                                                modelData.name,
                                                0,
                                                modelData.choices[currentIndex]);
                        }
                    }
                }
            }
        }
    }
}