-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductsPage.qml
263 lines (236 loc) · 8.83 KB
/
ProductsPage.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
import QtQuick 2.8
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.3
import QtQml 2.2
import sql.products.model 1.0
Page {
id: productPage
property variant currentDebtor: -1
property string currentDebtorName
property int currentDebt:-1
property bool pay
header: DebtToolBar {
Label {
text: currentDebtorName
font.pixelSize: 20
anchors.centerIn: parent
}
ToolButton {
text: qsTr("Back")
anchors.left: parent.left
anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter
onClicked: productPage.StackView.view.pop()
}
}
//Section Component
Component {
id: sectionHeading
ToolBar {
opacity: 0.8
width: listView.width
Label {
id: label
text: section
anchors.fill: parent
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
}
}
}
ListView {
id: listView
anchors.fill: parent
delegate: SwipeDelegate {
id: delegate
width: listView.width
onClicked: {
currentDebt=id;
pay=true;
dialog.preset();
dialog.createDebt(true);
}
property double debt: quantity*cost-paid_back
contentItem: ColumnLayout{
Label{
text: borrowed_time+ " :: " + lender_name
font.italic: true
color: "grey"
elide: Text.ElideRight
Layout.fillWidth: true
}
RowLayout{
Layout.fillWidth: true
ColumnLayout{
Layout.fillWidth: true
RowLayout {
id: rowLayout
Layout.fillWidth: true
Label {
text: product
font.bold: true
elide: Text.ElideRight
}
Rectangle{
color: "yellow"
Text {
id: rectId
text: quantity + " units"
anchors.centerIn: parent
}
height: rectId.implicitHeight+5
width: rectId.implicitWidth+5
radius: 2
}
Image {
id: money
source: "qrc:/images/money2.png"
sourceSize.width: 20
sourceSize.height: 20
}
Label{
text: cost
}
Label {
text: " :: "+comment_1
elide: Text.ElideRight
Layout.fillWidth: true
font.italic: true
color: "grey"
}
}
Label{
visible: paid_back!=""
text: paid_back_data
font.italic: true
color: "grey"
elide: Text.ElideRight
}
RowLayout{
Layout.fillWidth: true
visible: paid_back!=""
Label{
text: "Was returned "
font.italic: true
elide: Text.ElideRight
}
Rectangle {
color: "#5fba7d"
Text {
id: paidText
text: "+ " + paid_back
anchors.centerIn: parent
color: "white"
}
height: paidText.implicitHeight+5
width: paidText.implicitWidth+5
radius: 3
}
Label{
text: " to "+paid_back_to_name
font.italic: true
elide: Text.ElideRight
}
Label {
text: " :: "+comment_2
elide: Text.ElideRight
Layout.fillWidth: true
font.italic: true
color: "grey"
}
}
}
Rectangle {
color: debt!=0?"red":"#5fba7d"
Text {
id: totalDebt
text: debt===0?"Sunk":"-" + debt
anchors.centerIn: parent
color: "white"
font.pointSize: 12
}
height: totalDebt.implicitHeight+10
width: totalDebt.implicitWidth+10
radius: 3
}
}
}
//Right
swipe.right: Rectangle {
color: SwipeDelegate.pressed ? "#333" : "#444"
width: parent.width
height: parent.height
clip: true
SwipeDelegate.onClicked: listModel.remove(model.id)
Label {
font.pixelSize: delegate.font.pixelSize
text: "Remove"
color: "white"
anchors.centerIn: parent
}
}
//Left
swipe.left: Rectangle {
color: SwipeDelegate.pressed ? "#333" : "#444"
width: parent.width
height: parent.height
clip: true
SwipeDelegate.onClicked: {
currentDebt=id;
pay=false;
dialog.preset();
dialog.editDebt(listView.model.get(index));
}
Label {
font.pixelSize: delegate.font.pixelSize
text: "Edit"
color: "white"
anchors.centerIn: parent
}
}
}
model: ProductsModel {
id: listModel
curDebtor: currentDebtor
}
ScrollBar.vertical: ScrollBar { }
section.property: "borrowed_data"
section.criteria: ViewSection.FullString
section.delegate: sectionHeading
section.labelPositioning: listView.section.labelPositioning |= ViewSection.CurrentLabelAtStart
}
Label {
id: placeholder
text: qsTr("No Debts")
anchors.margins: 60
anchors.fill: parent
opacity: 0.5
visible: listView.count === 0
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
wrapMode: Label.WordWrap
font.pixelSize: 18
}
RoundButton {
text: qsTr("+")
highlighted: true
anchors.margins: 10
anchors.right: parent.right
anchors.bottom: parent.bottom
onClicked: {
currentDebt=-1;
dialog.preset();
dialog.createDebt(false);
}
}
ProductsDialog{
id: dialog
onFinished: {
if (currentDebt === -1)
listView.model.set(true,currentDebt,currentDebtor,product,quantity,cost, comment_1,borrowed_data,lender,paid_back,paid_back_data,comment_2,paid_back_to) //append
else
listView.model.set(false, currentDebt,currentDebtor, product,quantity,cost, comment_1,borrowed_data,lender,paid_back,paid_back_data,comment_2,paid_back_to) //pay and edit
}
}
}