File indexing completed on 2024-05-12 04:34:49

0001 /* ============================================================
0002 *
0003 * SPDX-FileCopyrightText: 2007-2012 Kåre Särs <kare.sars@iki .fi>
0004 * SPDX-FileCopyrightText: 2009 Arseniy Lartsev <receive-spam at yandex dot ru>
0005 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
0006 * SPDX-FileCopyrightText: 2018 Alexander Volkov <a.volkov@rusbitech.ru>
0007 *
0008 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0009 *
0010 * ============================================================ */
0011 
0012 #include "showimagedialog.h"
0013 #include "ImageViewer.h"
0014 
0015 #include <QVBoxLayout>
0016 #include <QHBoxLayout>
0017 #include <QDialogButtonBox>
0018 #include <QPushButton>
0019 #include <QToolButton>
0020 
0021 ShowImageDialog::ShowImageDialog(QWidget *parent)
0022     : QDialog(parent)
0023 {
0024     auto *mainLayout = new QVBoxLayout;
0025     setLayout(mainLayout);
0026 
0027     m_imageViewer = new ImageViewer;
0028 
0029     auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Discard);
0030     connect(buttonBox, &QDialogButtonBox::accepted, this, &ShowImageDialog::saveRequested);
0031     connect(buttonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, this, &QDialog::reject);
0032     m_saveButton = buttonBox->button(QDialogButtonBox::Save);
0033 
0034     auto *buttonsLayout = new QHBoxLayout;
0035     const auto imageViewerActions = m_imageViewer->actions();
0036     for (auto *action : imageViewerActions) {
0037         auto *toolButton = new QToolButton;
0038         toolButton->setDefaultAction(action);
0039         buttonsLayout->addWidget(toolButton);
0040     }
0041     buttonsLayout->addWidget(buttonBox);
0042 
0043     mainLayout->addWidget(m_imageViewer);
0044     mainLayout->addLayout(buttonsLayout);
0045 
0046     resize(640, 480);
0047 }
0048 
0049 void ShowImageDialog::setQImage(QImage *img)
0050 {
0051     m_imageViewer->setQImage(img);
0052 }
0053 
0054 void ShowImageDialog::zoom2Fit()
0055 {
0056     m_imageViewer->zoom2Fit();
0057 }
0058 
0059 void ShowImageDialog::showEvent(QShowEvent *e)
0060 {
0061     m_saveButton->setFocus();
0062     QDialog::showEvent(e);
0063 }
0064 
0065 #include "moc_showimagedialog.cpp"