-
Notifications
You must be signed in to change notification settings - Fork 3
/
TaskListDelegateModel.qml
190 lines (160 loc) · 7.2 KB
/
TaskListDelegateModel.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
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtQml.Models 2.2
Item {
property alias visualModel: visualModelId
property ListView listView
DelegateModel {
id: visualModelId
delegate: dragDelegate
}
Component {
id: dragDelegate
MouseArea {
id: dragArea
property bool held: false
property string itemcolor: object.color
property real backgroundOpacity: 0.8
anchors { left: parent.left; right: parent.right }
height: content.height
drag.target: held ? content : undefined
drag.axis: Drag.YAxis
drag.minimumY: 0
drag.maximumY: listView.contentHeight - dragArea.height
onPressAndHold: held = true
onReleased: held = false
onClicked: {
textAreaId.inEditMode = false
Qt.inputMethod.hide()
}
Rectangle {
id: content
height: textAreaId.height
width: parent.width
color: itemcolor
opacity: dragArea.backgroundOpacity
anchors {
verticalCenter: parent.verticalCenter
}
Drag.active: dragArea.held
Drag.source: dragArea
Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2
states: State {
when: dragArea.held
ParentChange { target: content; parent: listView }
AnchorChanges {
target: content
anchors { horizontalCenter: undefined; verticalCenter: undefined }
}
}
RowLayout {
id: rowId
anchors.verticalCenter: parent.verticalCenter
CheckBox {
id: checkboxId
checked: object.done
onCheckStateChanged: {
object.done = checked
}
}
TextArea {
id: textAreaId
property bool inEditMode: false
font.bold: true
font.strikeout: checkboxId.checked
text: object.title
readOnly: !inEditMode
wrapMode: TextEdit.WordWrap
Layout.maximumWidth: dragArea.width - checkboxId.width - deleteTaskButtonId.width - dragIndicatorTextId.width
background: Rectangle {
border.color: textAreaId.readOnly ? "transparent" : "#000000"
color: "transparent"
}
MouseArea {
anchors.fill: parent
enabled: textAreaId.inEditMode !== true
visible: textAreaId.inEditMode !== true
onPressAndHold: {
dragArea.held = true
}
onReleased: dragArea.held = false
drag.target: dragArea.held ? content : undefined
drag.axis: Drag.YAxis
drag.minimumY: 0
drag.maximumY: listView.contentHeight - dragArea.height
}
onEditingFinished: {
inEditMode = false
object.title = text
Qt.inputMethod.hide()
}
}
}
Button {
id: editTaskButtonId
text: textAreaId.inEditMode ? qsTr("\uE8FB") : qsTr("\uE104")
font.family: "Segoe MDL2 Assets"
visible: !object.done
anchors.verticalCenter: parent.verticalCenter
anchors.right: dragIndicatorTextId.right
anchors.rightMargin: 40
background: Rectangle {
anchors.fill: parent
color: editTaskButtonId.down ? "#99eeeeee" : "transparent"
}
onReleased: {
if (textAreaId.inEditMode) {
textAreaId.inEditMode = false
object.title = textAreaId.text
Qt.inputMethod.hide()
} else {
textAreaId.inEditMode = true
textAreaId.selectAll()
listView.positionViewAtIndex(index, ListView.Beginning)
}
}
}
Button {
id: deleteTaskButtonId
text: qsTr("\uE74D")
font.family: "Segoe MDL2 Assets"
visible: object.done
anchors.verticalCenter: parent.verticalCenter
anchors.right: dragIndicatorTextId.right
anchors.rightMargin: 40
background: Rectangle {
anchors.fill: parent
color: deleteTaskButtonId.down ? "#99eeeeee" : "transparent"
}
onReleased: {
backend.deleteCompletedTask(object)
}
}
Text {
id: dragIndicatorTextId
text: qsTr("\uE700")
font.family: "Segoe MDL2 Assets"
anchors.right: parent.right
width: 40
height: 40
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
color: dragArea.held ? "white" : "black"
Behavior on color { ColorAnimation { duration: 100 } }
}
}
DropArea {
anchors { fill: parent }
onEntered: {
object.order = drag.source.DelegateModel.itemsIndex
visualModel.items.move(
drag.source.DelegateModel.itemsIndex,
dragArea.DelegateModel.itemsIndex)
}
}
}
}
}