From 9c774f8329b29e10b9b41d4e0677d87cb9462aef Mon Sep 17 00:00:00 2001 From: lbwtw Date: Fri, 22 Nov 2024 16:52:03 +0800 Subject: [PATCH] fix: Boxshadow displays abnormally in fractional scaling scenarios - Temporary solution --- qmlplugin/qmlplugin_plugin.cpp | 2 ++ qt6/src/qml/BoxShadow.qml | 2 +- src/private/dquickborderimage.cpp | 26 ++++++++++++++++++++++++++ src/private/dquickborderimage_p.h | 29 +++++++++++++++++++++++++++++ src/qml/BoxShadow.qml | 2 +- 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 src/private/dquickborderimage.cpp create mode 100644 src/private/dquickborderimage_p.h diff --git a/qmlplugin/qmlplugin_plugin.cpp b/qmlplugin/qmlplugin_plugin.cpp index 0178de15..4be0df9c 100644 --- a/qmlplugin/qmlplugin_plugin.cpp +++ b/qmlplugin/qmlplugin_plugin.cpp @@ -28,6 +28,7 @@ #include "private/dquickarrowboxpath_p.h" #include "private/dquickcoloroverlay_p.h" #include "private/dquickapploaderitem_p.h" +#include "private/dquickborderimage_p.h" #endif #include "private/dquickimageprovider_p.h" @@ -195,6 +196,7 @@ void QmlpluginPlugin::registerTypes(const char *uri) dtkRegisterType(uri, implUri, 1, 0, "ArrowBoxPath"); dtkRegisterType(uri, implUri, 1, 0, "AppLoader"); dtkRegisterType(uri, implUri, 1, 0, "SoftwareColorOverlay"); + dtkRegisterType(uri, implUri, 1, 0, "DBorderImage"); dtkRegisterAnonymousType(uri, implUri, 1); dtkRegisterAnonymousType(uri, implUri, 1); diff --git a/qt6/src/qml/BoxShadow.qml b/qt6/src/qml/BoxShadow.qml index a9a9362d..2392a813 100644 --- a/qt6/src/qml/BoxShadow.qml +++ b/qt6/src/qml/BoxShadow.qml @@ -26,7 +26,7 @@ Item { readonly property real __minImageSize: 2 * __borderBase readonly property real __boxSize: __minImageSize - 2 * shadowBlur - 2 * __spread + 1 - BorderImage { + D.DBorderImage { id: image anchors { diff --git a/src/private/dquickborderimage.cpp b/src/private/dquickborderimage.cpp new file mode 100644 index 00000000..1901de8e --- /dev/null +++ b/src/private/dquickborderimage.cpp @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: 2024 - 2025 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include "dquickborderimage_p.h" + +#include +#include + +DQUICK_BEGIN_NAMESPACE + +DQuickBorderImage::DQuickBorderImage(QQuickItem *parent) + : QQuickBorderImage(parent) +{ +} + +void DQuickBorderImage::itemChange(ItemChange change, const ItemChangeData &value) +{ + if (change == ItemDevicePixelRatioHasChanged) { + return; + } + + QQuickBorderImage::itemChange(change, value); +} + +DQUICK_END_NAMESPACE diff --git a/src/private/dquickborderimage_p.h b/src/private/dquickborderimage_p.h new file mode 100644 index 00000000..a3809877 --- /dev/null +++ b/src/private/dquickborderimage_p.h @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2024 - 2025 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef DQUICKBORDERIMAGE_P_H +#define DQUICKBORDERIMAGE_P_H + +#include + +#include + +DQUICK_BEGIN_NAMESPACE + +class DQuickBorderImage : public QQuickBorderImage +{ + Q_OBJECT +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QML_NAMED_ELEMENT(DBorderImage) +#endif +public: + explicit DQuickBorderImage(QQuickItem *parent=nullptr); + +protected: + void itemChange(ItemChange change, const ItemChangeData &value) override; +}; + +DQUICK_END_NAMESPACE + +#endif // DQUICKBORDERIMAGE_P_H diff --git a/src/qml/BoxShadow.qml b/src/qml/BoxShadow.qml index a7bfa647..3e21e0be 100644 --- a/src/qml/BoxShadow.qml +++ b/src/qml/BoxShadow.qml @@ -26,7 +26,7 @@ Item { readonly property real __minImageSize: 2 * __borderBase readonly property real __boxSize: __minImageSize - 2 * shadowBlur - 2 * __spread + 1 - BorderImage { + D.DBorderImage { id: image anchors {