Warning, /maui/pix/src/widgets/views/Viewer/PixViewer.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 import QtQuick 2.13
0007 
0008 import QtQuick.Controls 2.13
0009 import QtQuick.Layouts 1.3
0010 import QtQuick.Window 2.13
0011 
0012 import org.mauikit.controls 1.3 as Maui
0013 import org.mauikit.filebrowsing 1.3 as FB
0014 import org.mauikit.imagetools 1.3 as IT
0015 import org.kde.kquickimageeditor 1.0 as KQuickImageEditor
0016 
0017 import org.maui.pix 1.0 as Pix
0018 
0019 import "../../../view_models"
0020 
0021 StackView
0022 {
0023     id: control
0024 
0025     readonly property alias viewer : viewer
0026     readonly property alias holder : holder
0027     readonly property alias tagBar : tagBar
0028     readonly property alias roll : galleryRoll
0029     readonly property bool editing : control.currentItem.objectName === "imageEditor"
0030 
0031     property alias model : viewer.model
0032 
0033     property bool currentPicFav: false
0034     property var currentPic : ({})
0035     property int currentPicIndex : 0
0036     property bool doodle : false
0037 
0038     property alias showCSDControls: _viewer.showCSDControls
0039 
0040     PixMenu
0041     {
0042         id: _picMenu
0043         index: control.currentPicIndex
0044         model: viewer.model
0045     }
0046 
0047     Component
0048     {
0049         id: _editorComponent
0050 
0051         IT.ImageEditor
0052         {
0053             objectName: "imageEditor"
0054             url: control.currentPic.url
0055             onGoBackTriggered: control.pop()
0056 
0057             headBar.farLeftContent: ToolButton
0058             {
0059                 icon.name: "go-previous"
0060                 onClicked:
0061                 {
0062                     control.pop()
0063                 }
0064             }
0065 
0066             headBar.rightContent: Maui.ToolButtonMenu
0067             {
0068                 icon.name: "document-save"
0069 
0070                 MenuItem
0071                 {
0072                     text: i18n("Save as")
0073                     icon.name: "document-save-as"
0074                     onTriggered:
0075                     {
0076                         dialogLoader.sourceComponent= fmDialogComponent
0077                         dialog.mode = dialog.modes.SAVE
0078                         dialog.settings.onlyDirs= false
0079                         dialog.singleSelection = true
0080                         dialog.callback = function(paths)
0081                         {
0082                             console.log("Save edit to", paths)
0083                             editor.saveAs(paths[0])
0084                         };
0085                         dialog.open()
0086                     }
0087                 }
0088 
0089                 MenuItem
0090                 {
0091                     text: i18n("Save")
0092                     icon.name: "document-save"
0093                     onTriggered: editor.save()
0094                 }
0095             }
0096         }
0097     }
0098 
0099     initialItem: Maui.Page
0100     {
0101         id: _viewer
0102 
0103         padding: 0
0104         title: currentPic.title
0105         showTitle: root.isWide
0106         altHeader: Maui.Handy.isMobile
0107 
0108         headBar.visible: true
0109 
0110         onGoBackTriggered: _stackView.pop()
0111 
0112         headBar.farLeftContent: [
0113             ToolButton
0114             {
0115                 icon.name: "go-previous"
0116                 text: i18n("Gallery")
0117                 display: ToolButton.TextBesideIcon
0118                 onClicked: toggleViewer()
0119             },
0120 
0121             Maui.ToolActions
0122             {
0123                 visible: !holder.visible && (!Maui.Handy.isMobile && !Maui.Handy.isTouch && Maui.Platform.hasKeyboard) && control.model.count > 1 //only show footbar control for desktop mode
0124 
0125                 expanded: true
0126                 autoExclusive: false
0127                 checkable: false
0128                 display: ToolButton.IconOnly
0129 
0130                 Action
0131                 {
0132                     text: i18n("Previous")
0133                     icon.name: "go-previous"
0134                     onTriggered: previous()
0135                 }
0136 
0137                 Action
0138                 {
0139                     icon.name: "go-next"
0140                     onTriggered: next()
0141                 }
0142             }
0143         ]
0144 
0145         headBar.rightContent: [
0146             ToolButton
0147             {
0148                 icon.name: "love"
0149                 checked: control.currentPicFav
0150                 onClicked:
0151                 {
0152                     if(control.currentPicFav)
0153                         tagBar.list.removeFromUrls("fav")
0154                     else
0155                         tagBar.list.insertToUrls("fav")
0156 
0157                     control.currentPicFav = !control.currentPicFav
0158                 }
0159             },
0160 
0161             ToolButton
0162             {
0163                 icon.name: "document-share"
0164                 onClicked:
0165                 {
0166                     Maui.Platform.shareFiles([control.currentPic.url])
0167                 }
0168             },
0169 
0170             ToolButton
0171             {
0172                 icon.name: "draw-freehand"
0173                 onClicked:
0174                 {
0175                     control.push(_editorComponent)
0176                 }
0177             },
0178 
0179             ToolButton
0180             {
0181                 visible: Maui.Handy.isLinux
0182                 icon.name: "format-text-bold"
0183                 onClicked:
0184                 {
0185                     var component = Qt.createComponent("qrc:/widgets/views/Viewer/OCRPage.qml")
0186                     if (component.status == Component.Ready)
0187                         var object = component.createObject()
0188                     else
0189                         component.statusChanged.connect(finishCreation);
0190 
0191                     control.push(object)
0192                 }
0193 
0194             },
0195 
0196             ToolButton
0197             {
0198                 icon.name: "view-fullscreen"
0199                 onClicked: toogleFullscreen()
0200                 checked: fullScreen
0201             }
0202         ]
0203 
0204         Maui.Holder
0205         {
0206             id: holder
0207             visible: viewer.count === 0 /*|| viewer.currentItem.status !== Image.Ready*/
0208             anchors.fill: parent
0209             emoji: "qrc:/assets/add-image.svg"
0210             isMask: true
0211             title : i18n("No Pics!")
0212             body: i18n("Open an image from your collection")
0213         }
0214 
0215         ColumnLayout
0216         {
0217             height: parent.height
0218             width: parent.width
0219             spacing: 0
0220 
0221             Viewer
0222             {
0223                 id: viewer
0224                 visible: !holder.visible
0225                 Layout.fillHeight: true
0226                 Layout.fillWidth: true
0227 
0228                 Rectangle
0229                 {
0230                     id: galleryRollBg
0231                     width: parent.width
0232                     anchors.bottom: parent.bottom
0233                     height: Math.min(100, Math.max(parent.height * 0.12, 60))
0234                     visible: viewerSettings.previewBarVisible && galleryRoll.rollList.count > 1 && opacity> 0
0235                     color: Qt.rgba(Maui.Theme.backgroundColor.r, Maui.Theme.backgroundColor.g, Maui.Theme.backgroundColor.b, 0.7)
0236 
0237                     Behavior on opacity
0238                     {
0239                         NumberAnimation
0240                         {
0241                             duration: Maui.Style.units.longDuration
0242                             easing.type: Easing.InOutQuad
0243                         }
0244                     }
0245 
0246                     GalleryRoll
0247                     {
0248                         id: galleryRoll
0249                         height: parent.height -Maui.Style.space.small
0250                         width: parent.width
0251                         anchors.centerIn: parent
0252                         model: control.model
0253                         onPicClicked: (index) => view(index)
0254                     }
0255                 }
0256             }
0257 
0258             FB.TagsBar
0259             {
0260                 id: tagBar
0261                 visible: !holder.visible && viewerSettings.tagBarVisible && !fullScreen
0262                 Layout.fillWidth: true
0263                 allowEditMode: true
0264                 list.urls: [currentPic.url]
0265                 list.strict: false
0266 
0267                 onAddClicked:
0268                 {
0269                     dialogLoader.sourceComponent = tagsDialogComponent
0270                     dialog.composerList.urls = [currentPic.url]
0271                     dialog.open()
0272                 }
0273 
0274                 onTagRemovedClicked: (index) => list.removeFromUrls(index)
0275                 onTagsEdited: (tags) => list.updateToUrls(tags)
0276 
0277                 Connections
0278                 {
0279                     target: dialog
0280                     ignoreUnknownSignals: true
0281                     enabled: dialogLoader.sourceComponent === tagsDialogComponent
0282                     function onTagsReady()
0283                     {
0284                         tagBar.list.refresh()
0285                     }
0286                 }
0287             }
0288         }
0289     }
0290 
0291     function next()
0292     {
0293         var index = control.currentPicIndex
0294 
0295         if(index < control.viewer.count-1)
0296             index++
0297         else
0298             index= 0
0299 
0300         view(index)
0301     }
0302 
0303     function previous()
0304     {
0305         var index = control.currentPicIndex
0306 
0307         if(index > 0)
0308             index--
0309         else
0310             index = control.viewer.count-1
0311 
0312         view(index)
0313     }
0314 
0315     function view(index)
0316     {
0317         if(control.viewer.count > 0 && index >= 0 && index < control.viewer.count)
0318         {
0319             control.currentPicIndex = index
0320             control.currentPic = control.model.get(control.currentPicIndex)
0321 
0322             control.currentPicFav = FB.Tagging.isFav(control.currentPic.url)
0323             root.title = control.currentPic.title
0324             control.roll.position(control.currentPicIndex)
0325         }
0326     }
0327 }
0328 
0329