mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-31 18:00:48 +03:00
abe4f8eb3c
Log: on wm like sway, it will cover the whole screen, and I cannot get the file save dialog, then the program will stay there, I must kill it, so I think hide it is better, because after, it will be closed
140 lines
3.4 KiB
QML
140 lines
3.4 KiB
QML
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
|
// SPDX-FileCopyrightText: 2023 Nheko Contributors
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import QtQuick 2.15
|
|
import QtQuick.Window 2.15
|
|
|
|
import ".."
|
|
|
|
import im.nheko 1.0
|
|
|
|
Window {
|
|
id: imageOverlay
|
|
|
|
required property string url
|
|
required property string eventId
|
|
required property Room room
|
|
required property int originalWidth
|
|
required property double proportionalHeight
|
|
|
|
flags: Qt.FramelessWindowHint
|
|
|
|
//visibility: Window.FullScreen
|
|
color: Qt.rgba(0.2,0.2,0.2,0.66)
|
|
|
|
Shortcut {
|
|
sequence: StandardKey.Cancel
|
|
onActivated: imageOverlay.close()
|
|
}
|
|
|
|
TapHandler {
|
|
onSingleTapped: imageOverlay.close();
|
|
}
|
|
|
|
|
|
Item {
|
|
id: imgContainer
|
|
|
|
property int imgSrcWidth: (imageOverlay.originalWidth && imageOverlay.originalWidth > 100) ? imageOverlay.originalWidth : Screen.width
|
|
property int imgSrcHeight: imageOverlay.proportionalHeight ? imgSrcWidth * imageOverlay.proportionalHeight : Screen.height
|
|
|
|
height: Math.min(parent.height || Screen.height, imgSrcHeight)
|
|
width: Math.min(parent.width || Screen.width, imgSrcWidth)
|
|
|
|
x: (parent.width - width) / 2
|
|
y: (parent.height - height) / 2
|
|
|
|
Image {
|
|
id: img
|
|
|
|
visible: !mxcimage.loaded
|
|
anchors.fill: parent
|
|
source: url.replace("mxc://", "image://MxcImage/")
|
|
asynchronous: true
|
|
fillMode: Image.PreserveAspectFit
|
|
smooth: true
|
|
mipmap: true
|
|
property bool loaded: status == Image.Ready
|
|
}
|
|
|
|
MxcAnimatedImage {
|
|
id: mxcimage
|
|
|
|
visible: loaded
|
|
anchors.fill: parent
|
|
roomm: imageOverlay.room
|
|
play: !Settings.animateImagesOnHover || mouseArea.hovered
|
|
eventId: imageOverlay.eventId
|
|
}
|
|
|
|
onScaleChanged: {
|
|
if (scale > 10) scale = 10;
|
|
if (scale < 0.1) scale = 0.1
|
|
}
|
|
}
|
|
|
|
Item {
|
|
anchors.fill: parent
|
|
|
|
|
|
PinchHandler {
|
|
target: imgContainer
|
|
maximumScale: 10
|
|
minimumScale: 0.1
|
|
}
|
|
|
|
WheelHandler {
|
|
property: "scale"
|
|
target: imgContainer
|
|
}
|
|
|
|
DragHandler {
|
|
target: imgContainer
|
|
}
|
|
|
|
HoverHandler {
|
|
id: mouseArea
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
anchors.top: parent.top
|
|
anchors.right: parent.right
|
|
anchors.margins: Nheko.paddingLarge
|
|
spacing: Nheko.paddingMedium
|
|
|
|
ImageButton {
|
|
height: 48
|
|
width: 48
|
|
hoverEnabled: true
|
|
image: ":/icons/icons/ui/download.svg"
|
|
//ToolTip.visible: hovered
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
//ToolTip.text: qsTr("Download")
|
|
onClicked: {
|
|
imageOverlay.hide();
|
|
if (room) {
|
|
room.saveMedia(eventId);
|
|
} else {
|
|
TimelineManager.saveMedia(url);
|
|
}
|
|
imageOverlay.close();
|
|
}
|
|
}
|
|
ImageButton {
|
|
height: 48
|
|
width: 48
|
|
hoverEnabled: true
|
|
image: ":/icons/icons/ui/dismiss.svg"
|
|
//ToolTip.visible: hovered
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
//ToolTip.text: qsTr("Close")
|
|
onClicked: imageOverlay.close()
|
|
}
|
|
}
|
|
|
|
}
|