2016-04-12 21:53:21 +02:00
|
|
|
/*****************************************************************************
|
2018-05-24 22:32:00 +02:00
|
|
|
* gta5view Grand Theft Auto V Profile Viewer
|
2020-11-25 00:36:12 +01:00
|
|
|
* Copyright (C) 2016-2020 Syping
|
2016-04-12 21:53:21 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-04-24 12:47:14 +02:00
|
|
|
#include "PictureDialog.h"
|
2016-04-12 21:53:21 +02:00
|
|
|
#include "PictureWidget.h"
|
|
|
|
#include "UiModLabel.h"
|
2020-11-25 00:36:12 +01:00
|
|
|
#include "AppEnv.h"
|
2016-11-20 10:41:21 +01:00
|
|
|
#include <QApplication>
|
2016-04-12 21:53:21 +02:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QEvent>
|
2020-09-28 05:33:04 +02:00
|
|
|
|
2016-04-12 21:53:21 +02:00
|
|
|
PictureWidget::PictureWidget(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
installEventFilter(this);
|
|
|
|
|
|
|
|
widgetLayout = new QHBoxLayout(this);
|
|
|
|
widgetLayout->setSpacing(0);
|
|
|
|
widgetLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
pictureLabel = new UiModLabel(this);
|
2016-04-24 12:47:14 +02:00
|
|
|
pictureLabel->setObjectName("pictureLabel");
|
2016-04-12 21:53:21 +02:00
|
|
|
pictureLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2016-04-24 12:47:14 +02:00
|
|
|
pictureLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
2016-04-12 21:53:21 +02:00
|
|
|
pictureLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
widgetLayout->addWidget(pictureLabel);
|
|
|
|
|
2016-04-24 12:47:14 +02:00
|
|
|
QObject::connect(pictureLabel, SIGNAL(mouseDoubleClicked(Qt::MouseButton)), this, SLOT(pictureDoubleClicked(Qt::MouseButton)));
|
|
|
|
QObject::connect(pictureLabel, SIGNAL(customContextMenuRequested(QPoint)), parent, SLOT(exportCustomContextMenuRequested(QPoint)));
|
2016-04-12 21:53:21 +02:00
|
|
|
|
|
|
|
setLayout(widgetLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
PictureWidget::~PictureWidget()
|
|
|
|
{
|
|
|
|
widgetLayout->removeWidget(pictureLabel);
|
|
|
|
delete pictureLabel;
|
|
|
|
delete widgetLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PictureWidget::eventFilter(QObject *obj, QEvent *ev)
|
|
|
|
{
|
2020-11-25 00:36:12 +01:00
|
|
|
if (obj == this) {
|
|
|
|
if (ev->type() == QEvent::KeyPress) {
|
2016-04-12 21:53:21 +02:00
|
|
|
QKeyEvent *keyEvent = (QKeyEvent*)ev;
|
2020-11-25 00:36:12 +01:00
|
|
|
switch (keyEvent->key()) {
|
2016-04-12 21:53:21 +02:00
|
|
|
case Qt::Key_Left:
|
|
|
|
emit previousPictureRequested();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Right:
|
|
|
|
emit nextPictureRequested();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:47:14 +02:00
|
|
|
void PictureWidget::pictureDoubleClicked(Qt::MouseButton button)
|
|
|
|
{
|
2020-11-25 00:36:12 +01:00
|
|
|
if (button == Qt::LeftButton) {
|
2016-04-24 12:47:14 +02:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 10:41:21 +01:00
|
|
|
void PictureWidget::setImage(QImage image_, QRect rec)
|
2016-04-12 21:53:21 +02:00
|
|
|
{
|
2020-11-25 00:36:12 +01:00
|
|
|
const qreal screenRatioPR = AppEnv::screenRatioPR();
|
2016-11-20 10:41:21 +01:00
|
|
|
image = image_;
|
2020-11-25 00:36:12 +01:00
|
|
|
QPixmap pixmap = QPixmap::fromImage(image.scaled(rec.width() * screenRatioPR, rec.height() * screenRatioPR, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
#if QT_VERSION >= 0x050600
|
|
|
|
pixmap.setDevicePixelRatio(AppEnv::screenRatioPR());
|
|
|
|
#endif
|
|
|
|
pictureLabel->setPixmap(pixmap);
|
2016-04-12 21:53:21 +02:00
|
|
|
}
|
|
|
|
|
2016-11-20 10:41:21 +01:00
|
|
|
void PictureWidget::setImage(QImage image_)
|
2016-04-12 21:53:21 +02:00
|
|
|
{
|
2020-11-25 00:36:12 +01:00
|
|
|
const qreal screenRatioPR = AppEnv::screenRatioPR();
|
2016-11-20 10:41:21 +01:00
|
|
|
image = image_;
|
2020-11-25 00:36:12 +01:00
|
|
|
QPixmap pixmap = QPixmap::fromImage(image.scaled(geometry().width() * screenRatioPR, geometry().height() * screenRatioPR, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
#if QT_VERSION >= 0x050600
|
|
|
|
pixmap.setDevicePixelRatio(screenRatioPR);
|
|
|
|
#endif
|
|
|
|
pictureLabel->setPixmap(pixmap);
|
2016-04-12 21:53:21 +02:00
|
|
|
}
|