File indexing completed on 2025-01-05 05:18:57

0001 // SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 // Code based on neochat code
0005 
0006 #pragma once
0007 
0008 #include <QObject>
0009 #include <QQmlEngine>
0010 #include <QQuickItem>
0011 #include <QQuickWindow>
0012 #ifdef HAVE_WINDOWSYSTEM
0013 #include <KWindowEffects>
0014 #endif
0015 /**
0016  * @class WindowController
0017  *
0018  * A singleton class to help manage the NeoChat window.
0019  */
0020 class WindowController : public QObject
0021 {
0022     Q_OBJECT
0023     QML_ELEMENT
0024     QML_SINGLETON
0025 
0026 public:
0027     static WindowController &instance();
0028     static WindowController *create(QQmlEngine *engine, QJSEngine *);
0029 
0030     /**
0031      * @brief Set the window that the will be managed.
0032      */
0033     void setWindow(QWindow *window);
0034 
0035     /**
0036      * @brief Get the window that the will be managed.
0037      */
0038     [[nodiscard]] QWindow *window() const;
0039 
0040     /**
0041      * @brief Restore any saved window geometry if available.
0042      */
0043     void restoreGeometry();
0044 
0045     /**
0046      * @brief Save the current window geometry.
0047      */
0048     void saveGeometry();
0049 
0050     /**
0051      * @brief Show the window and raise to the top.
0052      */
0053     void showAndRaiseWindow(const QString &startupId);
0054 
0055 Q_SIGNALS:
0056     /**
0057      * @brief Triggered if the managed window is changed.
0058      */
0059     void windowChanged();
0060 
0061 private:
0062     WindowController() = default;
0063 
0064     QWindow *mWindow = nullptr;
0065 };