Warning, /maui/pix/src/view_models/PixGrid.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.14 0002 0003 import QtQuick.Controls 2.14 0004 import QtQuick.Layouts 1.3 0005 0006 import org.mauikit.controls 1.3 as Maui 0007 0008 import org.maui.pix 1.0 0009 0010 import "../widgets/views/Viewer/Viewer.js" as VIEWER 0011 import "../widgets" 0012 0013 Maui.Page 0014 { 0015 id: control 0016 0017 Maui.Theme.inherit: false 0018 Maui.Theme.colorGroup: Maui.Theme.View 0019 0020 property int itemSize : browserSettings.previewSize 0021 0022 readonly property alias listModel : pixModel 0023 readonly property alias menu : _picMenu 0024 readonly property alias holder : _gridView.holder 0025 readonly property alias model: _gridView.model 0026 readonly property alias gridView: _gridView 0027 readonly property alias count: _gridView.count 0028 0029 property alias currentIndex: _gridView.currentIndex 0030 property string typingQuery 0031 0032 property GalleryList list : GalleryList 0033 { 0034 autoReload: browserSettings.autoReload 0035 } 0036 0037 flickable: _gridView.flickable 0038 showTitle: false 0039 0040 property Component searchFieldComponent : Maui.SearchField 0041 { 0042 enabled: control.list.count > 0 0043 text: pixModel.filters.join(",") 0044 placeholderText: i18np("Search image", "Search %1 images", control.list.count) 0045 onAccepted: 0046 { 0047 if(_ocrOption.checked) 0048 { 0049 control.list.scanImagesText() 0050 } 0051 0052 if(text.includes(",")) 0053 { 0054 model.filters = text.split(",") 0055 }else 0056 { 0057 model.filter = text 0058 } 0059 } 0060 0061 onCleared: model.clearFilters() 0062 0063 rightContent: Maui.ToolButtonMenu 0064 { 0065 icon.name: "view-filter" 0066 visible: Maui.Handy.isLinux 0067 0068 MenuItem 0069 { 0070 id: _ocrOption 0071 text: i18n("Image Text (OCR)") 0072 checkable: true 0073 } 0074 } 0075 } 0076 0077 Maui.GridBrowser 0078 { 0079 id: _gridView 0080 anchors.fill: parent 0081 enableLassoSelection: true 0082 holder.visible: _gridView.count === 0 0083 0084 itemSize : control.itemSize 0085 itemHeight: browserSettings.showLabels ? _gridView.itemSize * 1.5 : _gridView.itemSize 0086 cacheBuffer: control.height * 5 0087 0088 Loader 0089 { 0090 width: parent.width 0091 anchors.bottom: parent.bottom 0092 active: control.list.status === GalleryList.Loading 0093 visible: active 0094 sourceComponent: Maui.ProgressIndicator {} 0095 } 0096 0097 model: Maui.BaseModel 0098 { 0099 id: pixModel 0100 list: control.list 0101 0102 sort: browserSettings.sortBy 0103 sortOrder: browserSettings.sortOrder 0104 recursiveFilteringEnabled: true 0105 sortCaseSensitivity: Qt.CaseInsensitive 0106 filterCaseSensitivity: Qt.CaseInsensitive 0107 } 0108 0109 Maui.Chip 0110 { 0111 z: parent.z + 99999 0112 Maui.Theme.colorSet:Maui.Theme.Complementary 0113 visible: _typingTimer.running 0114 label.text: typingQuery 0115 anchors.left: parent.left 0116 anchors.bottom: parent.bottom 0117 showCloseButton: false 0118 anchors.margins: Maui.Style.space.medium 0119 } 0120 0121 Timer 0122 { 0123 id: _typingTimer 0124 interval: 250 0125 onTriggered: 0126 { 0127 const index = control.list.indexOfName(typingQuery) 0128 if(index > -1) 0129 { 0130 control.currentIndex = pixModel.mappedFromSource(index) 0131 } 0132 0133 typingQuery = "" 0134 } 0135 } 0136 0137 PixMenu 0138 { 0139 id: _picMenu 0140 index: control.currentIndex 0141 model: pixModel 0142 } 0143 0144 onItemsSelected: (indexes) => 0145 { 0146 for(var i in indexes) 0147 selectItem(pixModel.get(indexes[i])) 0148 } 0149 0150 onKeyPress: (event) => 0151 { 0152 const index = control.currentIndex 0153 const item = control.model.get(index) 0154 0155 var pat = /^([a-zA-Z0-9 _-]+)$/ 0156 if(event.count === 1 && pat.test(event.text)) 0157 { 0158 typingQuery += event.text 0159 _typingTimer.restart() 0160 event.accepted = true 0161 } 0162 0163 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)) 0164 { 0165 _gridView.itemsSelected([index]) 0166 } 0167 0168 if(event.key === Qt.Key_Space) 0169 { 0170 getFileInfo(item.url) 0171 event.accepted = true 0172 } 0173 0174 if(event.key === Qt.Key_Return) 0175 { 0176 openPic(index) 0177 event.accepted = true 0178 } 0179 0180 if(event.key === Qt.Key_A && (event.modifiers & Qt.ControlModifier)) 0181 { 0182 selectAll() 0183 event.accepted = true 0184 } 0185 } 0186 0187 delegate: Item 0188 { 0189 height: GridView.view.cellHeight 0190 width: GridView.view.cellWidth 0191 0192 PixPic 0193 { 0194 id: _gridDelegate 0195 0196 template.imageWidth: _gridView.itemSize 0197 template.imageHeight: _gridView.itemSize 0198 anchors.fill: parent 0199 anchors.margins: Maui.Handy.isMobile ? 0 : Maui.Style.space.medium 0200 0201 fit: browserSettings.fitPreviews 0202 labelsVisible: browserSettings.showLabels 0203 checkable: root.selectionMode 0204 radius: Maui.Handy.isMobile ? 0 : Maui.Style.radiusV 0205 0206 isCurrentItem: parent.GridView.isCurrentItem || checked 0207 checked: selectionBox.contains(model.url) 0208 0209 Drag.keys: ["text/uri-list"] 0210 Drag.mimeData: Drag.active ? { "text/uri-list": control.filterSelectedItems(model.url) } : {} 0211 0212 onClicked: 0213 { 0214 control.currentIndex = index 0215 if(root.selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier))) 0216 { 0217 _gridView.itemsSelected([index]) 0218 }else if(Maui.Handy.singleClick) 0219 { 0220 openPic(index) 0221 } 0222 } 0223 0224 onDoubleClicked: 0225 { 0226 control.currentIndex = index 0227 if(!Maui.Handy.singleClick && !root.selectionMode) 0228 { 0229 openPic(index) 0230 } 0231 } 0232 0233 onPressAndHold: 0234 { 0235 control.currentIndex = index 0236 _picMenu.show() 0237 } 0238 0239 onRightClicked: 0240 { 0241 control.currentIndex = index 0242 _picMenu.show() 0243 } 0244 0245 onToggled: 0246 { 0247 control.currentIndex = index 0248 selectItem(pixModel.get(index)) 0249 } 0250 } 0251 0252 Connections 0253 { 0254 target: selectionBox 0255 ignoreUnknownSignals: true 0256 0257 function onUriRemoved(uri) 0258 { 0259 if(uri === model.url) 0260 { 0261 _gridDelegate.checked = false 0262 } 0263 } 0264 0265 function onUriAdded(uri) 0266 { 0267 if(uri === model.url) 0268 { 0269 _gridDelegate.checked = true 0270 } 0271 } 0272 0273 function onCleared() 0274 { 0275 _gridDelegate.checked = false 0276 } 0277 } 0278 } 0279 } 0280 0281 0282 function filterSelectedItems(path) 0283 { 0284 if(selectionBox && selectionBox.count > 0 && selectionBox.contains(path)) 0285 { 0286 const uris = selectionBox.uris 0287 return uris.join("\n") 0288 } 0289 0290 return path 0291 } 0292 0293 function selectAll() 0294 { 0295 for(var item of pixModel.getAll()) 0296 { 0297 selectionBox.append(item.url, item) 0298 } 0299 } 0300 0301 function openPic(index) 0302 { 0303 VIEWER.open(pixModel, index) 0304 } 0305 }