diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 47fd2072..79e71cdb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,7 @@ file(GLOB TEST_SOURCES ut_dquickdciicon.cpp ut_dblurimagenode.cpp ut_dhandlecontextmenuwindow.cpp + ut_dquickbehindwindowblur.cpp ) if (EnableDtk5) list(APPEND TEST_SOURCES diff --git a/tests/data.qrc b/tests/data.qrc index 57fd0347..24b2ed4e 100644 --- a/tests/data.qrc +++ b/tests/data.qrc @@ -27,5 +27,6 @@ qml/DMaskEffectNode_TextureMaterial.qml qml/DSGBlurImageNode.qml qml/ContextMenuWindow.qml + qml/DQuickBehindWindowBlur.qml diff --git a/tests/qml/DQuickBehindWindowBlur.qml b/tests/qml/DQuickBehindWindowBlur.qml new file mode 100644 index 00000000..fdd859f9 --- /dev/null +++ b/tests/qml/DQuickBehindWindowBlur.qml @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.11 +import QtQuick.Window 2.11 +import org.deepin.dtk 1.0 as D + +Rectangle { + id: control + width: 200; height: 200 + color: "red" + Window { + // on top of the Rectangle's window + x: control.Window.window ? control.Window.window.x : 0 + y: control.Window.window ? control.Window.window.y : 0 + width: 100; height: 100 + visible: true + + D.DWindow.enabled: true + D.DWindow.alphaBufferSize: 8 + + D.BehindWindowBlur { + anchors.fill: parent + blendColor: Qt.rgba(0, 255, 0, 0.4) + cornerRadius: 10 + } + } +} diff --git a/tests/ut_dquickbehindwindowblur.cpp b/tests/ut_dquickbehindwindowblur.cpp new file mode 100644 index 00000000..283da366 --- /dev/null +++ b/tests/ut_dquickbehindwindowblur.cpp @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +#include + +#include "test_helper.hpp" + +#include + +#include "dquickbehindwindowblur_p.h" +DQUICK_USE_NAMESPACE + +TEST(ut_DQuickBehindWindowBlur, properties) +{ + QuickViewHelper<> helper("qrc:/qml/DQuickBehindWindowBlur.qml"); + ASSERT_TRUE(helper.object); + + DQuickBehindWindowBlur *target = helper.object->findChild(); + ASSERT_TRUE(target); + + if (!target->valid()) + GTEST_SKIP_("don't support BehindWindowBlur, it need WM support."); + + EXPECT_EQ(target->blendColor(), QColor(0, 255, 0, 0.4 * 255)); + EXPECT_EQ(target->cornerRadius(), 10); + + QImage img = helper.view->grabWindow(); + EXPECT_NE(img.pixelColor(QPoint(50, 50)), QColor(0, 255, 0, 0.4)); + EXPECT_EQ(img.pixelColor(QPoint(150, 50)), Qt::red); +}