-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathMMProjectDelegate.qml
More file actions
314 lines (241 loc) · 8.31 KB
/
Copy pathMMProjectDelegate.qml
File metadata and controls
314 lines (241 loc) · 8.31 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../../components"
import mm 1.0 as MM
Control {
id: root
property string projectDisplayName
property string projectId
property string projectDescription
property bool projectIsInSync: false
property real projectSyncProgress: 0.0
property var projectActionButtons: [] // possible values: upload, changes, sync, download, remove
property bool projectIsOpened: false
signal openRequested()
signal syncRequested()
signal migrateRequested()
signal removeRequested()
signal stopSyncRequested()
signal showChangesRequested()
height: implicitHeight
width: ListView.view.width - ListView.view.scrollBarWidth
topPadding: __style.margin20
rightPadding: __style.margin20
leftPadding: __style.margin20
// The last item in a section ('currently open' vs 'downloaded projects' in Home tab) gets an extra
// __style.margin28 padding, then the inset is also grown to keep the background at the correct size
bottomPadding: ListView.section !== ListView.nextSection ? __style.margin48: __style.margin20
bottomInset: ListView.section !== ListView.nextSection ? + __style.margin28: topInset
states: [
State { name: "OnServer" },
State { name: "UpToDate" }, // downloaded locally, no changes neither on server or locally
State { name: "Error" },
State { name: "NeedsSync" }
]
background: Rectangle {
color: root.projectIsOpened ? __style.forestColor : __style.polarColor
radius: __style.radius12
MouseArea {
anchors.fill: parent
onClicked: function( mouse ) {
mouse.accepted = true
root.openRequested()
}
}
}
contentItem: Item {
implicitHeight: contentColumn.height
Behavior on implicitHeight {
NumberAnimation { duration: 150 }
}
Column {
id: contentColumn
width: parent.width
spacing: __style.spacing12
RowLayout {
// title, desc and menu button
width: parent.width
Column {
Layout.fillWidth: true
spacing: 0
MMText {
width: parent.width
text: root.projectDisplayName
font: __style.t3
color: {
if ( root.projectIsOpened ) return __style.polarColor
if ( root.state === "Error" ) return __style.darkGreyColor
return __style.nightColor
}
elide: Text.ElideLeft
}
Row {
width: parent.width
spacing: __style.margin4
MMIcon {
id: projectStatusIcon
y: parent.height / 2 - height / 2
source: {
if ( root.state === "UpToDate" ) return __style.doneCircleIcon
if ( root.state === "OnServer" ) return __style.cloudIcon
if ( root.state === "Error" ) return __style.errorCircleIcon
if ( root.state === "NeedsSync" ) return __style.errorCircleIcon
return __style.errorCircleIcon
}
color: {
if ( root.state === "UpToDate" ) return __style.positiveColor
if ( root.state === "OnServer" ) return __style.informativeColor
if ( root.state === "Error" ) return __style.negativeColor
if ( root.state === "NeedsSync" ) return __style.warningColor
return __style.warningColor
}
size: __style.icon16
}
MMText {
width: parent.width - projectStatusIcon.width - parent.spacing
text: projectIsInSync ? qsTr( "Synchronising project changes" ) : root.projectDescription
font: __style.p6
color: root.projectIsOpened ? __style.polarColor : __style.nightColor
}
}
}
MMRoundButton {
iconSource: root.state === "OnServer" ? __style.downloadIcon : __style.moreVerticalIcon
bgndColor: root.projectIsOpened ? __style.polarColor : __style.lightGreenColor
visible: !(root.state === "OnServer" && root.projectIsInSync)
onClicked: {
if ( internal.hasMoreMenu ) {
moreMenuLoader.active = true
}
else {
root.syncRequested()
}
}
}
}
Column {
// sync component
width: parent.width
height: childrenRect.height
visible: root.projectIsInSync
spacing: __style.spacing12
MMProgressBar {
width: parent.width
position: root.projectSyncProgress
}
Row {
width: parent.width
height: childrenRect.height
spacing: __style.spacing12
MMText {
width: parent.width - parent.spacing - stopSyncGroup.width
text: qsTr( "Please don't close the app." )
font: __style.p6
color: root.projectIsOpened ? __style.polarColor : __style.nightColor
}
Item {
width: stopSyncGroup.width
height: stopSyncGroup.height
Row {
id: stopSyncGroup
spacing: __style.margin4
width: childrenRect.width + spacing
height: childrenRect.height
MMIcon {
source: __style.stopIcon
color: root.projectIsOpened ? __style.polarColor : __style.forestColor
}
MMText {
text: qsTr( "Stop" )
font: __style.t4
color: root.projectIsOpened ? __style.polarColor : __style.forestColor
}
}
MouseArea {
anchors.fill: parent
anchors.margins: -__style.margin12
onClicked: function( mouse ) {
mouse.accepted = true
root.stopSyncRequested()
}
}
}
}
}
}
}
Loader {
id: moreMenuLoader
active: false
asynchronous: true
sourceComponent: MMListDrawer {
id: moreMenu
drawerHeader.title: qsTr("More options")
list.model: ListModel { id: menuModel }
list.delegate: MMListDelegate {
text: model.name
leftContent: MMIcon {
source: model.iconSource
}
onClicked: {
let type = model.type
internal.moreMenuItems[type].callback()
moreMenu.close()
}
}
onClosed: moreMenuLoader.active = false
function fillMoreMenu() {
root.projectActionButtons.forEach( ( type ) => {
let item = internal.moreMenuItems[type]
item.type = type
menuModel.append( item )
} )
}
Component.onCompleted: {
fillMoreMenu()
open()
}
}
}
QtObject {
id: internal
property bool hasMoreMenu: root.projectActionButtons.length > 1
// possible options for the "more" menu
property var moreMenuItems: {
"download": {
"name": qsTr("Download"),
"iconSource": __style.downloadIcon,
"callback": () => root.syncRequested()
},
"sync": {
"name": qsTr("Synchronise project"),
"iconSource": __style.syncGreenIcon,
"callback": () => root.syncRequested()
},
"changes": {
"name": qsTr("Local changes"),
"iconSource": __style.infoIcon,
"callback": () => root.showChangesRequested()
},
"remove": {
"name": qsTr("Remove from device"),
"iconSource": __style.deleteIcon,
"callback": () => root.removeRequested()
},
"upload": {
"name": qsTr("Upload"),
"iconSource": __style.uploadIcon,
"callback": () => root.migrateRequested()
}
}
}
}