aboutsummaryrefslogtreecommitdiffstats
path: root/qt-mobile/qml/DiveDetails.qml
blob: a8db2990c2fe48a00ac338682d803522391d1f2c (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
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
import QtQuick 2.4
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.2
import org.subsurfacedivelog.mobile 1.0
import org.kde.plasma.mobilecomponents 0.2 as MobileComponents

MobileComponents.Page {
	id: diveDetailsPage
	property alias currentIndex: diveDetailsListView.currentIndex
	property alias dive_id: detailsEdit.dive_id
	property alias number: detailsEdit.number
	property alias date: detailsEdit.dateText
	property alias airtemp: detailsEdit.airtempText
	property alias watertemp: detailsEdit.watertempText
	property alias buddy: detailsEdit.buddyText
	property alias divemaster: detailsEdit.divemasterText
	property alias depth: detailsEdit.depthText
	property alias duration: detailsEdit.durationText
	property alias location: detailsEdit.locationText
	property alias notes: detailsEdit.notesText
	property alias suit: detailsEdit.suitText
	property alias weight: detailsEdit.weightText
	property alias startpressure: detailsEdit.startpressureText
	property alias endpressure: detailsEdit.endpressureText
	property alias gasmix: detailsEdit.gasmixText

	state: "view"

	states: [
		State {
			name: "view"
			PropertyChanges { target: diveDetailList; visible: true }
			PropertyChanges { target: detailsEditScroll; visible: false }
		},
		State {
			name: "edit"
			PropertyChanges { target: diveDetailList; visible: false }
			PropertyChanges { target: detailsEditScroll; visible: true }
		},
		State {
			name: "add"
			PropertyChanges { target: diveDetailList; visible: false }
			PropertyChanges { target: detailsEditScroll; visible: true }
		}

	]

	function endAddMode() {
		// edit was canceled - so remove the dive from the dive list
		manager.addDiveAborted(dive_id)
		state = "view"
		Qt.inputMethod.hide()
	}
/* this can be done by hitting the back key
	contextualActions: [
		Action {
			text: state === "view" ? "Back to dive list" : "Cancel"
			iconName: "dialog-cancel"
			onTriggered: {
				if (state === "view") {
					stackView.pop()
					contextDrawer.close()
				} else if (state === "edit") {
					endEditMode()
					contextDrawer.close()
				} else {
					endAddMode()
					contextDrawer.close()
				}
			}
		}
	]
 */
	mainAction: Action {
		iconName: state !== "view" ? "document-save" : "document-edit"
		onTriggered: {
			if (state === "edit" || state === "add") {
				detailsEdit.saveData()
			} else {
				startEditMode()
			}
		}
	}

	onBackRequested: {
		if (state === "edit") {
			endEditMode()
			event.accepted = true;
		} else if (state === "add") {
			endAddMode()
			event.accepted = true;
		}
		// if we were in view mode, don't accept the event and pop the page
	}

	function showDiveIndex(index) {
		currentIndex = index;
		diveDetailsListView.positionViewAtIndex(index, ListView.Beginning);
	}

	function endEditMode() {
		// just cancel the edit state
		state = "view";
		Qt.inputMethod.hide();
	}

	function startEditMode() {
		// set things up for editing - so make sure that the detailsEdit has
		// all the right data (using the property aliases set up above)
		dive_id = diveDetailsListView.currentItem.modelData.dive.id
		number = diveDetailsListView.currentItem.modelData.dive.number
		date = diveDetailsListView.currentItem.modelData.dive.date + " " + diveDetailsListView.currentItem.modelData.dive.time
		location = diveDetailsListView.currentItem.modelData.dive.location
		duration = diveDetailsListView.currentItem.modelData.dive.duration
		depth = diveDetailsListView.currentItem.modelData.dive.depth
		airtemp = diveDetailsListView.currentItem.modelData.dive.airTemp
		watertemp = diveDetailsListView.currentItem.modelData.dive.waterTemp
		suit = diveDetailsListView.currentItem.modelData.dive.suit
		buddy = diveDetailsListView.currentItem.modelData.dive.buddy
		divemaster = diveDetailsListView.currentItem.modelData.dive.divemaster
		notes = diveDetailsListView.currentItem.modelData.dive.notes
		if (diveDetailsListView.currentItem.modelData.dive.singleWeight) {
			// we have only one weight, go ahead, have fun and edit it
			weight = diveDetailsListView.currentItem.modelData.dive.sumWeight
		} else {
			// careful when translating, this text is "magic" in DiveDetailsEdit.qml
			weight = "cannot edit multiple weight systems"
		}
		if (diveDetailsListView.currentItem.modelData.dive.getCylinder != "Multiple" ) {
			startpressure = diveDetailsListView.currentItem.modelData.dive.startPressure
			endpressure = diveDetailsListView.currentItem.modelData.dive.endPressure
			gasmix = diveDetailsListView.currentItem.modelData.dive.firstGas
		} else {
			// careful when translating, this text is "magic" in DiveDetailsEdit.qml
			startpressure = "cannot edit multiple cylinders"
			endpressure = "cannot edit multiple cylinders"
			gasmix = "cannot edit multiple gases"
		}

		diveDetailsPage.state = "edit"
	}

	onWidthChanged: diveDetailsListView.positionViewAtIndex(diveDetailsListView.currentIndex, ListView.Beginning);

	ScrollView {
		id: diveDetailList
		anchors.fill: parent
		ListView {
			id: diveDetailsListView
			anchors.fill: parent
			model: diveModel
			currentIndex: -1
			boundsBehavior: Flickable.StopAtBounds
			maximumFlickVelocity: parent.width * 5
			orientation: ListView.Horizontal
			focus: true
			clip: true
			snapMode: ListView.SnapOneItem
			onMovementEnded: {
				currentIndex = indexAt(contentX+1, 1);
			}
			delegate: ScrollView {
				id: internalScrollView
				width: diveDetailsListView.width
				height: diveDetailsListView.height
				property var modelData: model
				Flickable {
					//contentWidth: parent.width
					contentHeight: diveDetails.height
					boundsBehavior: Flickable.StopAtBounds
					DiveDetailsView {
						id: diveDetails
						width: internalScrollView.width
					}
				}
			}
		}
	}
	Flickable {
		id: detailsEditScroll
		anchors.fill: parent
		anchors.margins: MobileComponents.Units.gridUnit
		contentWidth: contentItem.childrenRect.width;
		contentHeight: contentItem.childrenRect.height
		clip: true
		bottomMargin: MobileComponents.Units.gridUnit * 3
		DiveDetailsEdit {
			id: detailsEdit
		}
	}
}