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

pragma ComponentBehavior: Bound

import QtQuick
import QtQuick.Controls as QQC2
import WearableStyle

//! [LauncherPage start]
PathView {
    id: circularView

    signal launched(string title, string page, string fallbackpage)
//! [LauncherPage start]

    readonly property int cX: width / 2
    readonly property int cY: height / 2
    readonly property int size: Math.min(width - 80, height)
    readonly property int itemSize: size / 5
    readonly property int radius: size / 2 - itemSize / 4

    snapMode: PathView.SnapToItem

//! [Model start]
    model: ListModel {
//! [Model start]
        ListElement {
            title: qsTr("World Clock")
            pageIcon: "clock"
            page: "WorldClockPage.qml"
            fallback: ""
        }
//! [Model mid]
        ListElement {
            title: qsTr("Navigation")
            pageIcon: "maps"
            page: "NavigationPage.qml"
            fallback: "NavigationFallbackPage.qml"
        }
//! [Model mid]
        ListElement {
            title: qsTr("Weather")
            pageIcon: "weather"
            page: "WeatherPage.qml"
            fallback: "WeatherPage.qml"
        }
        ListElement {
            title: qsTr("Fitness")
            pageIcon: "hearth"
            page: "FitnessPage.qml"
            fallback: ""
        }
        ListElement {
            title: qsTr("Notifications")
            pageIcon: "notification"
            page: "NotificationsPage.qml"
            fallback: ""
        }
        ListElement {
            title: qsTr("Alarm")
            pageIcon: "bell"
            page: "AlarmsPage.qml"
            fallback: ""
        }
//! [Model end]
        ListElement {
            title: qsTr("Settings")
            pageIcon: "settings"
            page: "SettingsPage.qml"
            fallback: ""
        }
    }
//! [Model end]

//! [Delegate start]
    delegate: QQC2.RoundButton {
//! [Delegate start]
        width: circularView.itemSize
        height: circularView.itemSize

        required property string title
        required property string pageIcon
        required property string page
        required property string fallback
        required property int index

//! [Delegate mid]
        icon.width: 36
        icon.height: 36
        icon.source: UIStyle.iconPath(pageIcon)
        icon.color: UIStyle.textColor
//! [Delegate mid]
        padding: 12

        background: Rectangle {
            radius: width / 2
            color: parent.PathView.isCurrentItem ? UIStyle.highlightColor : UIStyle.buttonBackground
            border.width: 1
            border.color: UIStyle.buttonGrayOutLine

            Rectangle {
                radius: parent.radius
                anchors.fill: parent
                gradient: Gradient {
                    GradientStop {
                        position: 0.0
                        color: UIStyle.gradientOverlay1
                    }
                    GradientStop {
                        position: 1.0
                        color: UIStyle.gradientOverlay2
                    }
                }
            }
        }

//! [Delegate end]
        onClicked: {
            if (PathView.isCurrentItem)
                circularView.launched(title, Qt.resolvedUrl(page), Qt.resolvedUrl(fallback))
            else
                circularView.currentIndex = index
        }
    }
//! [Delegate end]

    path: Path {
        startX: circularView.cX
        startY: circularView.cY
        PathAttribute {
            name: "itemOpacity"
            value: 1.0
        }
        PathLine {
            x: circularView.cX + circularView.radius
            y: circularView.cY
        }
        PathAttribute {
            name: "itemOpacity"
            value: 0.7
        }
        PathArc {
            x: circularView.cX - circularView.radius
            y: circularView.cY
            radiusX: circularView.radius
            radiusY: circularView.radius
            useLargeArc: true
            direction: PathArc.Clockwise
        }
        PathAttribute {
            name: "itemOpacity"
            value: 0.5
        }
        PathArc {
            x: circularView.cX + circularView.radius
            y: circularView.cY
            radiusX: circularView.radius
            radiusY: circularView.radius
            useLargeArc: true
            direction: PathArc.Clockwise
        }
        PathAttribute {
            name: "itemOpacity"
            value: 0.3
        }
    }

    Text {
        id: appTitle

        property Item currentItem: circularView.currentItem

        visible: currentItem ? currentItem.PathView.itemOpacity === 1.0 : 0

        text: currentItem ? currentItem.title : ""
        anchors.centerIn: parent
        anchors.verticalCenterOffset: circularView.itemSize / 2 + height / 2

        font: UIStyle.h1
        color: UIStyle.textColor
    }
//! [LauncherPage end]
}
//! [LauncherPage end]