2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* imageviewer_moc.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2014-03-23 15:08:01 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
|
2022-05-28 15:32:20 +02:00
|
|
|
#include <QGuiApplication>
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2014-03-29 15:46:41 +03:00
|
|
|
#include "imageviewer_moc.h"
|
|
|
|
#include "ui_imageviewer_moc.h"
|
2014-03-23 15:08:01 +03:00
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
ImageViewer::ImageViewer(QWidget * parent)
|
|
|
|
: QDialog(parent), ui(new Ui::ImageViewer)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
2022-12-25 13:19:16 +02:00
|
|
|
void ImageViewer::changeEvent(QEvent *event)
|
|
|
|
{
|
2022-12-29 16:37:38 +02:00
|
|
|
if(event->type() == QEvent::LanguageChange)
|
2022-12-25 13:19:16 +02:00
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
2022-12-28 17:58:39 +02:00
|
|
|
QDialog::changeEvent(event);
|
2022-12-25 13:19:16 +02:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:01 +03:00
|
|
|
ImageViewer::~ImageViewer()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize ImageViewer::calculateWindowSize()
|
|
|
|
{
|
2022-05-28 15:32:20 +02:00
|
|
|
return QGuiApplication::primaryScreen()->availableGeometry().size() * 0.8;
|
2014-03-23 15:08:01 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void ImageViewer::showPixmap(QPixmap & pixmap, QWidget * parent)
|
2014-03-23 15:08:01 +03:00
|
|
|
{
|
|
|
|
assert(!pixmap.isNull());
|
|
|
|
|
|
|
|
ImageViewer * iw = new ImageViewer(parent);
|
|
|
|
|
|
|
|
QSize size = pixmap.size();
|
|
|
|
size.scale(iw->calculateWindowSize(), Qt::KeepAspectRatio);
|
|
|
|
iw->resize(size);
|
|
|
|
|
|
|
|
iw->setPixmap(pixmap);
|
|
|
|
iw->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
iw->setModal(Qt::WindowModal);
|
|
|
|
iw->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageViewer::setPixmap(QPixmap & pixmap)
|
|
|
|
{
|
|
|
|
ui->label->setPixmap(pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageViewer::mousePressEvent(QMouseEvent * event)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageViewer::keyPressEvent(QKeyEvent * event)
|
|
|
|
{
|
|
|
|
close(); // FIXME: it also closes on pressing modifiers (e.g. Ctrl/Alt). Not exactly expected
|
|
|
|
}
|