blob: 65642a0cb3610ae3bd09afb29dd3ea24b3384c86 (
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
|
pragma ComponentBehavior: Bound
import QtQuick
import qs.Common
import qs.Services
import qs.Widgets
StyledRect {
id: root
LayoutMirroring.enabled: I18n.isRtl
LayoutMirroring.childrenInherit: true
property string tab: ""
property var tags: []
property string settingKey: ""
property string title: ""
property string iconName: ""
property bool collapsible: false
property bool expanded: true
property real headerLeftPadding: 0
default property alias content: contentColumn.children
property alias headerActions: headerActionsRow.children
readonly property bool isHighlighted: settingKey !== "" && SettingsSearchService.highlightSection === settingKey
width: parent?.width ?? 0
height: {
var hasHeader = root.title !== "" || root.iconName !== "";
if (collapsed)
return headerRow.height + Theme.spacingL * 2;
var h = Theme.spacingL * 2 + contentColumn.height;
if (hasHeader)
h += headerRow.height + Theme.spacingM;
return h;
}
radius: Theme.cornerRadius
color: Theme.surfaceContainerHigh
readonly property bool collapsed: collapsible && !expanded
readonly property bool hasHeader: root.title !== "" || root.iconName !== ""
property bool userToggledCollapse: false
function findParentFlickable() {
let p = root.parent;
while (p) {
if (p.hasOwnProperty("contentY") && p.hasOwnProperty("contentItem")) {
return p;
}
p = p.parent;
}
return null;
}
Component.onCompleted: {
if (settingKey) {
let flickable = findParentFlickable();
if (flickable) {
SettingsSearchService.registerCard(settingKey, root, flickable);
}
}
}
Component.onDestruction: {
if (settingKey) {
SettingsSearchService.unregisterCard(settingKey);
}
}
Behavior on height {
enabled: root.userToggledCollapse
NumberAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
onRunningChanged: {
if (!running)
root.userToggledCollapse = false;
}
}
}
Rectangle {
id: highlightBorder
anchors.fill: parent
anchors.margins: -2
radius: root.radius + 2
color: "transparent"
border.width: 2
border.color: Theme.primary
opacity: root.isHighlighted ? 1 : 0
visible: opacity > 0
z: 100
Behavior on opacity {
NumberAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
}
Column {
id: mainColumn
anchors.fill: parent
anchors.margins: Theme.spacingL
spacing: root.hasHeader ? Theme.spacingM : 0
clip: true
Item {
id: headerRow
width: parent.width
height: root.hasHeader ? Math.max(headerIcon.height, headerText.height, headerActionsRow.height) : 0
visible: root.hasHeader
Row {
anchors.left: parent.left
anchors.leftMargin: root.headerLeftPadding
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingM
DankIcon {
id: headerIcon
name: root.iconName
size: Theme.iconSize
color: Theme.primary
anchors.verticalCenter: parent.verticalCenter
visible: root.iconName !== ""
}
StyledText {
id: headerText
text: root.title
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Medium
color: Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
visible: root.title !== ""
width: implicitWidth
horizontalAlignment: Text.AlignLeft
}
}
Row {
id: headerActionsRow
anchors.right: root.collapsible ? caretIcon.left : parent.right
anchors.rightMargin: root.collapsible ? Theme.spacingS : 0
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingXS
}
DankIcon {
id: caretIcon
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
name: root.expanded ? "expand_less" : "expand_more"
size: Theme.iconSize - 2
color: Theme.surfaceVariantText
visible: root.collapsible
}
MouseArea {
anchors.left: parent.left
anchors.right: headerActionsRow.left
anchors.top: parent.top
anchors.bottom: parent.bottom
enabled: root.collapsible
cursorShape: root.collapsible ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: {
root.userToggledCollapse = true;
root.expanded = !root.expanded;
}
}
MouseArea {
visible: root.collapsible
anchors.left: caretIcon.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.leftMargin: -Theme.spacingS
enabled: root.collapsible
cursorShape: root.collapsible ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: {
root.userToggledCollapse = true;
root.expanded = !root.expanded;
}
}
}
Column {
id: contentColumn
width: parent.width
spacing: Theme.spacingM
visible: !root.collapsed
}
}
}
|