summaryrefslogtreecommitdiffstats
path: root/basicsuite/ebike-ui/main.qml
blob: 33fe5e8137ecd0a047657ca7901b38546f2a468e (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
/****************************************************************************
**
** 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.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtQuick.VirtualKeyboard 2.1
import QtQml 2.2
import DataStore 1.0

import "./BikeStyle"

Rectangle {
    visible: true
    width: 640
    height: 480
    color: "#111520"
    id: root

    // Permanent placeholder for time display
    ClockView {
        id: clockButton
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top

        MouseArea {
            anchors.rightMargin: -20
            anchors.leftMargin: -20
            anchors.bottomMargin: -20
            anchors.fill: parent
            onClicked: drawer.open()
        }
    }

    FpsItem {
        anchors.top: parent.top
        anchors.left: parent.left
        visible: fps.visible
    }

    // The always-visible speed view
    SpeedView {
        id: speedView
        onShowMain: swipeView.currentIndex = 1
        showZero: naviPage.targetEdit.activeFocus

        states: [
            State {
                name: ""
                when: swipeView.currentIndex == 1 && (!speedView.enlarged)
                PropertyChanges {
                    target: speedView
                    width: UILayout.speedViewRadius * 2 + 2
                    height: UILayout.speedViewRadius * 2 + 2
                    anchors.topMargin: UILayout.speedViewTop
                    anchors.leftMargin: 0
                    anchors.bottomMargin: 0
                    color: "transparent"
                    dotcount: UILayout.speedViewDots
                    curvewidth: UILayout.speedViewInnerWidth
                    speedTextSize: UILayout.speedTextSize
                    speedBaselineOffset: UILayout.speedBaselineOffset + 1
                    innerRadius: UILayout.speedViewInnerRadius
                    speedUnitsSize: UILayout.speedUnitsSize
                    speedUnitBaselineOffset: UILayout.speedTextUnitMargin
                    speedIconsOffset: UILayout.speedIconsCenterOffset
                    speedInfoTextsOffset: 0
                    speedInfoTextsSize: UILayout.speedInfoTextsSize
                    speedInfoUnitsOffset: UILayout.speedInfoUnitsOffset
                    assistPowerIconOffset: UILayout.assistPowerIconOffset
                }
                AnchorChanges {
                    target: speedView
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.top: parent.top
                    anchors.left: undefined
                    anchors.bottom: undefined
                }
                PropertyChanges {
                    target: speedView.cornerRectangle
                    color: "transparent"
                }
                AnchorChanges {
                    target: speedView.cornerRectangle
                    anchors.horizontalCenter: speedView.horizontalCenter
                    anchors.verticalCenter: speedView.verticalCenter
                    anchors.left: undefined
                    anchors.bottom: undefined
                }
                StateChangeScript {
                    script: {
                        if (musicPlayer.lastMusicPlayerState === "" && (!drawer.viewTab.musicPlayerSwitch.checked))
                            musicPlayer.state = "";
                    }
                }
            },
            State {
                name: "CORNERED"
                when: swipeView.currentIndex != 1
                PropertyChanges {
                    target: speedView
                    width: UILayout.speedViewRadiusMinified * 2
                    height: UILayout.speedViewRadiusMinified * 2
                    anchors.topMargin: 0
                    anchors.leftMargin: UILayout.speedViewCornerLeftMargin
                    anchors.bottomMargin: UILayout.speedViewCornerBottomMargin
                    color: Colors.speedViewBackgroundCornered
                    dotcount: UILayout.speedViewDotsMinified
                    curvewidth: UILayout.speedViewInnerWidthMinified
                    speedTextSize: UILayout.speedTextSizeMinified
                    speedBaselineOffset: UILayout.speedBaselineOffsetMinified
                    innerRadius: UILayout.speedViewInnerRadiusMinified
                    speedUnitBaselineOffset: UILayout.speedTextUnitMarginMinified
                }
                AnchorChanges {
                    target: speedView
                    anchors.horizontalCenter: undefined
                    anchors.top: undefined
                    anchors.left: parent.left
                    anchors.bottom: parent.bottom
                }
                PropertyChanges {
                    target: speedView.cornerRectangle
                    color: Colors.speedViewBackgroundCornered
                }
                AnchorChanges {
                    target: speedView.cornerRectangle
                    anchors.horizontalCenter: undefined
                    anchors.verticalCenter: undefined
                    anchors.left: speedView.left
                    anchors.bottom: speedView.bottom
                }
                StateChangeScript {
                    script: {
                        musicPlayer.lastMusicPlayerState = musicPlayer.state;
                        musicPlayer.state = "hidden";
                    }
                }
            },
            State {
                name: "ENLARGED"
                when: swipeView.currentIndex == 1 && speedView.enlarged
                PropertyChanges {
                    target: speedView
                    width: UILayout.speedViewRadiusEnlarged * 2
                    height: UILayout.speedViewRadiusEnlarged * 2
                    anchors.topMargin: 35
                    dotcount: UILayout.speedViewDotsEnlarged
                    speedTextSize: UILayout.speedTextSizeEnlarged
                    speedBaselineOffset: UILayout.speedBaselineOffsetEnlarged
                    innerRadius: UILayout.speedViewInnerRadiusEnlarged
                    speedUnitsSize: UILayout.speedUnitsSizeEnlarged
                    speedUnitBaselineOffset: UILayout.speedTextUnitMarginEnlarged
                    speedIconsOffset: UILayout.speedIconsCenterOffsetEnlarged
                    speedInfoTextsOffset: UILayout.speedInfoTextsOffsetEnlarged
                    speedInfoTextsSize: UILayout.speedInfoTextsSizeEnlarged
                    speedInfoUnitsOffset: UILayout.speedInfoUnitsOffsetEnlarged
                    assistPowerIconOffset: UILayout.assistPowerIconOffsetEnlarged
                }
                PropertyChanges {
                    target: mainPage.statsButton
                    anchors.leftMargin: -mainPage.statsButton.width
                    anchors.topMargin: -mainPage.statsButton.height
                }
                PropertyChanges {
                    target: mainPage.naviButton
                    anchors.rightMargin: -mainPage.naviButton.width
                    anchors.topMargin: -mainPage.naviButton.height
                }
                PropertyChanges {
                    target: mainPage.lightsButton
                    anchors.leftMargin: -mainPage.statsButton.width
                    anchors.bottomMargin: -mainPage.statsButton.height
                }
                PropertyChanges {
                    target: mainPage.modeButton
                    anchors.rightMargin: -mainPage.statsButton.width
                    anchors.bottomMargin: -mainPage.statsButton.height
                }
                PropertyChanges {
                    target: clockButton
                    anchors.topMargin: -clockButton.height
                }
                AnchorChanges {
                    target: speedView
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.top: parent.top
                    anchors.left: undefined
                    anchors.bottom: undefined
                }
                StateChangeScript {
                    script: {
                        musicPlayer.lastMusicPlayerState = musicPlayer.state;
                        musicPlayer.state = "hidden";
                    }
                }
            }
        ]

        transitions: [
            Transition {
                from: ""; to: "ENLARGED"
                NumberAnimation {
                    properties: "anchors.leftMargin,anchors.rightMargin,anchors.topMargin,anchors.bottomMargin"
                    duration: 250
                }
                NumberAnimation {
                    properties: "width,height,dotcount,speedTextSize,speedBaselineOffset,innerRadius,speedUnitsSize,speedUnitBaselineOffset,speedIconsOffset,speedInfoTextsOffset,speedInfoTextsSize,speedInfoUnitsOffset,assistPowerIconOffset"
                    duration: 250
                }
                AnchorAnimation {
                    duration: 250
                }
            },
            Transition {
                from: "ENLARGED"; to: ""
                NumberAnimation {
                    properties: "anchors.leftMargin,anchors.rightMargin,anchors.topMargin,anchors.bottomMargin"
                    easing.type: Easing.OutBack
                    duration: 250
                }
                NumberAnimation {
                    properties: "width,height,dotcount,speedTextSize,speedBaselineOffset,innerRadius,speedUnitsSize,speedUnitBaselineOffset,speedIconsOffset,speedInfoTextsOffset,speedInfoTextsSize,speedInfoUnitsOffset,assistPowerIconOffset"
                    duration: 250
                }
                AnchorAnimation {
                    duration: 250
                }
            },
            Transition {
                NumberAnimation {
                    properties: "width,height,curvewidth,speedTextSize,speedBaselineOffset,innerRadius,speedUnitMargin"
                    easing.type: Easing.OutBack
                    duration: 250
                }
                ColorAnimation {
                    duration: 250
                }
                AnchorAnimation {
                    easing.type: Easing.OutBack
                    duration: 250
                }
            }
        ]
    }

    // Configuration and settings drawer
    ConfigurationDrawer {
        id: drawer
        height: 350
        width: root.width
        edge: Qt.TopEdge
        dragMargin: 20
    }

    // Inactive swipe view, for animations
    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: 1
        interactive: false

        // List of pages
        StatsPage {}
        MainPage {
            id: mainPage
            naviGuideArrowSource: naviPage.naviGuideArrowSource
            naviGuideDistance: naviPage.naviGuideDistance
            naviGuideAddress: naviPage.naviGuideAddress
        }
        NaviPage {
            id: naviPage;
        }
    }

    // Music player
    MusicPlayer {
        id: musicPlayer
        property string lastMusicPlayerState: "unknown"
        z: 1
    }

    Connections {
        target: datastore
        onDemoReset: drawer.close()
    }

    // Virtual keyboard
    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: root.height
        width: root.width

        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: root.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
    }
}