2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2022-01-02 23:46:29 +03:00
|
|
|
//
|
|
|
|
// 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
|
2022-04-10 05:10:32 +03:00
|
|
|
required property int originalWidth
|
|
|
|
required property double proportionalHeight
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
flags: Qt.FramelessWindowHint
|
|
|
|
|
2022-04-10 05:10:32 +03:00
|
|
|
//visibility: Window.FullScreen
|
2022-01-02 23:46:29 +03:00
|
|
|
color: Qt.rgba(0.2,0.2,0.2,0.66)
|
2023-02-10 20:01:47 +03:00
|
|
|
Component.onCompleted: Nheko.setWindowRole(imageOverlay, "imageoverlay")
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
Shortcut {
|
2023-09-26 01:03:57 +03:00
|
|
|
sequence: StandardKey.Cancel
|
2022-01-02 23:46:29 +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-04-23 21:55:28 +03:00
|
|
|
onActivated: {
|
|
|
|
if (room) {
|
|
|
|
room.copyMedia(eventId);
|
|
|
|
} else {
|
|
|
|
TimelineManager.copyImage(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 21:55:51 +03:00
|
|
|
TapHandler {
|
|
|
|
onSingleTapped: imageOverlay.close();
|
|
|
|
}
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
Item {
|
2022-04-10 05:10:32 +03:00
|
|
|
id: imgContainer
|
|
|
|
|
2022-05-10 04:19:53 +03:00
|
|
|
property int imgSrcWidth: (imageOverlay.originalWidth && imageOverlay.originalWidth > 100) ? imageOverlay.originalWidth : Screen.width
|
|
|
|
property int imgSrcHeight: imageOverlay.proportionalHeight ? imgSrcWidth * imageOverlay.proportionalHeight : Screen.height
|
2022-04-10 05:10:32 +03:00
|
|
|
|
2022-05-10 04:19:53 +03:00
|
|
|
height: Math.min(parent.height || Screen.height, imgSrcHeight)
|
|
|
|
width: Math.min(parent.width || Screen.width, imgSrcWidth)
|
2022-04-10 05:10:32 +03:00
|
|
|
|
2022-05-10 04:19:53 +03:00
|
|
|
x: (parent.width - width) / 2
|
|
|
|
y: (parent.height - height) / 2
|
2022-01-02 23:46:29 +03:00
|
|
|
|
|
|
|
Image {
|
|
|
|
id: img
|
|
|
|
|
|
|
|
visible: !mxcimage.loaded
|
|
|
|
anchors.fill: parent
|
|
|
|
source: url.replace("mxc://", "image://MxcImage/")
|
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
smooth: true
|
|
|
|
mipmap: true
|
2022-01-06 07:33:08 +03:00
|
|
|
property bool loaded: status == Image.Ready
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MxcAnimatedImage {
|
|
|
|
id: mxcimage
|
|
|
|
|
|
|
|
visible: loaded
|
|
|
|
anchors.fill: parent
|
|
|
|
roomm: imageOverlay.room
|
|
|
|
play: !Settings.animateImagesOnHover || mouseArea.hovered
|
|
|
|
eventId: imageOverlay.eventId
|
|
|
|
}
|
|
|
|
|
2022-04-10 05:10:32 +03:00
|
|
|
onScaleChanged: {
|
|
|
|
if (scale > 10) scale = 10;
|
|
|
|
if (scale < 0.1) scale = 0.1
|
2022-01-03 01:50:08 +03:00
|
|
|
}
|
2022-04-10 05:10:32 +03:00
|
|
|
}
|
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-03 01:50:08 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
PinchHandler {
|
2022-04-10 05:10:32 +03:00
|
|
|
target: imgContainer
|
|
|
|
maximumScale: 10
|
|
|
|
minimumScale: 0.1
|
2022-01-02 23:46:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WheelHandler {
|
|
|
|
property: "scale"
|
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
|
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.top: parent.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.margins: Nheko.paddingLarge
|
|
|
|
spacing: Nheko.paddingMedium
|
|
|
|
|
2023-04-23 21:55:28 +03:00
|
|
|
ImageButton {
|
|
|
|
height: 48
|
|
|
|
width: 48
|
|
|
|
hoverEnabled: true
|
|
|
|
image: ":/icons/icons/ui/copy.svg"
|
|
|
|
|
|
|
|
//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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
ImageButton {
|
|
|
|
height: 48
|
|
|
|
width: 48
|
|
|
|
hoverEnabled: true
|
|
|
|
image: ":/icons/icons/ui/download.svg"
|
2023-04-23 21:55:28 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
//ToolTip.visible: hovered
|
|
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
|
|
//ToolTip.text: qsTr("Download")
|
2023-04-23 21:55:28 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
onClicked: {
|
2023-01-20 17:10:22 +03:00
|
|
|
imageOverlay.hide();
|
2022-01-02 23:46:29 +03:00
|
|
|
if (room) {
|
|
|
|
room.saveMedia(eventId);
|
|
|
|
} else {
|
|
|
|
TimelineManager.saveMedia(url);
|
|
|
|
}
|
|
|
|
imageOverlay.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImageButton {
|
|
|
|
height: 48
|
|
|
|
width: 48
|
|
|
|
hoverEnabled: true
|
|
|
|
image: ":/icons/icons/ui/dismiss.svg"
|
2023-04-23 21:55:28 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
//ToolTip.visible: hovered
|
|
|
|
//ToolTip.delay: Nheko.tooltipDelay
|
|
|
|
//ToolTip.text: qsTr("Close")
|
2023-04-23 21:55:28 +03:00
|
|
|
|
2022-01-02 23:46:29 +03:00
|
|
|
onClicked: imageOverlay.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|