Move Controller::setBlur and Controller::hasWindowSystem to WindowController

This commit is contained in:
Tobias Fella
2023-10-30 21:24:39 +01:00
parent 33c5b418d2
commit 5df4fa297d
6 changed files with 56 additions and 48 deletions

View File

@@ -8,9 +8,6 @@
#include <KLocalizedString>
#include <KWindowConfig>
#ifdef HAVE_WINDOWSYSTEM
#include <KWindowEffects>
#endif
#include <QFile>
#include <QFileInfo>
@@ -392,32 +389,6 @@ QString Controller::formatDuration(quint64 msecs, KFormat::DurationFormatOptions
return KFormat().formatDuration(msecs, options);
}
void Controller::setBlur(QQuickItem *item, bool blur)
{
#ifdef HAVE_WINDOWSYSTEM
auto setWindows = [item, blur]() {
auto reg = QRect(QPoint(0, 0), item->window()->size());
KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg);
KWindowEffects::enableBlurBehind(item->window(), blur, reg);
};
disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr);
disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr);
connect(item->window(), &QQuickWindow::heightChanged, this, setWindows);
connect(item->window(), &QQuickWindow::widthChanged, this, setWindows);
setWindows();
#endif
}
bool Controller::hasWindowSystem() const
{
#ifdef HAVE_WINDOWSYSTEM
return true;
#else
return false;
#endif
}
void Controller::forceRefreshTextDocument(QQuickTextDocument *textDocument, QQuickItem *item)
{
// HACK: Workaround bug QTBUG 93281

View File

@@ -64,11 +64,6 @@ class Controller : public QObject
*/
Q_PROPERTY(bool supportSystemTray READ supportSystemTray CONSTANT)
/**
* @brief Whether KWindowSystem specific features are available.
*/
Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT)
/**
* @brief Whether NeoChat is currently able to connect to the server.
*/
@@ -128,11 +123,6 @@ public:
[[nodiscard]] bool supportSystemTray() const;
/**
* @brief Set the background blur status of the given item.
*/
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
bool isOnline() const;
/**
@@ -180,8 +170,6 @@ private:
bool m_isOnline = true;
QMap<Quotient::Room *, int> m_notificationCounts;
bool hasWindowSystem() const;
QPointer<PushRuleModel> m_pushRuleModel;
Quotient::AccountRegistry m_accountRegistry;

View File

@@ -235,7 +235,7 @@ FormCard.FormCardPage {
FormCard.FormCheckDelegate {
id: hasWindowSystemDelegate
visible: Controller.hasWindowSystem
visible: WindowController.hasWindowSystem
text: i18n("Use transparent chat page")
enabled: !Config.compactLayout && !Config.isBlurImmutable
checked: Config.blur
@@ -249,7 +249,7 @@ FormCard.FormCardPage {
FormCard.AbstractFormDelegate {
id: transparencyDelegate
visible: Controller.hasWindowSystem && Config.blur
visible: WindowController.hasWindowSystem && Config.blur
enabled: !Config.isTransparancyImmutable
background: Item {}
contentItem: ColumnLayout {

View File

@@ -190,7 +190,7 @@ Kirigami.ApplicationWindow {
}
Component.onCompleted: {
Controller.setBlur(pageStack, Config.blur && !Config.compactLayout);
WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout);
if (Config.minimizeToSystemTrayOnStartup && !Kirigami.Settings.isMobile && Controller.supportSystemTray && Config.systemTray) {
restoreWindowGeometryConnections.enabled = true; // To restore window size and position
} else {
@@ -201,10 +201,10 @@ Kirigami.ApplicationWindow {
Connections {
target: Config
function onBlurChanged() {
Controller.setBlur(pageStack, Config.blur && !Config.compactLayout);
WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout);
}
function onCompactLayoutChanged() {
Controller.setBlur(pageStack, Config.blur && !Config.compactLayout);
WindowController.setBlur(pageStack, Config.blur && !Config.compactLayout);
}
}

View File

@@ -76,4 +76,30 @@ void WindowController::showAndRaiseWindow(const QString &startupId)
#endif
}
bool WindowController::hasWindowSystem() const
{
#ifdef HAVE_WINDOWSYSTEM
return true;
#else
return false;
#endif
}
void WindowController::setBlur(QQuickItem *item, bool blur)
{
#ifdef HAVE_WINDOWSYSTEM
auto setWindows = [item, blur]() {
auto reg = QRect(QPoint(0, 0), item->window()->size());
KWindowEffects::enableBackgroundContrast(item->window(), blur, 1, 1, 1, reg);
KWindowEffects::enableBlurBehind(item->window(), blur, reg);
};
disconnect(item->window(), &QQuickWindow::heightChanged, this, nullptr);
disconnect(item->window(), &QQuickWindow::widthChanged, this, nullptr);
connect(item->window(), &QQuickWindow::heightChanged, this, setWindows);
connect(item->window(), &QQuickWindow::widthChanged, this, setWindows);
setWindows();
#endif
}
#include "moc_windowcontroller.cpp"

View File

@@ -4,8 +4,12 @@
#pragma once
#include <QObject>
#include <QWindow>
#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickWindow>
#ifdef HAVE_WINDOWSYSTEM
#include <KWindowEffects>
#endif
/**
* @class WindowController
*
@@ -14,9 +18,21 @@
class WindowController : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
/**
* @brief Whether KWindowSystem specific features are available.
*/
Q_PROPERTY(bool hasWindowSystem READ hasWindowSystem CONSTANT)
public:
static WindowController &instance();
static WindowController *create(QQmlEngine *engine, QJSEngine *)
{
engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership);
return &instance();
}
/**
* @brief Set the window that the will be managed.
@@ -43,6 +59,13 @@ public:
*/
void showAndRaiseWindow(const QString &startupId);
bool hasWindowSystem() const;
/**
* @brief Set the background blur status of the given item.
*/
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
Q_SIGNALS:
/**
* @brief Triggered if the managed window is changed.