Warning, /maui/mauikit-filebrowsing/src/controls.6/TagsDialog.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick
0002 import QtQuick.Controls
0003 import QtQuick.Layouts
0004
0005 import org.mauikit.controls 1.3 as Maui
0006 import org.mauikit.filebrowsing 1.3 as FB
0007
0008 /**
0009 * @inherit org::mauikit::controls::PopupPage
0010 * @brief A popup dialog for selecting between all the available tags to associate to a given set of file URLs.
0011 *
0012 * This popup page also allows to create new tags, edit existing ones and removing.
0013 *
0014 * To associate the set of file URLs, use the exposed property `composerList.urls`, which is an alias to TagsList::urls.
0015 * @see composerList
0016 * @see TagsList::urls
0017 * 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.
0018 *
0019 * @image html tagsdialog.png "Example using the TagsDialog control"
0020 *
0021 * @code
0022 * Maui.Page
0023 * {
0024 * Maui.Controls.showCSD: true
0025 * anchors.fill: parent
0026 *
0027 * title: "Add tags to a file"
0028 *
0029 * FB.FileBrowser
0030 * {
0031 * id: _fileBrowser
0032 * anchors.fill: parent
0033 * currentPath: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
0034 * settings.viewType: FB.FMList.LIST_VIEW
0035 * onItemClicked: (index) =>
0036 * {
0037 * _tagsDialog.composerList.urls = [_fileBrowser.currentFMModel.get(index).url]
0038 * _tagsDialog.open()
0039 * }
0040 * }
0041 *
0042 * FB.TagsDialog
0043 * {
0044 * id: _tagsDialog
0045 * composerList.strict: false //Show all the associated tags to the file
0046 * onTagsReady: (tags) => console.log(tags)
0047 * }
0048 * }
0049 * @endcode
0050 */
0051 Maui.PopupPage
0052 {
0053 id: control
0054
0055 /**
0056 * @brief An alias to the TagsList list/model controlling and listing all of the available tags.
0057 * @see TagsListmodel
0058 * @property TagsList TagsDialog::tagList
0059 */
0060 readonly property alias taglist : _tagsList
0061
0062 /**
0063 * @brief An alias to the Mauikit ListBrowser element listing the tag elements.
0064 * @property MauiKit::ListBrowser TagsDialog::listView
0065 */
0066 readonly property alias listView: _listView
0067
0068 /**
0069 * @brief An alias to the TagsList controller and model.
0070 * This property is exposed to set the file URLs to which perform any new assignment or removal of tags.
0071 * Refer to its documentation for more details on the available actions.
0072 * @property TagsList TagsDialog::composerList
0073 */
0074 readonly property alias composerList: tagListComposer.list
0075
0076 /**
0077 * @brief Emitted once the assignment of the new set of tags has been done. This can include removal or additions.
0078 * This won't actually write any changes to the file URLs, to write the changes refer to the `composerList.updateToUrls` function.
0079 * @see TagsList::updateToUrls
0080 * @param tags the list of the new tag names associated to the file URLs
0081 */
0082 signal tagsReady(var tags)
0083
0084 hint: 1
0085
0086 maxHeight: 500
0087 maxWidth: 400
0088
0089 actions: [
0090
0091 Action
0092 {
0093 text: i18nd("mauikitfilebrowsing", "Save")
0094 onTriggered: control.setTags()
0095 },
0096
0097 Action
0098 {
0099 text: i18nd("mauikitfilebrowsing", "Cancel")
0100 onTriggered: control.close()
0101 }
0102 ]
0103
0104 headBar.visible: true
0105 headBar.forceCenterMiddleContent: false
0106 headBar.middleContent: TextField
0107 {
0108 id: tagText
0109 Layout.fillWidth: true
0110 Layout.maximumWidth: 500
0111 placeholderText: i18nd("mauikitfilebrowsing", "Filter or add a new tag")
0112 // validator: RegExpValidator { regExp: /[0-9A-F]+/ }
0113 onAccepted:
0114 {
0115 const tags = tagText.text.split(",")
0116 for(var i in tags)
0117 {
0118 const myTag = tags[i].trim()
0119 _tagsList.insert(myTag)
0120 tagListComposer.list.append(myTag)
0121 }
0122 clear()
0123 _tagsModel.filter = ""
0124 }
0125
0126 onTextChanged:
0127 {
0128 _tagsModel.filter = text
0129 }
0130 }
0131
0132 Maui.InfoDialog
0133 {
0134 id: _deleteDialog
0135
0136 property string tag
0137 title: i18nd("mauikitfilebrowsing", "Delete %1", tag)
0138 message: i18nd("mauikitfilebrowsing", "Are you sure you want to delete this tag? This action can not be undone.")
0139 template.iconSource: "tag"
0140 onAccepted:
0141 {
0142 FB.Tagging.removeTag(tag)
0143 _deleteDialog.close()
0144 }
0145
0146 onRejected: _deleteDialog.close()
0147 }
0148
0149 Maui.ContextualMenu
0150 {
0151 id: _menu
0152
0153 MenuItem
0154 {
0155 text: i18nd("mauikitfilebrowsing", "Edit")
0156 icon.name: "document-edit"
0157 }
0158
0159 MenuItem
0160 {
0161 text: i18nd("mauikitfilebrowsing", "Delete")
0162 icon.name: "delete"
0163 onTriggered:
0164 {
0165 _deleteDialog.tag = _tagsModel.get(_listView.currentIndex).tag
0166 _deleteDialog.open()
0167 }
0168 }
0169 }
0170
0171 stack: [
0172
0173 Maui.ListBrowser
0174 {
0175 id: _listView
0176
0177 Layout.fillHeight: true
0178 Layout.fillWidth: true
0179 clip: true
0180 currentIndex: -1
0181
0182 holder.emoji: "qrc:/assets/tag.svg"
0183 holder.visible: _listView.count === 0
0184 holder.title : i18nd("mauikitfilebrowsing", "No Tags!")
0185 holder.body: i18nd("mauikitfilebrowsing", "Create new tags to organize your files.")
0186
0187 model: Maui.BaseModel
0188 {
0189 id: _tagsModel
0190 sort: "tag"
0191 sortOrder: Qt.AscendingOrder
0192 recursiveFilteringEnabled: true
0193 sortCaseSensitivity: Qt.CaseInsensitive
0194 filterCaseSensitivity: Qt.CaseInsensitive
0195 list: FB.TagsListModel
0196 {
0197 id: _tagsList
0198 strict: false
0199 }
0200 }
0201
0202 delegate: Maui.ListBrowserDelegate
0203 {
0204 width: ListView.view.width
0205 label1.text: model.tag
0206 iconSource: model.icon
0207 iconSizeHint: Maui.Style.iconSizes.small
0208
0209 template.content: Rectangle
0210 {
0211 color: model.color ? model.color : "transparent"
0212 height: Maui.Style.iconSizes.small
0213 radius: height/2
0214 width: height
0215 }
0216
0217 onClicked:
0218 {
0219 _listView.currentIndex = index
0220 if(Qt.styleHints.singleClickActivation)
0221 {
0222 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
0223 }
0224 }
0225
0226 onDoubleClicked:
0227 {
0228 _listView.currentIndex = index
0229 if(!Qt.styleHints.singleClickActivation)
0230 {
0231 tagListComposer.list.appendItem(_tagsModel.get(_listView.currentIndex))
0232 }
0233 }
0234
0235 onPressAndHold:
0236 {
0237 _listView.currentIndex = index
0238 _menu.open()
0239 }
0240
0241 onRightClicked:
0242 {
0243 _listView.currentIndex = index
0244 _menu.open()
0245 }
0246 }
0247 },
0248
0249 Loader
0250 {
0251 asynchronous: true
0252 active: tagListComposer.list.urls.length > 1
0253 visible: active
0254 Layout.fillWidth: true
0255
0256 sourceComponent: Maui.ListItemTemplate
0257 {
0258 id: _info
0259
0260 property var itemInfo : FB.FM.getFileInfo( tagListComposer.list.urls[0])
0261 label1.text: i18nd("mauikitfilebrowsing", "Tagging %1 files", tagListComposer.list.urls.length)
0262 label2.text: i18nd("mauikitfilebrowsing", "Add new tags for the selected files.")
0263 label2.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
0264 iconSource : itemInfo.icon
0265 imageSource: itemInfo.thumbnail
0266 // iconSizeHint: Maui.Style.iconSizes.huge
0267 // headerSizeHint: iconSizeHint + Maui.Style.space.big
0268
0269 iconComponent: Item
0270 {
0271 Item
0272 {
0273 anchors.fill: parent
0274 layer.enabled: true
0275
0276 Rectangle
0277 {
0278 anchors.fill: parent
0279 anchors.leftMargin: Maui.Style.space.small
0280 anchors.rightMargin: Maui.Style.space.small
0281 radius: Maui.Style.radiusV
0282 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))
0283 border.color: Maui.Theme.backgroundColor
0284 }
0285
0286 Rectangle
0287 {
0288 anchors.fill: parent
0289 anchors.topMargin: Maui.Style.space.tiny
0290 anchors.leftMargin: Maui.Style.space.tiny
0291 anchors.rightMargin: Maui.Style.space.tiny
0292 radius: Maui.Style.radiusV
0293 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))
0294 border.color: Maui.Theme.backgroundColor
0295 }
0296
0297 Rectangle
0298 {
0299 anchors.fill: parent
0300 anchors.topMargin: Maui.Style.space.small
0301 border.color: Maui.Theme.backgroundColor
0302
0303 radius: Maui.Style.radiusV
0304 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))
0305
0306 Maui.GridItemTemplate
0307 {
0308 anchors.fill: parent
0309 anchors.margins: Maui.Style.space.tiny
0310 iconSizeHint: _info.iconSizeHint
0311
0312 iconSource: _info.iconSource
0313 imageSource: _info.imageSource
0314 }
0315 }
0316 }
0317 }
0318 }
0319 }
0320 ]
0321
0322 page.footer: FB.TagList
0323 {
0324 id: tagListComposer
0325 width: parent.width
0326 visible: count > 0
0327
0328 onTagRemoved: list.remove(index)
0329 placeholderText: i18nd("mauikitfilebrowsing", "No tags yet.")
0330 }
0331
0332 onClosed:
0333 {
0334 composerList.urls = []
0335 tagText.clear()
0336 _tagsModel.filter = ""
0337 }
0338
0339 onOpened: tagText.forceActiveFocus()
0340
0341 /**
0342 * @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.
0343 */
0344 function setTags()
0345 {
0346 var tags = tagListComposer.list.tags
0347 control.tagsReady(tags)
0348 close()
0349 }
0350 }