-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPickUsername.qml
162 lines (160 loc) · 3.52 KB
/
PickUsername.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
// QMLeteroid - a QML clone of https://github.com/chaosdorf/meteroid
// Copyright (C) 2016 Niklas Sombert
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import QtQuick 2.5
import QtQuick.Controls 1.4
Rectangle
{
Rectangle
{
width: parent.width
height: addUserButton.height
Text
{
id: label
text: "Select your account:"
height: parent.height
width: parent.width - addUserButton.width - changeURLButton.width
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
Button
{
id: addUserButton
x: label.width
action: addUserAction
}
Button
{
id: changeURLButton
x: label.width + addUserButton.width
action: changeURLAction
}
}
Rectangle
{
id: usersRect
y: label.height
width: parent.width
height: parent.height - label.height - saveButton.height
GridView
{
id: usersGrid
anchors.fill: parent
anchors.margins: 20
clip: true
cellWidth: 140 + 10 //margin
cellHeight: 140 + 30 // the text
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
focus: true
model: usersModel
delegate: Column
{
property int uid: id
Image
{
width: 140
height: 140
fillMode: Image.PreserveAspectFit
source: portrait
anchors.horizontalCenter: parent.horizontalCenter
MouseArea
{
anchors.fill: parent
onClicked: usersGrid.currentIndex = index
}
}
Text
{
text: name
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
}
Button
{
id: saveButton
width: parent.width
y: label.height + usersRect.height
action: saveAction
}
Action
{
id: saveAction
text: "&Save"
iconName: "go-next"
onTriggered:
{
console.log("Saving uid: " + usersGrid.currentItem.uid);
globalSettings.uid = usersGrid.currentItem.uid;
pageLoader.source = "BuyDrink.qml";
}
}
Action
{
id: addUserAction
text: "&Add"
iconName: "contact-new"
onTriggered:
{
globalSettings.uid = -1;
pageLoader.source = "UserSettings.qml";
}
}
Action
{
id: changeURLAction
text: "Change &URL"
iconName: "preferences-other"
onTriggered: pageLoader.source = "ChangeURL.qml"
}
ListModel
{
id: usersModel
}
Component.onCompleted:
{
py.call('lib.get_users_data', [globalSettings.url], function(result)
{
if(result)
{
// Load the received data into the list model
for (var i=0; i<result.length; i++)
{
usersModel.append(result[i]);
}
console.log("Got list of users.");
console.log("Saved uid is: " + globalSettings.uid);
// Restore the saved settings
usersGrid.highlightFollowsCurrentItem = false;
var found = false;
for (usersGrid.currentIndex = 0; usersGrid.currentIndex < usersGrid.count; usersGrid.currentIndex++)
{
if (usersGrid.currentItem.uid == globalSettings.uid)
{
found = true;
break;
}
}
if (!found)
{
usersGrid.currentIndex = -1;
}
usersGrid.highlightFollowsCurrentItem = true;
}
});
}
}