File indexing completed on 2024-05-12 03:54:29
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 * Returns whether a given KConfig group has any saved window size data. 0037 * 0038 * @param config The config group to read from. 0039 * @since 6.0 0040 */ 0041 KCONFIGGUI_EXPORT bool hasSavedWindowSize(KConfigGroup &config); 0042 0043 /** 0044 * Restores the dialog's size from the configuration according to 0045 * the screen size. 0046 * 0047 * If you're calling this from a constructor (for a mainwindow or dialog, for instance) 0048 * you should first call winId() so that a QWindow is created, then you can call windowHandle() 0049 * to pass to this method. 0050 * 0051 * Example code: 0052 * @code 0053 * create(); // ensure there's a window created 0054 * const QSize availableSize = windowHandle()->screen()->availableSize(); 0055 * windowHandle()->resize(availableSize.width() * 0.7, availableSize.height() * 0.5); // default size 0056 * KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("MyDialog")); 0057 * resize(windowHandle()->size()); // workaround for QTBUG-40584 0058 * @endcode 0059 * 0060 * @note the group must be set before calling 0061 * 0062 * @param window The window to restore size. 0063 * @param config The config group to read from. 0064 * @since 5.0. 0065 */ 0066 KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config); 0067 0068 /** 0069 * Saves the window's position either to the global or application config file. 0070 * This function has no effect on Wayland, where the compositor is responsible 0071 * for window positioning. 0072 * 0073 * @note the group must be set before calling 0074 * 0075 * @param window The window whose position to save. 0076 * @param config The config group to read from. 0077 * @param options passed to KConfigGroup::writeEntry() 0078 * @since 5.74 0079 */ 0080 KCONFIGGUI_EXPORT void saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal); 0081 0082 /** 0083 * Returns whether a given KConfig group has any saved window position data. 0084 * 0085 * @note: always returns false on Wayland where saving and restoring window 0086 * position data is not supported. 0087 * 0088 * @param config The config group to read from. 0089 * @since 6.0 0090 */ 0091 KCONFIGGUI_EXPORT bool hasSavedWindowPosition(KConfigGroup &config); 0092 /** 0093 * Restores the window's screen position from the configuration and calls restoreWindowScreenPosition. 0094 * This function has no effect on Wayland, where the compositor is responsible 0095 * for window positioning. 0096 * 0097 * @note the group must be set before calling 0098 * 0099 * @param window The window whose position to restore. 0100 * @param config The config group to read from. 0101 * @since 5.74 0102 */ 0103 KCONFIGGUI_EXPORT void restoreWindowPosition(QWindow *window, const KConfigGroup &config); 0104 0105 /** 0106 * Restores the window's position on provided screen from the configuration. 0107 * This function has no effect on Wayland, where the compositor is responsible 0108 * for window positioning. 0109 * 0110 * @note the group must be set before calling 0111 * 0112 * @param window The window whose position to restore. 0113 * @param screen Screen on which window should be placed. 0114 * @param config The config group to read from. 0115 * @since 5.99 0116 */ 0117 KCONFIGGUI_EXPORT void restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config); 0118 } 0119 #endif // KWINDOWCONFIG_H