2022-01-02 23:46:29 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Window 2.15
|
2022-04-16 03:13:01 +03:00
|
|
|
import "../"
|
2022-04-15 03:58:44 +03:00
|
|
|
import im.nheko
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
Window {
|
|
|
|
id: imageOverlay
|
|
|
|
|
|
|
|
required property string eventId
|
2022-04-10 05:10:32 +03:00
|
|
|
required property int originalWidth
|
|
|
|
required property double proportionalHeight
|
2022-04-16 03:13:01 +03:00
|
|
|
required property Room room
|
|
|
|
required property string url
|
2022-01-02 23:46:29 +03:00
|
|
|
|
2022-04-10 05:10:32 +03:00
|
|
|
//visibility: Window.FullScreen
|
2022-04-16 03:13:01 +03:00
|
|
|
color: Qt.rgba(0.2, 0.2, 0.2, 0.66)
|
|
|
|
flags: Qt.FramelessWindowHint
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
Shortcut {
|
|
|
|
sequence: StandardKey.Cancel
|
2022-04-16 03:13:01 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
onActivated: imageOverlay.close()
|
|
|
|
}
|
|
|
|
Item {
|
2022-04-10 05:10:32 +03:00
|
|
|
id: imgContainer
|
|
|
|
|
|
|
|
property int imgSrcHeight: proportionalHeight ? imgSrcWidth * proportionalHeight : Screen.height
|
2022-04-16 03:13:01 +03:00
|
|
|
property int imgSrcWidth: (originalWidth && originalWidth > 200) ? originalWidth : Screen.width
|
2022-04-10 05:10:32 +03:00
|
|
|
|
|
|
|
height: Math.min(parent.height, imgSrcHeight)
|
|
|
|
width: Math.min(parent.width, imgSrcWidth)
|
|
|
|
x: (parent.width - width)
|
|
|
|
y: (parent.height - height)
|
2022-01-02 23:46:29 +03:00
|
|
|
|
2022-04-16 03:13:01 +03:00
|
|
|
onScaleChanged: {
|
|
|
|
if (scale > 10)
|
|
|
|
scale = 10;
|
|
|
|
if (scale < 0.1)
|
|
|
|
scale = 0.1;
|
|
|
|
}
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
Image {
|
|
|
|
id: img
|
|
|
|
|
2022-04-16 03:13:01 +03:00
|
|
|
property bool loaded: status == Image.Ready
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
mipmap: true
|
2022-04-16 03:13:01 +03:00
|
|
|
smooth: true
|
|
|
|
source: url.replace("mxc://", "image://MxcImage/")
|
|
|
|
visible: !mxcimage.loaded
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
MxcAnimatedImage {
|
|
|
|
id: mxcimage
|
|
|
|
anchors.fill: parent
|
|
|
|
eventId: imageOverlay.eventId
|
2022-04-16 03:13:01 +03:00
|
|
|
play: !Settings.animateImagesOnHover || mouseArea.hovered
|
|
|
|
roomm: imageOverlay.room
|
|
|
|
visible: loaded
|
2022-01-03 01:50:08 +03:00
|
|
|
}
|
2022-04-10 05:10:32 +03:00
|
|
|
}
|
|
|
|
Item {
|
|
|
|
anchors.fill: parent
|
2022-01-06 07:33:08 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
PinchHandler {
|
2022-04-10 05:10:32 +03:00
|
|
|
maximumScale: 10
|
|
|
|
minimumScale: 0.1
|
2022-04-16 03:13:01 +03:00
|
|
|
target: imgContainer
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
WheelHandler {
|
|
|
|
property: "scale"
|
2022-04-10 05:10:32 +03:00
|
|
|
target: imgContainer
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
DragHandler {
|
2022-04-10 05:10:32 +03:00
|
|
|
target: imgContainer
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
HoverHandler {
|
|
|
|
id: mouseArea
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Row {
|
|
|
|
anchors.margins: Nheko.paddingLarge
|
2022-04-16 03:13:01 +03:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
2022-01-02 23:46:29 +03:00
|
|
|
spacing: Nheko.paddingMedium
|
|
|
|
|
|
|
|
ImageButton {
|
|
|
|
height: 48
|
|
|
|
hoverEnabled: true
|
|
|
|
image: ":/icons/icons/ui/download.svg"
|
2022-04-16 03:13:01 +03:00
|
|
|
width: 48
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
//ToolTip.visible: hovered
|
|
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
|
|
//ToolTip.text: qsTr("Download")
|
|
|
|
onClicked: {
|
|
|
|
if (room) {
|
|
|
|
room.saveMedia(eventId);
|
|
|
|
} else {
|
|
|
|
TimelineManager.saveMedia(url);
|
|
|
|
}
|
|
|
|
imageOverlay.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImageButton {
|
|
|
|
height: 48
|
|
|
|
hoverEnabled: true
|
|
|
|
image: ":/icons/icons/ui/dismiss.svg"
|
2022-04-16 03:13:01 +03:00
|
|
|
width: 48
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
//ToolTip.visible: hovered
|
|
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
|
|
//ToolTip.text: qsTr("Close")
|
|
|
|
onClicked: imageOverlay.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|