-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathMMListDelegate.qml
More file actions
124 lines (90 loc) · 3.03 KB
/
Copy pathMMListDelegate.qml
File metadata and controls
124 lines (90 loc) · 3.03 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
/***************************************************************************
* *
* 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.Layouts
//
// MMListDelegate item should be used within various lists
// It has left and right content that can be used to add MMIcon, MMSwitch, badges and more
// See gallery for more details
//
Item {
id: root
signal clicked()
property string text
property string secondaryText
property alias leftContent: leftContentGroup.children
property alias rightContent: rightContentGroup.children
property bool hasLine: {
// calculate automatically when this item is a delegate in list
if ( typeof index != "undefined" ) {
if ( ListView?.view ?? false ) {
return index < ListView.view.count - 1
}
}
return true
}
property real verticalSpacing: root.secondaryText ? __style.margin8 : __style.margin20
implicitWidth: ListView?.view?.width - ListView?.view?.scrollBarWidth ?? 0 // in case ListView is injected as attached property (usually it is)
implicitHeight: contentLayout.implicitHeight
height: visible ? implicitHeight : 0.1 // hide invisible items, for some reason setting 0 does not work ¯\_(ツ)_/¯
MouseArea {
anchors.fill: contentLayout
onClicked: function( mouse ) {
mouse.accepted = true
root.clicked()
}
}
Column {
id: contentLayout
width: parent.width
Item { width: 1; height: verticalSpacing }
RowLayout {
// content
width: parent.width
spacing: __style.margin12
Item {
id: leftContentGroup
Layout.preferredHeight: childrenRect.height
Layout.preferredWidth: childrenRect.width
visible: children.length > 0
}
Column {
Layout.fillWidth: true
spacing: 0
MMText {
width: parent.width
font: __style.t3
text: root.text
textFormat: Text.PlainText
color: __style.nightColor
}
MMText {
width: parent.width
visible: root.secondaryText
font: __style.p6
text: root.secondaryText
color: __style.nightColor
}
}
Item {
id: rightContentGroup
Layout.preferredHeight: childrenRect.height
Layout.preferredWidth: childrenRect.width
visible: children.length > 0
}
}
Item { width: 1; height: verticalSpacing }
Rectangle {
width: parent.width
height: __style.row1
visible: root.hasLine
color: __style.greyColor
}
}
}