File indexing completed on 2024-09-29 07:24:47
0001 // SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QObject> 0007 #include <QQmlEngine> 0008 #include <QQuickItem> 0009 #include <QQuickWindow> 0010 #ifdef HAVE_WINDOWSYSTEM 0011 #include <KWindowEffects> 0012 #endif 0013 /** 0014 * @class WindowController 0015 * 0016 * A singleton class to help manage the NeoChat window. 0017 */ 0018 class WindowController : public QObject 0019 { 0020 Q_OBJECT 0021 QML_ELEMENT 0022 QML_SINGLETON 0023 0024 /** 0025 * @brief Whether KWindowSystem specific features are available. 0026 */ 0027 Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT) 0028 0029 public: 0030 static WindowController &instance(); 0031 static WindowController *create(QQmlEngine *engine, QJSEngine *) 0032 { 0033 engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership); 0034 return &instance(); 0035 } 0036 0037 /** 0038 * @brief Set the window that the will be managed. 0039 */ 0040 void setWindow(QWindow *window); 0041 0042 /** 0043 * @brief Get the window that the will be managed. 0044 */ 0045 QWindow *window() const; 0046 0047 /** 0048 * @brief Restore any saved window geometry if available. 0049 */ 0050 void restoreGeometry(); 0051 0052 /** 0053 * @brief Save the current window geometry. 0054 */ 0055 Q_INVOKABLE void saveGeometry(); 0056 0057 /** 0058 * @brief Show the window and raise to the top. 0059 */ 0060 void showAndRaiseWindow(const QString &startupId); 0061 0062 bool hasWindowSystem() const; 0063 0064 /** 0065 * @brief Set the background blur status of the given item. 0066 */ 0067 Q_INVOKABLE void setBlur(QQuickItem *item, bool blur); 0068 0069 /** 0070 * Toggles the window between hidden and visible. 0071 */ 0072 void toggleWindow(); 0073 0074 Q_SIGNALS: 0075 /** 0076 * @brief Triggered if the managed window is changed. 0077 */ 0078 void windowChanged(); 0079 0080 private: 0081 WindowController() = default; 0082 0083 QWindow *m_window = nullptr; 0084 };