aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/wearable/Wearable/Main.qml
blob: 4bd2d268ac4963a20839d2d51da2088118c1539e (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Shapes

import WearableSettings
import WearableStyle

//! [window start]
QQC2.ApplicationWindow {
    id: window
//! [window start]
    visible: true
    width: 380
    height: 380
    title: qsTr("Wearable")

    background: Shape {//Shape because Rectangle does not support diagonal gradient
        preferredRendererType: Shape.CurveRenderer

        ShapePath {
            strokeWidth: 0
            startX: 0; startY: 0

            PathLine {
                x: window.width
                y: 0
            }
            PathLine {
                x: window.width
                y: window.height
            }
            PathLine {
                x: 0
                y: window.height
            }
            fillGradient: LinearGradient {
                x1: window.width / 3
                y1: 0
                x2: window.width
                y2: 1.3 * window.height
                GradientStop {
                    position: 0.0
                    color: UIStyle.background1
                }
                GradientStop {
                    position: 0.5
                    color: UIStyle.background2
                }
                GradientStop {
                    position: 1.0
                    color: UIStyle.background3
                }
            }
        }
    }

//! [stackview start]
    QQC2.StackView {
        id: stackView
//! [stackview start]

        anchors.fill: parent

        focus: true

//! [onLaunched connection]
        initialItem: LauncherPage {
            onLaunched: (title, page, fallback) => {
                            var createdPage = Qt.createComponent(page)
                            if (createdPage.status !== Component.Ready)
                                createdPage = Qt.createComponent(fallback)
                            stackView.push(createdPage)
                            header.title = title
                        }
        }
//! [onLaunched connection]
//! [stackview end]
    }

//! [stackview end]
    MenuHeader {
        id: header

        anchors.top: parent.top
        width: parent.width

        title: ""

        enabled: stackView.depth > 1

        onBackClicked: stackView.pop()
    }

//! [DemoMode]
    DemoMode {
        stackView: stackView
    }

//! [DemoMode]
//! [DemoModeIndicator]
    DemoModeIndicator {
        id: demoModeIndicator
        y: WearableSettings.demoMode ? header.height + 3 : -height - 5
        anchors.horizontalCenter: parent.horizontalCenter
        z: header.z + 1
    }

//! [DemoModeIndicator]
//! [MouseArea]
    MouseArea {
        enabled: WearableSettings.demoMode
        anchors.fill: parent
        onClicked: {
            // Stop demo mode and return to the launcher page.
            WearableSettings.demoMode = false
            stackView.pop(null)
        }
    }
//! [MouseArea]
//! [window end]
}
//! [window end]