-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmain.qml
416 lines (394 loc) · 12.7 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
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
// ekke (Ekkehard Gentz) @ekkescorner
import QtQuick 2.5
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import QtQuick.Controls.Material 2.2
import QtGraphicalEffects 1.0
import "common"
import "pages"
// This app demonstrates HowTo use Qt 5.8 and Qt Quick Controls 2.1, High DPI and more
// This app is NOT a production ready app
// This app's goal is only to help you to understand some concepts
// see blog http://j.mp/qt-x to learn about Qt 5.8 for Material - styled Android or iOS Apps
// learn about this stacked_pages_x app from this article: http://j.mp/qt-stacked-pages-x
// ekke (Ekkehard gentz) @ekkescorner
ApplicationWindow {
id: appWindow
// visibile must set to true - default is false
visible: true
width: 400
height: 600
// primary and accent properties:
property variant primaryPalette: myApp.defaultPrimaryPalette()
property color primaryLightColor: primaryPalette[0]
property color primaryColor: primaryPalette[1]
property color primaryDarkColor: primaryPalette[2]
property color textOnPrimaryLight: primaryPalette[3]
property color textOnPrimary: primaryPalette[4]
property color textOnPrimaryDark: primaryPalette[5]
property string iconOnPrimaryLightFolder: primaryPalette[6]
property string iconOnPrimaryFolder: primaryPalette[7]
property string iconOnPrimaryDarkFolder: primaryPalette[8]
property variant accentPalette: myApp.defaultAccentPalette()
property color accentColor: accentPalette[0]
property color textOnAccent: accentPalette[1]
property string iconOnAccentFolder: accentPalette[2]
Material.primary: primaryColor
Material.accent: accentColor
// theme Dark vs Light properties:
property variant themePalette: myApp.defaultThemePalette()
property color dividerColor: themePalette[0]
property color cardAndDialogBackground: themePalette[1]
property real primaryTextOpacity: themePalette[2]
property real secondaryTextOpacity: themePalette[3]
property real dividerOpacity: themePalette[4]
property real iconActiveOpacity: themePalette[5]
property real iconInactiveOpacity: themePalette[6]
property string iconFolder: themePalette[7]
property int isDarkTheme: themePalette[8]
property color flatButtonTextColor: themePalette[9]
// Material.dropShadowColor OK for Light, but too dark for dark theme
property color dropShadow: isDarkTheme? "#E4E4E4" : Material.dropShadowColor
onIsDarkThemeChanged: {
if(isDarkTheme == 1) {
Material.theme = Material.Dark
} else {
Material.theme = Material.Light
}
}
// font sizes - defaults from Google Material Design Guide
property int fontSizeDisplay4: 112
property int fontSizeDisplay3: 56
property int fontSizeDisplay2: 45
property int fontSizeDisplay1: 34
property int fontSizeHeadline: 24
property int fontSizeTitle: 20
property int fontSizeSubheading: 16
property int fontSizeBodyAndButton: 14 // is Default
property int fontSizeCaption: 12
// fonts are grouped into primary and secondary with different Opacity
// to make it easier to get the right property,
// here's the opacity per size:
property real opacityDisplay4: secondaryTextOpacity
property real opacityDisplay3: secondaryTextOpacity
property real opacityDisplay2: secondaryTextOpacity
property real opacityDisplay1: secondaryTextOpacity
property real opacityHeadline: primaryTextOpacity
property real opacityTitle: primaryTextOpacity
property real opacitySubheading: primaryTextOpacity
// body can be both: primary or secondary text
property real opacityBodyAndButton: primaryTextOpacity
property real opacityBodySecondary: secondaryTextOpacity
property real opacityCaption: secondaryTextOpacity
//
SwipeArea{
id:swipeId
anchors.fill: parent
onSwipe: {
console.log("pop pre page");
//通过手势pop出来
if(direction=="left") navPane.popOnePage()
}
}
header: StackTextTitle {
id: titleBar
text: navPane.currentItem? navPane.currentItem.title : qsTr("A simple Stacked - Pages APP")
}
// primaryDarkColor is used because FAB can overlap Raised Buttons colored in primaryColor
FloatingActionButton {
property string imageName: navPane.depth < 5? "/directions.png" : "/home.png"
z: 1
anchors.margins: 16
anchors.right: parent.right
anchors.bottom: parent.bottom
imageSource: "qrc:/images/"+iconOnPrimaryDarkFolder+imageName
backgroundColor: primaryDarkColor
onClicked: {
if(navPane.depth < 5) {
navPane.pushNextPage()
} else {
navPane.goToPage(1)
}
}
} // FAB
StackView {
id: navPane
focus: true
anchors.fill: parent
anchors.bottomMargin: 40
initialItem: pageOne
// support of BACK key
Keys.onBackPressed: {
event.accepted = navPane.depth > 1
popOnePage()
if(navPane.depth == 1) {
// perhaps ask user if app should really quit
var page = navPane.get(0)
page.cleanup()
}
}
// some keyboard shortcuts if:
// * running on BlackBerry PRIV (Slider with hardware keyboard)
// * or attached Bluetooth Keyboard
// Jump to Page 1 (w), 2 (e), 3 (r), 4 (s), 5(d)
// Goto next page: 'n'
// Goto previous page: 'p'
Shortcut {
sequence: "w"
onActivated: navPane.goToPage(1)
}
Shortcut {
sequence: "Alt+w"
onActivated: navPane.goToPage(1)
}
Shortcut {
sequence: "e"
onActivated: navPane.goToPage(2)
}
Shortcut {
sequence: "Alt+e"
onActivated: navPane.goToPage(2)
}
Shortcut {
sequence: "r"
onActivated: navPane.goToPage(3)
}
Shortcut {
sequence: "Alt+r"
onActivated: navPane.goToPage(3)
}
Shortcut {
sequence: "s"
onActivated: navPane.goToPage(4)
}
Shortcut {
sequence: "Alt+s"
onActivated: navPane.goToPage(4)
}
Shortcut {
sequence: "d"
onActivated: navPane.goToPage(5)
}
Shortcut {
sequence: "Alt+d"
onActivated: navPane.goToPage(5)
}
// n == NEXT
Shortcut {
sequence: "n"
onActivated: navPane.pushNextPage()
}
// p == PREVIOUS
Shortcut {
sequence: "p"
onActivated: navPane.popOnePage()
}
Shortcut {
sequence: " "
onActivated: navPane.pushNextPage()
}
Shortcut {
sequence: "Shift+ "
onActivated: navPane.popOnePage()
}
// go one level back in stack
function popOnePage() {
if(navPane.depth == 1) {
return
}
// check if target page already is on the stack
var targetIsUninitialized = false
if(!navPane.get(navPane.depth-2)) {
targetIsUninitialized = true
}
var page = pop()
if(targetIsUninitialized) {
navPane.currentItem.init()
}
// do cleanup from previous page
page.cleanup()
} // popOnePage
function pushOnePage(pageComponent) {
var page = push(pageComponent)
page.init()
}
function pushNextPage() {
switch(navPane.depth) {
case 1:
pushOnePage(pageTwo)
break;
case 2:
pushOnePage(pageThree)
break;
case 3:
pushOnePage(pageFour)
break;
case 4:
pushOnePage(pageFive)
break;
default:
// nothing - 5 is max
}
} // pushNextPage
function findPage(pageName) {
var targetPage = find(function(item) {
return item.name == pageName;
})
if(targetPage) {
return targetPage.StackView.index
} else {
console.log("Page not found in StackView: "+pageName)
return -1
}
}
function goUpTo(pageNumber) {
var count = pageNumber-navPane.depth
var pages = new Array (count)
for(var i = 0; i < count; i++) {
var thePageNumber = navPane.depth+i+1
switch(thePageNumber) {
case 1:
pages[i] = pageOne
break;
case 2:
pages[i] = pageTwo
break;
case 3:
pages[i] = pageThree
break;
case 4:
pages[i] = pageFour
break;
case 5:
pages[i] = pageFive
break;
default:
// nothing
return
}
}
var page = push(pages)
page.init()
} // goUpTo
function goDownTo(pageNumber) {
// check if cleanup must be done for popped pages
var count = navPane.depth-pageNumber
for(var i = 0; i < count; i++) {
if(navPane.get(navPane.depth-i-1)) {
navPane.get(navPane.depth-i-1).cleanup()
}
}
// pop all pages until targetPage will be on top
// check if target page already is on the stack
var targetIsUninitialized = false
if(!navPane.get(pageNumber-1)) {
targetIsUninitialized = true
}
// don't forget to set StackView.ForceLoad
// otherwise if get() is null and get(null) means jump to root
pop(navPane.get(pageNumber-1, StackView.ForceLoad))
if(targetIsUninitialized) {
navPane.get(pageNumber-1).init()
}
} // goDownTo
function goToPage(pageNumber) {
if(pageNumber == navPane.depth) {
// it's the current page
return
}
if(pageNumber > navPane.depth) {
goUpTo(pageNumber)
return
}
goDownTo(pageNumber)
} // goToPage
} // navPane
Component {
id: pageOne
PageOne {
id: page
// we only need this for initialItem
// items on stack will init() after push()
Component.onCompleted: {
page.init()
}
}
} // pageOne
Component {
id: pageTwo
PageTwo {
}
} // pageTwo
Component {
id: pageThree
PageThree {
}
}
Component {
id: pageFour
PageFour {
}
}
Component {
id: pageFive
PageFive {
}
}
function switchPrimaryPalette(paletteIndex) {
primaryPalette = myApp.primaryPalette(paletteIndex)
}
function switchAccentPalette(paletteIndex) {
accentPalette = myApp.accentPalette(paletteIndex)
}
// we can loose the focus if Menu or Popup is opened
function resetFocus() {
navPane.focus = true
}
//
PopupPalette {
id: popup
onAboutToHide: {
resetFocus()
}
}
footer: Rectangle{
id:footerId
width: parent.width
height: 40
color:dropShadow
RowLayout{
anchors.fill: parent
spacing: 0
ButtonRaised {
text: qsTr("Home")
onClicked: {
navPane.pushOnePage(pageOne)
}
}
ButtonRaised {
text: qsTr("Recieve")
onClicked: {
navPane.pushOnePage(pageTwo)
}
}
ButtonRaised {
text: qsTr("Send")
onClicked: {
navPane.pushOnePage(pageThree)
}
}
ButtonRaised {
text: qsTr("Trade")
onClicked: {
navPane.pushOnePage(pageFour)
}
}
ButtonRaised {
text: qsTr("Message")
onClicked: {
navPane.pushOnePage(pageFive)
}
}
}
}
} // app window