Warning, /maui/pix/src/main.qml is written in an unsupported language. File is not indexed.

0001 // Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
0002 // Copyright 2018-2020 Nitrux Latinoamericana S.C.
0003 //
0004 // SPDX-License-Identifier: GPL-3.0-or-later
0005 
0006 
0007 /***
0008 Pix  Copyright (C) 2018  Camilo Higuita
0009 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
0010 This is free software, and you are welcome to redistribute it
0011 under certain conditions; type `show c' for details.
0012 
0013  This program is free software: you can redistribute it and/or modify
0014 it under the terms of the GNU General Public License as published by
0015 the Free Software Foundation, either version 3 of the License, or
0016 (at your option) any later version.
0017 
0018 This program is distributed in the hope that it will be useful,
0019 but WITHOUT ANY WARRANTY; without even the implied warranty of
0020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021 GNU General Public License for more details.
0022 
0023 You should have received a copy of the GNU General Public License
0024 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025 ***/
0026 
0027 import QtQuick 2.14
0028 import QtQuick.Controls 2.14
0029 import QtQuick.Layouts 1.15
0030 
0031 import QtQuick.Window 2.13
0032 import Qt.labs.settings 1.0
0033 
0034 import org.mauikit.controls 1.3 as Maui
0035 import org.mauikit.filebrowsing 1.3 as FB
0036 import org.mauikit.imagetools 1.3 as IT
0037 import org.maui.pix 1.0 as Pix
0038 
0039 import "widgets"
0040 import "widgets/views"
0041 import "widgets/views/Viewer"
0042 
0043 import "widgets/views/Viewer/Viewer.js" as VIEWER
0044 
0045 Maui.ApplicationWindow
0046 {
0047     id: root
0048     title: _pixViewer.currentPic.title || Maui.App.displayName
0049     
0050     Maui.Style.styleType: Maui.Handy.isAndroid ? (browserSettings.darkMode ? Maui.Style.Dark : Maui.Style.Light) : undefined
0051 
0052     readonly property alias dialog : dialogLoader.item
0053 
0054     readonly property bool fullScreen : root.visibility === Window.FullScreen
0055     
0056     readonly property var previewSizes: ({small: 72,
0057                                              medium: 90,
0058                                              large: 120,
0059                                              extralarge: 160})
0060     property bool selectionMode : false
0061 
0062     Settings
0063     {
0064         id: browserSettings
0065         category: "Browser"
0066         property bool showLabels : false
0067         property bool fitPreviews : false
0068         property bool autoReload: true
0069         property int previewSize : previewSizes.medium
0070         property string sortBy : "modified"
0071         property int sortOrder: Qt.DescendingOrder
0072         property bool darkMode : true
0073         property bool gpsTags : false
0074     }
0075     
0076     Settings
0077     {
0078         id: viewerSettings
0079         property bool tagBarVisible : true
0080         property bool previewBarVisible : false
0081     }
0082     
0083     StackView
0084     {
0085         id: _stackView
0086         anchors.fill: parent
0087         
0088         Keys.enabled: true
0089         Keys.onEscapePressed: _stackView.pop()
0090         
0091         initialItem: initModule === "viewer" ? _pixViewer : _collectionViewComponent
0092         
0093         Loader
0094         {
0095             id: _collectionViewComponent
0096             active:  StackView.status === StackView.Active || item
0097             property string pendingFolder : initModule === "folder" ? initData : ""
0098             
0099             sourceComponent: CollectionView {}
0100         }
0101         
0102         PixViewer
0103         {
0104             id: _pixViewer
0105             visible: StackView.status === StackView.Active
0106             showCSDControls: initModule === "viewer"
0107         }
0108     }
0109     
0110     Loader
0111     {
0112         anchors.fill: parent
0113         visible: _dropAreaLoader.item.containsDrag
0114         asynchronous: true
0115 
0116         sourceComponent: Rectangle
0117         {
0118             color: Qt.rgba(Maui.Theme.backgroundColor.r, Maui.Theme.backgroundColor.g, Maui.Theme.backgroundColor.b, 0.95)
0119 
0120             Maui.Rectangle
0121             {
0122                 anchors.fill: parent
0123                 anchors.margins: Maui.Style.space.medium
0124                 color: "transparent"
0125                 borderColor: Maui.Theme.textColor
0126                 solidBorder: false
0127 
0128                 Maui.Holder
0129                 {
0130                     anchors.fill: parent
0131                     visible: true
0132                     emoji: "qrc:/img/assets/add-image.svg"
0133                     emojiSize: Maui.Style.iconSizes.huge
0134                     title: i18n("Open images")
0135                     body: i18n("Drag and drop images here.")
0136                 }
0137             }
0138         }
0139     }
0140     
0141     Loader
0142     {
0143         id: _dropAreaLoader
0144         anchors.fill: parent
0145 
0146         sourceComponent: DropArea
0147         {
0148             onDropped: (drop) =>
0149             {
0150                 if(drop.urls)
0151                 {
0152                     VIEWER.openExternalPics(drop.urls, 0)
0153                 }
0154             }
0155 
0156             onEntered: (drag) =>
0157             {
0158                 if(drag.source)
0159                 {
0160                     return
0161                 }
0162 
0163                 _stackView.push(_pixViewer)
0164             }
0165         }
0166     }
0167     
0168     Component
0169     {
0170         id: _infoDialogComponent
0171         IT.ImageInfoDialog {}
0172     }
0173     
0174     Component
0175     {
0176         id: tagsDialogComponent
0177         FB.TagsDialog
0178         {
0179             onTagsReady: (tags) => composerList.updateToUrls(tags)
0180             composerList.strict: false
0181         }
0182     }
0183     
0184     Component
0185     {
0186         id: fmDialogComponent
0187         FB.FileDialog
0188         {
0189             settings.filterType: FB.FMList.IMAGE
0190             settings.onlyDirs: true
0191             mode: modes.OPEN
0192         }
0193     }
0194     
0195     Component
0196     {
0197         id: _settingsDialogComponent
0198         SettingsDialog {}
0199     }
0200     
0201     Component
0202     {
0203         id: _removeDialogComponent
0204         
0205         Maui.FileListingDialog
0206         {
0207             id: removeDialog
0208             urls: selectionBox.uris
0209             title: i18np("Delete %1 file?", "Delete %1 files?", urls.length)
0210             
0211             message: i18np("Are sure you want to delete this file? This action can not be undone.", "Are sure you want to delete these files? This action can not be undone.", urls.length)
0212             
0213             onAccepted: close()
0214             onRejected:
0215             {
0216                 FB.FM.removeFiles(removeDialog.urls)
0217                 selectionBox.clear()
0218                 close()
0219             }
0220         }
0221     }
0222     
0223     Loader { id: dialogLoader }
0224     
0225     FB.OpenWithDialog
0226     {
0227         id: _openWithDialog
0228     }
0229     
0230     Connections
0231     {
0232         target: Pix.Collection
0233         
0234         function onViewPics(pics)
0235         {
0236             VIEWER.openExternalPics(pics, 0)
0237         }
0238     }
0239     
0240     Component.onCompleted:
0241     {
0242         if(Maui.Handy.isAndroid)
0243         {
0244             setAndroidStatusBarColor()
0245         }
0246     }
0247     
0248     function setAndroidStatusBarColor()
0249     {
0250         if(Maui.Handy.isAndroid)
0251         {
0252             Maui.Android.statusbarColor( Maui.Theme.backgroundColor, !browserSettings.darkMode)
0253             Maui.Android.navBarColor(Maui.Theme.backgroundColor, !browserSettings.darkMode)
0254         }
0255     }
0256     
0257     function setPreviewSize(size)
0258     {
0259         console.log(size)
0260         browserSettings.previewSize = size
0261     }
0262     
0263     function getFileInfo(url)
0264     {
0265         dialogLoader.sourceComponent= _infoDialogComponent
0266         dialog.url = url
0267         dialog.open()
0268     }
0269     
0270     function toogleTagbar()
0271     {
0272         viewerSettings.tagBarVisible = !viewerSettings.tagBarVisible
0273     }
0274     
0275     function tooglePreviewBar()
0276     {
0277         viewerSettings.previewBarVisible = !viewerSettings.previewBarVisible
0278     }
0279     
0280     function toogleFullscreen()
0281     {
0282         if(root.visibility === Window.FullScreen)
0283         {
0284             root.showNormal()
0285         }else
0286         {
0287             root.showFullScreen()
0288         }
0289     }
0290     
0291     function toggleViewer()
0292     {
0293         if(_pixViewer.visible)
0294         {
0295             if(_stackView.depth === 1)
0296             {
0297                 _stackView.replace(_pixViewer, _collectionViewComponent)
0298                 
0299             }else
0300             {
0301                 _stackView.pop()
0302             }
0303             
0304         }else
0305         {
0306             _stackView.push(_pixViewer)
0307         }
0308         
0309         _stackView.currentItem.forceActiveFocus()
0310     }
0311     
0312     function openFileDialog()
0313     {
0314         dialogLoader.sourceComponent = fmDialogComponent
0315         dialog.mode = dialog.modes.OPEN
0316         dialog.settings.filterType = FB.FMList.IMAGE
0317         dialog.settings.onlyDirs= false
0318         dialog.callback = function(paths)
0319         {
0320             Pix.Collection.openPics(paths)
0321             dialogLoader.sourceComponent = null
0322         };
0323         dialog.open()
0324     }
0325     
0326     function openSettingsDialog()
0327     {
0328         dialogLoader.sourceComponent = _settingsDialogComponent
0329         dialog.open()
0330     }
0331     
0332     function openFolder(url, filters)
0333     {
0334         if(!_collectionViewComponent.visible)
0335         {
0336             toggleViewer()
0337         }
0338         
0339         _collectionViewComponent.item.openFolder(url, filters)
0340     }
0341 }