File indexing completed on 2024-05-05 05:44:47

0001 /***************************************************************************
0002  *   Copyright (C) 2016 Christian Ehrlicher <ch.ehrlicher@gmx.de>          *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #include "windowgeometryhelper.h"
0021 #include "settings/kdesvnsettings.h"
0022 
0023 #include <KConfig>
0024 #include <KConfigGroup>
0025 #include <KWindowConfig>
0026 #include <QWidget>
0027 #include <QWindow>
0028 
0029 WindowGeometryHelper::WindowGeometryHelper(QWidget *w, const QString &groupName)
0030     : m_widget(w)
0031     , m_config(Kdesvnsettings::self()->config())
0032     , m_groupName(groupName)
0033 {
0034     restore();
0035 }
0036 
0037 void WindowGeometryHelper::restore(QWidget *w, const QString &groupName)
0038 {
0039     KConfigGroup kcg(Kdesvnsettings::self()->config(), groupName);
0040     KWindowConfig::restoreWindowSize(w->windowHandle(), kcg);
0041     w->resize(w->windowHandle()->size()); // needed, see https://git.reviewboard.kde.org/r/119594/
0042 }
0043 
0044 void WindowGeometryHelper::save(QWidget *w, const QString &groupName)
0045 {
0046     KConfigGroup kcg(Kdesvnsettings::self()->config(), groupName);
0047     KWindowConfig::saveWindowSize(w->windowHandle(), kcg);
0048 }
0049 
0050 void WindowGeometryHelper::restore()
0051 {
0052     if (!m_widget) {
0053         return;
0054     }
0055     KConfigGroup kcg(m_config, m_groupName);
0056     KWindowConfig::restoreWindowSize(m_widget->windowHandle(), kcg);
0057     m_widget->resize(m_widget->windowHandle()->size()); // needed, see https://git.reviewboard.kde.org/r/119594/
0058 }
0059 
0060 void WindowGeometryHelper::save()
0061 {
0062     if (!m_widget) {
0063         return;
0064     }
0065     KConfigGroup kcg(m_config, m_groupName);
0066     KWindowConfig::saveWindowSize(m_widget->windowHandle(), kcg);
0067 }