1 /* ============================================================ 2 * 3 * SPDX-FileCopyrightText: 2007-2012 Kåre Särs <kare.sars@iki .fi> 4 * SPDX-FileCopyrightText: 2009 Arseniy Lartsev <receive-spam at yandex dot ru> 5 * SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks 6 * SPDX-FileCopyrightText: 2018 Alexander Volkov <a.volkov@rusbitech.ru> 7 * 8 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 9 * 10 * ============================================================ */ 11 12 #include "showimagedialog.h" 13 #include "ImageViewer.h" 14 15 #include <QVBoxLayout> 16 #include <QHBoxLayout> 17 #include <QDialogButtonBox> 18 #include <QPushButton> 19 #include <QToolButton> 20 ShowImageDialog(QWidget * parent)21ShowImageDialog::ShowImageDialog(QWidget *parent) 22 : QDialog(parent) 23 { 24 auto *mainLayout = new QVBoxLayout; 25 setLayout(mainLayout); 26 27 m_imageViewer = new ImageViewer; 28 29 auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Discard); 30 connect(buttonBox, &QDialogButtonBox::accepted, this, &ShowImageDialog::saveRequested); 31 connect(buttonBox->button(QDialogButtonBox::Discard), &QPushButton::clicked, this, &QDialog::reject); 32 m_saveButton = buttonBox->button(QDialogButtonBox::Save); 33 34 auto *buttonsLayout = new QHBoxLayout; 35 const auto imageViewerActions = m_imageViewer->actions(); 36 for (auto *action : imageViewerActions) { 37 auto *toolButton = new QToolButton; 38 toolButton->setDefaultAction(action); 39 buttonsLayout->addWidget(toolButton); 40 } 41 buttonsLayout->addWidget(buttonBox); 42 43 mainLayout->addWidget(m_imageViewer); 44 mainLayout->addLayout(buttonsLayout); 45 46 resize(640, 480); 47 } 48 setQImage(QImage * img)49void ShowImageDialog::setQImage(QImage *img) 50 { 51 m_imageViewer->setQImage(img); 52 } 53 zoom2Fit()54void ShowImageDialog::zoom2Fit() 55 { 56 m_imageViewer->zoom2Fit(); 57 } 58 showEvent(QShowEvent * e)59void ShowImageDialog::showEvent(QShowEvent *e) 60 { 61 m_saveButton->setFocus(); 62 QDialog::showEvent(e); 63 } 64