MauiKit File Browsing

FileListingDialog.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21import QtQuick.Controls
22import QtQuick.Layouts
23
24import org.mauikit.controls as Maui
25import org.mauikit.filebrowsing as FB
26
27/**
28 * @inherit PopupPage
29 * @since org.mauikit.controls
30 * @brief A dialog for listing file URLs and for suggesting to perform an action[s].
31 *
32 * This controls inherits from MauiKit PopupPage, to checkout its inherited properties refer to the docs.
33 * @see PopupPage
34 *
35 * The listed files can also be removed from the dialog itself, and the `urls` property will be updated properly.
36 * The delegate used to display the files can be assigned to a custom element.
37 *
38 * To add actions use the inherited property `actions` from the PopupPage control.
39 *
40 * @image html Misc/filelistingdialog.png "Listing a group of files and three actions"
41 *
42 * @code
43 * Maui.FileListingDialog
44 * {
45 * id: _dialog
46 * title: "File Listing"
47 * message: "This is a file listing dialog. Used to list files and suggest to perfom an action upon them."
48 *
49 * urls: ["/home/camiloh/Downloads/premium_photo-1664203068007-52240d0ca48f.avif", "/home/camiloh/Downloads/ide_4x.webp", "/home/camiloh/Downloads/photo-app-fereshtehpb.webp", "/home/camiloh/Downloads/ide-reskin.webp", "/home/camiloh/Downloads/nx-software-center-latest-x86_64.AppImage", "/home/camiloh/Downloads/hand-drawn-flat-design-metaverse-background.zip"]
50 *
51 * actions: [
52 * Action
53 * {
54 * text: "Action1"
55 * },
56 *
57 * Action
58 * {
59 * text: "Action2"
60 * },
61 *
62 * Action
63 * {
64 * text: "Action3"
65 * }
66 * ]
67 * }
68 * @endcode
69 *
70 * @section notes Notes
71 * The title will not be visible by default as the `headBar` is hidden. To force show it use the `headBar.visible` property.
72 *
73 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/FileListingDialog.qml">You can find a more complete example at this link.</a>
74 */
75Maui.PopupPage
76{
77 id: control
78
79 /**
80 * @brief Any child item will be placed under the information section of this dialog. This is the default property and is handled by a ColumnLayout, so to place items use the Layout attached properties.
81 * @property list<QtObject> FileListingDialog::content
82 */
83 default property alias content : _content.data
84
85 /**
86 * @brief The array of URLs to be listed. This will be used as the model for the file listing section.
87 */
88 property var urls: []
89
90 /**
91 * @brief The body of the message. This will go right under the title.
92 */
93 property string message : ""
94
95 /**
96 * @brief This is a information map of the first file in the `urls` list. It is used to display a miniature image in the dialog information section.
97 */
98 readonly property var singleItem : FB.FM.getFileInfo(control.urls[0])
100 /**
101 * @brief An alias for the template element handling the information section. This is exposed to access it and fine tune details, or embed more element into it. This template is handled by a ListItemTemplate.
102 * @see ListItemTemplate
103 * @property ListItemTemplate FileListingDialog::template.
104 */
105 readonly property alias template : _template
106
107 hint: 1
108 maxWidth: 350
109
110 headBar.visible: false
112 Maui.ListItemTemplate
113 {
114 id: _template
115 visible: control.message.length
116 Layout.fillWidth: true
117 label2.text: message
118 label2.textFormat : TextEdit.AutoText
119 label2.wrapMode: TextEdit.WordWrap
120 iconVisible: control.width > Maui.Style.units.gridUnit * 10
121
122 iconSizeHint: Maui.Style.iconSizes.large
123 spacing: Maui.Style.space.big
124
125 leftLabels.spacing: control.spacing
126
127 headerSizeHint: template.iconSizeHint + Maui.Style.space.big
128 iconSource: singleItem.icon
129 imageSource: singleItem.thumbnail
130 implicitHeight: Math.max(template.leftLabels.implicitHeight, 64)
131
132 leftLabels.data: ColumnLayout
133 {
134 id: _content
135 Layout.fillWidth: true
136 spacing: control.spacing
137 }
138
139 iconComponent: Item
140 {
141 Item
142 {
143 height: Math.min(parent.height, 120, width)
144 width: parent.width
145 anchors.centerIn: parent
146 layer.enabled: true
147
148 Rectangle
149 {
150 visible: control.urls ? control.urls.length > 1 : false
151 anchors.fill: parent
152
153 anchors.leftMargin: Maui.Style.space.small
154 anchors.rightMargin: Maui.Style.space.small
155
156 radius: Maui.Style.radiusV
157 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))
158 border.color: Maui.Theme.backgroundColor
159 }
160
161 Rectangle
162 {
163 visible: control.urls ? control.urls.length > 1 : false
164 anchors.fill: parent
165
166 anchors.topMargin: Maui.Style.space.tiny
167 anchors.leftMargin: Maui.Style.space.tiny
168 anchors.rightMargin: Maui.Style.space.tiny
169
170 radius: Maui.Style.radiusV
171 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))
172 border.color: Maui.Theme.backgroundColor
173 }
174
175 Rectangle
176 {
177 anchors.fill: parent
178 anchors.topMargin: control.urls.length > 1 ? Maui.Style.space.small : 0
179 border.color: Maui.Theme.backgroundColor
180
181 radius: Maui.Style.radiusV
182 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))
183
184 Maui.GridItemTemplate
185 {
186 anchors.fill: parent
187 anchors.margins: Maui.Style.space.tiny
188 iconSizeHint: Math.min(height, width)
189
190 iconSource: control.template.iconSource
191 imageSource: control.template.imageSource
192 }
193 }
194 }
195 }
196 }
197
198 /**
199 * @brief The list delegate item to be used to display the file URLs.
200 * This is set to a MauiKit ListItemTemplate element by default with a image or icon preview and the file name.
201 * This can be changed to any other element. The model is populated by the `urls` property, so to extract information for a custom element, use the `modelData` attribute to get the URL for each instance.
202 */
203 property Component listDelegate : Maui.ListItemTemplate
204 {
205 width: ListView.view.width
206 height: Maui.Style.rowHeight
207 property var item : FB.FM.getFileInfo(modelData)
208 label1.text: item.label
209 label3.text: Maui.Handy.formatSize(item.size)
210 rightLabels.visible: true
211 iconVisible: true
212 iconSource: item.icon
213 imageSource: item.thumbnail
214 iconSizeHint: Maui.Style.iconSizes.medium
215
216 ToolButton
217 {
218 //text: i18nd("mauikit", "Clear")
219 icon.name: "edit-clear"
220 icon.width: Maui.Style.iconSizes.small
221 icon.height: Maui.Style.iconSizes.small
222
223 onClicked:
224 {
225 var array = control.urls
226 const index = array.indexOf(modelData);
227 if (index > -1) {
228 array.splice(index, 1);
229 }
230
231 if(array.length === 0)
232 {
233 control.close()
234 return
235 }
236
237 control.urls = array
238 }
239 }
240 }
241
242 Loader
243 {
244 id: _listViewLoader
245
246 asynchronous: true
247 active: control.urls.length > 0
248 visible: active
249
250 Layout.fillWidth: true
251
252 sourceComponent: Maui.ListBrowser
253 {
254 clip: true
255 implicitHeight: Math.min(contentHeight, 300)
256 model: urls
257 spacing: Maui.Style.defaultSpacing
258 padding: 0
259
260 delegate: control.listDelegate
261 }
262 }
263}
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.