-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.qml
More file actions
396 lines (357 loc) · 14.5 KB
/
Task.qml
File metadata and controls
396 lines (357 loc) · 14.5 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import QtQuick
import QtQuick.Layouts
Item {
id: rootItem
width: lView.width
height: 70
property bool isBeingDeleted: false
Behavior on height {
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
}
Behavior on x {
NumberAnimation { duration: 300; easing.type: Easing.OutQuad }
}
Behavior on opacity {
NumberAnimation { duration: 300 }
}
Rectangle {
id: rec
width: parent.width - 20
anchors.horizontalCenter: parent.horizontalCenter
y: 10
border.color: root.isDeleting ? root.trashDeletingColor : model.finished === 0 ? root.borderColor : root.taskFinished
Behavior on border.color {
ColorAnimation {
duration: 200
}
}
border.width: 2
radius: 10
height: 60
color: root.bgColor
property bool isOpened: false
property bool isContentVisible: false
property int expandedHeight: Math.max(120, 60 + descriptionLbl.height + buttonRow.height + 20) // Dynamic height based on content
Behavior on height {
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
enabled: !rootItem.isBeingDeleted
cursorShape: root.isDeleting ? Qt.PointingHandCursor : Qt.ArrowCursor
onEntered: {
gradientBackground.fadeDirection = "in";
fadeTimer.start();
}
onExited: {
gradientBackground.fadeDirection = "out";
fadeTimer.start();
}
onClicked: {
if(root.isDeleting && !isBeingDeleted){
// Start delete animation
rootItem.isBeingDeleted = true;
// Store the current index for the deletion
var currentIndex = -1;
for(let i = 0; i < lModel.count; ++i){
if(lModel.get(i).id === model.id){
currentIndex = i;
break;
}
}
if(currentIndex !== -1) {
// Schedule the deletion after animations
deleteTimer.modelIndex = currentIndex;
deleteTimer.start();
taskManager.removeTaskDB(model.id);
}
}
else{
rec.isOpened = !rec.isOpened;
contentTimer.stop();
collapseTimer.stop();
if (rec.isOpened) {
rec.height = rec.expandedHeight;
rootItem.height = rec.expandedHeight + 10;
contentTimer.start();
} else {
rec.isContentVisible = false;
collapseTimer.start();
}
}
}
Timer {
id: safetyTimer
interval: 250
repeat: false
running: rec.isOpened !== rec.isContentVisible
onTriggered: {
rec.isContentVisible = rec.isOpened;
}
}
}
Timer {
id: contentTimer
interval: 200
repeat: false
onTriggered: {
rec.isContentVisible = true;
}
}
Timer {
id: collapseTimer
interval: 150
repeat: false
onTriggered: {
rec.height = 60;
rootItem.height = 70;
}
}
Rectangle {
id: gradientBackground
anchors.fill: parent
anchors.margins: parent.border.width
anchors.centerIn: parent
radius: parent.radius - parent.border.width
opacity: 0
Timer {
id: fadeTimer
interval: 1
repeat: true
onTriggered: {
if (gradientBackground.opacity < 1 && gradientBackground.opacity >= 0 && gradientBackground.fadeDirection === "in") {
gradientBackground.opacity += 0.02;
} else if (gradientBackground.opacity > 0 && gradientBackground.fadeDirection === "out") {
gradientBackground.opacity -= 0.02;
} else {
fadeTimer.stop();
}
}
}
property string fadeDirection: ""
property color hoverColor: root.isDeleting ? root.trashDeletingColor : model.finished === 0 ? root.borderColor : root.taskFinished
Behavior on hoverColor {
ColorAnimation {
duration: 200
}
}
gradient: Gradient {
GradientStop { position: 0.0; color: root.bgColor }
GradientStop { position: 0.5; color: root.bgColor }
GradientStop { position: 1.0; color: gradientBackground.hoverColor }
}
}
Row {
anchors.fill: parent
anchors.leftMargin: 10
spacing: rec.width - leftCol.width - 30
Column {
id: leftCol
anchors.top: parent.top
anchors.topMargin: 5
Text {
Layout.bottomMargin: 5
id: nameLbl
text: model.name
font.strikeout: model.finished
font.pointSize: 15
font.bold: true
color: model.finished===0 ? root.textColor : root.taskFinished
Behavior on color {
ColorAnimation {
duration: 200
}
}
Behavior on font.strikeout {
NumberAnimation {
duration: 200
}
}
}
Text {
id: deadlineLbl
text: model.deadline
color: root.textColor
Layout.bottomMargin: 20
}
Text {
id: descriptionLbl
text: model.description
width: rootItem.width - 40
wrapMode: Text.Wrap
color: root.textColor
font.pointSize: 8
opacity: rec.isContentVisible ? 1 : 0
// Update the rectangle's expanded height whenever the text changes
onTextChanged: {
// Force layout update to get correct height
descriptionLbl.height = implicitHeight;
rec.expandedHeight = Math.max(120, 60 + descriptionLbl.height + buttonRow.height + 20);
// If already expanded, update heights immediately
if (rec.isOpened) {
rec.height = rec.expandedHeight;
rootItem.height = rec.expandedHeight + 10;
}
}
// Also update on component completion
Component.onCompleted: {
descriptionLbl.height = implicitHeight;
rec.expandedHeight = Math.max(120, 60 + descriptionLbl.height + buttonRow.height + 20);
}
Behavior on opacity {
NumberAnimation { duration: 150 }
}
}
Item {
y: rec.expandedHeight - 49
Row{
id: buttonRow
spacing: 10
Rectangle {
id: trashTask
width: 33
height: 33
color: "red"
radius: 20
opacity: rec.isContentVisible ? 1 : 0
Behavior on opacity {
NumberAnimation { duration: 150 }
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: {
// Start delete animation
rootItem.isBeingDeleted = true;
// Store the current index for the deletion
var currentIndex = -1;
for(let i = 0; i < lModel.count; ++i){
if(lModel.get(i).id === model.id){
currentIndex = i;
break;
}
}
if(currentIndex !== -1) {
// Schedule the deletion after animations
deleteTimer.modelIndex = currentIndex;
deleteTimer.start();
taskManager.removeTaskDB(model.id);
}
}
}
Image {
source: "qrc:/qt/qml/Serenify/Images/Trash.png"
width: trashTask.width * 0.8
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
smooth: true
}
}
Rectangle {
id: editTask
width: 33
height: 33
color: "yellow"
radius: 20
opacity: rec.isContentVisible ? 1 : 0
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
taskPopup.startName = model.name
taskPopup.startDesc = model.description
taskPopup.startPriority = model.priority
taskPopup.currentId = model.id
taskPopup.isEditing = true
dateTimeSelector.selectedDate = model.deadline
taskPopup.open()
}
}
Behavior on opacity {
NumberAnimation { duration: 150 }
}
Image {
source: "qrc:/qt/qml/Serenify/Images/pencil.png"
width: editTask.width * 0.6
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
smooth: true
}
}
Rectangle {
id: finishTask
width: 33
height: 33
color: "green"
radius: 20
opacity: rec.isContentVisible ? 1 : 0
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
if(model.finished===0){
model.finished = 1;
}
else model.finished = 0;
taskManager.updateTaskDB(model.id, model.name, model.description, model. deadline, model.priority, model.finished)
root.sortTasks();
}
}
Behavior on opacity {
NumberAnimation { duration: 150 }
}
Image {
source: "qrc:/qt/qml/Serenify/Images/checkmark.png"
width: finishTask.width * 0.6
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
smooth: true
}
}
}
}
}
Column {
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
Rectangle {
id: priorityRec
function assignColor(){
if (model.priority === "Low") return "green";
if (model.priority === "Medium") return "yellow";
if (model.priority === "High") return "red";
else return "green";
}
color: assignColor()
width: 12
height: 12
radius: 10
}
}
}
}
// Handle the deletion animation
states: [
State {
name: "deleting"
when: rootItem.isBeingDeleted
PropertyChanges { target: rootItem; x: rootItem.width }
PropertyChanges { target: rootItem; opacity: 0 }
}
]
// Timer to actually remove the item after animation
Timer {
id: deleteTimer
interval: 300 // Match the duration of the delete animation
repeat: false
property int modelIndex: -1
onTriggered: {
if(modelIndex !== -1) {
lModel.remove(modelIndex);
rootItem.isBeingDeleted = false;
}
}
}
}