diff --git a/core/libs/dplugins/widgets/dplugindialog.cpp b/core/libs/dplugins/widgets/dplugindialog.cpp index 0ef14bd125..bd202c0adf 100644 --- a/core/libs/dplugins/widgets/dplugindialog.cpp +++ b/core/libs/dplugins/widgets/dplugindialog.cpp @@ -1,117 +1,123 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2018-12-31 * Description : digiKam plugin main dialog * * Copyright (C) 2018-2019 by Gilles Caulier * * 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, or (at your option) * any later version. * * 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. * * ============================================================ */ #include "dplugindialog.h" // Qt includes #include -#include -#include #include +#include +#include // KDE includes #include #include // Local includes #include "dxmlguiwindow.h" #include "dpluginaboutdlg.h" #include "dplugin.h" namespace Digikam { DPluginDialog::DPluginDialog(QWidget* const parent, const QString& objName) : QDialog(parent), m_buttons(nullptr), m_tool(nullptr) { setObjectName(objName); setWindowFlags((windowFlags() & ~Qt::Dialog) | Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowMinMaxButtonsHint); m_buttons = new QDialogButtonBox(this); restoreDialogSize(); } DPluginDialog::~DPluginDialog() { saveDialogSize(); } void DPluginDialog::setPlugin(DPlugin* const tool) { m_tool = tool; if (m_tool) { QPushButton* const help = m_buttons->addButton(QDialogButtonBox::Help); help->setText(i18n("About...")); connect(help, SIGNAL(clicked()), this, SLOT(slotAboutPlugin())); } } void DPluginDialog::slotAboutPlugin() { QPointer dlg = new DPluginAboutDlg(m_tool); dlg->exec(); delete dlg; } void DPluginDialog::restoreDialogSize() { KConfig config; KConfigGroup group = config.group(objectName()); if (group.exists()) { winId(); DXmlGuiWindow::restoreWindowSize(windowHandle(), group); resize(windowHandle()->size()); } else { - QDesktopWidget* const desktop = QApplication::desktop(); - int screen = desktop->screenNumber(); - QRect srect = desktop->availableGeometry(screen); + QScreen* screen = QApplication::primaryScreen(); + QWidget* const widget = QApplication::activeWindow(); + + if (widget) + { + screen = widget->windowHandle()->screen(); + } + + QRect srect = screen->availableGeometry(); resize(800 <= srect.width() ? 800 : srect.width(), 750 <= srect.height() ? 750 : srect.height()); } } void DPluginDialog::saveDialogSize() { KConfig config; KConfigGroup group = config.group(objectName()); DXmlGuiWindow::saveWindowSize(windowHandle(), group); config.sync(); } } // namespace Digikam diff --git a/core/libs/dplugins/widgets/dwizarddlg.cpp b/core/libs/dplugins/widgets/dwizarddlg.cpp index ce983cb789..5ec10d3c63 100644 --- a/core/libs/dplugins/widgets/dwizarddlg.cpp +++ b/core/libs/dplugins/widgets/dwizarddlg.cpp @@ -1,109 +1,115 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2009-11-13 * Description : a template to create wizard dialog. * * Copyright (C) 2009-2019 by Gilles Caulier * * 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, or (at your option) any later version. * * 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. * * ============================================================ */ #include "dwizarddlg.h" // Qt includes -#include -#include #include +#include #include +#include // KDE includes #include #include // Local includes #include "dxmlguiwindow.h" #include "dpluginaboutdlg.h" namespace Digikam { DWizardDlg::DWizardDlg(QWidget* const parent, const QString& objName) : QWizard(parent), m_tool(nullptr) { setWizardStyle(QWizard::ClassicStyle); setObjectName(objName); restoreDialogSize(); } DWizardDlg::~DWizardDlg() { saveDialogSize(); } void DWizardDlg::setPlugin(DPlugin* const tool) { m_tool = tool; if (m_tool) { setOption(QWizard::HaveHelpButton); setButtonText(QWizard::HelpButton, i18n("About...")); connect(button(QWizard::HelpButton), SIGNAL(clicked()), this, SLOT(slotAboutPlugin())); } } void DWizardDlg::slotAboutPlugin() { QPointer dlg = new DPluginAboutDlg(m_tool); dlg->exec(); delete dlg; } void DWizardDlg::restoreDialogSize() { KConfig config; KConfigGroup group = config.group(objectName()); if (group.exists()) { winId(); DXmlGuiWindow::restoreWindowSize(windowHandle(), group); resize(windowHandle()->size()); } else { - QDesktopWidget* const desktop = QApplication::desktop(); - int screen = desktop->screenNumber(); - QRect srect = desktop->availableGeometry(screen); + QScreen* screen = QApplication::primaryScreen(); + QWidget* const widget = QApplication::activeWindow(); + + if (widget) + { + screen = widget->windowHandle()->screen(); + } + + QRect srect = screen->availableGeometry(); resize(800 <= srect.width() ? 800 : srect.width(), 750 <= srect.height() ? 750 : srect.height()); } } void DWizardDlg::saveDialogSize() { KConfig config; KConfigGroup group = config.group(objectName()); DXmlGuiWindow::saveWindowSize(windowHandle(), group); config.sync(); } } // namespace Digikam