blob: 4c82c053b8a5b83d30e000754cc236a419130ca5 (
plain) (
blame)
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
|
// SPDX-License-Identifier: GPL-2.0
import QtQuick 2.6
import QtQuick.Controls 2.2 as Controls
import QtQuick.Layouts 1.2
import org.subsurfacedivelog.mobile 1.0
import org.kde.kirigami 2.4 as Kirigami
Kirigami.Page {
id: tripEditPage
objectName: "TripDetails"
property string tripId
property string tripLocation
property string tripNotes
title: "" !== tripLocation ? tripLocation : qsTr("Trip details")
state: "view"
padding: Kirigami.largeSpacing
background: Rectangle { color: subsurfaceTheme.backgroundColor }
actions.main: saveAction
actions.right: cancelAction
onVisibleChanged: {
resetState()
}
onTripIdChanged: {
resetState()
}
function resetState() {
// make sure we have the right width and reset focus / state if there aren't any unsaved changes
width = parent.width
if (tripLocation === tripLocationField.text && tripNotes === tripNotesField.text) {
tripLocationField.focus = false
tripNotesField.focus = false
state = "view"
}
}
states: [
State {
name: "view"
PropertyChanges { target: saveAction; enabled: false }
},
State {
name: "edit"
PropertyChanges { target: saveAction; enabled: true }
}
]
property QtObject saveAction: Kirigami.Action {
icon {
name: ":/icons/document-save.svg"
color: enabled ? subsurfaceTheme.primaryColor : subsurfaceTheme.backgroundColor
}
text: enabled ? qsTr("Save edits") : ""
onTriggered: {
manager.appendTextToLog("Save trip details triggered")
manager.updateTripDetails(tripId, tripLocationField.text, tripNotesField.text)
Qt.inputMethod.hide()
pageStack.pop()
}
}
property QtObject cancelAction: Kirigami.Action {
text: qsTr("Cancel edit")
icon {
name: ":/icons/dialog-cancel.svg"
}
onTriggered: {
manager.appendTextToLog("Cancel trip details edit")
state = "view"
pageStack.pop()
}
}
Flickable {
id: tripEditFlickable
anchors.fill: parent
GridLayout {
columns: 2
width: tripEditFlickable.width
TemplateLabel {
Layout.columnSpan: 2
id: title
text: qsTr("Edit trip details")
font.pointSize: subsurfaceTheme.titlePointSize
font.bold: true
}
Rectangle {
id: spacer
Layout.columnSpan: 2
color: subsurfaceTheme.backgroundColor
height: Kirigami.Units.gridUnit
width: 1
}
TemplateLabel {
text: qsTr("Trip location:")
opacity: 0.6
}
SsrfTextField {
id: tripLocationField
Layout.fillWidth: true
text: tripLocation
flickable: tripEditFlickable
onFocusChanged: {
tripEditPage.state = "edit"
}
}
TemplateLabel {
Layout.columnSpan: 2
text: qsTr("Trip notes")
opacity: 0.6
}
Controls.TextArea {
id: tripNotesField
text: tripNotes
textFormat: TextEdit.PlainText
Layout.columnSpan: 2
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumHeight: Kirigami.Units.gridUnit * 6
selectByMouse: true
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
onActiveFocusChanged: {
tripEditPage.state = "edit"
}
}
}
}
}
|