Skip to content

Commit b8f708c

Browse files
committed
added editing, postview, styling, icons for extra fields and more
1 parent c7c1988 commit b8f708c

17 files changed

+348
-127
lines changed

AddPostView.qml

+90-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import QtQuick 2.0
2-
import QtQuick 2.2
1+
import QtQuick 2.7
32
import QtQuick.Controls 1.4
43
import QtQuick.Layouts 1.3
54
import QtQuick.Controls.Styles 1.4
@@ -9,21 +8,54 @@ Rectangle {
98
id: rootRectangle
109
anchors.fill: parent
1110

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+
1221
property var photos : [];
1322

23+
function reportError(txt) {
24+
alertDialog.text = txt;
25+
alertDialog.open();
26+
27+
return false;
28+
}
29+
1430
function validateInput() {
1531
if (titleField.text.trim().length < 1)
16-
return false;
32+
return reportError("Error. Title is Empty");
1733

1834
if (contentField.text.trim().length < 1)
19-
return false;
35+
return reportError("Error. Content is Empty");
2036

2137
if (!reactionGroup.current)
22-
return false;
38+
return reportError("Error. Choose a reaction first");
2339

2440
return true;
2541
}
2642

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+
2759
CustomToolbar {
2860
id: mainToolBar
2961
subtitle: "Add a new post"
@@ -65,6 +97,8 @@ Rectangle {
6597
Column {
6698
id: photosGroup
6799
width: parent.width
100+
spacing: 20
101+
anchors.topMargin: 20
68102
anchors.horizontalCenter: parent.horizontalCenter
69103

70104
FileDialog {
@@ -226,24 +260,26 @@ Rectangle {
226260

227261
Column {
228262
id: titleGroup
263+
width: parent.width
264+
spacing: 12
229265
anchors.horizontalCenter: parent.horizontalCenter
230266

231-
Text {
232-
id: titleLabel
233-
anchors.horizontalCenter: parent.horizontalCenter
267+
HighlightedText {
234268
text: "Title"
235269
}
236270

237271
TextField {
238272
id: titleField
239-
width: 200
240-
height: 30
273+
anchors.horizontalCenter: parent.horizontalCenter
274+
width: parent.width * 0.7
241275
style: TextFieldStyle {
242276
padding.top: 4
243277
padding.bottom: 4
244278
padding.right: 20
245279
padding.left: 20
246280
}
281+
font.pixelSize: 24
282+
text: prevTitle
247283
placeholderText: "Post title..."
248284
}
249285
}
@@ -260,40 +296,48 @@ Rectangle {
260296

261297
ReactionImage {
262298
reaction: "angry"
299+
selected: initSelected("angry")
263300
}
264301

265302
ReactionImage {
266303
reaction: "sad"
304+
selected: initSelected("sad")
267305
}
268306

269307
ReactionImage {
270308
reaction: "yay"
271-
selected: true
309+
selected: initSelected("yay")
272310
}
273311

274312
ReactionImage {
275313
reaction: "haha"
314+
selected: initSelected("haha")
276315
}
277316

278317
ReactionImage {
279318
reaction: "wow"
319+
selected: initSelected("wow")
280320
}
281321
}
282322

283323
Separator {}
284324

285325
Column {
286326
id: contentGroup
327+
spacing: 12
328+
width: parent.width
287329
anchors.horizontalCenter: parent.horizontalCenter
288330

289-
Text{
290-
id: contentLabel
291-
anchors.horizontalCenter: parent.horizontalCenter
331+
HighlightedText {
292332
text: "Content"
293333
}
294334

295335
TextArea {
296336
id: contentField
337+
anchors.horizontalCenter: parent.horizontalCenter
338+
font.pixelSize: 18
339+
text: prevContent
340+
width: parent.width * 0.7
297341
}
298342
}
299343

@@ -319,6 +363,7 @@ Rectangle {
319363

320364
TextField {
321365
id: weightField
366+
text: prevWeight
322367
anchors.verticalCenter: parent.verticalCenter
323368
}
324369
}
@@ -333,6 +378,7 @@ Rectangle {
333378

334379
TextField {
335380
id: caloriesField
381+
text: prevCalories
336382
anchors.verticalCenter: parent.verticalCenter
337383
}
338384
}
@@ -348,6 +394,7 @@ Rectangle {
348394
CheckBox {
349395
id: runCheckBox
350396
anchors.verticalCenter: parent.verticalCenter
397+
checked: editing && prevRun
351398
}
352399
}
353400
}
@@ -356,11 +403,20 @@ Rectangle {
356403

357404
Button {
358405
anchors.horizontalCenter: parent.horizontalCenter
359-
text: "Add Post"
360406

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+
}
363418

419+
onClicked: {
364420
if (!validateInput())
365421
return;
366422

@@ -372,15 +428,28 @@ Rectangle {
372428
var calories = parseInt(caloriesField.text);
373429
var run = runCheckBox.checked;
374430

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+
}
378436

379-
mediator.insertPost(title, date, content, reaction, weight, calories, run, rootRectangle.photos);
380437
mainStack.pop();
381438
}
382439
}
383440
}
384441
}
385442
}
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+
}
386455
}

HighlightedText.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import QtQuick 2.0
22

33
Rectangle {
44
property string text;
5-
property int textPadding: 20;
5+
property int textPadding: 10;
66

77
id: rect
88
color: "#42f480"

PostField.qml

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import QtQuick 2.0
1+
import QtQuick 2.7
22
import QtQuick.Layouts 1.3
3+
import QtQuick.Controls 1.4
34

4-
Rectangle {
5+
Row {
56
property string fieldText
7+
property string fieldIcon
8+
property int fieldWidth: -1
9+
property bool checkbox: false
10+
property bool fieldChecked
611

7-
width: parent.width
8-
height: parent.height * 0.25
12+
width: fieldWidth < 0 ? parent.width: fieldWidth
13+
topPadding: 2
14+
bottomPadding: 2
15+
leftPadding: 4
16+
rightPadding: 4
17+
18+
Image {
19+
source: fieldIcon
20+
}
921

1022
Text {
11-
anchors.verticalCenter: parent.verticalCenter
12-
anchors.left: parent.left
13-
anchors.leftMargin: 10
14-
anchors.right: parent.right
15-
anchors.rightMargin: 10
23+
leftPadding: 4
1624
text: fieldText
25+
visible: !checkbox ? true: false
26+
}
27+
28+
CheckBox {
29+
enabled: false
30+
checked: fieldChecked
31+
visible: checkbox
1732
}
1833
}

0 commit comments

Comments
 (0)