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 Maui.Controls.status: Maui.Controls.Positive
94 text: i18nd("mauikitfilebrowsing", "Save")
95 onTriggered: control.setTags()
96 },
97
98 Action
99 {
100 text: i18nd("mauikitfilebrowsing", "Cancel")
101 onTriggered: control.close()
102 }
103 ]
104
105 headBar.visible: true
106 headBar.forceCenterMiddleContent: false
107 headBar.middleContent: Maui.TextField
108 {
109 id: tagText
110 Layout.fillWidth: true
111 Layout.maximumWidth: 500
112 placeholderText: i18nd("mauikitfilebrowsing", "Filter or add a new tag")
113 icon.source: "tag"
114 // validator: RegExpValidator { regExp: /[0-9A-F]+/ }
115 onAccepted: //here we append a new tag to the model but we do not insert it into the DB until the user saves the tag to an url
116 {
117 const tags = tagText.text.split(",")
118 for(var i in tags)
119 {
120 const myTag = tags[i].trim()
121 _tagsList.append(myTag)
122 tagListComposer.list.append(myTag)
123 }
124 clear()
125 // _tagsModel.filter = ""
126 }
127
128 onTextChanged:
129 {
130 _tagsModel.filter = text
131 }
132 }
133
134 Maui.InfoDialog
135 {
136 id: _deleteDialog
137
138 property string tag
139 title: i18nd("mauikitfilebrowsing", "Delete %1", tag)
140 message: i18nd("mauikitfilebrowsing", "Are you sure you want to delete this tag? This action can not be undone.")
141 template.iconSource: "tag"
142 onAccepted:
143 {
144 FB.Tagging.removeTag(tag)
145 _deleteDialog.close()
146 }
147
148 onRejected: _deleteDialog.close()
149 }
150
151 Maui.ContextualMenu
152 {
153 id: _menu
154
155 MenuItem
156 {
157 text: i18nd("mauikitfilebrowsing", "Edit")
158 icon.name: "document-edit"
159 }
160
161 MenuItem
162 {
163 text: i18nd("mauikitfilebrowsing", "Delete")
164 icon.name: "delete"
165 onTriggered:
166 {
167 _deleteDialog.tag = _tagsModel.get(_listView.currentIndex).tag
168 _deleteDialog.open()
169 }
170 }
171 }
172
173 stack: [
174
175 Maui.ListBrowser
176 {
177 id: _listView
178
179 Layout.fillHeight: true
180 Layout.fillWidth: true
181 clip: true
182 currentIndex: -1
183
184 holder.emoji: "qrc:/assets/tag.svg"
185 holder.visible: _listView.count === 0
186 holder.title : i18nd("mauikitfilebrowsing", "No Tags!")
187 holder.body: i18nd("mauikitfilebrowsing", "Create new tags to organize your files.")
188
189 model: Maui.BaseModel
190 {
191 id: _tagsModel
192 sort: "tag"
193 sortOrder: Qt.AscendingOrder
194 recursiveFilteringEnabled: true
195 sortCaseSensitivity: Qt.CaseInsensitive
196 filterCaseSensitivity: Qt.CaseInsensitive
197 list: FB.TagsListModel
198 {
199 id: _tagsList
200 strict: false
201 }
202 }
203
204 delegate: Maui.ListBrowserDelegate
205 {
206 width: ListView.view.width
207 label1.text: model.tag
208 iconSource: model.icon
209 iconSizeHint: Maui.Style.iconSizes.small
210
211 template.content: Rectangle
212 {
213 color: model.color ? model.color : "transparent"
214 height: Maui.Style.iconSizes.small
215 radius: height/2
216 width: height
217 }
218
219 onClicked:
220 {
221 _listView.currentIndex = index
222 if(Maui.Handy.singleClick)
223 {
224 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
225 }
226 }
227
228 onDoubleClicked:
229 {
230 _listView.currentIndex = index
231 if(!Maui.Handy.singleClick)
232 {
233 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
234 }
235 }
236
237 onPressAndHold:
238 {
239 _listView.currentIndex = index
240 _menu.open()
241 }
242
243 onRightClicked:
244 {
245 _listView.currentIndex = index
246 _menu.open()
247 }
248 }
249 },
250
251 Loader
252 {
253 asynchronous: true
254 active: tagListComposer.list.urls.length > 1
255 visible: active
256 Layout.fillWidth: true
257
258 sourceComponent: Maui.ListItemTemplate
259 {
260 id: _info
261
262 property var itemInfo : FB.FM.getFileInfo( tagListComposer.list.urls[0])
263 label1.text: i18nd("mauikitfilebrowsing", "Tagging %1 files", tagListComposer.list.urls.length)
264 label2.text: i18nd("mauikitfilebrowsing", "Add new tags for the selected files.")
265 label2.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
266 iconSource : itemInfo.icon
267 imageSource: itemInfo.thumbnail
268 // iconSizeHint: Maui.Style.iconSizes.huge
269 // headerSizeHint: iconSizeHint + Maui.Style.space.big
270
271 iconComponent: Item
272 {
273 Item
274 {
275 anchors.fill: parent
276 layer.enabled: true
277
278 Rectangle
279 {
280 anchors.fill: parent
281 anchors.leftMargin: Maui.Style.space.small
282 anchors.rightMargin: Maui.Style.space.small
283 radius: Maui.Style.radiusV
284 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))
285 border.color: Maui.Theme.backgroundColor
286 }
287
288 Rectangle
289 {
290 anchors.fill: parent
291 anchors.topMargin: Maui.Style.space.tiny
292 anchors.leftMargin: Maui.Style.space.tiny
293 anchors.rightMargin: Maui.Style.space.tiny
294 radius: Maui.Style.radiusV
295 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))
296 border.color: Maui.Theme.backgroundColor
297 }
298
299 Rectangle
300 {
301 anchors.fill: parent
302 anchors.topMargin: Maui.Style.space.small
303 border.color: Maui.Theme.backgroundColor
304
305 radius: Maui.Style.radiusV
306 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))
307
308 Maui.GridItemTemplate
309 {
310 anchors.fill: parent
311 anchors.margins: Maui.Style.space.tiny
312 iconSizeHint: _info.iconSizeHint
313
314 iconSource: _info.iconSource
315 imageSource: _info.imageSource
316 }
317 }
318 }
319 }
320 }
321 }
322 ]
323
324 page.footer: FB.TagList
325 {
326 id: tagListComposer
327 width: parent.width
328 visible: count > 0
329
330 onTagRemoved: (index) => list.remove(index)
331 placeholderText: i18nd("mauikitfilebrowsing", "No tags yet.")
332 }
333
334 onClosed:
335 {
336 composerList.urls = []
337 tagText.clear()
338 _tagsModel.filter = ""
339 }
340
341 onOpened: tagText.forceActiveFocus()
342
343 /**
344 * @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.
345 */
346 function setTags()
347 {
348 var tags = tagListComposer.list.tags
349 control.tagsReady(tags)
350 close()
351 }
352}
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
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 Sat Dec 21 2024 16:58:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.