File indexing completed on 2024-05-12 15:34:14

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2012 Benjamin Port <benjamin.port@ben2367.fr>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef KWINDOWCONFIG_H
0009 #define KWINDOWCONFIG_H
0010 
0011 #include <kconfiggroup.h>
0012 #include <kconfiggui_export.h>
0013 
0014 class QWindow;
0015 class QScreen;
0016 
0017 /**
0018  * Save and load window sizes into a config
0019  */
0020 namespace KWindowConfig
0021 {
0022 /**
0023  * Saves the window's size dependent on the screen dimension either to the
0024  * global or application config file.
0025  *
0026  * @note the group must be set before calling
0027  *
0028  * @param window The window to save size.
0029  * @param config The config group to read from.
0030  * @param options passed to KConfigGroup::writeEntry()
0031  * @since 5.0
0032  */
0033 KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
0034 
0035 /**
0036  * Restores the dialog's size from the configuration according to
0037  * the screen size.
0038  *
0039  * If you're calling this from a constructor (for a mainwindow or dialog, for instance)
0040  * you should first call winId() so that a QWindow is created, then you can call windowHandle()
0041  * to pass to this method.
0042  *
0043  * Example code:
0044  * @code
0045  *   create(); // ensure there's a window created
0046  *   const QSize availableSize = windowHandle()->screen()->availableSize();
0047  *   windowHandle()->resize(availableSize.width() * 0.7, availableSize.height() * 0.5); // default size
0048  *   KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("MyDialog"));
0049  *   resize(windowHandle()->size()); // workaround for QTBUG-40584
0050  * @endcode
0051  *
0052  * @note the group must be set before calling
0053  *
0054  * @param window The window to restore size.
0055  * @param config The config group to read from.
0056  * @since 5.0.
0057  */
0058 KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config);
0059 
0060 /**
0061  * Saves the window's position either to the global or application config file.
0062  * This function has no effect on Wayland, where the compositor is responsible
0063  * for window positioning.
0064  *
0065  * @note the group must be set before calling
0066  *
0067  * @param window The window whose position to save.
0068  * @param config The config group to read from.
0069  * @param options passed to KConfigGroup::writeEntry()
0070  * @since 5.74
0071  */
0072 KCONFIGGUI_EXPORT void saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
0073 
0074 /**
0075  * Restores the window's screen position from the configuration and calls restoreWindowScreenPosition.
0076  * This function has no effect on Wayland, where the compositor is responsible
0077  * for window positioning.
0078  *
0079  * @note the group must be set before calling
0080  *
0081  * @param window The window whose position to restore.
0082  * @param config The config group to read from.
0083  * @since 5.74
0084  */
0085 KCONFIGGUI_EXPORT void restoreWindowPosition(QWindow *window, const KConfigGroup &config);
0086 
0087 /**
0088  * Restores the window's position on provided screen from the configuration.
0089  * This function has no effect on Wayland, where the compositor is responsible
0090  * for window positioning.
0091  *
0092  * @note the group must be set before calling
0093  *
0094  * @param window The window whose position to restore.
0095  * @param screen Screen on which window should be placed.
0096  * @param config The config group to read from.
0097  * @since 5.99
0098  */
0099 KCONFIGGUI_EXPORT void restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config);
0100 }
0101 #endif // KWINDOWCONFIG_H