-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
394 lines (322 loc) · 11.5 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
import QtQuick 2.9
import QtQuick.Window 2.12
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.3
import QtQuick.Layouts 1.3
import Qt.labs.settings 1.0
import Models 1.0
ApplicationWindow {
width: 640
height: 480
visible: true
Component.onCompleted: {
toolbar.notaTable = notaDb;
stack.push("IdentificationView.qml", {'stack':stack,'toolbar':toolbar});
}
property var window: this
property var idToRemove
Material.theme: theme.checked ? Material.Dark : Material.Light
header: MyToolbar{
id:toolbar
visible: false
menu: menu
stack: stack
onTextEdited: {
if(stack.currentItem.isGrid !== undefined){
stack.currentItem.filter = text;
}
}
onListGridButtonAction: {
if(stack.currentItem.nameWindow == 'Home'){
if(stack.currentItem.isGrid){
toolbar.iconList = 'icons/view-grid-outline.png'
stack.currentItem.isGrid = false
}else{
toolbar.iconList = 'icons/format-list-bulleted-square.png'
stack.currentItem.isGrid = true
}
}
}
onMarkerButtonAction: {
markersDialog.open()
}
onDeleteItemAction: {
excluirDialog.open()
idToRemove = idOfItem;
}
}
Item {
anchors.right: parent.right
Menu{
id:menu
MenuItem{
Switch{
id:theme
anchors.fill: parent
text: "Dark mode"
checked: true
onCheckedChanged: {
}
}
}
MenuItem{
text: "help"
onPressed: {
dialog.open();
}
}
}
}
Dialog{
id:excluirDialog
modal:true
anchors.centerIn: parent
title: 'Excluir?'
standardButtons: Dialog.No | Dialog.Yes
Label{
anchors.centerIn: parent
text: 'Tem certeza que deseja excluir a nota?'
wrapMode: "Wrap"
}
onRejected: {
//close
}
onAccepted: {
if(idToRemove !== undefined){
notaDb.deleteRow(idToRemove);
stack.pop();
}
}
}
Dialog{
id:markersDialog
modal:true
anchors.centerIn: parent
width: parent.width * 0.6
height: Qt.platform.os == 'android' ? parent.height*0.4 : parent.height*0.6
//height: parent.height * 0.6
title: 'Adicionar marcador'
standardButtons: Dialog.Ok
ColumnLayout{
anchors.fill: parent
ListView{
id:dlist
Layout.fillWidth: true
Layout.fillHeight: true
ScrollBar.vertical: ScrollBar {
visible: true
}
add: Transition {
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 500 }
NumberAnimation { property: "scale"; easing.type: Easing.OutBounce; from: 0; to: 1.0; duration: 550 }
}
remove: Transition {
NumberAnimation { property: "x"; to: 50; duration: 200 }
NumberAnimation { property: "opacity"; from: 1.0; to: 0; duration: 200 }
}
model: ListModel{
id:listModel
onRowsInserted: {
toolbar.setBadgeMarkerValue(listModel.count - 1);
}
onRowsRemoved: {
toolbar.setBadgeMarkerValue(listModel.count - 1);
}
ListElement{
id2:''
id3:''
idd: ''
boxChecked: true
nome: 'Front'
}
}
delegate: RowLayout{
property int currentIndex;
width: parent.width
Text {
visible: false
text: idd || ''
}
CheckBox{
id:box
enabled: false
checked: boxChecked
}
TextField{
id:marcadorField
focus: true
Layout.fillWidth: true
placeholderText: 'Marcador'
text: nome
function addNewLine(){
if(marcadorField.text.trim().length > 0){
box.checked = true
box.enabled = true
marcadorField.focus = false;
console.log('>>>>'+dlist.count)
currentIndex = dlist.count - 1;
id3 = currentIndex+''
listModel.append({'id3':'','boxChecked':false,'nome':''});
marcadorDelete.enabled = true
dlist.currentIndex = dlist.count - 1
dlist.currentItem.children[1].focus = true
}
}
Keys.onTabPressed: {
addNewLine();
}
onAccepted: {
addNewLine();
}
}
ToolButton{
id:marcadorDelete
enabled: nome.trim().length > 0
icon.source: 'icons/delete.png'
onPressed: {
for(let i = parseInt(id3) + 1; i < listModel.count; i++){
listModel.get(i).id3 = (parseInt(listModel.get(i).id3) - 1)+'';
}
//console.log('>>>>>>>>> '+id3+' '+dlist.count+' '+nome + ' ' + currentIndex);
if(idd){
marcadorDb.deleteRow(idd);
}
//console.log('>>>>>>>>>>>>>>> '+id3)
listModel.remove(id3);
}
}
}
}
}
}
Dialog{
id:dialog
modal: true
anchors.centerIn: parent
width: parent.width * 0.6
height: parent.height
title:'Help'
standardButtons: Dialog.Ok
Label{
wrapMode: "Wrap"
anchors.fill: parent
text: 'O objetivo deste desafio é criar um clone do Google Keep.\nEste app suporta, inserção, atualização, busca e exclusão de notas. As notas podem ser visualizadas na forma de lista, ou grade, apertando o botão com ícone de grade ou lista na toolbar.\nTambém é possível alternar entre Modo Dark e Light.\nO Grid e a lista se adaptam a tela, o Grid aumenta o número de colunas com base no tamanho do monitor (responsivo). A data de alteração e ou inserção é registrada somente se dados forem alterados, evitando que notas totalmente vazias sejam armazenadas no Banco de dados. O banco de dados utiliza relacionamento simples, que relaciona a tabela User, com a tabela Notas.'
}
onAccepted: {
}
}
footer: ToolBar{
id:bottomBar
visible: false
RowLayout{
anchors.fill: parent
visible: false
ToolButton{
visible: false
icon.source: "icons/magnify.png"
}
}
ToolButton{
id:fab
visible: false
width: 50
height: 50
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 15
icon.source: "icons/plus.png"
Rectangle{
radius:parent.width
anchors.fill: parent
color: Material.background
border.color: Material.primary
z:-1
}
onPressed: {
toolbar.date = ''
stack.push('AdicionarNotaView.qml',{"stack":stack, "markersModel":listModel,"markersListView": dlist})
}
}
}
NotaDatabaseModel{
id:notaDb
}
MarcadorDatabaseModel{
id:marcadorDb
}
StackView{
id: stack
property real offset: 10
visible: true
focus:true
anchors.fill: parent
Layout.fillWidth: true
Keys.onBackPressed: {
event.accepted = stack.depth > 0
pop();
}
pushEnter: Transition {
PropertyAnimation {
property: "opacity"
from: 0
to:1
duration: 200
}
}
pushExit: Transition {
PropertyAnimation {
property: "opacity"
from: 1
to:0
duration: 200
}
}
popEnter: Transition {
PropertyAnimation {
property: "opacity"
from: 0
to:1
duration: 200
}
}
popExit: Transition {
PropertyAnimation {
property: "opacity"
from: 1
to:0
duration: 200
}
}
property var quitable: false
onCurrentItemChanged: {
if(stack.currentItem.nameWindow == 'Home'){
stack.currentItem.toolbar = toolbar;
toolbar.showActions();
toolbar.showBackButton = false;
fab.visible = true;
toolbar.visible = true;
bottomBar.visible = true;
quitable = true;
stack.currentItem.notaTable = notaDb;
stack.currentItem.marcadorTable = marcadorDb;
stack.currentItem.stack = stack;
stack.currentItem.markersListView = dlist
stack.currentItem.markersModel = listModel
}
else if(stack.currentItem.nameWindow == 'AdicionarNota'){
toolbar.hideActions();
fab.visible = false;
bottomBar.visible = false;
toolbar.showBackButton = true;
stack.currentItem.notaTable = notaDb;
stack.currentItem.marcadorTable = marcadorDb;
stack.currentItem.markersListView = dlist
stack.currentItem.markersModel = listModel
}else if(stack.currentItem.nameWindow == 'Identification'){
if(quitable){
Qt.quit();
}
}
}
}
}