mirror of https://github.com/Nheko-Reborn/nheko
parent
c3e2e73175
commit
66520eae19
@ -0,0 +1,110 @@ |
||||
// SPDX-FileCopyrightText: 2022 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 |
||||
|
||||
flags: Qt.FramelessWindowHint |
||||
|
||||
visibility: Window.FullScreen |
||||
color: Qt.rgba(0.2,0.2,0.2,0.66) |
||||
|
||||
Shortcut { |
||||
sequence: StandardKey.Cancel |
||||
onActivated: imageOverlay.close() |
||||
} |
||||
|
||||
|
||||
Item { |
||||
height: Math.min(parent.height, img.implicitHeight) |
||||
width: Math.min(parent.width, img.implicitWidth) |
||||
x: (parent.width - img.width)/2 |
||||
y: (parent.height - img.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 |
||||
} |
||||
|
||||
MxcAnimatedImage { |
||||
id: mxcimage |
||||
|
||||
visible: loaded |
||||
anchors.fill: parent |
||||
roomm: imageOverlay.room |
||||
play: !Settings.animateImagesOnHover || mouseArea.hovered |
||||
eventId: imageOverlay.eventId |
||||
} |
||||
|
||||
PinchHandler { |
||||
} |
||||
|
||||
WheelHandler { |
||||
property: "scale" |
||||
} |
||||
|
||||
DragHandler { |
||||
} |
||||
|
||||
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: { |
||||
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() |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,102 +0,0 @@ |
||||
// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QApplication> |
||||
#include <QGuiApplication> |
||||
#include <QPainter> |
||||
#include <QScreen> |
||||
|
||||
#include "dialogs/ImageOverlay.h" |
||||
|
||||
#include "Utils.h" |
||||
|
||||
using namespace dialogs; |
||||
|
||||
ImageOverlay::ImageOverlay(const QPixmap &image, QWidget *parent) |
||||
: QWidget{parent} |
||||
, originalImage_{image} |
||||
{ |
||||
setMouseTracking(true); |
||||
setParent(nullptr); |
||||
|
||||
setWindowFlags(windowFlags() | Qt::FramelessWindowHint); |
||||
setWindowRole(QStringLiteral("imageoverlay")); |
||||
|
||||
setAttribute(Qt::WA_NoSystemBackground, true); |
||||
setAttribute(Qt::WA_TranslucentBackground, true); |
||||
setAttribute(Qt::WA_DeleteOnClose, true); |
||||
setWindowState(Qt::WindowFullScreen); |
||||
close_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this); |
||||
|
||||
connect(close_shortcut_, &QShortcut::activated, this, &ImageOverlay::closing); |
||||
connect(this, &ImageOverlay::closing, this, &ImageOverlay::close); |
||||
|
||||
raise(); |
||||
} |
||||
|
||||
void |
||||
ImageOverlay::paintEvent(QPaintEvent *event) |
||||
{ |
||||
Q_UNUSED(event); |
||||
|
||||
QPainter painter(this); |
||||
painter.setRenderHint(QPainter::Antialiasing); |
||||
|
||||
// Full screen overlay.
|
||||
painter.fillRect(QRect(0, 0, width(), height()), QColor(55, 55, 55, 170)); |
||||
|
||||
// Left and Right margins
|
||||
int outer_margin = width() * 0.12; |
||||
int buttonSize = 36; |
||||
int margin = outer_margin * 0.1; |
||||
|
||||
int max_width = width() - 2 * outer_margin; |
||||
int max_height = height(); |
||||
|
||||
image_ = utils::scaleDown(max_width, max_height, originalImage_); |
||||
|
||||
int diff_x = max_width - image_.width(); |
||||
int diff_y = max_height - image_.height(); |
||||
|
||||
content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height()); |
||||
close_button_ = QRect(width() - margin - buttonSize, margin, buttonSize, buttonSize); |
||||
save_button_ = QRect(width() - (2 * margin) - (2 * buttonSize), margin, buttonSize, buttonSize); |
||||
|
||||
// Draw main content_.
|
||||
painter.drawPixmap(content_, image_); |
||||
|
||||
// Draw top right corner X.
|
||||
QPen pen; |
||||
pen.setCapStyle(Qt::RoundCap); |
||||
pen.setWidthF(5); |
||||
pen.setColor("gray"); |
||||
|
||||
auto center = close_button_.center(); |
||||
|
||||
painter.setPen(pen); |
||||
painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15)); |
||||
painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15)); |
||||
|
||||
// Draw download button
|
||||
center = save_button_.center(); |
||||
painter.drawLine(center - QPointF(0, 15), center + QPointF(0, 15)); |
||||
painter.drawLine(center - QPointF(15, 0), center + QPointF(0, 15)); |
||||
painter.drawLine(center + QPointF(0, 15), center + QPointF(15, 0)); |
||||
} |
||||
|
||||
void |
||||
ImageOverlay::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
if (event->button() != Qt::LeftButton) |
||||
return; |
||||
|
||||
if (close_button_.contains(event->pos())) |
||||
emit closing(); |
||||
else if (save_button_.contains(event->pos())) |
||||
emit saving(); |
||||
else if (!content_.contains(event->pos())) |
||||
emit closing(); |
||||
} |
@ -1,39 +0,0 @@ |
||||
// SPDX-FileCopyrightText: 2017 Konstantinos Sideris <siderisk@auth.gr>
|
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QDialog> |
||||
#include <QMouseEvent> |
||||
#include <QPixmap> |
||||
#include <QShortcut> |
||||
|
||||
namespace dialogs { |
||||
|
||||
class ImageOverlay : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
ImageOverlay(const QPixmap &image, QWidget *parent = nullptr); |
||||
|
||||
protected: |
||||
void mousePressEvent(QMouseEvent *event) override; |
||||
void paintEvent(QPaintEvent *event) override; |
||||
|
||||
signals: |
||||
void closing(); |
||||
void saving(); |
||||
|
||||
private: |
||||
QPixmap originalImage_; |
||||
QPixmap image_; |
||||
|
||||
QRect content_; |
||||
QRect close_button_; |
||||
QRect save_button_; |
||||
QShortcut *close_shortcut_; |
||||
}; |
||||
} // dialogs
|
Loading…
Reference in new issue