ProgrammView.qml 7.69 KB
Newer Older
Leander Schulten's avatar
Leander Schulten committed
1
2
3
4
5
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.2

6
7
ModelView{
    model:programmModel
Leander Schulten's avatar
Leander Schulten committed
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
    id:modelView
    rows: 9
    rowSpacing: 2
    addButton.text: "Add Programm"
    removeButton.text: "Remove Programm"

    Label{
        text: "Speed : "
    }
    TextInputField{
        text: modelView.currentItem?modelView.currentItem.data.speed:""
        validator: DoubleValidator{}
        onTextChanged: modelView.currentItem.data.speed = text
    }
    Label{
        text: "Time Distortion:"
        font.underline: true
    }
    Label{}
    Label{
        Layout.leftMargin: 6
        id:beginTD
        text:"Enabled:"
    }
    CheckBox{
        id:topTD
        Layout.preferredHeight: 25
        Layout.leftMargin: -10
        checked: modelView.currentItem?modelView.currentItem.data.timeDistortion.enabled:false
        onCheckStateChanged: modelView.currentItem.data.timeDistortion.enabled = checked
    }
    Label{
        Layout.leftMargin: 6
        text:"Intervall:"
    }
    TextInputField{
        Layout.fillWidth: true
        validator: DoubleValidator{}
        text: modelView.currentItem?modelView.currentItem.data.timeDistortion.intervall:""
        onTextChanged: {if(modelView.currentItem!==null)modelView.currentItem.data.timeDistortion.intervall = text;}
    }
    Label{
        Layout.leftMargin: 6
        text: "Distortion Curve:"
    }
    ComboBox{
        Layout.fillWidth: true
        Layout.rightMargin: 5
        id:endTD
        model:easingModel
        currentIndex: modelView.currentItem?modelView.currentItem.data.timeDistortion.distortionCurve.type:0
        onCurrentIndexChanged: {if(modelView.currentItem!==null)modelView.currentItem.data.timeDistortion.distortionCurve.type = currentIndex;}
    }
    Rectangle{
        anchors.top: topTD.top
        anchors.bottom: endTD.bottom
        anchors.right: beginTD.left
        color: "lightgreen"
        width: 2
        anchors.margins: 2
        anchors.leftMargin: 6
    }

    ListView{
        clip:true
        Layout.column: 2
        Layout.columnSpan: 2
        Layout.row: 7
        Layout.fillHeight: true
        Layout.fillWidth: true

        id : channelView

        delegate: ItemDelegate{
            anchors.margins: 5
            clip : true
            width: parent.width
            height: ListView.isCurrentItem ? gridLayout.height+20:defaultHeightReference.height+20
            Behavior on height {
                NumberAnimation{
                    duration: 500
                    easing.type: Easing.OutQuart
                }
            }
            onClicked: channelView.currentIndex = index
            GridLayout{
                anchors.leftMargin: 10
                x:10
                y:10
                rowSpacing:10
                Layout.margins: 5
                columns: 2
                id:gridLayout
                Label{
                    id:defaultHeightReference
                    text:"Gerät : "
                }
                Label{
                    text: modelData.device.name
                }
                Label{
                    text:"Programm: "
                }
                Label{
                    text: modelData.programmPrototype.name
                }
                Label{
                    text:"Offset : "
                }
                TextInputField{
                    text : modelData.offset
                    onTextChanged: modelData.offset = text
                    validator: DoubleValidator{}
                }
                Label{
                    text:"Speed : "
                }
                TextInputField{
                    text : modelData.speed
                    onTextChanged: modelData.speed = text
                    validator: DoubleValidator{}
                }

            }
        }
        model: modelView.currentItem?modelView.currentItem.data.programs:null
        highlight: Rectangle{
            color: "blue"
            opacity: 0.7
        }
    }

    onAddClicked: ModelManager.addProgramm("New Programm");

    RowLayout{
        Layout.row: 8
        Layout.column: 2
        Layout.columnSpan: 2
        Layout.fillWidth: true
        Button{
            Layout.fillWidth: true
            text:"Add Programmprototype"
            font.pixelSize: 15
            onClicked: dialog.visible=true
        }
        Button{
            Layout.fillWidth: true
            text:"Remove Programmprototype"
            font.pixelSize: 15
            onClicked: modelView.currentItem.data.removeDeviceProgramm(channelView.currentIndex)
        }
    }


    Dialog{
        modality: Qt.WindowModal
        id:dialog
        title: "Ein neues DeviceProgramm hinzufügen"
        width:300
        contentItem: RowLayout {
            Pane{
                Layout.fillWidth: true
                ColumnLayout{
                    anchors.left: parent.left
                    anchors.right: parent.right
                    spacing: 10
                    ComboBox{
                        Layout.fillWidth: true
                        id:device
                        model: deviceModel
                        textRole: "display"
                    }


                    ComboBox{
                        Layout.fillWidth: true
                        id:programmPrototype
                        model: programmPrototypeModel
                        textRole: "itemData"
                        function hasProgrammPrototypeSelected(){
                            return programmPrototypeModel.data(programmPrototypeModel.index(programmPrototype.currentIndex,0),-1).devicePrototype === deviceModel.data(deviceModel.index(device.currentIndex,0),-1).prototype;
                        }
                        displayText: hasProgrammPrototypeSelected() ? programmPrototypeModel.data(programmPrototypeModel.index(currentIndex,0)):"Keine Auswahl getroffen";
                        delegate: ItemDelegate{
                            text: itemData.name
                            width: programmPrototype.popup.contentItem.width
                            visible: device.model.data(device.model.index(device.currentIndex,0),-1).prototype === itemData.devicePrototype
                        }
                    }
                    RowLayout{
                        Label{
                            id:nameLabel
                            text:"Time Offset :"
                        }
                        TextInputField{
                            Layout.fillWidth: true
                            id:name
                            text:"0"
                            validator: DoubleValidator{
                            }
                        }
                    }
                    RowLayout{
                        Button{
                            Layout.fillWidth: true
                            text:"Abbrechen"
                            onClicked: dialog.visible = false
                        }
                        Button{
                            Layout.fillWidth: true
                            text:"Erzeugen"
                            enabled: programmPrototypeModel.data(programmPrototypeModel.index(programmPrototype.currentIndex,0),-1).devicePrototype === deviceModel.data(deviceModel.index(device.currentIndex,0),-1).prototype
                            onClicked: {
                                dialog.visible = false;

                                modelView.currentItem.data.addDeviceProgramm(deviceModel.data(deviceModel.index(device.currentIndex,0),-1),programmPrototypeModel.data(programmPrototypeModel.index(programmPrototype.currentIndex,0),-1),name.text);

                            }
                        }
                    }
                }
            }
        }
    }

233
}