2017-04-30 01:55:10 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-08-06 10:35:32 +03:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2019-07-05 04:20:19 +03:00
|
|
|
#include <QGuiApplication>
|
2017-04-30 01:55:10 +03:00
|
|
|
#include <QPainter>
|
2019-07-05 04:20:19 +03:00
|
|
|
#include <QScreen>
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-11-30 21:02:46 +03:00
|
|
|
#include "dialogs/ImageOverlay.h"
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "Utils.h"
|
|
|
|
|
2017-11-30 21:02:46 +03:00
|
|
|
using namespace dialogs;
|
|
|
|
|
|
|
|
ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
: QWidget{parent}
|
|
|
|
, originalImage_{image}
|
2017-04-30 01:55:10 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
setMouseTracking(true);
|
2020-02-04 06:58:43 +03:00
|
|
|
setParent(nullptr);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground, true);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
setWindowState(Qt::WindowFullScreen);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
connect(this, SIGNAL(closing()), this, SLOT(close()));
|
2017-05-04 13:11:04 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
raise();
|
2017-04-30 01:55:10 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2017-11-30 21:02:46 +03:00
|
|
|
ImageOverlay::paintEvent(QPaintEvent *event)
|
2017-04-30 01:55:10 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_UNUSED(event);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Full screen overlay.
|
2020-02-13 17:11:15 +03:00
|
|
|
painter.fillRect(QRect(0, 0, width(), height()), QColor(55, 55, 55, 170));
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Left and Right margins
|
2020-02-13 17:11:15 +03:00
|
|
|
int outer_margin = width() * 0.12;
|
2017-09-10 12:59:21 +03:00
|
|
|
int buttonSize = 36;
|
|
|
|
int margin = outer_margin * 0.1;
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2020-02-13 17:11:15 +03:00
|
|
|
int max_width = width() - 2 * outer_margin;
|
|
|
|
int max_height = height();
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2018-08-01 21:10:03 +03:00
|
|
|
image_ = utils::scaleDown(max_width, max_height, originalImage_);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
int diff_x = max_width - image_.width();
|
|
|
|
int diff_y = max_height - image_.height();
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height());
|
2020-02-13 17:11:15 +03:00
|
|
|
close_button_ = QRect(width() - margin - buttonSize, margin, buttonSize, buttonSize);
|
2019-01-31 02:01:36 +03:00
|
|
|
save_button_ =
|
2020-02-13 17:11:15 +03:00
|
|
|
QRect(width() - (2 * margin) - (2 * buttonSize), margin, buttonSize, buttonSize);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Draw main content_.
|
|
|
|
painter.drawPixmap(content_, image_);
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
// Draw top right corner X.
|
|
|
|
QPen pen;
|
|
|
|
pen.setCapStyle(Qt::RoundCap);
|
|
|
|
pen.setWidthF(5);
|
|
|
|
pen.setColor("gray");
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
auto center = close_button_.center();
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
painter.setPen(pen);
|
|
|
|
painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15));
|
|
|
|
painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15));
|
2019-01-31 02:01:36 +03:00
|
|
|
|
|
|
|
// 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));
|
2017-04-30 01:55:10 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
2017-11-30 21:02:46 +03:00
|
|
|
ImageOverlay::mousePressEvent(QMouseEvent *event)
|
2017-04-30 01:55:10 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (event->button() != Qt::LeftButton)
|
|
|
|
return;
|
2017-04-30 01:55:10 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (close_button_.contains(event->pos()))
|
|
|
|
emit closing();
|
2019-01-31 02:01:36 +03:00
|
|
|
else if (save_button_.contains(event->pos()))
|
|
|
|
emit saving();
|
2017-09-10 12:59:21 +03:00
|
|
|
else if (!content_.contains(event->pos()))
|
|
|
|
emit closing();
|
2017-04-30 01:55:10 +03:00
|
|
|
}
|