Warning, /maui/mauikit/src/controls.6/FileListingDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003  *
0004  *   This program is free software; you can redistribute it and/or modify
0005  *   it under the terms of the GNU Library General Public License as
0006  *   published by the Free Software Foundation; either version 2, or
0007  *   (at your option) any later version.
0008  *
0009  *   This program is distributed in the hope that it will be useful,
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *   GNU General Public License for more details
0013  *
0014  *   You should have received a copy of the GNU Library General Public
0015  *   License along with this program; if not, write to the
0016  *   Free Software Foundation, Inc.,
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018  */
0019 
0020 import QtQuick
0021 import QtQuick.Controls
0022 import QtQuick.Layouts
0023 
0024 import org.mauikit.controls 1.3 as Maui
0025 import org.mauikit.filebrowsing 1.3 as FB
0026 
0027 /**
0028  * @inherit PopupPage
0029  *    @since org.mauikit.controls
0030  *    @brief A dialog for listing file URLs and for suggesting to perform an action[s].
0031  * 
0032  *    This controls inherits from MauiKit PopupPage, to checkout its inherited properties refer to the docs.
0033  *    @see PopupPage
0034  * 
0035  *    The listed files can also be removed from the dialog itself, and the `urls` property will be updated properly.
0036  *    The delegate used to display the files can be assigned to a custom element.
0037  * 
0038  *    To add actions use the inherited property `actions` from the PopupPage control.
0039  * 
0040  *    @image html Misc/filelistingdialog.png "Listing a group of files and three actions"
0041  * 
0042  *    @code
0043  *    Maui.FileListingDialog
0044  *    {
0045  *        id: _dialog
0046  *        title: "File Listing"
0047  *        message: "This is a file listing dialog. Used to list files and suggest to perfom an action upon them."
0048  * 
0049  *        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"]
0050  * 
0051  *        actions: [
0052  *            Action
0053  *            {
0054  *                text: "Action1"
0055  *            },
0056  * 
0057  *            Action
0058  *            {
0059  *                text: "Action2"
0060  *            },
0061  * 
0062  *            Action
0063  *            {
0064  *                text: "Action3"
0065  *            }
0066  *        ]
0067  *    }
0068  *    @endcode
0069  * 
0070  *    @section notes Notes
0071  *    The title will not be visible by default as the `headBar` is hidden. To force show it use the `headBar.visible` property.
0072  * 
0073  *    <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>
0074  */
0075 Maui.PopupPage
0076 {
0077     id: control
0078     
0079     /**
0080      * @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.
0081      * @property list<QtObject> FileListingDialog::content
0082      */
0083     default property alias content : _content.data
0084         
0085         /**
0086          * @brief The array of URLs to be listed. This will be used as the model for the file listing section.
0087          */
0088         property var urls: []
0089         
0090         /**
0091          * @brief The body of the message. This will go right under the title.
0092          */
0093         property string message : ""
0094         
0095         /**
0096          * @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.
0097          */
0098         readonly property var singleItem : FB.FM.getFileInfo(control.urls[0])
0099         
0100         /**
0101          * @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.
0102          * @see ListItemTemplate
0103          * @property ListItemTemplate FileListingDialog::template.
0104          */
0105         readonly property alias template : _template
0106         
0107         hint: 1
0108         maxWidth: 350
0109         
0110         headBar.visible: false
0111         
0112         Maui.ListItemTemplate
0113         {
0114             id: _template
0115             visible: control.message.length
0116             Layout.fillWidth: true
0117             label2.text: message
0118             label2.textFormat : TextEdit.AutoText
0119             label2.wrapMode: TextEdit.WordWrap
0120             iconVisible: control.width > Maui.Style.units.gridUnit * 10
0121             
0122             iconSizeHint: Maui.Style.iconSizes.large
0123             spacing: Maui.Style.space.big
0124             
0125             leftLabels.spacing: control.spacing
0126             
0127             headerSizeHint: template.iconSizeHint + Maui.Style.space.big
0128             iconSource: singleItem.icon
0129             imageSource: singleItem.thumbnail
0130             implicitHeight: Math.max(template.leftLabels.implicitHeight, 64)
0131             
0132             leftLabels.data: ColumnLayout
0133             {
0134                 id: _content
0135                 Layout.fillWidth: true
0136                 spacing: control.spacing
0137             }
0138             
0139             iconComponent: Item
0140             {
0141                 Item
0142                 {
0143                     height: Math.min(parent.height, 120, width)
0144                     width: parent.width
0145                     anchors.centerIn: parent
0146                     layer.enabled: true
0147                     
0148                     Rectangle
0149                     {
0150                         visible: control.urls ? control.urls.length > 1 : false
0151                         anchors.fill: parent
0152                         
0153                         anchors.leftMargin: Maui.Style.space.small
0154                         anchors.rightMargin: Maui.Style.space.small
0155                         
0156                         radius: Maui.Style.radiusV
0157                         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))
0158                         border.color: Maui.Theme.backgroundColor
0159                     }
0160                     
0161                     Rectangle
0162                     {
0163                         visible: control.urls ? control.urls.length > 1 : false
0164                         anchors.fill: parent
0165                         
0166                         anchors.topMargin: Maui.Style.space.tiny
0167                         anchors.leftMargin: Maui.Style.space.tiny
0168                         anchors.rightMargin: Maui.Style.space.tiny
0169                         
0170                         radius: Maui.Style.radiusV
0171                         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))
0172                         border.color: Maui.Theme.backgroundColor
0173                     }
0174                     
0175                     Rectangle
0176                     {
0177                         anchors.fill: parent
0178                         anchors.topMargin:  control.urls.length > 1 ? Maui.Style.space.small : 0
0179                         border.color: Maui.Theme.backgroundColor
0180                         
0181                         radius: Maui.Style.radiusV
0182                         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))
0183                         
0184                         Maui.GridItemTemplate
0185                         {
0186                             anchors.fill: parent
0187                             anchors.margins: Maui.Style.space.tiny
0188                             iconSizeHint: Math.min(height, width)
0189                             
0190                             iconSource: control.template.iconSource
0191                             imageSource:  control.template.imageSource
0192                         }
0193                     }
0194                 }
0195             }
0196         }
0197         
0198         /**
0199          * @brief The list delegate item to be used to display the file URLs.
0200          * This is set to a MauiKit ListItemTemplate element by default with a image  or icon preview and the file name.
0201          * 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.
0202          */
0203         property Component listDelegate : Maui.ListItemTemplate
0204         {
0205             width: ListView.view.width
0206             height: Maui.Style.rowHeight
0207             property var item : FB.FM.getFileInfo(modelData)
0208             label1.text: item.label
0209             label3.text: Maui.Handy.formatSize(item.size)
0210             rightLabels.visible: true
0211             iconVisible: true
0212             iconSource: item.icon
0213             imageSource: item.thumbnail
0214             iconSizeHint: Maui.Style.iconSizes.medium
0215             
0216             ToolButton
0217             {
0218                 //text: i18nd("mauikit", "Clear")
0219                 icon.name: "edit-clear"
0220                 icon.width: Maui.Style.iconSizes.small
0221                 icon.height: Maui.Style.iconSizes.small
0222                 
0223                 onClicked:
0224                 {
0225                     var array = control.urls
0226                     const index = array.indexOf(modelData);
0227                     if (index > -1) {
0228                         array.splice(index, 1);
0229                     }
0230                     
0231                     if(array.length === 0)
0232                     {
0233                         control.close()
0234                         return
0235                     }
0236                     
0237                     control.urls = array
0238                 }
0239             }
0240         }
0241         
0242         Loader
0243         {
0244             id: _listViewLoader
0245             
0246             asynchronous: true
0247             active: control.urls.length > 0
0248             visible: active
0249             
0250             Layout.fillWidth: true
0251             
0252             sourceComponent: Maui.ListBrowser
0253             {
0254                 clip: true
0255                 implicitHeight: Math.min(contentHeight, 300)
0256                 model: urls
0257                 spacing: Maui.Style.defaultSpacing
0258                 padding: 0
0259                 
0260                 delegate: control.listDelegate
0261             }
0262         }
0263 }