From f15ca8daf04f07945e970d00e1b3baa7fa517b3f Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 12 Oct 2022 14:08:26 +0800 Subject: [PATCH] fix various issues 1. Fix mica material doesn't work normally when used on multiple windows. 2. Fix build on Qt5. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/dialog/main.cpp | 6 +- examples/mainwindow/main.cpp | 6 +- examples/openglwidget/main.cpp | 6 +- examples/quick/ApplicationWindow.qml | 108 ++++++++++++++++++ examples/quick/CMakeLists.txt | 4 +- examples/quick/HomePage.qml | 35 ++++++ examples/quick/{MainWindow.qml => Window.qml} | 12 +- examples/quick/main.cpp | 22 ++-- examples/quick/resources.qrc | 4 +- examples/quick/settings.cpp | 6 +- examples/widget/main.cpp | 11 +- examples/widget/widget.cpp | 6 +- include/FramelessHelper/Core/micamaterial.h | 1 - .../Core/private/micamaterial_p.h | 2 +- .../Widgets/private/widgetssharedhelper_p.h | 2 +- src/core/micamaterial.cpp | 28 ++--- src/quick/framelessquickmodule.cpp | 8 +- src/quick/quickmicamaterial.cpp | 6 +- src/widgets/widgetssharedhelper.cpp | 8 +- 19 files changed, 206 insertions(+), 75 deletions(-) create mode 100644 examples/quick/ApplicationWindow.qml create mode 100644 examples/quick/HomePage.qml rename examples/quick/{MainWindow.qml => Window.qml} (92%) diff --git a/examples/dialog/main.cpp b/examples/dialog/main.cpp index 35f22fb..d688ec2 100644 --- a/examples/dialog/main.cpp +++ b/examples/dialog/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) // of any Q(Core|Gui)Application instances. FramelessHelper::Widgets::initialize(); - QApplication application(argc, argv); + const QScopedPointer application(new QApplication(argc, argv)); // Must be called after QGuiApplication has been constructed, we are using // some private functions from QPA which won't be available until there's @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); - Dialog dialog; - dialog.show(); + const QScopedPointer dialog(new Dialog); + dialog->show(); const int exec = QCoreApplication::exec(); diff --git a/examples/mainwindow/main.cpp b/examples/mainwindow/main.cpp index 0d37ab9..9366ef5 100644 --- a/examples/mainwindow/main.cpp +++ b/examples/mainwindow/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) // of any Q(Core|Gui)Application instances. FramelessHelper::Widgets::initialize(); - QApplication application(argc, argv); + const QScopedPointer application(new QApplication(argc, argv)); // Must be called after QGuiApplication has been constructed, we are using // some private functions from QPA which won't be available until there's @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); - MainWindow mainWindow; - mainWindow.show(); + const QScopedPointer mainWindow(new MainWindow); + mainWindow->show(); const int exec = QCoreApplication::exec(); diff --git a/examples/openglwidget/main.cpp b/examples/openglwidget/main.cpp index 9512147..8780a1d 100644 --- a/examples/openglwidget/main.cpp +++ b/examples/openglwidget/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) // of any Q(Core|Gui)Application instances. FramelessHelper::Widgets::initialize(); - QApplication application(argc, argv); + const QScopedPointer application(new QApplication(argc, argv)); // Must be called after QGuiApplication has been constructed, we are using // some private functions from QPA which won't be available until there's @@ -100,8 +100,8 @@ int main(int argc, char *argv[]) QSurfaceFormat::setDefaultFormat(fmt); - MainWindow mainWindow; - mainWindow.show(); + const QScopedPointer mainWindow(new MainWindow); + mainWindow->show(); const int exec = QCoreApplication::exec(); diff --git a/examples/quick/ApplicationWindow.qml b/examples/quick/ApplicationWindow.qml new file mode 100644 index 0000000..8f87805 --- /dev/null +++ b/examples/quick/ApplicationWindow.qml @@ -0,0 +1,108 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import QtQuick +import QtQuick.Controls.Basic +import org.wangwenx190.FramelessHelper +import Demo + +FramelessApplicationWindow { + id: window + objectName: "applicationWindow" + visible: false // Hide the window before we sets up it's correct size and position. + width: 800 + height: 600 + title: qsTr("FramelessHelper demo application - Qt Quick") + color: { + if (FramelessHelper.blurBehindWindowEnabled) { + return "transparent"; + } + if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) { + return FramelessUtils.defaultSystemDarkColor; + } + return FramelessUtils.defaultSystemLightColor; + } + onClosing: Settings.saveGeometry(window) + + FramelessHelper.onReady: { + // Let FramelessHelper know what's our homemade title bar, otherwise + // our window won't be draggable. + FramelessHelper.titleBarItem = titleBar; + // Make our own items visible to the hit test and on Windows, enable + // the snap layout feature (available since Windows 11). + FramelessHelper.setSystemButton(titleBar.minimizeButton, FramelessHelperConstants.Minimize); + FramelessHelper.setSystemButton(titleBar.maximizeButton, FramelessHelperConstants.Maximize); + FramelessHelper.setSystemButton(titleBar.closeButton, FramelessHelperConstants.Close); + if (!Settings.restoreGeometry(window)) { + FramelessHelper.moveWindowToDesktopCenter(); + } + // Finally, show the window after everything is setted. + window.visible = true; + } + + Shortcut { + sequences: [ StandardKey.Cancel, StandardKey.Close, StandardKey.Quit ] + onActivated: { + if (window.visibility === Window.FullScreen) { + window.toggleFullScreen(); + } else { + window.close(); + } + } + } + + Shortcut { + sequences: [ StandardKey.FullScreen, "ALT+RETURN" ] + onActivated: window.toggleFullScreen() + } + + Timer { + interval: 500 + running: true + repeat: true + onTriggered: timeLabel.text = Qt.formatTime(new Date(), "hh:mm:ss") + } + + Label { + id: timeLabel + anchors.centerIn: parent + font { + pointSize: 70 + bold: true + } + color: (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) ? Qt.color("white") : Qt.color("black") + } + + StandardTitleBar { + id: titleBar + anchors { + top: parent.top + topMargin: window.visibility === Window.Windowed ? 1 : 0 + left: parent.left + right: parent.right + } + windowIcon: "qrc:///Demo/images/microsoft.svg" + windowIconVisible: true + } +} diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index c9769ca..d08a8e5 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -53,7 +53,9 @@ if(${QT_VERSION} VERSION_GREATER_EQUAL 6.2) QtQuick.Controls.Basic/auto org.wangwenx190.FramelessHelper/auto QML_FILES - MainWindow.qml + Window.qml + ApplicationWindow.qml + HomePage.qml #ENABLE_TYPE_COMPILER # We can't use it for now due to it still can't compile singletons. # There's some hope to get it supported in Qt 6.5. ) diff --git a/examples/quick/HomePage.qml b/examples/quick/HomePage.qml new file mode 100644 index 0000000..3e9bb97 --- /dev/null +++ b/examples/quick/HomePage.qml @@ -0,0 +1,35 @@ +/* + * MIT License + * + * Copyright (C) 2022 by wangwenx190 (Yuhang Zhao) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import QtQml + +QtObject { + property Window window: Window{} + property ApplicationWindow applicationWindow: ApplicationWindow{} + + Component.onCompleted: { + window.show(); + applicationWindow.show(); + } +} diff --git a/examples/quick/MainWindow.qml b/examples/quick/Window.qml similarity index 92% rename from examples/quick/MainWindow.qml rename to examples/quick/Window.qml index 7660166..d913a3c 100644 --- a/examples/quick/MainWindow.qml +++ b/examples/quick/Window.qml @@ -28,18 +28,8 @@ import org.wangwenx190.FramelessHelper import Demo FramelessWindow { - property int __savedWindowState: Window.Windowed - - function toggleFullScreen() { - if (window.visibility === Window.FullScreen) { - window.visibility = window.__savedWindowState; - } else { - window.__savedWindowState = window.visibility; - window.showFullScreen(); - } - } - id: window + objectName: "window" visible: false // Hide the window before we sets up it's correct size and position. width: 800 height: 600 diff --git a/examples/quick/main.cpp b/examples/quick/main.cpp index 08c9224..41c2706 100644 --- a/examples/quick/main.cpp +++ b/examples/quick/main.cpp @@ -36,7 +36,7 @@ #include #include "settings.h" #if QMLTC_ENABLED -# include +# include #endif FRAMELESSHELPER_USE_NAMESPACE @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) // of any Q(Core|Gui)Application instances. FramelessHelper::Quick::initialize(); - QGuiApplication application(argc, argv); + const QScopedPointer application(new QGuiApplication(argc, argv)); // Must be called after QGuiApplication has been constructed, we are using // some private functions from QPA which won't be available until there's @@ -80,14 +80,14 @@ int main(int argc, char *argv[]) #endif } - QQmlApplicationEngine engine; + const QScopedPointer engine(new QQmlApplicationEngine); #if (!QMLTC_ENABLED && !defined(QUICK_USE_QMAKE)) - engine.addImportPath(FRAMELESSHELPER_STRING_LITERAL("../imports")); + engine->addImportPath(FRAMELESSHELPER_STRING_LITERAL("../imports")); #endif #if (((QT_VERSION < QT_VERSION_CHECK(6, 2, 0)) || defined(QUICK_USE_QMAKE)) && !QMLTC_ENABLED) // Don't forget to register our own custom QML types! - FramelessHelper::Quick::registerTypes(&engine); + FramelessHelper::Quick::registerTypes(engine.data()); qmlRegisterSingletonType("Demo", 1, 0, "Settings", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * { @@ -110,18 +110,18 @@ int main(int argc, char *argv[]) #endif #if !QMLTC_ENABLED - const QUrl mainUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///Demo/MainWindow.qml")); + const QUrl mainUrl(FRAMELESSHELPER_STRING_LITERAL("qrc:///Demo/HomePage.qml")); #endif #if (QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)) - QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &application, + QObject::connect(engine.data(), &QQmlApplicationEngine::objectCreationFailed, qApp, [](const QUrl &url){ qCritical() << "The QML engine failed to create component:" << url; QCoreApplication::exit(-1); }, Qt::QueuedConnection); #elif !QMLTC_ENABLED const QMetaObject::Connection connection = QObject::connect( - &engine, &QQmlApplicationEngine::objectCreated, &application, + engine.data(), &QQmlApplicationEngine::objectCreated, &application, [&mainUrl, &connection](QObject *object, const QUrl &url) { if (url != mainUrl) { return; @@ -135,12 +135,12 @@ int main(int argc, char *argv[]) #endif #if !QMLTC_ENABLED - engine.load(mainUrl); + engine->load(mainUrl); #endif #if QMLTC_ENABLED - QScopedPointer mainWindow(new MainWindow(&engine)); - mainWindow->show(); + QScopedPointer homePage(new HomePage(engine.data())); + homePage->show(); #endif const int exec = QCoreApplication::exec(); diff --git a/examples/quick/resources.qrc b/examples/quick/resources.qrc index 15e67e9..152647e 100644 --- a/examples/quick/resources.qrc +++ b/examples/quick/resources.qrc @@ -1,6 +1,8 @@ images/microsoft.svg - MainWindow.qml + Window.qml + ApplicationWindow.qml + HomePage.qml diff --git a/examples/quick/settings.cpp b/examples/quick/settings.cpp index 0df0da8..bdad7f8 100644 --- a/examples/quick/settings.cpp +++ b/examples/quick/settings.cpp @@ -29,7 +29,7 @@ #include #include -FRAMELESSHELPER_STRING_CONSTANT2(IniKeyPath, "Window/Geometry") +FRAMELESSHELPER_STRING_CONSTANT2(IniKeyPathTemplate, "%1/Geometry") Settings::Settings(QObject *parent) : QObject(parent) { @@ -51,7 +51,7 @@ void Settings::saveGeometry(QWindow *window) QDataStream stream(&data, QDataStream::WriteOnly); stream.setVersion(QDataStream::Qt_5_6); stream << window->geometry(); - m_settings->setValue(kIniKeyPath, data); + m_settings->setValue(kIniKeyPathTemplate.arg(window->objectName()), data); } bool Settings::restoreGeometry(QWindow *window) @@ -60,7 +60,7 @@ bool Settings::restoreGeometry(QWindow *window) if (!window) { return false; } - const QByteArray data = m_settings->value(kIniKeyPath).toByteArray(); + const QByteArray data = m_settings->value(kIniKeyPathTemplate.arg(window->objectName())).toByteArray(); if (data.isEmpty()) { return false; } diff --git a/examples/widget/main.cpp b/examples/widget/main.cpp index 87029d9..32098a4 100644 --- a/examples/widget/main.cpp +++ b/examples/widget/main.cpp @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) // of any Q(Core|Gui)Application instances. FramelessHelper::Widgets::initialize(); - QApplication application(argc, argv); + const QScopedPointer application(new QApplication(argc, argv)); // Must be called after QGuiApplication has been constructed, we are using // some private functions from QPA which won't be available until there's @@ -48,8 +48,13 @@ int main(int argc, char *argv[]) FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); FramelessConfig::instance()->set(Global::Option::DisableLazyInitializationForMicaMaterial); - Widget widget; - widget.show(); + const QScopedPointer window1(new Widget); + window1->setObjectName(FRAMELESSHELPER_STRING_LITERAL("window1")); + window1->show(); + + const QScopedPointer window2(new Widget); + window2->setObjectName(FRAMELESSHELPER_STRING_LITERAL("window2")); + window2->show(); const int exec = QCoreApplication::exec(); diff --git a/examples/widget/widget.cpp b/examples/widget/widget.cpp index aef6491..fd3b18e 100644 --- a/examples/widget/widget.cpp +++ b/examples/widget/widget.cpp @@ -46,7 +46,7 @@ FRAMELESSHELPER_USE_NAMESPACE using namespace Global; -FRAMELESSHELPER_STRING_CONSTANT2(IniKeyPath, "Window/Geometry") +FRAMELESSHELPER_STRING_CONSTANT2(IniKeyPathTemplate, "%1/Geometry") [[nodiscard]] static inline QSettings *appConfigFile() { @@ -77,7 +77,7 @@ void Widget::timerEvent(QTimerEvent *event) void Widget::closeEvent(QCloseEvent *event) { const QScopedPointer settings(appConfigFile()); - settings->setValue(kIniKeyPath, saveGeometry()); + settings->setValue(kIniKeyPathTemplate.arg(objectName()), saveGeometry()); FramelessWidget::closeEvent(event); } @@ -135,7 +135,7 @@ void Widget::initialize() helper->setSystemButton(m_titleBar->closeButton(), SystemButtonType::Close); connect(helper, &FramelessWidgetsHelper::ready, this, [this, helper](){ const QScopedPointer settings(appConfigFile()); - const QByteArray data = settings->value(kIniKeyPath).toByteArray(); + const QByteArray data = settings->value(kIniKeyPathTemplate.arg(objectName())).toByteArray(); if (data.isEmpty()) { helper->moveWindowToDesktopCenter(); } else { diff --git a/include/FramelessHelper/Core/micamaterial.h b/include/FramelessHelper/Core/micamaterial.h index 26fd9ec..221e0c4 100644 --- a/include/FramelessHelper/Core/micamaterial.h +++ b/include/FramelessHelper/Core/micamaterial.h @@ -57,7 +57,6 @@ public: public Q_SLOTS: void paint(QPainter *painter, const QSize &size, const QPoint &pos); - Q_NODISCARD static MicaMaterial *findOrCreateMicaMaterial(QObject *target); Q_SIGNALS: void tintColorChanged(); diff --git a/include/FramelessHelper/Core/private/micamaterial_p.h b/include/FramelessHelper/Core/private/micamaterial_p.h index 0467ced..c6bcb89 100644 --- a/include/FramelessHelper/Core/private/micamaterial_p.h +++ b/include/FramelessHelper/Core/private/micamaterial_p.h @@ -47,7 +47,6 @@ public Q_SLOTS: void maybeGenerateBlurredWallpaper(const bool force = false); void updateMaterialBrush(); void paint(QPainter *painter, const QSize &size, const QPoint &pos); - Q_NODISCARD static MicaMaterial *findOrCreateMicaMaterial(QObject *target); private: void initialize(); @@ -59,6 +58,7 @@ private: qreal tintOpacity = 0.0; qreal noiseOpacity = 0.0; QBrush micaBrush = {}; + bool initialized = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h index 1584277..e8e9623 100644 --- a/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h +++ b/include/FramelessHelper/Widgets/private/widgetssharedhelper_p.h @@ -79,7 +79,7 @@ private: QPointer m_screen = nullptr; #endif bool m_micaEnabled = false; - QPointer m_micaMaterial; + QScopedPointer m_micaMaterial; QMetaObject::Connection m_micaRedrawConnection = {}; qreal m_screenDpr = 0.0; QMetaObject::Connection m_screenDpiChangeConnection = {}; diff --git a/src/core/micamaterial.cpp b/src/core/micamaterial.cpp index 295161d..e0f11c1 100644 --- a/src/core/micamaterial.cpp +++ b/src/core/micamaterial.cpp @@ -569,8 +569,10 @@ void MicaMaterialPrivate::updateMaterialBrush() painter.setOpacity(noiseOpacity); painter.fillRect(rect, QBrush(noiseTexture)); micaBrush = QBrush(micaTexture); - Q_Q(MicaMaterial); - Q_EMIT q->shouldRedraw(); + if (initialized) { + Q_Q(MicaMaterial); + Q_EMIT q->shouldRedraw(); + } } void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoint &pos) @@ -593,24 +595,14 @@ void MicaMaterialPrivate::paint(QPainter *painter, const QSize &size, const QPoi painter->restore(); } -MicaMaterial *MicaMaterialPrivate::findOrCreateMicaMaterial(QObject *target) -{ - Q_ASSERT(target); - if (!target) { - return nullptr; - } - if (const auto instance = target->findChild()) { - return instance; - } - return new MicaMaterial(target); -} - void MicaMaterialPrivate::initialize() { tintColor = kDefaultTransparentColor; tintOpacity = kDefaultTintOpacity; noiseOpacity = kDefaultNoiseOpacity; + updateMaterialBrush(); + connect(FramelessManager::instance(), &FramelessManager::systemThemeChanged, this, &MicaMaterialPrivate::updateMaterialBrush); connect(FramelessManager::instance(), &FramelessManager::wallpaperChanged, @@ -621,6 +613,8 @@ void MicaMaterialPrivate::initialize() if (FramelessConfig::instance()->isSet(Option::DisableLazyInitializationForMicaMaterial)) { prepareGraphicsResources(); } + + initialized = true; } void MicaMaterialPrivate::prepareGraphicsResources() @@ -633,7 +627,6 @@ void MicaMaterialPrivate::prepareGraphicsResources() g_micaMaterialData()->graphicsResourcesReady = true; g_micaMaterialData()->mutex.unlock(); maybeGenerateBlurredWallpaper(); - updateMaterialBrush(); } MicaMaterial::MicaMaterial(QObject *parent) @@ -707,9 +700,4 @@ void MicaMaterial::paint(QPainter *painter, const QSize &size, const QPoint &pos d->paint(painter, size, pos); } -MicaMaterial *MicaMaterial::findOrCreateMicaMaterial(QObject *target) -{ - return MicaMaterialPrivate::findOrCreateMicaMaterial(target); -} - FRAMELESSHELPER_END_NAMESPACE diff --git a/src/quick/framelessquickmodule.cpp b/src/quick/framelessquickmodule.cpp index e3804af..9f85d12 100644 --- a/src/quick/framelessquickmodule.cpp +++ b/src/quick/framelessquickmodule.cpp @@ -30,8 +30,8 @@ #include "quickimageitem.h" #include "quickwindowborder.h" #include "framelessquickwindow_p.h" -#include "framelessquickapplicationwindow_p.h" #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +# include "framelessquickapplicationwindow_p.h" # include "quickstandardsystembutton_p.h" # include "quickstandardtitlebar_p.h" #endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) @@ -87,15 +87,17 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine) qmlRegisterType(QUICK_URI_EXPAND("FramelessHelper")); qmlRegisterType(QUICK_URI_EXPAND("FramelessWindow")); - qmlRegisterType(QUICK_URI_EXPAND("FramelessApplicationWindow")); qmlRegisterType(QUICK_URI_EXPAND("MicaMaterial")); qmlRegisterType(QUICK_URI_EXPAND("ImageItem")); qmlRegisterType(QUICK_URI_EXPAND("WindowBorder")); #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + qmlRegisterType(QUICK_URI_EXPAND("FramelessApplicationWindow")); qmlRegisterType(QUICK_URI_EXPAND("StandardSystemButton")); qmlRegisterType(QUICK_URI_EXPAND("StandardTitleBar")); -#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#else // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("FramelessApplicationWindow"), + FRAMELESSHELPER_STRING_LITERAL("FramelessApplicationWindow is not available until Qt6.")); qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardSystemButton"), FRAMELESSHELPER_STRING_LITERAL("StandardSystemButton is not available until Qt6.")); qmlRegisterTypeNotAvailable(QUICK_URI_EXPAND("StandardTitleBar"), diff --git a/src/quick/quickmicamaterial.cpp b/src/quick/quickmicamaterial.cpp index 1be10f9..9e66bbb 100644 --- a/src/quick/quickmicamaterial.cpp +++ b/src/quick/quickmicamaterial.cpp @@ -71,7 +71,7 @@ private: QPointer m_item = nullptr; QSGSimpleTextureNode *m_node = nullptr; QPixmap m_pixmapCache = {}; - QPointer m_micaMaterial = nullptr; + QScopedPointer m_micaMaterial; }; WallpaperImageNode::WallpaperImageNode(QuickMicaMaterial *item) @@ -91,7 +91,7 @@ void WallpaperImageNode::initialize() g_data()->mutex.lock(); QQuickWindow * const window = m_item->window(); - m_micaMaterial = MicaMaterial::findOrCreateMicaMaterial(window); + m_micaMaterial.reset(new MicaMaterial); m_node = new QSGSimpleTextureNode; m_node->setFiltering(QSGTexture::Linear); @@ -103,7 +103,7 @@ void WallpaperImageNode::initialize() appendChildNode(m_node); - connect(m_micaMaterial, &MicaMaterial::shouldRedraw, this, [this](){ + connect(m_micaMaterial.data(), &MicaMaterial::shouldRedraw, this, [this](){ maybeGenerateWallpaperImageCache(true); }); connect(window, &QQuickWindow::beforeRendering, this, diff --git a/src/widgets/widgetssharedhelper.cpp b/src/widgets/widgetssharedhelper.cpp index 6944404..a3ebc4a 100644 --- a/src/widgets/widgetssharedhelper.cpp +++ b/src/widgets/widgetssharedhelper.cpp @@ -74,12 +74,12 @@ void WidgetsSharedHelper::setup(QWidget *widget) m_targetWidget->update(); } }); - m_micaMaterial = MicaMaterial::findOrCreateMicaMaterial(m_targetWidget); + m_micaMaterial.reset(new MicaMaterial); if (m_micaRedrawConnection) { disconnect(m_micaRedrawConnection); m_micaRedrawConnection = {}; } - m_micaRedrawConnection = connect(m_micaMaterial, &MicaMaterial::shouldRedraw, + m_micaRedrawConnection = connect(m_micaMaterial.data(), &MicaMaterial::shouldRedraw, this, [this](){ if (m_targetWidget) { m_targetWidget->update(); @@ -253,8 +253,8 @@ void WidgetsSharedHelper::handleScreenChanged(QScreen *screen) return; } m_screenDpr = currentDpr; - if (m_micaEnabled && m_micaMaterial) { - MicaMaterialPrivate::get(m_micaMaterial)->maybeGenerateBlurredWallpaper(true); + if (m_micaEnabled && !m_micaMaterial.isNull()) { + MicaMaterialPrivate::get(m_micaMaterial.data())->maybeGenerateBlurredWallpaper(true); } }); }