1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2009-11-13
7 * Description : a template to create wizard dialog.
8 *
9 * Copyright (C) 2009-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * ============================================================ */
22
23 #include "dwizarddlg.h"
24
25 // Qt includes
26
27 #include <QAbstractButton>
28 #include <QApplication>
29 #include <QPointer>
30 #include <QScreen>
31
32 // KDE includes
33
34 #include <klocalizedstring.h>
35 #include <ksharedconfig.h>
36 #include <kconfiggroup.h>
37
38 // Local includes
39
40 #include "dxmlguiwindow.h"
41 #include "dpluginaboutdlg.h"
42
43 namespace Digikam
44 {
45
DWizardDlg(QWidget * const parent,const QString & objName)46 DWizardDlg::DWizardDlg(QWidget* const parent, const QString& objName)
47 : QWizard(parent),
48 m_tool (nullptr)
49 {
50 setWizardStyle(QWizard::ClassicStyle);
51 setObjectName(objName);
52 restoreDialogSize();
53 }
54
~DWizardDlg()55 DWizardDlg::~DWizardDlg()
56 {
57 saveDialogSize();
58 }
59
setPlugin(DPlugin * const tool)60 void DWizardDlg::setPlugin(DPlugin* const tool)
61 {
62 m_tool = tool;
63
64 if (m_tool)
65 {
66 setOption(QWizard::HaveHelpButton);
67 setButtonText(QWizard::HelpButton, i18nc("@action: button", "About..."));
68
69 connect(button(QWizard::HelpButton), SIGNAL(clicked()),
70 this, SLOT(slotAboutPlugin()));
71 }
72 }
73
slotAboutPlugin()74 void DWizardDlg::slotAboutPlugin()
75 {
76 QPointer<DPluginAboutDlg> dlg = new DPluginAboutDlg(m_tool);
77 dlg->exec();
78 delete dlg;
79 }
80
restoreDialogSize()81 void DWizardDlg::restoreDialogSize()
82 {
83 KSharedConfigPtr config = KSharedConfig::openConfig();
84 KConfigGroup group = config->group(objectName());
85
86 if (group.exists())
87 {
88 winId();
89 DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
90 resize(windowHandle()->size());
91 }
92 else
93 {
94 QScreen* screen = qApp->primaryScreen();
95
96 if (QWidget* const widget = qApp->activeWindow())
97 {
98 if (QWindow* const window = widget->windowHandle())
99 {
100 screen = window->screen();
101 }
102 }
103
104 QRect srect = screen->availableGeometry();
105 resize(800 <= srect.width() ? 800 : srect.width(),
106 750 <= srect.height() ? 750 : srect.height());
107 }
108 }
109
saveDialogSize()110 void DWizardDlg::saveDialogSize()
111 {
112 KSharedConfigPtr config = KSharedConfig::openConfig();
113 KConfigGroup group = config->group(objectName());
114 DXmlGuiWindow::saveWindowSize(windowHandle(), group);
115 config->sync();
116 }
117
118 } // namespace Digikam
119