diff --git a/libdialogutil/dialogstatesaver.cpp b/libdialogutil/dialogstatesaver.cpp index 93b2a7d..5021374 100644 --- a/libdialogutil/dialogstatesaver.cpp +++ b/libdialogutil/dialogstatesaver.cpp @@ -1,143 +1,140 @@ /************************************************************************ * * * This file is part of Kooka, a scanning/OCR application using * * Qt and KDE Frameworks . * * * * Copyright (C) 2016 Jonathan Marten * * * * Kooka is free software; you can redistribute it and/or modify it * * under the terms of the GNU Library General Public License as * * published by the Free Software Foundation and appearing in the * * file COPYING included in the packaging of this file; either * * version 2 of the License, or (at your option) any later version. * * * * As a special exception, permission is given to link this program * * with any version of the KADMOS OCR/ICR engine (a product of * * reRecognition GmbH, Kreuzlingen), and distribute the resulting * * executable without including the source code for KADMOS in the * * source distribution. * * * * 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; see the file COPYING. If * * not, see . * * * ************************************************************************/ #include "dialogstatesaver.h" #include -#include -#include +#include +#include #include #include #include static bool sSaveSettings = true; DialogStateSaver::DialogStateSaver(QDialog *pnt) { Q_ASSERT(pnt!=nullptr); mParent = pnt; } static KConfigGroup configGroupFor(QWidget *window) { QString objName = window->objectName(); if (objName.isEmpty()) { objName = window->metaObject()->className(); qWarning() << "object name not set, using class name" << objName; } else qDebug() << "for" << objName << "which is a" << window->metaObject()->className(); return (KSharedConfig::openConfig(QString(), KConfig::NoCascade)->group(objName)); } void DialogStateSaver::restoreConfig() { if (!sSaveSettings) return; // settings not to be restored const KConfigGroup grp = configGroupFor(mParent); this->restoreConfig(mParent, grp); } void DialogStateSaver::restoreConfig(QDialog *dialog, const KConfigGroup &grp) { restoreWindowState(dialog, grp); } void DialogStateSaver::restoreWindowState(QWidget *window) { const KConfigGroup grp = configGroupFor(window); restoreWindowState(window, grp); } void DialogStateSaver::restoreWindowState(QWidget *window, const KConfigGroup &grp) { - // from KDE4 KDialog::restoreDialogSize() - int scnum = QApplication::desktop()->screenNumber(window->parentWidget()); - QRect desk = QApplication::desktop()->screenGeometry(scnum); - int width = window->sizeHint().width(); - int height = window->sizeHint().height(); + // originally from KDE4 KDialog::restoreDialogSize() + const QRect desk = window->parentWidget()->window()->windowHandle()->screen()->geometry(); + const QSize sizeDefault = window->sizeHint(); qDebug() << "from" << grp.name() << "in" << grp.config()->name(); - width = grp.readEntry(QString::fromLatin1("Width %1").arg(desk.width()), width); - height = grp.readEntry(QString::fromLatin1("Height %1").arg(desk.height()), height); + const int width = grp.readEntry(QString::fromLatin1("Width %1").arg(desk.width()), sizeDefault.width()); + const int height = grp.readEntry(QString::fromLatin1("Height %1").arg(desk.height()), sizeDefault.height()); window->resize(width, height); } void DialogStateSaver::saveConfig() const { if (!sSaveSettings) return; // settings not to be saved KConfigGroup grp = configGroupFor(mParent); this->saveConfig(mParent, grp); grp.sync(); } void DialogStateSaver::saveConfig(QDialog *dialog, KConfigGroup &grp) const { saveWindowState(dialog, grp); } void DialogStateSaver::saveWindowState(QWidget *window) { KConfigGroup grp = configGroupFor(window); saveWindowState(window, grp); } void DialogStateSaver::saveWindowState(QWidget *window, KConfigGroup &grp) { - // from KDE4 KDialog::saveDialogSize() - const int scnum = QApplication::desktop()->screenNumber(window->parentWidget()); - QRect desk = QApplication::desktop()->screenGeometry(scnum); + // originally from KDE4 KDialog::saveDialogSize() + const QRect desk = window->parentWidget()->window()->windowHandle()->screen()->geometry(); const QSize sizeToSave = window->size(); qDebug() << "to" << grp.name() << "in" << grp.config()->name(); grp.writeEntry(QString::fromLatin1("Width %1").arg(desk.width()), sizeToSave.width()); grp.writeEntry( QString::fromLatin1("Height %1").arg(desk.height()), sizeToSave.height()); grp.sync(); } void DialogStateSaver::setSaveSettingsDefault(bool on) { sSaveSettings = on; }