Warning, /plasma-mobile/spacebar/src/contents/ui/PreviewPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Michael Lang <criticaltemp@protonmail.com>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick
0006 import QtQuick.Layouts
0007 import QtQuick.Controls as Controls
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 import org.kde.spacebar
0012 
0013 Kirigami.Page {
0014     id: page
0015     padding: 0
0016 
0017     property string filePath
0018     property string type
0019     property real defaultSize: Math.min(page.width, page.height)
0020 
0021     Component.onCompleted: applicationWindow().controlsVisible = false
0022 
0023     Component.onDestruction: applicationWindow().controlsVisible = true
0024 
0025     Rectangle {
0026         id: background
0027         anchors.fill: parent
0028         color: "black"
0029 
0030         Controls.Button {
0031             visible: applicationWindow().controlsVisible == false
0032             text: i18n("Back")
0033             icon.name: "go-previous"
0034             onClicked: pageStack.layers.pop()
0035             z: root.z + 1;
0036         }
0037 
0038         Flickable {
0039             id: flickable
0040             anchors.fill: parent
0041             contentWidth: Math.max(page.width, image.width * image.scale)
0042             contentHeight: Math.max(page.height, image.height * image.scale)
0043             interactive: !pinch.active
0044 
0045             Image {
0046                 id: image
0047                 anchors.centerIn: parent
0048                 source: filePath
0049                 cache: false
0050                 fillMode: Image.PreserveAspectFit
0051                 mipmap: true
0052                 scale: defaultSize / Math.max(sourceSize.width, sourceSize.height, 100)
0053 
0054                 AnimatedImage {
0055                     source: type == "image/gif" ? parent.source : ""
0056                     anchors.fill: parent
0057                     cache: false
0058                 }
0059             }
0060 
0061             //TODO adjust flickable position relative to touch position
0062             PinchHandler {
0063                 id: pinch
0064                 target: image
0065                 minimumScale: 0.1
0066                 maximumScale: 10
0067                 minimumRotation: 0
0068                 maximumRotation: 0
0069             }
0070 
0071             MouseArea {
0072                 id: dragArea
0073                 hoverEnabled: true
0074                 anchors.fill: parent
0075                 onWheel: {
0076                     if (image.width * image.scale < 100 && wheel.angleDelta.y < 0) {
0077                         return
0078                     }
0079                     // minimum size
0080                     image.scale += image.scale * wheel.angleDelta.y / 120 / 10;
0081 
0082                     // position image relative to cursor
0083                     if (image.width * image.scale > page.width) {
0084                         flickable.contentX += mouseX * wheel.angleDelta.y / 120 / 10;
0085                     } else {
0086                         flickable.contentX = 0
0087                     }
0088                     if (image.height * image.scale > page.height) {
0089                         flickable.contentY += mouseY * wheel.angleDelta.y / 120 / 10;
0090                     } else {
0091                         flickable.contentY = 0
0092                     }
0093                 }
0094             }
0095         }
0096     }
0097 }