-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.qml
268 lines (216 loc) · 7.64 KB
/
main.qml
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
import QtQuick 2.4
import Material 0.2
import Material.ListItems 0.1 as ListItem
ApplicationWindow {
id: demo
title: "Material for QtQuick Demo"
// Necessary when loading the window from C++
visible: true
theme {
primaryColor: "blue"
accentColor: "red"
tabHighlightColor: "white"
}
property var styles: [
"Custom Icons", "Color Palette", "Typography"
]
property var basicComponents: [
"Button", "CheckBox", "Progress Bar", "Radio Button",
"Slider", "Switch", "TextField"
]
property var compoundComponents: [
"Bottom Sheet", "Dialog", "Forms", "List Items", "Page Stack", "Time Picker", "Date Picker"
]
property var sections: [ basicComponents, styles, compoundComponents ]
property var sectionTitles: [ "Basic Components", "Style", "Compound Components" ]
property string selectedComponent: sections[0][0]
initialPage: TabbedPage {
id: page
title: "Demo"
actionBar.maxActionCount: navDrawer.enabled ? 3 : 4
actions: [
Action {
iconName: "alert/warning"
name: "Dummy error"
onTriggered: demo.showError("Something went wrong", "Do you want to retry?", "Close", true)
},
Action {
iconName: "image/color_lens"
name: "Colors"
onTriggered: colorPicker.show()
},
Action {
iconName: "action/settings"
name: "Settings"
hoverAnimation: true
},
Action {
iconName: "alert/warning"
name: "THIS SHOULD BE HIDDEN!"
visible: false
},
Action {
iconName: "action/language"
name: "Language"
enabled: false
},
Action {
iconName: "action/account_circle"
name: "Accounts"
}
]
backAction: navDrawer.action
NavigationDrawer {
id: navDrawer
enabled: page.width < dp(500)
onEnabledChanged: smallLoader.active = enabled
Flickable {
anchors.fill: parent
contentHeight: Math.max(content.implicitHeight, height)
Column {
id: content
anchors.fill: parent
Repeater {
model: sections
delegate: Column {
width: parent.width
ListItem.Subheader {
text: sectionTitles[index]
}
Repeater {
model: modelData
delegate: ListItem.Standard {
text: modelData
selected: modelData == demo.selectedComponent
onClicked: {
demo.selectedComponent = modelData
navDrawer.close()
}
}
}
}
}
}
}
}
Repeater {
model: !navDrawer.enabled ? sections : 0
delegate: Tab {
title: sectionTitles[index]
property string selectedComponent: modelData[0]
property var section: modelData
sourceComponent: tabDelegate
}
}
Loader {
id: smallLoader
anchors.fill: parent
sourceComponent: tabDelegate
property var section: []
visible: active
active: false
}
}
Dialog {
id: colorPicker
title: "Pick color"
positiveButtonText: "Done"
MenuField {
id: selection
model: ["Primary color", "Accent color", "Background color"]
width: dp(160)
}
Grid {
columns: 7
spacing: dp(8)
Repeater {
model: [
"red", "pink", "purple", "deepPurple", "indigo",
"blue", "lightBlue", "cyan", "teal", "green",
"lightGreen", "lime", "yellow", "amber", "orange",
"deepOrange", "grey", "blueGrey", "brown", "black",
"white"
]
Rectangle {
width: dp(30)
height: dp(30)
radius: dp(2)
color: Palette.colors[modelData]["500"]
border.width: modelData === "white" ? dp(2) : 0
border.color: Theme.alpha("#000", 0.26)
Ink {
anchors.fill: parent
onPressed: {
switch(selection.selectedIndex) {
case 0:
theme.primaryColor = parent.color
break;
case 1:
theme.accentColor = parent.color
break;
case 2:
theme.backgroundColor = parent.color
break;
}
}
}
}
}
}
onRejected: {
// TODO set default colors again but we currently don't know what that is
}
}
Component {
id: tabDelegate
Item {
Sidebar {
id: sidebar
expanded: !navDrawer.enabled
Column {
width: parent.width
Repeater {
model: section
delegate: ListItem.Standard {
text: modelData
selected: modelData == selectedComponent
onClicked: selectedComponent = modelData
}
}
}
}
Flickable {
id: flickable
anchors {
left: sidebar.right
right: parent.right
top: parent.top
bottom: parent.bottom
}
clip: true
contentHeight: Math.max(example.implicitHeight + 40, height)
Loader {
id: example
anchors.fill: parent
asynchronous: true
visible: status == Loader.Ready
// selectedComponent will always be valid, as it defaults to the first component
source: {
if (navDrawer.enabled) {
return Qt.resolvedUrl("%1Demo.qml").arg(demo.selectedComponent.replace(" ", ""))
} else {
return Qt.resolvedUrl("%1Demo.qml").arg(selectedComponent.replace(" ", ""))
}
}
}
ProgressCircle {
anchors.centerIn: parent
visible: example.status == Loader.Loading
}
}
Scrollbar {
flickableItem: flickable
}
}
}
}