1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2012 Benjamin Port <benjamin.port@ben2367.fr>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef KWINDOWCONFIG_H
9#define KWINDOWCONFIG_H
10
11#include <kconfiggroup.h>
12#include <kconfiggui_export.h>
13
14class QWindow;
15class QScreen;
16
17/**
18 * Save and load window sizes into a config
19 */
20namespace KWindowConfig
21{
22/**
23 * Saves the window's size dependent on the screen dimension either to the
24 * global or application config file.
25 *
26 * @note the group must be set before calling
27 *
28 * @param window The window to save size.
29 * @param config The config group to read from.
30 * @param options passed to KConfigGroup::writeEntry()
31 * @since 5.0
32 */
33KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
34
35/**
36 * Returns whether a given KConfig group has any saved window size data.
37 *
38 * @param config The config group to read from.
39 * @since 6.0
40 */
41KCONFIGGUI_EXPORT bool hasSavedWindowSize(KConfigGroup &config);
42
43/**
44 * Restores the dialog's size from the configuration according to
45 * the screen size.
46 *
47 * If you're calling this from a constructor (for a mainwindow or dialog, for instance)
48 * you should first call winId() so that a QWindow is created, then you can call windowHandle()
49 * to pass to this method.
50 *
51 * Example code:
52 * @code
53 * create(); // ensure there's a window created
54 * const QSize availableSize = windowHandle()->screen()->availableSize();
55 * windowHandle()->resize(availableSize.width() * 0.7, availableSize.height() * 0.5); // default size
56 * KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("MyDialog"));
57 * resize(windowHandle()->size()); // workaround for QTBUG-40584
58 * @endcode
59 *
60 * @note the group must be set before calling
61 *
62 * @param window The window to restore size.
63 * @param config The config group to read from.
64 * @since 5.0.
65 */
66KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config);
67
68/**
69 * Saves the window's position either to the global or application config file.
70 * This function has no effect on Wayland, where the compositor is responsible
71 * for window positioning.
72 *
73 * @note the group must be set before calling
74 *
75 * @param window The window whose position to save.
76 * @param config The config group to read from.
77 * @param options passed to KConfigGroup::writeEntry()
78 * @since 5.74
79 */
80KCONFIGGUI_EXPORT void saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
81
82/**
83 * Returns whether a given KConfig group has any saved window position data.
84 *
85 * @note: always returns false on Wayland where saving and restoring window
86 * position data is not supported.
87 *
88 * @param config The config group to read from.
89 * @since 6.0
90 */
91KCONFIGGUI_EXPORT bool hasSavedWindowPosition(KConfigGroup &config);
92/**
93 * Restores the window's screen position from the configuration and calls restoreWindowScreenPosition.
94 * This function has no effect on Wayland, where the compositor is responsible
95 * for window positioning.
96 *
97 * @note the group must be set before calling
98 *
99 * @param window The window whose position to restore.
100 * @param config The config group to read from.
101 * @since 5.74
102 */
103KCONFIGGUI_EXPORT void restoreWindowPosition(QWindow *window, const KConfigGroup &config);
104
105/**
106 * Restores the window's position on provided screen from the configuration.
107 * This function has no effect on Wayland, where the compositor is responsible
108 * for window positioning.
109 *
110 * @note the group must be set before calling
111 *
112 * @param window The window whose position to restore.
113 * @param screen Screen on which window should be placed.
114 * @param config The config group to read from.
115 * @since 5.99
116 */
117KCONFIGGUI_EXPORT void restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config);
118}
119#endif // KWINDOWCONFIG_H
120

source code of kconfig/src/gui/kwindowconfig.h