blob: 26d346a9156010d25d4f4f13168a93c567bcd6a3 (
plain)
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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
Pane {
ColumnLayout {
spacing: 40
anchors.fill: parent
anchors.topMargin: 20
Label {
Layout.fillWidth: true
wrapMode: Label.Wrap
horizontalAlignment: Qt.AlignHCenter
text: "Delegate controls are used as delegates in views such as ListView."
}
ListView {
id: listView
clip: true
section.property: "type"
section.delegate: Pane {
id: sectionPane
required property string section
width: ListView.view.width
height: sectionLabel.implicitHeight + 20
Label {
id: sectionLabel
text: sectionPane.section
anchors.centerIn: parent
}
}
Layout.fillWidth: true
Layout.fillHeight: true
readonly property var delegateComponentMap: {
"ItemDelegate": itemDelegateComponent,
"SwipeDelegate": swipeDelegateComponent,
"CheckDelegate": checkDelegateComponent,
"RadioDelegate": radioDelegateComponent,
"SwitchDelegate": switchDelegateComponent
}
Component {
id: itemDelegateComponent
ItemDelegate {
// qmllint disable unqualified
text: value
// qmllint enable unqualified
width: parent.width
}
}
Component {
id: swipeDelegateComponent
SwipeDelegate {
id: swipeDelegate
// qmllint disable unqualified
text: value
// qmllint enable unqualified
width: parent.width
Component {
id: removeComponent
Rectangle {
color: SwipeDelegate.pressed ? "#333" : "#444"
width: parent.width
height: parent.height
clip: true
SwipeDelegate.onClicked: {
// qmllint disable unqualified
view.model.remove(ourIndex)
// qmllint enable unqualified
}
Label {
// qmllint disable unqualified
font.pixelSize: swipeDelegate.font.pixelSize
// qmllint enable unqualified
text: "Remove"
color: "white"
anchors.centerIn: parent
}
}
}
SequentialAnimation {
id: removeAnimation
PropertyAction {
// qmllint disable unqualified
target: delegateItem
// qmllint enable unqualified
property: "ListView.delayRemove"
value: true
}
NumberAnimation {
// qmllint disable unqualified
target: delegateItem.item
// qmllint enable unqualified
property: "height"
to: 0
easing.type: Easing.InOutQuad
}
PropertyAction {
// qmllint disable unqualified
target: delegateItem
// qmllint enable unqualified
property: "ListView.delayRemove"
value: false
}
}
swipe.left: removeComponent
swipe.right: removeComponent
ListView.onRemove: removeAnimation.start()
}
}
Component {
id: checkDelegateComponent
CheckDelegate {
// qmllint disable unqualified
text: value
// qmllint enable unqualified
}
}
ButtonGroup {
id: radioButtonGroup
}
Component {
id: radioDelegateComponent
RadioDelegate {
// qmllint disable unqualified
text: value
ButtonGroup.group: radioButtonGroup
// qmllint enable unqualified
}
}
Component {
id: switchDelegateComponent
SwitchDelegate {
// qmllint disable unqualified
text: value
// qmllint enable unqualified
}
}
model: ListModel {
ListElement { type: "ItemDelegate"; value: "ItemDelegate1" }
ListElement { type: "ItemDelegate"; value: "ItemDelegate2" }
ListElement { type: "ItemDelegate"; value: "ItemDelegate3" }
ListElement { type: "SwipeDelegate"; value: "SwipeDelegate1" }
ListElement { type: "SwipeDelegate"; value: "SwipeDelegate2" }
ListElement { type: "SwipeDelegate"; value: "SwipeDelegate3" }
ListElement { type: "CheckDelegate"; value: "CheckDelegate1" }
ListElement { type: "CheckDelegate"; value: "CheckDelegate2" }
ListElement { type: "CheckDelegate"; value: "CheckDelegate3" }
ListElement { type: "RadioDelegate"; value: "RadioDelegate1" }
ListElement { type: "RadioDelegate"; value: "RadioDelegate2" }
ListElement { type: "RadioDelegate"; value: "RadioDelegate3" }
ListElement { type: "SwitchDelegate"; value: "SwitchDelegate1" }
ListElement { type: "SwitchDelegate"; value: "SwitchDelegate2" }
ListElement { type: "SwitchDelegate"; value: "SwitchDelegate3" }
}
delegate: Loader {
id: delegateLoader
width: ListView.view.width
// qmllint disable unqualified
sourceComponent: listView.delegateComponentMap[type]
// qmllint enable unqualified
required property string value
required property string type
required property var model
required property int index
property Loader delegateItem: delegateLoader
// qmllint disable unqualified
property ListView view: listView
// qmllint enable unqualified
property int ourIndex: index
}
}
}
}
|