File indexing completed on 2025-01-19 03:55:43
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-11-13 0007 * Description : a template to create wizard dialog. 0008 * 0009 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dwizarddlg.h" 0016 0017 // Qt includes 0018 0019 #include <QAbstractButton> 0020 #include <QApplication> 0021 #include <QPointer> 0022 #include <QScreen> 0023 #include <QPushButton> 0024 #include <QMenu> 0025 #include <QAction> 0026 #include <QIcon> 0027 0028 // KDE includes 0029 0030 #include <klocalizedstring.h> 0031 #include <ksharedconfig.h> 0032 #include <kconfiggroup.h> 0033 0034 // Local includes 0035 0036 #include "digikam_globals.h" 0037 #include "dxmlguiwindow.h" 0038 #include "dpluginaboutdlg.h" 0039 0040 namespace Digikam 0041 { 0042 0043 DWizardDlg::DWizardDlg(QWidget* const parent, const QString& objName) 0044 : QWizard(parent), 0045 m_tool (nullptr) 0046 { 0047 setWizardStyle(QWizard::ClassicStyle); 0048 setObjectName(objName); 0049 restoreDialogSize(); 0050 } 0051 0052 DWizardDlg::~DWizardDlg() 0053 { 0054 saveDialogSize(); 0055 } 0056 0057 void DWizardDlg::setPlugin(DPlugin* const tool) 0058 { 0059 m_tool = tool; 0060 0061 if (m_tool) 0062 { 0063 setOption(QWizard::HaveHelpButton); 0064 setButtonText(QWizard::HelpButton, i18nc("@action:button", "Help")); 0065 0066 QPushButton* const help = reinterpret_cast<QPushButton*>(button(QWizard::HelpButton)); 0067 help->setIcon(QIcon::fromTheme(QLatin1String("help-browser"))); 0068 QMenu* const menu = new QMenu(help); 0069 QAction* const handbookAction = menu->addAction(QIcon::fromTheme(QLatin1String("globe")), i18n("Online Handbook...")); 0070 QAction* const aboutAction = menu->addAction(QIcon::fromTheme(QLatin1String("help-about")), i18n("About...")); 0071 help->setMenu(menu); 0072 0073 connect(handbookAction, SIGNAL(triggered()), 0074 this, SLOT(slotOnlineHandbook())); 0075 0076 connect(aboutAction, SIGNAL(triggered()), 0077 this, SLOT(slotAboutPlugin())); 0078 } 0079 } 0080 0081 void DWizardDlg::slotAboutPlugin() 0082 { 0083 QPointer<DPluginAboutDlg> dlg = new DPluginAboutDlg(m_tool); 0084 dlg->exec(); 0085 delete dlg; 0086 } 0087 0088 void DWizardDlg::slotOnlineHandbook() 0089 { 0090 openOnlineDocumentation(m_tool->handbookSection(), m_tool->handbookChapter(), m_tool->handbookReference()); 0091 } 0092 0093 void DWizardDlg::restoreDialogSize() 0094 { 0095 KSharedConfigPtr config = KSharedConfig::openConfig(); 0096 KConfigGroup group = config->group(objectName()); 0097 0098 if (group.exists()) 0099 { 0100 winId(); 0101 DXmlGuiWindow::restoreWindowSize(windowHandle(), group); 0102 resize(windowHandle()->size()); 0103 } 0104 else 0105 { 0106 QScreen* screen = qApp->primaryScreen(); 0107 0108 if (QWidget* const widget = qApp->activeWindow()) 0109 { 0110 if (QWindow* const window = widget->windowHandle()) 0111 { 0112 screen = window->screen(); 0113 } 0114 } 0115 0116 QRect srect = screen->availableGeometry(); 0117 resize(800 <= srect.width() ? 800 : srect.width(), 0118 750 <= srect.height() ? 750 : srect.height()); 0119 } 0120 } 0121 0122 void DWizardDlg::saveDialogSize() 0123 { 0124 KSharedConfigPtr config = KSharedConfig::openConfig(); 0125 KConfigGroup group = config->group(objectName()); 0126 DXmlGuiWindow::saveWindowSize(windowHandle(), group); 0127 config->sync(); 0128 } 0129 0130 } // namespace Digikam 0131 0132 #include "moc_dwizarddlg.cpp"