1
- import QtQuick 2.0
2
- import QtQuick 2.2
1
+ import QtQuick 2.7
3
2
import QtQuick.Controls 1.4
4
3
import QtQuick.Layouts 1.3
5
4
import QtQuick.Controls.Styles 1.4
@@ -9,21 +8,54 @@ Rectangle {
9
8
id: rootRectangle
10
9
anchors .fill : parent
11
10
11
+ property bool editing: false
12
+ property int postIndex
13
+ property string prevTitle
14
+ property date prevDate
15
+ property string prevContent
16
+ property string prevReaction
17
+ property int prevWeight
18
+ property int prevCalories
19
+ property bool prevRun
20
+
12
21
property var photos : [];
13
22
23
+ function reportError (txt ) {
24
+ alertDialog .text = txt;
25
+ alertDialog .open ();
26
+
27
+ return false ;
28
+ }
29
+
14
30
function validateInput () {
15
31
if (titleField .text .trim ().length < 1 )
16
- return false ;
32
+ return reportError ( " Error. Title is Empty " ) ;
17
33
18
34
if (contentField .text .trim ().length < 1 )
19
- return false ;
35
+ return reportError ( " Error. Content is Empty " ) ;
20
36
21
37
if (! reactionGroup .current )
22
- return false ;
38
+ return reportError ( " Error. Choose a reaction first " ) ;
23
39
24
40
return true ;
25
41
}
26
42
43
+ function initSelected (type ) {
44
+ if (! editing)
45
+ return type === " yay" ? true : false ;
46
+
47
+ return type === prevReaction ? true : false ;
48
+ }
49
+
50
+ MessageDialog {
51
+ id: alertDialog
52
+ visible: false
53
+ title: " Alert"
54
+ text: " "
55
+ standardButtons: StandardButton .Ok
56
+ icon: StandardIcon .Warning
57
+ }
58
+
27
59
CustomToolbar {
28
60
id: mainToolBar
29
61
subtitle: " Add a new post"
@@ -65,6 +97,8 @@ Rectangle {
65
97
Column {
66
98
id: photosGroup
67
99
width: parent .width
100
+ spacing: 20
101
+ anchors .topMargin : 20
68
102
anchors .horizontalCenter : parent .horizontalCenter
69
103
70
104
FileDialog {
@@ -226,24 +260,26 @@ Rectangle {
226
260
227
261
Column {
228
262
id: titleGroup
263
+ width: parent .width
264
+ spacing: 12
229
265
anchors .horizontalCenter : parent .horizontalCenter
230
266
231
- Text {
232
- id: titleLabel
233
- anchors .horizontalCenter : parent .horizontalCenter
267
+ HighlightedText {
234
268
text: " Title"
235
269
}
236
270
237
271
TextField {
238
272
id: titleField
239
- width : 200
240
- height : 30
273
+ anchors . horizontalCenter : parent . horizontalCenter
274
+ width : parent . width * 0.7
241
275
style: TextFieldStyle {
242
276
padding .top : 4
243
277
padding .bottom : 4
244
278
padding .right : 20
245
279
padding .left : 20
246
280
}
281
+ font .pixelSize : 24
282
+ text: prevTitle
247
283
placeholderText: " Post title..."
248
284
}
249
285
}
@@ -260,40 +296,48 @@ Rectangle {
260
296
261
297
ReactionImage {
262
298
reaction: " angry"
299
+ selected: initSelected (" angry" )
263
300
}
264
301
265
302
ReactionImage {
266
303
reaction: " sad"
304
+ selected: initSelected (" sad" )
267
305
}
268
306
269
307
ReactionImage {
270
308
reaction: " yay"
271
- selected: true
309
+ selected: initSelected ( " yay " )
272
310
}
273
311
274
312
ReactionImage {
275
313
reaction: " haha"
314
+ selected: initSelected (" haha" )
276
315
}
277
316
278
317
ReactionImage {
279
318
reaction: " wow"
319
+ selected: initSelected (" wow" )
280
320
}
281
321
}
282
322
283
323
Separator {}
284
324
285
325
Column {
286
326
id: contentGroup
327
+ spacing: 12
328
+ width: parent .width
287
329
anchors .horizontalCenter : parent .horizontalCenter
288
330
289
- Text {
290
- id: contentLabel
291
- anchors .horizontalCenter : parent .horizontalCenter
331
+ HighlightedText {
292
332
text: " Content"
293
333
}
294
334
295
335
TextArea {
296
336
id: contentField
337
+ anchors .horizontalCenter : parent .horizontalCenter
338
+ font .pixelSize : 18
339
+ text: prevContent
340
+ width: parent .width * 0.7
297
341
}
298
342
}
299
343
@@ -319,6 +363,7 @@ Rectangle {
319
363
320
364
TextField {
321
365
id: weightField
366
+ text: prevWeight
322
367
anchors .verticalCenter : parent .verticalCenter
323
368
}
324
369
}
@@ -333,6 +378,7 @@ Rectangle {
333
378
334
379
TextField {
335
380
id: caloriesField
381
+ text: prevCalories
336
382
anchors .verticalCenter : parent .verticalCenter
337
383
}
338
384
}
@@ -348,6 +394,7 @@ Rectangle {
348
394
CheckBox {
349
395
id: runCheckBox
350
396
anchors .verticalCenter : parent .verticalCenter
397
+ checked: editing && prevRun
351
398
}
352
399
}
353
400
}
@@ -356,11 +403,20 @@ Rectangle {
356
403
357
404
Button {
358
405
anchors .horizontalCenter : parent .horizontalCenter
359
- text: " Add Post"
360
406
361
- onClicked: {
362
- console .log (" add post" );
407
+ style: ButtonStyle {
408
+ label: Text {
409
+ renderType: Text .NativeRendering
410
+ verticalAlignment: Text .AlignVCenter
411
+ horizontalAlignment: Text .AlignHCenter
412
+ font .pointSize : 18
413
+ padding: 8
414
+ color: " #333333"
415
+ text: ! editing ? " Add Post" : " Save Changes"
416
+ }
417
+ }
363
418
419
+ onClicked: {
364
420
if (! validateInput ())
365
421
return ;
366
422
@@ -372,15 +428,28 @@ Rectangle {
372
428
var calories = parseInt (caloriesField .text );
373
429
var run = runCheckBox .checked ;
374
430
375
- console .log (" check" );
376
- console .log (runCheckBox .checkedState );
377
- console .log (runCheckBox .checked );
431
+ if (editing) {
432
+ mediator .editPost (postIndex, title, date, content, reaction, weight, calories, run, rootRectangle .photos );
433
+ } else {
434
+ mediator .insertPost (title, date, content, reaction, weight, calories, run, rootRectangle .photos );
435
+ }
378
436
379
- mediator .insertPost (title, date, content, reaction, weight, calories, run, rootRectangle .photos );
380
437
mainStack .pop ();
381
438
}
382
439
}
383
440
}
384
441
}
385
442
}
443
+
444
+ Component .onCompleted : {
445
+ if (editing) {
446
+ for (var i = 0 ; i < photos .length ; i++ ) {
447
+ photosModel .append ({" icon" : photos[i]});
448
+
449
+ // make photo path visible and run once
450
+ if (i == 0 )
451
+ photosPathView .visible = true
452
+ }
453
+ }
454
+ }
386
455
}
0 commit comments