File indexing completed on 2024-05-05 04:22:02

0001 /* SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team
0002 
0003    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "MiniViewer.h"
0007 
0008 #include <DB/ImageInfo.h>
0009 
0010 #include <KLocalizedString>
0011 #include <QDialogButtonBox>
0012 #include <QImage>
0013 #include <QLabel>
0014 #include <QLayout>
0015 #include <QPushButton>
0016 #include <QTransform>
0017 
0018 using namespace ImportExport;
0019 
0020 MiniViewer *MiniViewer::s_instance = nullptr;
0021 
0022 void MiniViewer::show(QImage img, DB::ImageInfoPtr info, QWidget *parent)
0023 {
0024     if (!s_instance)
0025         s_instance = new MiniViewer(parent);
0026 
0027     if (info->angle() != 0) {
0028         QTransform matrix;
0029         matrix.rotate(info->angle());
0030         img = img.transformed(matrix);
0031     }
0032     if (img.width() > 800 || img.height() > 600)
0033         img = img.scaled(800, 600, Qt::KeepAspectRatio);
0034 
0035     s_instance->m_pixmap->setPixmap(QPixmap::fromImage(img));
0036     s_instance->QDialog::show();
0037     s_instance->raise();
0038 }
0039 
0040 void MiniViewer::closeEvent(QCloseEvent *)
0041 {
0042     slotClose();
0043 }
0044 
0045 void MiniViewer::slotClose()
0046 {
0047     s_instance = nullptr;
0048     deleteLater();
0049 }
0050 
0051 MiniViewer::MiniViewer(QWidget *parent)
0052     : QDialog(parent)
0053 {
0054     QVBoxLayout *vlay = new QVBoxLayout(this);
0055     m_pixmap = new QLabel(this);
0056     vlay->addWidget(m_pixmap);
0057     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Close, this);
0058     box->button(QDialogButtonBox::Close)->setShortcut(Qt::CTRL | Qt::Key_Return);
0059     connect(box, &QDialogButtonBox::rejected, this, &MiniViewer::slotClose);
0060     vlay->addWidget(box);
0061 }
0062 
0063 // vi:expandtab:tabstop=4 shiftwidth=4:
0064 
0065 #include "moc_MiniViewer.cpp"