Warning, /maui/pix/src/widgets/views/Folders/FoldersView.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15
0003 import QtQuick.Layouts 1.3
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 
0007 import org.mauikit.filebrowsing 1.3 as FB
0008 
0009 import org.maui.pix 1.0
0010 
0011 import "../../../view_models"
0012 import "../.."
0013 import"../Gallery"
0014 
0015 StackView
0016 {
0017     id: control
0018 
0019     readonly property string currentFolder : currentItem.currentFolder
0020     readonly property alias picsView : control.currentItem
0021     readonly property Flickable flickable : picsView.flickable
0022 
0023     Component.onCompleted:
0024     {
0025         if(_collectionViewComponent.pendingFolder.length > 0)
0026         {
0027             openFolder(_collectionViewComponent.pendingFolder)
0028         }
0029     }
0030 
0031     initialItem: Maui.Page
0032     {
0033         id: _foldersPage
0034         readonly property string currentFolder : "folders:///"
0035 
0036         Maui.Theme.inherit: false
0037         Maui.Theme.colorGroup: Maui.Theme.View
0038 
0039         flickable: _foldersGrid.flickable
0040         headBar.visible: false
0041 
0042         property Component searchFieldComponent : Maui.SearchField
0043         {
0044             placeholderText: i18np("Filter %1 folder", "Filter %1 folders", foldersList.count)
0045             onAccepted:
0046             {
0047                 folderModel.filters = text.split(",")
0048             }
0049 
0050             onCleared: folderModel.clearFilters()
0051         }
0052 
0053         StackView.onDeactivated:
0054         {
0055             folderModel.clearFilters()
0056         }
0057 
0058         Maui.GridBrowser
0059         {
0060             id: _foldersGrid
0061             anchors.fill: parent
0062             itemSize: Math.min(260, Math.max(140, Math.floor(availableWidth* 0.3)))
0063             itemHeight: itemSize + Maui.Style.rowHeight
0064             currentIndex: -1
0065 
0066             holder.emoji: "qrc:/assets/view-preview.svg"
0067             holder.title : foldersList.count === 0 ?
0068                                i18n("No Folders!") : i18n("Nothing Here!")
0069             holder.body: foldersList.count === 0 ? i18n("Add new image sources.") : i18n("Try something different.")
0070             holder.visible: _foldersGrid.count === 0
0071 
0072             onKeyPress: (event) =>
0073             {
0074                 if(event.key === Qt.Key_Return || event.key === Qt.Key_Enter)
0075                 {
0076                     openFolder(_foldersGrid.currentItem.path)
0077                 }
0078             }
0079 
0080             model: Maui.BaseModel
0081             {
0082                 id: folderModel
0083                 list: FoldersList
0084                 {
0085                     id: foldersList
0086                     folders: Collection.allImagesModel.folders
0087                 }
0088 
0089                 sortOrder: Qt.DescendingOrder
0090                 sort: "modified"
0091                 recursiveFilteringEnabled: false
0092                 sortCaseSensitivity: Qt.CaseInsensitive
0093                 filterCaseSensitivity: Qt.CaseInsensitive
0094             }
0095 
0096             delegate: Item
0097             {
0098                 readonly property string path : model.path
0099                 height: GridView.view.cellHeight
0100                 width: GridView.view.cellWidth
0101 
0102                 Maui.CollageItem
0103                 {
0104                     imageWidth: 120
0105                     imageHeight: 120
0106 
0107                     anchors.fill: parent
0108                     anchors.margins: !root.isWide ? Maui.Style.space.tiny : Maui.Style.space.big
0109 
0110                     isCurrentItem: parent.GridView.isCurrentItem
0111                     images: model.preview.split(",")
0112 
0113                     tooltipText: model.path
0114                     label1.text: model.label
0115                     label2.text: Qt.formatDateTime(new Date(model.modified), "d MMM yyyy")
0116 
0117                     draggable: true
0118 
0119                     Drag.keys: ["text/uri-list"]
0120                     Drag.mimeData: Drag.active ? { "text/uri-list": model.path } : {}
0121 
0122                 onClicked:
0123                 {
0124                     _foldersGrid.currentIndex = index
0125 
0126                     if(Maui.Handy.singleClick)
0127                     {
0128                         openFolder(model.path)
0129                     }
0130                 }
0131 
0132                 onDoubleClicked:
0133                 {
0134                     _foldersGrid.currentIndex = index
0135 
0136                     if(!Maui.Handy.singleClick)
0137                     {
0138                         openFolder(model.path)
0139                     }
0140                 }
0141             }
0142         }
0143     }
0144 }
0145 
0146 Component
0147 {
0148     id: picsViewComponent
0149 
0150     PixGrid
0151     {
0152         id: _picsView
0153         property string currentFolder
0154         readonly property var folderInfo : FB.FM.getFileInfo(currentFolder)
0155 
0156         headBar.visible: false
0157         title: control.folderInfo.label
0158 
0159         list.recursive: false
0160         list.urls: [currentFolder]
0161         list.activeGeolocationTags: browserSettings.gpsTags
0162 
0163         holder.emoji: "qrc:/assets/add-image.svg"
0164         holder.title : i18n("Folder is empty!")
0165         holder.body: i18n("There're no images in this folder")
0166 
0167         Keys.enabled: true
0168         Keys.onEscapePressed: control.pop()
0169 
0170         gridView.header: Column
0171         {
0172             width: parent.width
0173             spacing: Maui.Style.space.medium
0174 
0175             Maui.SectionHeader
0176             {
0177                 width: parent.width
0178                 label1.text: folderInfo.label
0179                 label2.text: folderInfo.url ? (folderInfo.url).replace(FB.FM.homePath(), "") : ""
0180                 template.label3.text: i18np("No images.", "%1 images", _picsView.gridView.count)
0181                 template.label4.text: Qt.formatDateTime(new Date(folderInfo.modified), "d MMM yyyy")
0182                 template.iconSource: folderInfo.icon
0183 
0184                 template.content: ToolButton
0185                 {
0186                     icon.name: "folder-open"
0187                     onClicked: Qt.openUrlExternally(currentFolder)
0188                 }
0189             }
0190 
0191             Flow
0192             {
0193                 spacing: Maui.Style.space.medium
0194                 width: parent.width
0195                 Repeater
0196                 {
0197                     model: Maui.BaseModel
0198                     {
0199                         list: CitiesList
0200                         {
0201                             cities:  _picsView.list.cities
0202                         }
0203                     }
0204 
0205                     delegate: Maui.Chip
0206                     {
0207                         text: model.name
0208                         iconSource: "gps"
0209                         checked:  _picsView.model.filters.indexOf(model.id) === 0
0210                         checkable: true
0211                         onClicked:
0212                         {
0213                             if( _picsView.model.filters.indexOf(model.id) === 0)
0214                             {
0215                                 _picsView.model.clearFilters()
0216                             }else
0217                             {
0218                                 _picsView.model.filters = [model.id]
0219                             }
0220                         }
0221 
0222                     }
0223                 }
0224             }
0225         }
0226     }
0227 }
0228 
0229 Component
0230 {
0231     id: _allPicsComponent
0232 
0233     GalleryView
0234     {
0235         property string currentFolder : "collection:///"
0236         headBar.visible: false
0237 
0238         list: Collection.allImagesModel
0239     }
0240 }
0241 
0242 function refresh()
0243 {
0244     foldersList.refresh()
0245 }
0246 
0247 function openFolder(url, filters)
0248 {
0249     if(currentFolder === url)
0250         return;
0251 
0252     if(control.depth === 1)
0253     {
0254         if(url.startsWith("collection:///"))
0255         {
0256             control.push(_allPicsComponent, ({'currentFolder': url}))
0257         }else
0258         {
0259             control.push(picsViewComponent, ({'currentFolder': url}))
0260         }
0261     }else
0262     {
0263         if(currentFolder.startsWith("collection:///"))
0264         {
0265             if(url.startsWith("collection:///"))
0266             {
0267                 control.currentItem.currentFolder = url
0268             }else
0269             {
0270                 control.pop()
0271                 control.push(picsViewComponent, ({'currentFolder': url}))
0272             }
0273         }else
0274         {
0275             if(url.startsWith("collection:///"))
0276             {
0277                 control.pop()
0278                 control.push(_allPicsComponent, ({'currentFolder': url}))
0279             }else
0280             {
0281                 control.currentItem.currentFolder = url
0282             }
0283         }
0284     }
0285 
0286     control.currentItem.model.clearFilters()
0287     control.currentItem.model.filters = filters
0288 }
0289 }