summaryrefslogtreecommitdiffstats
path: root/app/logfile/LogPlay.qml
blob: c8e68fd35ae6092d770fd5a41da96ddfa07f7ce3 (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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
 * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import LogPlayImpl 1.0
import '..'

ColumnLayout {
    property int blankheight : 50
    property bool playing: false

    property var timelist : ''
    property var stime : ['1970', '01', '01', '00', '00', '00']
    property var etime : ['1970', '01', '01', '00', '00', '00']
    property var portslist : ['None']

    anchors.left: parent.left
    anchors.right: parent.right

    Item { height:blankheight }

    RowLayout{
        anchors.left: parent.left
        anchors.right: parent.right
        Label { text: 'CAN Log files: ' ; color: '#59FF7F'}
        RowLayout{
            anchors.right: parent.right
            Label { text: 'Port : ' }
            ComboBox {
                id: ports
                implicitWidth: 220
                font.family: 'Roboto'
                font.pixelSize: 30
                model: portslist
                contentItem: Text {
                    text: ports.displayText
                    font: ports.font
                    color: ports.pressed ? "#17a81a" : "white"
                    horizontalAlignment: Text.AlignLeft
                    verticalAlignment: Text.AlignVCenter
                    elide: Text.ElideRight
                }
                indicator: Canvas {
                    id: canvas
                    x: ports.width - width - ports.rightPadding
                    y: ports.topPadding + (ports.availableHeight - height) / 2
                    width: 20
                    height: 12
                    contextType: "2d"

                    Connections {
                        target: ports
                        onPressedChanged: canvas.requestPaint()
                    }

                    onPaint: {
                        context.reset();
                        context.moveTo(0, 0);
                        context.lineTo(width, 0);
                        context.lineTo(width / 2, height);
                        context.closePath();
                        context.fillStyle = ports.pressed ? "#17a81a" : "white";
                        context.fill();
                    }
                }
                popup: Popup {
                    id: portspopup
                    y: ports.height - 1
                    implicitWidth: ports.width
                    implicitHeight: listview.contentHeight
                    padding: 0

                    contentItem: ListView {
                        id: listview
                        clip: true
                        model: portspopup.visible ? ports.delegateModel : null
                        currentIndex: ports.highlightedIndex
                        ScrollIndicator.vertical: ScrollIndicator { }
                    }

                    background: Image {
                        source:'./images/HMI_Settings_Button_Cancel.svg'
                    }
                }
                delegate: ItemDelegate {
                    id: popupdelegate
                    width: ports.width
                    contentItem: Item {
                        implicitHeight: 30
                        Text {
                            text: modelData
                            color: popupdelegate.pressed || highlighted ? "#21be2b" : "white"
                            font: ports.font
                            elide: Text.ElideRight
                            verticalAlignment: Text.AlignVCenter
                        }
                    }

                    highlighted: ports.highlightedIndex == index
                }

                background: Image {
                    source:'./images/HMI_Settings_Button_Cancel.svg'
                }
                onCurrentTextChanged: {
                    if(currentText != 'None') {
                        timelist = logplayimpl.getCanLogTime(currentText)
                    }
                }
                onModelChanged: {
                    if(currentText == '' || currentText == 'None') {
                        enabled = false
                    }
                    else {
                        enabled = true
                    }
                }
            }
        }
    }
    Item { height:blankheight/3 }
    Image { source: '../images/HMI_Settings_DividingLine.svg' }
    Item { height:blankheight/3 }
    ListView {
        id: loglist
        property int impheight: 0
        property int listitemheight : 50
        property int listmaxheight : 600

        anchors.left: parent.left
        anchors.right: parent.right
        anchors.margins: 20
        implicitHeight: 0
        clip: true
        model:logplayimpl
        delegate: MouseArea {
            height: loglist.listitemheight
            width: ListView.view.width
            Label {
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                visible: model.children > 0 ? true : false
                text: '' + model.children
                color: 'gray'
                font.pixelSize: 30
            }
            Image {
                source: '../images/HMI_Settings_DividingLine.svg'
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                visible: model.index > 0
            }
            Image {
                visible: loglist.currentIndex === model.index ? true : false
                anchors.fill: parent
                source:'./images/HMI_Settings_Button_Cancel.svg'
            }
            Label {
                anchors.left: parent.left
                anchors.bottom: parent.bottom
                anchors.margins: 5
                text: model.folder ? model.name : ' > ' + model.name
                color: model.folder ? 'gray' : (loglist.currentIndex === model.index ? 'orange' : 'white')
                font.pixelSize: 30
            }
            onClicked: {
                if(!model.folder) {
                    loglist.currentIndex = model.index
                }
            }
        }
        onCountChanged: {
            impheight = (count * listitemheight) > listmaxheight ? listmaxheight : (count * listitemheight)
            implicitHeight = impheight
        }

        Component.onCompleted: {
            currentIndex = -1
        }
        onCurrentIndexChanged: {
            model.setLogFileIndex(currentIndex)
            portslist = model.getPortsList()
            if(portslist.length == 0) {
                portslist = ['None']
            }
            timelist = model.getCanLogTime(ports.currentText)
        }
    }
    Item { height:blankheight/3 }
    Image { source: '../images/HMI_Settings_DividingLine.svg' }
    Item { height:blankheight/3 }
    Repeater {
        id: logtime
        model: ['Start Time : ', 'End Time : ']
        delegate: RowLayout {
            property var curidx: model.index
            Item {
                implicitHeight: 50
                implicitWidth: 250
                Label {
                    anchors.right: parent.right
                    anchors.bottom: parent.bottom
                    text: model.modelData
                }
            }
            Repeater{
                id: datetime
                property list<IntValidator> range: [
                    IntValidator{bottom: 0; top: 23;},
                    IntValidator{bottom: 0; top: 59;},
                    IntValidator{bottom: 0; top: 59;}
                ]
                model: 6
                RowLayout {
                    implicitHeight: 50
                    implicitWidth: 120
                    Label {
                        anchors.bottom: parent.bottom
                        visible: model.index > 0 ? true : false
                        text: model.index === 3 ? '   ' : model.index > 3 ? ':' : '/'
                        color: model.index < 3 ? 'gray' : 'white'
                        font.pixelSize: 30
                    }
                    TextField {
                        implicitWidth: model.index > 0 ? 60 : 90
                        width: model.index > 0 ? 60 : 90
                        text: (curidx*datetime.count + model.index) >= timelist.length ? '-' : timelist[(curidx*datetime.count + model.index)]
                        color: model.index > 2 ? 'white' : 'gray'
                        enabled: false
                        font.pixelSize: 30
                        horizontalAlignment: TextInput.AlignHCenter
                        verticalAlignment: TextInput.AlignBottom
                        onTextChanged: {
                            if(model.index > 2 && text !== '/') {
                                enabled = true
                                if(text.length > 2) {
                                    text = text.substring(text.length-2, text.length)
                                }
                            }
                            else {
                                enabled = false
                            }
                            if(curidx == 0 ) {
                                if(model.index < stime.length) {
                                    stime[model.index] = text;
                                }
                            }
                            else {
                                if(model.index < stime.length) {
                                    etime[model.index] = text;
                                }
                            }
                        }
                        onFocusChanged: {
                            root.updateKeyBoard()
                            if(!focus) {
                                if(text.length === 0) {
                                    text = '00'
                                }
                                else if(text.length === 1 && text !== '/') {
                                    text = '0' + text
                                }
                            }
                        }
                    }
                }
                Component.onCompleted: {
                    for(var i = 3, j = 0; i < count && j < range.length; i++, j++) {
                        itemAt(i).children[1].validator = range[j]
                        root.addTarget(itemAt(i).children[1])
                    }
                }
            }
            Label {
                property int timeindex: 3+curidx*datetime.count
                anchors.right: parent.right
                anchors.bottom: parent.bottom
                text: (timelist.length <= timeindex+2) ? '(-:-:-)' :
                                                         '('+timelist[timeindex]+':'+timelist[timeindex+1]+':'+timelist[timeindex+2]+')'
                color: 'gray'
                font.pixelSize: 20
            }
        }
    }
    Item { height:blankheight/3 }
    RowLayout {
        anchors.left: parent.left
        anchors.right: parent.right
        Button {
            anchors.left: parent.left
            anchors.leftMargin: 100
            text: 'Refresh'
            highlighted: true
            onClicked: {
                loglist.currentIndex = -1
                logplayimpl.refresh()
            }
        }
        Button {
            anchors.right: parent.right
            anchors.rightMargin: 100
            text: playing ? 'Stop' : 'Play'
            highlighted: true
            onClicked: {
                if(playing) {
                    playing = false
                    logplayimpl.CANPlay(false)
                }
                else {
                    if(logplayimpl.checkTime(ports.currentText, stime, etime))
                    {
                        logplayimpl.setCANProperty(loglist.currentIndex, ports.currentText, stime, etime)
                        if(logplayimpl.CANPlay(true))
                            playing = true
                    }
                }
            }
        }
    }

    LogPlayImpl { id: logplayimpl }

    onVisibleChanged: {
        if(visible) {
            logplayimpl.refresh()
        }
        else {
            resetPosition()
        }
    }

    function adjustPosition(offset) {
        loglist.implicitHeight -= offset
        loglist.positionViewAtIndex(loglist.currentIndex, ListView.Beginning)
    }

    function resetPosition() {
        loglist.implicitHeight = loglist.impheight
    }
}