MauiKit File Browsing

TagsDialog.qml
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import org.mauikit.controls as Maui
6import org.mauikit.filebrowsing as FB
7
8/**
9 * @inherit org::mauikit::controls::PopupPage
10 * @brief A popup dialog for selecting between all the available tags to associate to a given set of file URLs.
11 *
12 * This popup page also allows to create new tags, edit existing ones and removing.
13 *
14 * To associate the set of file URLs, use the exposed property `composerList.urls`, which is an alias to TagsList::urls.
15 * @see composerList
16 * @see TagsList::urls
17 * The `composerList` property exposes most of the available properties for tweaking the behaviour, and also contains the methods to perform any modifications to the tags.
18 *
19 * @image html tagsdialog.png "Example using the TagsDialog control"
20 *
21 * @code
22 * Maui.Page
23 * {
24 * Maui.Controls.showCSD: true
25 * anchors.fill: parent
26 *
27 * title: "Add tags to a file"
28 *
29 * FB.FileBrowser
30 * {
31 * id: _fileBrowser
32 * anchors.fill: parent
33 * currentPath: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
34 * settings.viewType: FB.FMList.LIST_VIEW
35 * onItemClicked: (index) =>
36 * {
37 * _tagsDialog.composerList.urls = [_fileBrowser.currentFMModel.get(index).url]
38 * _tagsDialog.open()
39 * }
40 * }
41 *
42 * FB.TagsDialog
43 * {
44 * id: _tagsDialog
45 * composerList.strict: false //Show all the associated tags to the file
46 * onTagsReady: (tags) => console.log(tags)
47 * }
48 * }
49 * @endcode
50 */
51Maui.PopupPage
52{
53 id: control
54
55 /**
56 * @brief An alias to the TagsList list/model controlling and listing all of the available tags.
57 * @see TagsListmodel
58 * @property TagsList TagsDialog::tagList
59 */
60 readonly property alias taglist : _tagsList
61
62 /**
63 * @brief An alias to the Mauikit ListBrowser element listing the tag elements.
64 * @property MauiKit::ListBrowser TagsDialog::listView
65 */
66 readonly property alias listView: _listView
67
68 /**
69 * @brief An alias to the TagsList controller and model.
70 * This property is exposed to set the file URLs to which perform any new assignment or removal of tags.
71 * Refer to its documentation for more details on the available actions.
72 * @property TagsList TagsDialog::composerList
73 */
74 readonly property alias composerList: tagListComposer.list
75
76 /**
77 * @brief Emitted once the assignment of the new set of tags has been done. This can include removal or additions.
78 * This won't actually write any changes to the file URLs, to write the changes refer to the `composerList.updateToUrls` function.
79 * @see TagsList::updateToUrls
80 * @param tags the list of the new tag names associated to the file URLs
81 */
82 signal tagsReady(var tags)
83
84 hint: 1
85
86 maxHeight: 500
87 maxWidth: 400
88
89 actions: [
90
91 Action
92 {
93 text: i18nd("mauikitfilebrowsing", "Save")
94 onTriggered: control.setTags()
95 },
96
97 Action
98 {
99 text: i18nd("mauikitfilebrowsing", "Cancel")
100 onTriggered: control.close()
101 }
102 ]
103
104 headBar.visible: true
105 headBar.forceCenterMiddleContent: false
106 headBar.middleContent: Maui.TextField
107 {
108 id: tagText
109 Layout.fillWidth: true
110 Layout.maximumWidth: 500
111 placeholderText: i18nd("mauikitfilebrowsing", "Filter or add a new tag")
112 icon.source: "tag"
113 // validator: RegExpValidator { regExp: /[0-9A-F]+/ }
114 onAccepted:
115 {
116 const tags = tagText.text.split(",")
117 for(var i in tags)
118 {
119 const myTag = tags[i].trim()
120 _tagsList.insert(myTag)
121 tagListComposer.list.append(myTag)
122 }
123 clear()
124 _tagsModel.filter = ""
125 }
126
127 onTextChanged:
128 {
129 _tagsModel.filter = text
130 }
131 }
132
133 Maui.InfoDialog
134 {
135 id: _deleteDialog
136
137 property string tag
138 title: i18nd("mauikitfilebrowsing", "Delete %1", tag)
139 message: i18nd("mauikitfilebrowsing", "Are you sure you want to delete this tag? This action can not be undone.")
140 template.iconSource: "tag"
141 onAccepted:
142 {
143 FB.Tagging.removeTag(tag)
144 _deleteDialog.close()
145 }
146
147 onRejected: _deleteDialog.close()
148 }
149
150 Maui.ContextualMenu
151 {
152 id: _menu
153
154 MenuItem
155 {
156 text: i18nd("mauikitfilebrowsing", "Edit")
157 icon.name: "document-edit"
158 }
159
160 MenuItem
161 {
162 text: i18nd("mauikitfilebrowsing", "Delete")
163 icon.name: "delete"
164 onTriggered:
165 {
166 _deleteDialog.tag = _tagsModel.get(_listView.currentIndex).tag
167 _deleteDialog.open()
168 }
169 }
170 }
171
172 stack: [
173
174 Maui.ListBrowser
175 {
176 id: _listView
177
178 Layout.fillHeight: true
179 Layout.fillWidth: true
180 clip: true
181 currentIndex: -1
182
183 holder.emoji: "qrc:/assets/tag.svg"
184 holder.visible: _listView.count === 0
185 holder.title : i18nd("mauikitfilebrowsing", "No Tags!")
186 holder.body: i18nd("mauikitfilebrowsing", "Create new tags to organize your files.")
187
188 model: Maui.BaseModel
189 {
190 id: _tagsModel
191 sort: "tag"
192 sortOrder: Qt.AscendingOrder
193 recursiveFilteringEnabled: true
194 sortCaseSensitivity: Qt.CaseInsensitive
195 filterCaseSensitivity: Qt.CaseInsensitive
196 list: FB.TagsListModel
197 {
198 id: _tagsList
199 strict: false
200 }
201 }
202
203 delegate: Maui.ListBrowserDelegate
204 {
205 width: ListView.view.width
206 label1.text: model.tag
207 iconSource: model.icon
208 iconSizeHint: Maui.Style.iconSizes.small
209
210 template.content: Rectangle
211 {
212 color: model.color ? model.color : "transparent"
213 height: Maui.Style.iconSizes.small
214 radius: height/2
215 width: height
216 }
217
218 onClicked:
219 {
220 _listView.currentIndex = index
221 if(Qt.styleHints.singleClickActivation)
222 {
223 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
224 }
225 }
226
227 onDoubleClicked:
228 {
229 _listView.currentIndex = index
230 if(!Qt.styleHints.singleClickActivation)
231 {
232 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
233 }
234 }
235
236 onPressAndHold:
237 {
238 _listView.currentIndex = index
239 _menu.open()
240 }
241
242 onRightClicked:
243 {
244 _listView.currentIndex = index
245 _menu.open()
246 }
247 }
248 },
249
250 Loader
251 {
252 asynchronous: true
253 active: tagListComposer.list.urls.length > 1
254 visible: active
255 Layout.fillWidth: true
256
257 sourceComponent: Maui.ListItemTemplate
258 {
259 id: _info
260
261 property var itemInfo : FB.FM.getFileInfo( tagListComposer.list.urls[0])
262 label1.text: i18nd("mauikitfilebrowsing", "Tagging %1 files", tagListComposer.list.urls.length)
263 label2.text: i18nd("mauikitfilebrowsing", "Add new tags for the selected files.")
264 label2.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
265 iconSource : itemInfo.icon
266 imageSource: itemInfo.thumbnail
267 // iconSizeHint: Maui.Style.iconSizes.huge
268 // headerSizeHint: iconSizeHint + Maui.Style.space.big
269
270 iconComponent: Item
271 {
272 Item
273 {
274 anchors.fill: parent
275 layer.enabled: true
276
277 Rectangle
278 {
279 anchors.fill: parent
280 anchors.leftMargin: Maui.Style.space.small
281 anchors.rightMargin: Maui.Style.space.small
282 radius: Maui.Style.radiusV
283 color: Qt.tint(control.Maui.Theme.textColor, Qt.rgba(control.Maui.Theme.backgroundColor.r, control.Maui.Theme.backgroundColor.g, control.Maui.Theme.backgroundColor.b, 0.9))
284 border.color: Maui.Theme.backgroundColor
285 }
286
287 Rectangle
288 {
289 anchors.fill: parent
290 anchors.topMargin: Maui.Style.space.tiny
291 anchors.leftMargin: Maui.Style.space.tiny
292 anchors.rightMargin: Maui.Style.space.tiny
293 radius: Maui.Style.radiusV
294 color: Qt.tint(control.Maui.Theme.textColor, Qt.rgba(control.Maui.Theme.backgroundColor.r, control.Maui.Theme.backgroundColor.g, control.Maui.Theme.backgroundColor.b, 0.9))
295 border.color: Maui.Theme.backgroundColor
296 }
297
298 Rectangle
299 {
300 anchors.fill: parent
301 anchors.topMargin: Maui.Style.space.small
302 border.color: Maui.Theme.backgroundColor
303
304 radius: Maui.Style.radiusV
305 color: Qt.tint(control.Maui.Theme.textColor, Qt.rgba(control.Maui.Theme.backgroundColor.r, control.Maui.Theme.backgroundColor.g, control.Maui.Theme.backgroundColor.b, 0.9))
306
307 Maui.GridItemTemplate
308 {
309 anchors.fill: parent
310 anchors.margins: Maui.Style.space.tiny
311 iconSizeHint: _info.iconSizeHint
312
313 iconSource: _info.iconSource
314 imageSource: _info.imageSource
315 }
316 }
317 }
318 }
319 }
320 }
321 ]
322
323 page.footer: FB.TagList
324 {
325 id: tagListComposer
326 width: parent.width
327 visible: count > 0
328
329 onTagRemoved: list.remove(index)
330 placeholderText: i18nd("mauikitfilebrowsing", "No tags yet.")
331 }
332
333 onClosed:
334 {
335 composerList.urls = []
336 tagText.clear()
337 _tagsModel.filter = ""
338 }
339
340 onOpened: tagText.forceActiveFocus()
341
342 /**
343 * @brief Gathers the composed set of tags in the bottom composing TagsBar to the given file URLs, emits the `tagsReady` signal and then closes the dialog.
344 */
345 function setTags()
346 {
347 var tags = tagListComposer.list.tags
348 control.tagsReady(tags)
349 close()
350 }
351}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
KGuiItem clear()
const QList< QKeySequence > & close()
void remove(qsizetype i, qsizetype n)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.