summaryrefslogtreecommitdiffstats
path: root/basicsuite/ebike-ui/BikeInfoTab.qml
blob: 0dc4f27af43ffb329312a31f17056c1b8eddfc06 (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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the E-Bike demo project.
**
** $QT_BEGIN_LICENSE:LGPL3$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import DataStore 1.0

import "./BikeStyle"

Item {
    property string selectedComponent: "battery"
    property string bikeImageSource: "images/bike-battery.png"
    property string componentName: "Battery"
    property string componentStatusImageSource: "images/ok.png"
    property color statusLineColor: selectedComponent === "rearwheel" ? Colors.bikeInfoLineWarning : Colors.bikeInfoLineOk
    property int statusLineLength: 280
    property string primaryDetails: "Health"
    property string primaryDetailsValue: "85%"
    property bool primaryDetailsOk: true
    property var activeComponent: batteryCircle

    function updateComponent() {
        if (selectedComponent === "")
            bikeImageSource = "images/bike.png";
        else
            bikeImageSource = "images/bike-" + selectedComponent + ".png";

        if (selectedComponent === "battery") {
            componentName = "Battery";
            primaryDetails = "Health";
            primaryDetailsValue = "85%";
            primaryDetailsOk = true;
            statusLineLength = 280;
        } else if (selectedComponent === "brakes") {
            componentName = "Brakes";
            primaryDetails = "Health";
            primaryDetailsValue = "85%";
            primaryDetailsOk = true;
            statusLineLength = 448;
        } else if (selectedComponent === "chain") {
            componentName = "Chain";
            primaryDetails = "Health";
            primaryDetailsValue = "85%";
            primaryDetailsOk = true;
            statusLineLength = 0;
        } else if (selectedComponent === "gears") {
            componentName = "Gears";
            primaryDetails = "Health";
            primaryDetailsValue = "85%";
            primaryDetailsOk = true;
            statusLineLength = 245;
        } else if (selectedComponent === "light") {
            componentName = "Light";
            primaryDetails = "Health";
            primaryDetailsValue = "85%";
            primaryDetailsOk = true;
            statusLineLength = 300;
        } else if (selectedComponent === "frontwheel") {
            componentName = "Front wheel";
            primaryDetails = "Tire pressure";
            primaryDetailsValue = "6.8 bar / 100 psi";
            primaryDetailsOk = true;
            statusLineLength = 340;
        } else if (selectedComponent === "rearwheel") {
            componentName = "Rear wheel";
            primaryDetails = "Tire pressure";
            primaryDetailsValue = "4.0 bar / 58 psi";
            primaryDetailsOk = false;
            statusLineLength = 210;
        }
    }

    Text {
        id: bikeInfoText
        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
        }
        height: UILayout.configurationItemHeight
        width: parent.width
        text: qsTr("BIKE INFO")
        font {
            family: "Montserrat, Medium"
            weight: Font.Medium
            pixelSize: UILayout.configurationTitleSize
        }
        color: Colors.tabTitleColor
        verticalAlignment: Text.AlignVCenter
    }

    ColumnSpacer {
        id: spacer
        anchors.top: bikeInfoText.bottom
        color: Colors.tabItemBorder
    }


    Image {
        id: bikeImage
        anchors {
            top: spacer.bottom
            right: parent.right
            rightMargin: -30
        }
        source: bikeImageSource
    }

    Rectangle {
        id: brakesCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 43
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 243
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "brakes" ? Colors.bikeInfoLineOk : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = brakesCircle;
                selectedComponent = "brakes"
                updateComponent()
            }
        }
    }

    Rectangle {
        id: lightCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 77
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 252
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "light" ? Colors.bikeInfoLineOk : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = lightCircle;
                selectedComponent = "light"
                updateComponent()
            }
        }
    }

    Rectangle {
        id: batteryCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 106
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 200
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "battery" ? Colors.bikeInfoLineOk : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = batteryCircle;
                selectedComponent = "battery"
                updateComponent()
            }
        }
    }

    Rectangle {
        id: gearsCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 143
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 106
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "gears" ? Colors.bikeInfoLineOk : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = gearsCircle;
                selectedComponent = "gears"
                updateComponent()
            }
        }
    }

    Rectangle {
        id: rearWheelCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 144
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 56
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "rearwheel" ? Colors.bikeInfoLineWarning : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = rearWheelCircle;
                selectedComponent = "rearwheel"
                updateComponent()
            }
        }

        Image {
            anchors.centerIn: parent
            source: "images/warning.png"
        }
    }

    Rectangle {
        id: frontWheelCircle
        width: 2 * UILayout.bikeInfoCircleRadius
        height: 2 * UILayout.bikeInfoCircleRadius
        radius: UILayout.bikeInfoCircleRadius
        anchors {
            verticalCenter: bikeImage.top
            verticalCenterOffset: 144
            horizontalCenter: bikeImage.left
            horizontalCenterOffset: 322
        }

        color: "transparent"
        border.width: UILayout.bikeInfoLineWidth
        border.color: selectedComponent === "frontwheel" ? Colors.bikeInfoLineOk : Colors.bikeInfoDeselected

        MouseArea {
            anchors.fill: parent
            onClicked: {
                activeComponent = frontWheelCircle;
                selectedComponent = "frontwheel"
                updateComponent()
            }
        }
    }

    Canvas {
        id: slantedLine
        anchors {
            left: statusLineHorizontal.right
            top: statusLineHorizontal.top
            right: activeComponent.horizontalCenter
            bottom: activeComponent.verticalCenter
        }

        onPaint: {
            var ctx = getContext("2d");
            ctx.reset();

            // Calculate line length and subtract circle radius
            var lineLength = Math.sqrt(slantedLine.width * slantedLine.width +
                                       slantedLine.height * slantedLine.height);
            lineLength -= UILayout.bikeInfoCircleRadius;

            // Calculate angle
            var angle = Math.atan2(slantedLine.height, slantedLine.width);

            // Calculate new endpoints
            var x = Math.cos(angle) * lineLength;
            var y = Math.sin(angle) * lineLength;

            ctx.lineCap = "round";
            ctx.strokeStyle = statusLineColor;
            ctx.lineWidth = UILayout.bikeInfoLineWidth;
            ctx.beginPath();
            ctx.moveTo(0, 1);
            ctx.lineTo(x, y);
            ctx.stroke();
        }
    }

    Image {
        id: componentStatusImage
        anchors {
            verticalCenter: spacer.bottom
            verticalCenterOffset: (UILayout.bikeInfoComponentBaselineOffset + UILayout.bikeInfoComponentLineOffset) / 2
            left: parent.left
        }
        source: componentStatusImageSource
        visible: selectedComponent != ""
    }

    Text {
        id: componentNameText
        anchors {
            baseline: spacer.bottom
            baselineOffset: UILayout.bikeInfoComponentBaselineOffset
            left: componentStatusImage.right
            leftMargin: 5
        }
        font {
            family: "Montserrat, Medium"
            weight: Font.Medium
            pixelSize: UILayout.bikeInfoComponentHeaderTextSize
        }
        color: Colors.bikeInfoComponentHeader
        text: componentName
        visible: selectedComponent != ""
    }

    // The line goes here somehow
    Rectangle {
        id: statusLineHorizontal
        anchors {
            top: componentNameText.baseline
            topMargin: UILayout.bikeInfoComponentLineOffset
            left: parent.left
        }
        height: UILayout.bikeInfoLineWidth
        width: statusLineLength
        color: statusLineColor
        visible: selectedComponent != ""
    }

    Text {
        id: primaryDetailsText
        anchors {
            baseline: statusLineHorizontal.bottom
            baselineOffset: UILayout.bikeInfoLineDetailsMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Light"
            weight: Font.Light
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: Colors.bikeInfoComponentText
        text: primaryDetails
        visible: selectedComponent != ""
    }

    Text {
        id: primaryDetailsValueText
        anchors {
            baseline: primaryDetailsText.baseline
            baselineOffset: UILayout.bikeInfoDetailsValueMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Medium"
            weight: Font.Medium
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: primaryDetailsOk ? Colors.bikeInfoComponentOk : Colors.bikeInfoComponentWarning
        text: primaryDetailsValue
        visible: selectedComponent != ""
    }

    Text {
        id: lastMaintenanceText
        anchors {
            baseline: primaryDetailsValueText.baseline
            baselineOffset: UILayout.bikeInfoDetailsBaselineMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Light"
            weight: Font.Light
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: Colors.bikeInfoComponentText
        text: qsTr("Last maintenance")
        visible: selectedComponent != ""
    }

    Text {
        id: lastMaintenanceValueText
        anchors {
            baseline: lastMaintenanceText.baseline
            baselineOffset: UILayout.bikeInfoDetailsValueMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Medium"
            weight: Font.Medium
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: Colors.bikeInfoComponentOk
        text: "10/3/2017"
        visible: selectedComponent != ""
    }

    Text {
        id: nextMaintenanceText
        anchors {
            baseline: lastMaintenanceValueText.baseline
            baselineOffset: UILayout.bikeInfoDetailsBaselineMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Light"
            weight: Font.Light
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: Colors.bikeInfoComponentText
        text: qsTr("Scheduled maintenance")
        visible: selectedComponent != ""
    }

    Text {
        id: nextMaintenanceValueText
        anchors {
            baseline: nextMaintenanceText.baseline
            baselineOffset: UILayout.bikeInfoDetailsValueMargin
            left: parent.left
        }
        font {
            family: "Montserrat, Medium"
            weight: Font.Medium
            pixelSize: UILayout.bikeInfoInfoHeaderTextSize
        }
        color: Colors.bikeInfoComponentOk
        text: "10/3/2018"
        visible: selectedComponent != ""
    }
}