Warning, /maui/clip/src/views/BrowserLayout.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.14
0002 import QtQuick.Controls 2.14
0003 import QtQuick.Layouts 1.3
0004 
0005 import org.mauikit.controls 1.3 as Maui
0006 
0007 import org.maui.clip 1.0 as Clip
0008 import QtMultimedia 5.8
0009 
0010 Maui.AltBrowser
0011 {
0012     id: control
0013     property alias list : _collectionList
0014     property alias urls : _collectionList.urls
0015     property alias listModel : _collectionModel
0016     property alias searchField:  _searchField
0017 
0018     signal itemClicked(var item)
0019     signal itemRightClicked(var item)
0020 
0021     headBar.forceCenterMiddleContent: false
0022     gridView.itemSize: 180
0023 
0024     enableLassoSelection: true
0025 
0026     holder.visible: _collectionList.count === 0
0027     holder.emojiSize: Maui.Style.iconSizes.huge
0028 
0029     viewType: control.width < Maui.Style.units.gridUnit * 30 ? Maui.AltBrowser.ViewType.List : Maui.AltBrowser.ViewType.Grid
0030 
0031     Connections
0032     {
0033         target: control.currentView
0034         ignoreUnknownSignals: true
0035 
0036         function onItemsSelected(indexes)
0037         {
0038             for(var i in indexes)
0039                 selectionBar.insert(_collectionModel.get(indexes[i]))
0040         }
0041 
0042         function onKeyPress(event)
0043         {
0044             const index = control.currentIndex
0045             const item = control.model.get(index)
0046 
0047             if((event.key == Qt.Key_Left || event.key == Qt.Key_Right || event.key == Qt.Key_Down || event.key == Qt.Key_Up) && (event.modifiers & Qt.ControlModifier) && (event.modifiers & Qt.ShiftModifier))
0048             {
0049                 control.currentView.itemsSelected([index])
0050             }
0051         }
0052     }
0053 
0054     ItemMenu
0055     {
0056         id: _menu
0057         index: control.currentIndex
0058         model: control.model
0059     }
0060 
0061     headBar.middleContent: Maui.SearchField
0062     {
0063         id: _searchField
0064         enabled: _collectionList.count > 0
0065         Layout.fillWidth: true
0066         Layout.maximumWidth: 500
0067         Layout.alignment: Qt.AlignCenter
0068 
0069         placeholderText: i18np("Search %1 video", "Search %1 videos", _collectionList.count)
0070         onAccepted: _collectionModel.filter = text
0071         onCleared: _collectionModel.filter = ""
0072     }
0073 
0074     model: Maui.BaseModel
0075     {
0076         id: _collectionModel
0077         sortOrder: settings.sortOrder
0078         sort: settings.sortBy
0079         recursiveFilteringEnabled: true
0080         sortCaseSensitivity: Qt.CaseInsensitive
0081         filterCaseSensitivity: Qt.CaseInsensitive
0082         list: Clip.Videos
0083         {
0084             id: _collectionList
0085             urls: ["collection:///"]
0086         }
0087     }
0088 
0089     listDelegate: ListDelegate
0090     {
0091         id: _listDelegate
0092         width: ListView.view.width
0093 
0094         onToggled:
0095         {
0096             control.currentIndex = index
0097             control.currentView.itemsSelected([index])
0098         }
0099 
0100         onClicked: (mouse) =>
0101         {
0102             control.currentIndex = index
0103             if(selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0104             {
0105                 control.currentView.itemsSelected([index])
0106             }else if(Maui.Handy.singleClick)
0107             {
0108                 control.itemClicked(listModel.get(index))
0109             }
0110         }
0111 
0112         onDoubleClicked:
0113         {
0114             control.currentIndex = index
0115             if(!Maui.Handy.singleClick && !selectionMode)
0116             {
0117                 control.itemClicked(listModel.get(index))
0118             }
0119         }
0120 
0121         onPressAndHold:
0122         {
0123             if(!Maui.Handy.isTouch)
0124                 return
0125 
0126             control.currentIndex = index
0127             control.itemRightClicked(listModel.get(index))
0128             _menu.show()
0129         }
0130 
0131         onRightClicked:
0132         {
0133             control.currentIndex = index
0134             control.itemRightClicked(listModel.get(index))
0135             _menu.show()
0136         }
0137 
0138         Connections
0139         {
0140             target: selectionBar
0141 
0142             function onUriRemoved(uri)
0143             {
0144                 if(uri === model.url)
0145                     _listDelegate.checked = false
0146             }
0147 
0148             function onUriAdded(uri)
0149             {
0150                 if(uri === model.url)
0151                     _listDelegate.checked = true
0152             }
0153 
0154             function onCleared(uri)
0155             {
0156                 _listDelegate.checked = false
0157             }
0158         }
0159     }
0160 
0161     gridDelegate: Item
0162     {
0163         readonly property bool isCurrentItem : GridView.isCurrentItem
0164         height: GridView.view.cellHeight
0165         width: GridView.view.cellWidth
0166 
0167         property bool preview : false
0168 
0169         Timer
0170         {
0171             id:  _timer
0172             interval: 1500
0173             onTriggered: parent.preview = true
0174         }
0175 
0176         Maui.GridBrowserDelegate
0177         {
0178             id: delegate
0179 
0180             onHoveredChanged:
0181             {
0182                 if(hovered)
0183                 {
0184                     _timer.start()
0185                 }else
0186                 {
0187                     _timer.stop()
0188                     preview = false
0189                 }
0190             }
0191 
0192             iconSizeHint: Maui.Style.iconSizes.big
0193             label1.text: model.label
0194 
0195             anchors.centerIn: parent
0196             height: control.gridView.cellHeight - 15
0197             width: control.gridView.itemSize - 20
0198             padding: Maui.Style.space.tiny
0199             isCurrentItem: parent.isCurrentItem || checked
0200             tooltipText: model.url
0201             checkable: root.selectionMode
0202             checked: (selectionBar ? selectionBar.contains(model.url) : false)
0203             draggable: true
0204 
0205             Drag.keys: ["text/uri-list"]
0206             Drag.mimeData: Drag.active ?
0207                                {
0208                                    "text/uri-list": control.filterSelectedItems(model.url)
0209                                } : {}
0210 
0211         template.iconComponent: Loader
0212         {
0213             sourceComponent: preview && !Maui.Handy.isMobile ? videoComponent : imgComponent
0214 
0215             Component
0216             {
0217                 id: videoComponent
0218                 Video
0219                 {
0220                     autoPlay: true
0221                     autoLoad: true
0222                     source: model.url
0223                     muted: true
0224                     fillMode: VideoOutput.PreserveAspectFit
0225                     playbackRate: 5.0
0226                     loops: 3
0227                     flushMode: VideoOutput.LastFrame
0228                 }
0229             }
0230 
0231             Component
0232             {
0233                 id: imgComponent
0234                 Maui.IconItem
0235                 {
0236                     imageSource: model.preview
0237                     iconSource: model.icon
0238                     fillMode: Image.PreserveAspectFit
0239                 }
0240             }
0241         }
0242 
0243         onClicked: (mouse) =>
0244         {
0245             control.currentIndex = index
0246             if(selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier)))
0247             {
0248                 control.currentView.itemsSelected([index])
0249             }else if(Maui.Handy.singleClick)
0250             {
0251                 control.itemClicked(listModel.get(index))
0252             }
0253         }
0254 
0255         onDoubleClicked:
0256         {
0257             control.currentIndex = index
0258             if(!Maui.Handy.singleClick && !selectionMode)
0259             {
0260                 control.itemClicked(listModel.get(index))
0261             }
0262         }
0263 
0264         onPressAndHold:
0265         {
0266             if(!Maui.Handy.isTouch)
0267                 return
0268 
0269             control.currentIndex = index
0270             control.itemRightClicked(listModel.get(index))
0271             _menu.show()
0272         }
0273 
0274         onRightClicked:
0275         {
0276             control.currentIndex = index
0277             control.itemRightClicked(listModel.get(index))
0278             _menu.show()
0279         }
0280 
0281         onToggled:
0282         {
0283             control.currentIndex = index
0284             control.currentView.itemsSelected([index])
0285         }
0286 
0287         onContentDropped:
0288         {
0289             //                _dropMenu.urls = drop.urls.join(",")
0290             //                _dropMenu.target = model.url
0291             //                _dropMenu.popup()
0292         }
0293 
0294         Connections
0295         {
0296             target: selectionBar
0297 
0298             function onUriRemoved(uri)
0299             {
0300                 if(uri === model.url)
0301                     delegate.checked = false
0302             }
0303 
0304             function onUriAdded(uri)
0305             {
0306                 if(uri === model.url)
0307                     delegate.checked = true
0308             }
0309 
0310             function onCleared(uri)
0311             {
0312                 delegate.checked = false
0313             }
0314         }
0315     }
0316 }
0317 
0318 function filterSelectedItems(url)
0319 {
0320     if(selectionBar && selectionBar.count > 0 && selectionBar.contains(url))
0321     {
0322         const uris = selectionBox.uris
0323         return uris.join("\n")
0324     }
0325 
0326     return url
0327 }
0328 
0329 }