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 * \namespace KWindowConfig
19 * \inmodule KConfigGui
20 *
21 * \brief Save and load window sizes into a config.
22 */
23namespace KWindowConfig
24{
25/*!
26 * Saves the window's size dependent on the screen dimension either to the
27 * global or application config file.
28 *
29 * \a window The window to save size.
30 *
31 * \a config The config group to read from.
32 *
33 * \a options passed to KConfigGroup::writeEntry()
34 *
35 * \since 5.0
36 */
37KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
38
39/*!
40 * Returns whether a given KConfig group has any saved window size data.
41 *
42 * \a config The config group to read from.
43 *
44 * \since 6.0
45 */
46KCONFIGGUI_EXPORT bool hasSavedWindowSize(KConfigGroup &config);
47
48/*!
49 * Restores the dialog's size from the configuration according to
50 * the screen size.
51 *
52 * If you're calling this from a constructor (for a mainwindow or dialog, for instance)
53 * you should first call winId() so that a QWindow is created, then you can call windowHandle()
54 * to pass to this method.
55 *
56 * Example code:
57 * \code
58 * create(); // ensure there's a window created
59 * const QSize availableSize = windowHandle()->screen()->availableSize();
60 * windowHandle()->resize(availableSize.width() * 0.7, availableSize.height() * 0.5); // default size
61 * KWindowConfig::restoreWindowSize(windowHandle(), KSharedConfig::openConfig()->group("MyDialog"));
62 * resize(windowHandle()->size()); // workaround for QTBUG-40584
63 * \endcode
64 *
65 * \a window The window to restore size.
66 *
67 * \a config The config group to read from.
68 *
69 * \since 5.0.
70 */
71KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config);
72
73/*!
74 * Saves the window's position either to the global or application config file.
75 * This function has no effect on Wayland, where the compositor is responsible
76 * for window positioning.
77 *
78 * \a window The window whose position to save.
79 *
80 * \a config The config group to read from.
81 *
82 * \a options passed to KConfigGroup::writeEntry()
83 *
84 * \since 5.74
85 */
86KCONFIGGUI_EXPORT void saveWindowPosition(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options = KConfigGroup::Normal);
87
88/*!
89 * Returns whether a given KConfig group has any saved window position data.
90 *
91 * \note: always returns false on Wayland where saving and restoring window
92 * position data is not supported.
93 *
94 * \a config The config group to read from.
95 *
96 * \since 6.0
97 */
98KCONFIGGUI_EXPORT bool hasSavedWindowPosition(KConfigGroup &config);
99/*!
100 * Restores the window's screen position from the configuration and calls restoreWindowScreenPosition.
101 * This function has no effect on Wayland, where the compositor is responsible
102 * for window positioning.
103 *
104 * \a window The window whose position to restore.
105 *
106 * \a config The config group to read from.
107 *
108 * \since 5.74
109 */
110KCONFIGGUI_EXPORT void restoreWindowPosition(QWindow *window, const KConfigGroup &config);
111
112/*!
113 * Restores the window's position on provided screen from the configuration.
114 * This function has no effect on Wayland, where the compositor is responsible
115 * for window positioning.
116 *
117 * \a window The window whose position to restore.
118 *
119 * \a screen Screen on which window should be placed.
120 *
121 * \a config The config group to read from.
122 *
123 * \since 5.99
124 */
125KCONFIGGUI_EXPORT void restoreWindowScreenPosition(QWindow *window, const QScreen *screen, const KConfigGroup &config);
126}
127#endif // KWINDOWCONFIG_H
128

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