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 | |
12 | void KWindowStateSaverQuick::classBegin() |
13 | { |
14 | } |
15 | |
16 | void KWindowStateSaverQuick::componentComplete() |
17 | { |
18 | const auto parentItem = qobject_cast<QQuickItem *>(o: 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 *>(o: 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. |
36 | if (window->windowState() == Qt::WindowMaximized) { |
37 | window->setVisibility(QWindow::Visibility::Maximized); |
38 | } |
39 | } |
40 | |
41 | void KWindowStateSaverQuick::setConfigGroupName(const QString &name) |
42 | { |
43 | if (m_configGroupName != name) { |
44 | m_configGroupName = name; |
45 | Q_EMIT configGroupNameChanged(); |
46 | } |
47 | } |
48 | |
49 | QString KWindowStateSaverQuick::configGroupName() const |
50 | { |
51 | return m_configGroupName; |
52 | } |
53 | |
54 | #include "moc_kwindowstatesaverquick.cpp" |
55 | |