diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -set(skanlite_SRCS main.cpp skanlite.cpp ImageViewer.cpp KSaneImageSaver.cpp SaveLocation.cpp DBusInterface.cpp) +set(skanlite_SRCS main.cpp skanlite.cpp ImageViewer.cpp showimagedialog.cpp KSaneImageSaver.cpp SaveLocation.cpp DBusInterface.cpp) ki18n_wrap_ui(skanlite_SRCS settings.ui SaveLocation.ui) diff --git a/src/showimagedialog.h b/src/showimagedialog.h new file mode 100644 --- /dev/null +++ b/src/showimagedialog.h @@ -0,0 +1,55 @@ +/* ============================================================ +* +* Copyright (C) 2007-2012 by Kåre Särs +* Copyright (C) 2009 by Arseniy Lartsev +* Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks +* Copyright (C) 2018 by Alexander Volkov +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 +* +* ============================================================ */ + +#ifndef SHOWIMAGEDIALOG_H +#define SHOWIMAGEDIALOG_H + +#include + +class ImageViewer; + +class ShowImageDialog : public QDialog +{ + Q_OBJECT +public: + explicit ShowImageDialog(QWidget *parent = nullptr); + + void setQImage(QImage *img); + +public Q_SLOTS: + void zoom2Fit(); + +Q_SIGNALS: + void saveRequested(); + +protected: + void showEvent(QShowEvent *e) override; + +private: + QPushButton *m_saveButton = nullptr; + ImageViewer *m_imageViewer = nullptr; +}; + +#endif // SHOWIMAGEDIALOG_H diff --git a/src/showimagedialog.cpp b/src/showimagedialog.cpp new file mode 100644 --- /dev/null +++ b/src/showimagedialog.cpp @@ -0,0 +1,66 @@ +/* ============================================================ +* +* Copyright (C) 2007-2012 by Kåre Särs +* Copyright (C) 2009 by Arseniy Lartsev +* Copyright (C) 2014 by Gregor Mitsch: port to KDE5 frameworks +* Copyright (C) 2018 by Alexander Volkov +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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 +* +* ============================================================ */ + +#include "showimagedialog.h" +#include "ImageViewer.h" + +#include +#include +#include + +ShowImageDialog::ShowImageDialog(QWidget *parent) + : QDialog(parent) +{ + auto *mainLayout = new QVBoxLayout; + setLayout(mainLayout); + + m_imageViewer = new ImageViewer; + + auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Discard); + connect(buttonBox, &QDialogButtonBox::accepted, this, &ShowImageDialog::saveRequested); + connect(buttonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, this, &QDialog::reject); + m_saveButton = buttonBox->button(QDialogButtonBox::Save); + + mainLayout->addWidget(m_imageViewer); + mainLayout->addWidget(buttonBox); + + resize(640, 480); +} + +void ShowImageDialog::setQImage(QImage *img) +{ + m_imageViewer->setQImage(img); +} + +void ShowImageDialog::zoom2Fit() +{ + m_imageViewer->zoom2Fit(); +} + +void ShowImageDialog::showEvent(QShowEvent *e) +{ + m_saveButton->setFocus(); + QDialog::showEvent(e); +} diff --git a/src/skanlite.h b/src/skanlite.h --- a/src/skanlite.h +++ b/src/skanlite.h @@ -30,9 +30,9 @@ #include #include "ui_settings.h" -#include "ImageViewer.h" #include "DBusInterface.h" +class ShowImageDialog; class SaveLocation; class KAboutData; @@ -95,9 +95,7 @@ KSaneWidget *m_ksanew = nullptr; Ui::SkanliteSettings m_settingsUi; QDialog *m_settingsDialog = nullptr; - QDialog *m_showImgDialog = nullptr; - // having this variable here is not so nice; ShowImgageDialog should be separate class - QPushButton *m_showImgDialogSaveButton = nullptr; + ShowImageDialog *m_showImgDialog = nullptr; SaveLocation *m_saveLocation = nullptr; QString m_deviceName; QMap m_defaultScanOpts; @@ -108,7 +106,6 @@ int m_bytesPerLine; int m_format; - ImageViewer m_imageViewer; DBusInterface m_dbusInterface; QStringList m_filterList; QStringList m_filter16BitList; diff --git a/src/skanlite.cpp b/src/skanlite.cpp --- a/src/skanlite.cpp +++ b/src/skanlite.cpp @@ -26,6 +26,7 @@ #include "KSaneImageSaver.h" #include "SaveLocation.h" +#include "showimagedialog.h" #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include @@ -189,27 +191,9 @@ } // prepare the Show Image Dialog - { - m_showImgDialog = new QDialog(this); - - QVBoxLayout *mainLayout = new QVBoxLayout(m_showImgDialog); - - QDialogButtonBox *imgButtonBox = new QDialogButtonBox(m_showImgDialog); - // "Close" (now Discard) and "User1"=Save - imgButtonBox->setStandardButtons(QDialogButtonBox::Discard | QDialogButtonBox::Save); - - mainLayout->addWidget(&m_imageViewer); - mainLayout->addWidget(imgButtonBox); - - m_showImgDialogSaveButton = imgButtonBox->button(QDialogButtonBox::Save); - m_showImgDialogSaveButton->setDefault(true); // still needed? - - m_showImgDialog->resize(640, 480); - connect(imgButtonBox, &QDialogButtonBox::accepted, this, &Skanlite::saveImage); - //connect(imgButtonBox, &QDialogButtonBox::accepted, m_showImgDialog, &QDialog::accept); - connect(imgButtonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, m_ksanew, &KSaneWidget::scanCancel); - connect(imgButtonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, m_showImgDialog, &QDialog::reject); - } + m_showImgDialog = new ShowImageDialog(this); + connect(m_showImgDialog, &ShowImageDialog::saveRequested, this, &Skanlite::saveImage); + connect(m_showImgDialog, &ShowImageDialog::rejected, m_ksanew, &KSaneWidget::scanCancel); // save the default sane options for later use m_ksanew->getOptVals(m_defaultScanOpts); @@ -376,9 +360,8 @@ if (m_settingsUi.showB4Save->isChecked() == true) { /* copy the image data into m_img and show it*/ m_img = m_ksanew->toQImageSilent(data, w, h, bpl, (KSaneIface::KSaneWidget::ImageFormat)f); - m_imageViewer.setQImage(&m_img); - m_imageViewer.zoom2Fit(); - m_showImgDialogSaveButton->setFocus(); + m_showImgDialog->setQImage(&m_img); + m_showImgDialog->zoom2Fit(); m_showImgDialog->exec(); // save has been done as a result of save or then we got cancel }