Warning, /maui/shelf/src/views/library/LibraryView.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 import org.mauikit.filebrowsing 1.3 as FB 0007 0008 import org.maui.shelf 1.0 as Shelf 0009 0010 Maui.SideBarView 0011 { 0012 id: control 0013 property alias list : _libraryList 0014 property alias showCSDControls : _browser.showCSDControls 0015 property alias flickable : _browser.flickable 0016 property alias sources : _libraryList.sources 0017 0018 sideBar.preferredWidth: 200 0019 sideBar.minimumWidth: 200 0020 sideBar.resizeable: false 0021 sideBar.content: Sidebar 0022 { 0023 anchors.fill: parent 0024 } 0025 0026 LibraryMenu 0027 { 0028 id: _menu 0029 index: _browser.currentIndex 0030 model: _libraryModel 0031 } 0032 0033 Maui.AltBrowser 0034 { 0035 id: _browser 0036 anchors.fill: parent 0037 enableLassoSelection: true 0038 gridView.itemSize: Math.min(180, Math.floor(gridView.availableWidth/3)) 0039 gridView.itemHeight: 220 0040 viewType: viewerSettings.viewType 0041 0042 Connections 0043 { 0044 target: _browser.currentView 0045 function onItemsSelected(indexes) 0046 { 0047 for(var i in indexes) 0048 { 0049 const item = _browser.model.get(indexes[i]) 0050 _selectionbar.append(item.path, item) 0051 } 0052 } 0053 } 0054 0055 holder.visible: _browser.count === 0 0056 holder.title: i18n("Nothing here!") 0057 holder.body: i18n("Add new sources to manage your documents.") 0058 holder.emoji: "qrc:/assets/document-new.svg" 0059 holder.actions:[ 0060 0061 Action 0062 { 0063 text: i18n("Open file") 0064 onTriggered: openFileDialog() 0065 }, 0066 0067 Action 0068 { 0069 text: i18n("Add sources") 0070 onTriggered: openSettingsDialog() 0071 } 0072 ] 0073 0074 model: Maui.BaseModel 0075 { 0076 id: _libraryModel 0077 sort: "modified" 0078 sortOrder: Qt.DescendingOrder 0079 recursiveFilteringEnabled: true 0080 sortCaseSensitivity: Qt.CaseInsensitive 0081 filterCaseSensitivity: Qt.CaseInsensitive 0082 list: Shelf.LibraryList 0083 { 0084 id: _libraryList 0085 } 0086 } 0087 0088 altHeader: Maui.Handy.isMobile 0089 headBar.forceCenterMiddleContent: root.isWide 0090 headBar.leftContent: [ToolButton 0091 { 0092 visible: control.sideBar.collapsed 0093 icon.name: control.sideBar.visible ? "sidebar-collapse" : "sidebar-expand" 0094 onClicked: control.sideBar.toggle() 0095 checked: control.sideBar.visible 0096 ToolTip.delay: 1000 0097 ToolTip.timeout: 5000 0098 ToolTip.visible: hovered 0099 ToolTip.text: i18n("Toggle sidebar") 0100 }, 0101 0102 ToolButton 0103 { 0104 visible: viewerView.tabView.count 0105 icon.name: "view-readermode-active" 0106 text: viewerView.tabView.count 0107 onClicked: toggleViewer() 0108 } 0109 0110 ] 0111 0112 headBar.rightContent:[ 0113 Maui.ToolButtonMenu 0114 { 0115 icon.name: _browser.viewType === Maui.AltBrowser.ViewType.List ? "view-list-details" : "view-list-icons" 0116 0117 MenuItem 0118 { 0119 text: i18n("Open") 0120 icon.name: "document-open" 0121 onTriggered: openFileDialog() 0122 } 0123 0124 MenuSeparator {} 0125 0126 MenuItem 0127 { 0128 text: i18n("List") 0129 checkable: true 0130 icon.name: "view-list-details" 0131 checked: _browser.viewType === Maui.AltBrowser.ViewType.List 0132 onTriggered: viewerSettings.viewType = Maui.AltBrowser.ViewType.List 0133 } 0134 0135 MenuItem 0136 { 0137 text: i18n("Grid") 0138 checkable: true 0139 icon.name: "view-list-icons" 0140 checked: _browser.viewType === Maui.AltBrowser.ViewType.Grid 0141 onTriggered: viewerSettings.viewType = Maui.AltBrowser.ViewType.Grid 0142 } 0143 0144 MenuSeparator {} 0145 0146 MenuItem 0147 { 0148 text: i18n("Title") 0149 checkable: true 0150 checked: _libraryModel.sort === "label" 0151 onTriggered: _libraryModel.sort = "label" 0152 } 0153 0154 MenuItem 0155 { 0156 text: i18n("Date") 0157 checkable: true 0158 checked: _libraryModel.sort === "modified" 0159 onTriggered: _libraryModel.sort = "modified" 0160 } 0161 0162 MenuItem 0163 { 0164 text: i18n("Size") 0165 checkable: true 0166 checked: _libraryModel.sort === "size" 0167 onTriggered: _libraryModel.sort = "size" 0168 } 0169 0170 MenuSeparator {} 0171 0172 MenuItem 0173 { 0174 text: i18n("Ascending") 0175 checked: _libraryModel.sortOrder === Qt.AscendingOrder 0176 onTriggered: _libraryModel.sortOrder = Qt.AscendingOrder 0177 } 0178 0179 MenuItem 0180 { 0181 text: i18n("Descending") 0182 checked: _libraryModel.sortOrder === Qt.DescendingOrder 0183 onTriggered: _libraryModel.sortOrder = Qt.DescendingOrder 0184 } 0185 0186 MenuSeparator {} 0187 0188 MenuItem 0189 { 0190 text: i18n("Settings") 0191 icon.name: "settings-configure" 0192 onTriggered: openSettingsDialog() 0193 } 0194 0195 MenuItem 0196 { 0197 text: i18n("About") 0198 icon.name: "documentinfo" 0199 onTriggered: root.about() 0200 } 0201 } 0202 ] 0203 0204 headBar.middleContent: Maui.SearchField 0205 { 0206 Layout.fillWidth: true 0207 Layout.maximumWidth: 500 0208 Layout.alignment: Qt.AlignCenter 0209 placeholderText: i18n("Filter...") 0210 onAccepted: _browser.model.filter = text 0211 onCleared: _libraryModel.clearFilters() 0212 } 0213 0214 0215 gridDelegate: Item 0216 { 0217 height: GridView.view.cellHeight 0218 width: GridView.view.cellWidth 0219 0220 Maui.GridBrowserDelegate 0221 { 0222 id: _gridTemplate 0223 anchors.fill: parent 0224 anchors.margins: !root.isWide ? Maui.Style.space.tiny : Maui.Style.space.big 0225 0226 imageHeight: _browser.gridView.itemSize 0227 imageWidth: _browser.gridView.itemSize 0228 0229 isCurrentItem: parent.GridView.isCurrentItem || checked 0230 0231 draggable: true 0232 Drag.keys: ["text/uri-list"] 0233 0234 Drag.mimeData: Drag.active ? 0235 { 0236 "text/uri-list": _browser.filterSelectedItems(model.path) 0237 } : {} 0238 0239 0240 label1.text: model.label 0241 imageSource: viewerSettings.showThumbnails ? model.preview : "" 0242 iconSource: model.icon 0243 iconSizeHint: Maui.Style.iconSizes.huge 0244 template.labelSizeHint: 32 0245 template.fillMode: Image.PreserveAspectFit 0246 0247 checkable: root.selectionMode 0248 checked: _selectionbar.contains(model.path) 0249 onToggled: _selectionbar.append(model.path, _browser.model.get(index)) 0250 0251 Connections 0252 { 0253 target: _selectionbar 0254 function onUriRemoved(uri) 0255 { 0256 if(uri === model.path) 0257 _gridTemplate.checked = false 0258 } 0259 0260 function onUriAdded(uri) 0261 { 0262 if(uri === model.path) 0263 _gridTemplate.checked = true 0264 } 0265 0266 function onCleared() 0267 { 0268 _gridTemplate.checked = false 0269 } 0270 } 0271 0272 onClicked: 0273 { 0274 _browser.currentIndex = index 0275 const item = _browser.model.get(_browser.currentIndex) 0276 0277 if(selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier))) 0278 { 0279 const item = _browser.model.get(_browser.currentIndex) 0280 _selectionbar.append(item.path, item) 0281 0282 }else if(Maui.Handy.singleClick) 0283 { 0284 Shelf.Library.openFiles([item.url]) 0285 } 0286 } 0287 0288 onDoubleClicked: 0289 { 0290 _browser.currentIndex = index 0291 if(!Maui.Handy.singleClick && !selectionMode) 0292 { 0293 const item = _browser.model.get(_browser.currentIndex) 0294 Shelf.Library.openFiles([item.url]) 0295 } 0296 } 0297 0298 onPressAndHold: 0299 { 0300 _browser.currentIndex = index 0301 _menu.show() 0302 } 0303 0304 onRightClicked: 0305 { 0306 _browser.currentIndex = index 0307 _menu.show() 0308 } 0309 } 0310 } 0311 0312 listDelegate: Maui.ListBrowserDelegate 0313 { 0314 id: _listDelegate 0315 0316 isCurrentItem: ListView.isCurrentItem || checked 0317 0318 height: Math.floor(Maui.Style.rowHeight * 1.6) 0319 width: ListView.view.width 0320 0321 draggable: true 0322 Drag.keys: ["text/uri-list"] 0323 Drag.mimeData: Drag.active ? 0324 { 0325 "text/uri-list": _browser.filterSelectedItems(model.path) 0326 } : {} 0327 0328 label1.text: model.label 0329 label2.text: String(FB.FM.fileDir(model.path)).replace(FB.FM.homePath(), "") 0330 0331 label3.text: Qt.formatDateTime(new Date(model.modified), "d MMM yyyy") 0332 imageSource: viewerSettings.showThumbnails ? model.preview : "" 0333 0334 iconSource: model.icon 0335 iconSizeHint: Maui.Style.iconSizes.medium 0336 checkable: root.selectionMode 0337 checked: _selectionbar.contains(model.path) 0338 onToggled: _selectionbar.append(model.path, _browser.model.get(index)) 0339 0340 Connections 0341 { 0342 target: _selectionbar 0343 function onUriRemoved(uri) 0344 { 0345 if(uri === model.path) 0346 _listDelegate.checked = false 0347 } 0348 0349 function onUriAdded(uri) 0350 { 0351 if(uri === model.path) 0352 _listDelegate.checked = true 0353 } 0354 0355 function onCleared() 0356 { 0357 _listDelegate.checked = false 0358 } 0359 } 0360 0361 onClicked: 0362 { 0363 _browser.currentIndex = index 0364 const item = _browser.model.get(_browser.currentIndex) 0365 0366 if(selectionMode || (mouse.button == Qt.LeftButton && (mouse.modifiers & Qt.ControlModifier))) 0367 { 0368 _selectionbar.append(item.path, item) 0369 0370 }else if(Maui.Handy.singleClick) 0371 { 0372 Shelf.Library.openFiles([item.path]) 0373 } 0374 } 0375 0376 onDoubleClicked: 0377 { 0378 _browser.currentIndex = index 0379 0380 if(!Maui.Handy.singleClick && !selectionMode) 0381 { 0382 const item = _browser.model.get(_browser.currentIndex) 0383 Shelf.Library.openFiles([item.path]) 0384 } 0385 } 0386 0387 onPressAndHold: 0388 { 0389 _browser.currentIndex = index 0390 _menu.show() 0391 } 0392 0393 onRightClicked: 0394 { 0395 _browser.currentIndex = index 0396 _menu.show() 0397 } 0398 } 0399 0400 footer: Maui.SelectionBar 0401 { 0402 id: _selectionbar 0403 // implicitHeight: 80 0404 anchors.horizontalCenter: parent.horizontalCenter 0405 width: Math.min(parent.width-(Maui.Style.space.medium*2), implicitWidth) 0406 0407 maxListHeight: _stackView.height - Maui.Style.space.medium 0408 0409 onItemClicked : console.log(index) 0410 0411 onExitClicked: 0412 { 0413 clear() 0414 root.selectionMode = false 0415 } 0416 0417 Action 0418 { 0419 text: i18n("Open") 0420 icon.name: "folder_open" 0421 onTriggered: 0422 { 0423 Shelf.Library.openFiles(_selectionbar.uris) 0424 } 0425 } 0426 0427 Action 0428 { 0429 text: i18n("Tag") 0430 icon.name: "tag" 0431 onTriggered: 0432 { 0433 _dialogLoader.sourceComponent = tagsDialogComponent 0434 dialog.composerList.urls = _selectionbar.uris 0435 dialog.open() 0436 } 0437 } 0438 0439 Action 0440 { 0441 text: i18n("Share") 0442 icon.name: "document-share" 0443 onTriggered: 0444 { 0445 Maui.Platform.shareFiles(_selectionbar.uris) 0446 } 0447 } 0448 0449 Action 0450 { 0451 text: i18n("Export") 0452 icon.name: "document-export" 0453 } 0454 } 0455 0456 } 0457 0458 function openFolders(paths) 0459 { 0460 control.sources = paths 0461 } 0462 0463 function filterSelection(url) 0464 { 0465 if(_selectionbar.contains(url)) 0466 { 0467 return selectionBox.uris 0468 }else 0469 { 0470 return [url] 0471 } 0472 } 0473 0474 function filterSelectedItems(path) 0475 { 0476 if(_selectionbar && _selectionbar.count > 0 && _selectionbar.contains(path)) 0477 { 0478 const uris = _selectionbar.uris 0479 return uris.join("\n") 0480 } 0481 0482 return path 0483 } 0484 0485 function openFileDialog() 0486 { 0487 _dialogLoader.sourceComponent = _fileDialog 0488 _dialogLoader.item.open() 0489 } 0490 0491 function openSettingsDialog() 0492 { 0493 _dialogLoader.sourceComponent = _settingsDialogComponent 0494 _dialogLoader.item.open() 0495 } 0496 0497 }