-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreEditor.qml
447 lines (393 loc) · 15.3 KB
/
StoreEditor.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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4
import "Common"
import "Store"
import "Common/sizes.js" as Sizes
import "Common/palette.js" as Palette
import "Common/icons.js" as Icons
import "Store/utils.js" as Utils
Page {
id: page
width: 320
height: 480
color: Palette.MODAL
property string storeID: ""
property alias title: toolbar.text
function save(){
var data = {
type: itemType.currentIndex,
style: itemStyle.currentIndex,
title: itemTitle.text,
login: itemLogin.text,
number: itemNumber.text,
password: itemPass.text,
pin: itemPin.text,
relate: Utils.cleanURL(itemRelate.text),
description: itemDescription.text
};
if (storeID !== ""){
store.set(storeID, data);
app.toast("Saved");
}else if (itemTitle.text != ""){
store.add(data);
app.toast("Added");
}
app.goBack();
}
onShow: {
if (storeID !== ""){
var v = store.get(storeID);
itemType.currentIndex = v.type;
itemStyle.currentIndex = v.style;
itemTitle.text = v.title;
itemLogin.text = v.login;
itemNumber.text = v.number;
itemPass.text = v.password;
itemPin.text = v.pin;
itemRelate.text = v.relate;
itemDescription.text = v.description;
}
}
onShown: {
itemTitle.focus = true;
itemTitle.forceActiveFocus();
}
onHidden: {
itemType.currentIndex = 0;
itemStyle.currentIndex = 0;
itemTitle.text = "";
itemLogin.text = "";
itemNumber.text = "";
itemPass.text = "";
itemPin.text = "";
itemRelate.text = "";
itemDescription.text = "";
storeID = "";
itemTitle.focus = false;
itemLogin.focus = false;
itemNumber.focus = false;
itemPass.focus = false;
itemPin.focus = false;
itemRelate.focus = false;
itemDescription.focus = false;
}
ColumnLayout {
anchors.fill: parent
spacing: 0
VToolbar {
id: toolbar
icon: Icons.UI_BACK
text: "New card"
// shadow: true
// color: Palette.BLANK
// textColor: Palette.TITLE
// shadow: flickable.contentY > 0
Layout.fillHeight: false
onAction: app.goBack()
VButton {
text: "save"
anchors.verticalCenter: parent.verticalCenter
Layout.fillWidth: false
Layout.alignment: Qt.AlignRight
onClicked: page.save()
enabled: itemTitle.text.length > 0
}
}
Flickable {
id: flickable
flickableDirection: Flickable.VerticalFlick
Layout.fillWidth: true
Layout.fillHeight: true
contentWidth: width
contentHeight: content.height
clip: true
Column {
id: content
spacing: Sizes.MARGIN
anchors.right: parent.right
anchors.left: parent.left
anchors {rightMargin: Sizes.MARGIN; leftMargin: Sizes.MARGIN}
Item {
anchors.right: parent.right
anchors.left: parent.left
height: Sizes.MARGIN
}
SLabel {
text: qsTr("Service type:")
}
Item {
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
height: itemType.height
TextField {
id: itemType
anchors.left: parent.left
anchors.right: parent.right
property int currentIndex: 0
text: typePicker.getNameByID(0);
onCurrentIndexChanged: text = typePicker.getNameByID(currentIndex);
}
Icon {
name: Icons.UI_LIST
size: Sizes.ICON
anchors.right: parent.right
anchors.rightMargin: Sizes.MARGIN_HALF
anchors.verticalCenter: parent.verticalCenter
}
MouseArea{
anchors.fill: parent
onClicked: typePicker.open(itemType.currentIndex)
}
}
// RowLayout {
// anchors.right: parent.right
// anchors.left: parent.left
// spacing: Sizes.MARGIN_HALF
// SLabel {
// text: qsTr("Service type:")
// Layout.fillWidth: false
// lineHeight: 1
// anchors.verticalCenter: parent.verticalCenter
// }
// VLabel {
// id: itemType
// Layout.fillWidth: true
// anchors.verticalCenter: parent.verticalCenter
// property int currentIndex: 0
// onCurrentIndexChanged: text = typePicker.getNameByID(currentIndex);
// Image {
// source: "image://icons/16x16/caretdown"
// anchors.right: parent.right
// anchors.verticalCenter: parent.verticalCenter
// }
// MouseArea{
// anchors.fill: parent
// onClicked: typePicker.open(itemType.currnetIndex)
// }
// }
// }
// ComboBox {
// id: itemType
// anchors.right: parent.right
// anchors.left: parent.left
// anchors.leftMargin: Sizes.MARGIN
// currentIndex: itemTypeModel.count - 1
// model: ItemTypes{
// id: itemTypeModel
// }
// }
SLabel {
text: qsTr("Service name:")
}
TextField {
id: itemTitle
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("My Service")
// menu: VTextEditMenu {
// attachedTo: itemTitle
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemTitle);
// }
// onEditingFinished: editToolbar.hide();
VInputItemButton{
icon: Icons.UI_CLEAR
iconSize: Sizes.ICON_16
onClicked: parent.text = ""
}
}
SLabel {
text: qsTr("Service detials:")
}
TextField {
id: itemNumber
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("Account number")
inputMethodHints: Qt.ImhPreferNumbers | Qt.ImhNoPredictiveText
// menu: VTextEditMenu{
// attachedTo: itemNumber
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemNumber);
// }
// onEditingFinished: editToolbar.hide();
VInputItemButton {
icon: Icons.UI_CLEAR
iconSize: Sizes.ICON_16
onClicked: parent.text = ""
}
}
TextField {
id: itemLogin
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("User name / bank card number")
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
// menu: VTextEditMenu{
// attachedTo: itemLogin
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemLogin);
// }
// onEditingFinished: editToolbar.hide();
VInputItemButton{
icon: Icons.UI_CLEAR
iconSize: Sizes.ICON_16
onClicked: parent.text = ""
}
}
TextField {
id: itemPass
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("Password")
echoMode: TextInput.Password
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
// menu: VTextEditMenu{
// attachedTo: itemPass
// MenuItem {
// text: "Generate"
// shortcut: "Ctrl+G"
// onTriggered: attachedTo.text = Utils.generatePassword()
// }
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemPass);
// }
// onEditingFinished: editToolbar.hide();
VInputItemButton{
icon: parent.echoMode == TextInput.Password? Icons.UI_VISIBILITY_OFF: Icons.UI_VISIBILITY_ON
iconSize: Sizes.ICON_16
onClicked: parent.echoMode = (parent.echoMode == TextInput.Password? TextInput.Normal: TextInput.Password)
}
}
TextField {
id: itemPin
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("Pin number")
echoMode: TextInput.Password
inputMethodHints: Qt.ImhPreferNumbers | Qt.ImhNoPredictiveText
// menu: VTextEditMenu{
// attachedTo: itemPin
// MenuItem {
// text: "Generate"
// shortcut: "Ctrl+G"
// onTriggered: attachedTo.text = Utils.generatePin()
// }
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemPin);
// }
// onEditingFinished: editToolbar.hide();
VInputItemButton{
icon: parent.echoMode == TextInput.Password? Icons.UI_VISIBILITY_OFF: Icons.UI_VISIBILITY_ON
iconSize: Sizes.ICON_16
onClicked: parent.echoMode = (parent.echoMode == TextInput.Password? TextInput.Normal: TextInput.Password)
}
}
TextField {
id: itemRelate
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
placeholderText: qsTr("Service URL")
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
// menu: VTextEditMenu{
// attachedTo: itemRelate
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemRelate);
// }
// onEditingFinished: editToolbar.hide()
VInputItemButton{
icon: Icons.UI_CLEAR
iconSize: Sizes.ICON_16
onClicked: parent.text = ""
}
}
SLabel {
text: qsTr("Style:")
}
Item {
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Sizes.MARGIN
height: itemType.height
TextField {
id: itemStyle
anchors.left: parent.left
anchors.right: parent.right
property int currentIndex: 0
text: colorPicker.getNameByID(0);
onCurrentIndexChanged: text = colorPicker.getNameByID(currentIndex);
}
Icon {
name: Icons.UI_LIST
size: Sizes.ICON
anchors.right: parent.right
anchors.rightMargin: Sizes.MARGIN_HALF
anchors.verticalCenter: parent.verticalCenter
}
MouseArea{
anchors.fill: parent
onClicked: colorPicker.open(itemStyle.currentIndex)
}
}
// ComboBox {
// id: itemStyle
// property int value: 0
// anchors.right: parent.right
// anchors.left: parent.left
// anchors.leftMargin: Sizes.MARGIN
// model: ItemStyles {
// id: itemStyleModel
// }
// }
SLabel {
text: qsTr("Additional notes:")
}
TextArea {
id: itemDescription
anchors.right: parent.right
anchors.left: parent.left
anchors.leftMargin: Sizes.MARGIN
// menu: VTextEditMenu{
// attachedTo: itemDescription
// }
// onFocusChanged: {
// if (focus) editToolbar.show(itemDescription);
// else editToolbar.hide();
// }
VInputItemButton{
icon: Icons.UI_CLEAR
iconSize: Sizes.ICON_16
onClicked: parent.text = ""
}
}
Item {
anchors.right: parent.right
anchors.left: parent.left
height: Sizes.MARGIN
}
}
}
}
VTypePicker{
id: typePicker
onSelectionMade: itemType.currentIndex = selection;
}
VColorPicker{
id: colorPicker
onSelectionMade: itemStyle.currentIndex = selection;
}
}