matrixion/resources/qml/dialogs/ImageOverlay.qml

169 lines
4.6 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 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 eventId
required property int originalWidth
required property double proportionalHeight
2023-10-31 05:11:03 +03:00
required property Room room
required property string url
2023-10-31 05:11:03 +03:00
//visibility: Window.FullScreen
color: Qt.rgba(0.2, 0.2, 0.2, 0.66)
flags: Qt.FramelessWindowHint
Component.onCompleted: Nheko.setWindowRole(imageOverlay, "imageoverlay")
Shortcut {
2023-06-09 03:40:50 +03:00
sequences: [StandardKey.Cancel]
2023-10-31 05:11:03 +03:00
onActivated: imageOverlay.close()
}
2023-04-23 21:55:28 +03:00
Shortcut {
2023-06-09 03:40:50 +03:00
sequences: [StandardKey.Copy]
2023-10-31 05:11:03 +03:00
2023-04-23 21:55:28 +03:00
onActivated: {
if (room) {
room.copyMedia(eventId);
} else {
TimelineManager.copyImage(url);
}
}
}
TapHandler {
2023-10-31 05:11:03 +03:00
onSingleTapped: imageOverlay.close()
}
Item {
id: imgContainer
2022-05-10 04:19:53 +03:00
property int imgSrcHeight: imageOverlay.proportionalHeight ? imgSrcWidth * imageOverlay.proportionalHeight : Screen.height
2023-10-31 05:11:03 +03:00
property int imgSrcWidth: (imageOverlay.originalWidth && imageOverlay.originalWidth > 100) ? imageOverlay.originalWidth : Screen.width
2022-05-10 04:19:53 +03:00
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
2023-10-31 05:11:03 +03:00
onScaleChanged: {
if (scale > 10)
scale = 10;
if (scale < 0.1)
scale = 0.1;
}
Image {
id: img
2023-10-31 05:11:03 +03:00
property bool loaded: status == Image.Ready
anchors.fill: parent
asynchronous: true
fillMode: Image.PreserveAspectFit
mipmap: true
2023-10-31 05:11:03 +03:00
smooth: true
source: url.replace("mxc://", "image://MxcImage/")
visible: !mxcimage.loaded
}
MxcAnimatedImage {
id: mxcimage
anchors.fill: parent
eventId: imageOverlay.eventId
2023-10-31 05:11:03 +03:00
play: !Settings.animateImagesOnHover || mouseArea.hovered
roomm: imageOverlay.room
visible: loaded
2022-01-03 01:50:08 +03:00
}
}
Item {
anchors.fill: parent
PinchHandler {
maximumScale: 10
minimumScale: 0.1
2023-10-31 05:11:03 +03:00
target: imgContainer
}
WheelHandler {
2023-06-09 03:40:50 +03:00
// workaround for QTBUG-87646 / QTBUG-112394 / QTBUG-112432:
// Magic Mouse pretends to be a trackpad but doesn't work with PinchHandler
// and we don't yet distinguish mice and trackpads on Wayland either
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
2023-10-31 05:11:03 +03:00
property: "scale"
target: imgContainer
}
DragHandler {
target: imgContainer
}
HoverHandler {
id: mouseArea
2023-10-31 05:11:03 +03:00
}
}
Row {
anchors.margins: Nheko.paddingLarge
2023-10-31 05:11:03 +03:00
anchors.right: parent.right
anchors.top: parent.top
spacing: Nheko.paddingMedium
2023-04-23 21:55:28 +03:00
ImageButton {
height: 48
hoverEnabled: true
image: ":/icons/icons/ui/copy.svg"
2023-10-31 05:11:03 +03:00
width: 48
2023-04-23 21:55:28 +03:00
//ToolTip.visible: hovered
//ToolTip.delay: Nheko.tooltipDelay
//ToolTip.text: qsTr("Copy to clipboard")
onClicked: {
imageOverlay.hide();
if (room) {
room.copyMedia(eventId);
} else {
TimelineManager.copyImage(url);
}
imageOverlay.close();
}
}
ImageButton {
height: 48
hoverEnabled: true
image: ":/icons/icons/ui/download.svg"
2023-10-31 05:11:03 +03:00
width: 48
2023-04-23 21:55:28 +03:00
//ToolTip.visible: hovered
//ToolTip.delay: Nheko.tooltipDelay
//ToolTip.text: qsTr("Download")
2023-04-23 21:55:28 +03:00
onClicked: {
imageOverlay.hide();
if (room) {
room.saveMedia(eventId);
} else {
TimelineManager.saveMedia(url);
}
imageOverlay.close();
}
}
ImageButton {
height: 48
hoverEnabled: true
image: ":/icons/icons/ui/dismiss.svg"
2023-10-31 05:11:03 +03:00
width: 48
2023-04-23 21:55:28 +03:00
//ToolTip.visible: hovered
//ToolTip.delay: Nheko.tooltipDelay
//ToolTip.text: qsTr("Close")
2023-10-31 05:11:03 +03:00
onClicked: imageOverlay.close()
}
}
}