KConfig

kwindowstatesaverquick.cpp
1// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4#include "kwindowstatesaverquick.h"
5#include "kconfig_qml_log_settings.h"
6
7#include <QQuickItem>
8#include <QQuickWindow>
9
10#include <KWindowStateSaver>
11
12void KWindowStateSaverQuick::classBegin()
13{
14}
15
16void KWindowStateSaverQuick::componentComplete()
17{
18 const auto parentItem = qobject_cast<QQuickItem *>(parent());
19 if (!parentItem) {
20 qCWarning(KCONFIG_QML_LOG) << "WindowStateSaver requires a parent item";
21 return;
22 }
23
24 const auto window = qobject_cast<QWindow *>(parentItem->window());
25 if (!window) {
26 qCWarning(KCONFIG_QML_LOG) << "WindowStateSaver requires the parent to be a type that inherits QWindow";
27 return;
28 }
29
30 new KWindowStateSaver(window, m_configGroupName);
31
32 // To work around oddities in QtQuick window visibility handling.
33 // If we do not set the window visible now, then our window state is
34 // overwritten during QQuickWindowQmlImpl::setWindowVisibility() because
35 // QQuickWindow is AutomaticVisibility by default.
37 window->setVisibility(QWindow::Visibility::Maximized);
38 }
39}
40
41void KWindowStateSaverQuick::setConfigGroupName(const QString &name)
42{
43 if (m_configGroupName != name) {
44 m_configGroupName = name;
45 Q_EMIT configGroupNameChanged();
46 }
47}
48
49QString KWindowStateSaverQuick::configGroupName() const
50{
51 return m_configGroupName;
52}
53
54#include "moc_kwindowstatesaverquick.cpp"
Saves and restores a window size and (when possible) position.
QString name(GameStandardAction id)
QWidget * window(QObject *job)
Q_EMITQ_EMIT
QObject * parent() const const
T qobject_cast(QObject *object)
WindowMaximized
Qt::WindowStates windowState() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.