diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c2361af0..226d46ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [6.7.54] - 2026-11-18 + +### Fixed + +- Prevent Qt6 menu from closing on Alt + +## [6.7.53] - 2026-11-10 + +### Fixed + +- Preserve Qt6 text field cursor with TapHandler +- Cancel pending URL loads when setting base64 icon +- Adjust dialog layout sizing to prevent stretch issues +- Silence -Wunused-result in color selector unit test + +### Removed + +- Delete backdrop renderer on invalidated + +## [6.7.52] - 2026-10-28 + +### Added + +- Add window blur control to DialogWindow + +### Fixed + +- Prevent palette feedback binding loops + ## [6.7.51] - 2026-10-15 ### Changed diff --git a/VERSION b/VERSION index 2b097dadd..96fe3bb10 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.7.51 +6.7.54 diff --git a/archlinux/PKGBUILD b/archlinux/PKGBUILD index 80299cf5f..d6ff8d90e 100644 --- a/archlinux/PKGBUILD +++ b/archlinux/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: zccrs pkgname=dtkdeclarative-git -pkgver=6.7.51 +pkgver=6.7.54 pkgrel=1 sourcename=dtkdeclarative sourcetars=("$sourcename"_"$pkgver".tar.xz) diff --git a/debian/changelog b/debian/changelog index f9fc34cab..57fcd4013 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,21 @@ +dtkdeclarative (6.7.54) unstable; urgency=medium + + * Release 6.7.54 + + -- yeshanshan Wed, 18 Nov 2026 16:43:56 +0800 + +dtkdeclarative (6.7.53) unstable; urgency=medium + + * Release 6.7.53 + + -- yeshanshan Tue, 10 Nov 2026 20:32:44 +0800 + +dtkdeclarative (6.7.52) unstable; urgency=medium + + * Release 6.7.52 + + -- yeshanshan Wed, 28 Oct 2026 16:31:26 +0800 + dtkdeclarative (6.7.51) unstable; urgency=medium * Release 6.7.51 diff --git a/qt6/src/qml/ArrowListView.qml b/qt6/src/qml/ArrowListView.qml index b8f7e5db2..1f6c9896a 100644 --- a/qt6/src/qml/ArrowListView.qml +++ b/qt6/src/qml/ArrowListView.qml @@ -15,22 +15,32 @@ FocusScope { property int itemHeight: DS.Style.arrowListView.itemHeight property alias view: itemsView + // Fixed per show: rows realized while scrolling can differ in height. + property real _measuredRowHeight: 0 + readonly property real _rowHeight: _measuredRowHeight > 0 ? _measuredRowHeight : itemHeight + // Full height of the list, to size a popup before it is mapped. readonly property real sizedHeight: { if (itemsView.count === 0) return 0 - const item = itemsView.itemAtIndex(0) - const measured = itemsView.contentHeight > 0 && item ? (item.height || item.implicitHeight) : 0 - const showArrows = itemsView.count > maxVisibleItems - const topMargin = contentLayout.anchors.topMargin - const extraHeight = topMargin + (showArrows - ? 2 * (DS.Style.arrowListView.stepButtonSize.height + contentLayout.spacing) : 0) - return Math.min(itemsView.count, maxVisibleItems) * (measured > 0 ? measured : itemHeight) + extraHeight + if (itemsView.contentHeight > 0) + return implicitHeight + const arrowStrips = itemsView.count > maxVisibleItems + ? 2 * (DS.Style.arrowListView.stepButtonSize.height + contentLayout.spacing) : 0 + return Math.min(itemsView.count, maxVisibleItems) * _rowHeight + arrowStrips + contentLayout.anchors.topMargin } implicitWidth: Math.max(DS.Style.arrowListView.width, contentLayout.implicitWidth) implicitHeight: contentLayout.implicitHeight + contentLayout.anchors.topMargin + onVisibleChanged: { + if (!visible) + return + itemsView.itemMaxWidth = 0 + _measuredRowHeight = 0 + itemsView.refreshContentItemWidth() + } + ColumnLayout { id: contentLayout anchors.fill: parent @@ -49,21 +59,14 @@ FocusScope { ListView { id: itemsView + property real itemMaxWidth: 0 clip: true Layout.fillWidth: true Layout.fillHeight: true onHeightChanged: if (height > 0 && contentHeight === 0) forceLayout() - implicitHeight: itemsView.count > 0 ? Math.min(contentHeight, maxVisibleItems * contentHeight / itemsView.count) : 0 - implicitWidth:{ - var maxWidth = DS.Style.arrowListView.width - for (var i = 0; i < itemsView.count; ++i) { - var item = itemsView.itemAtIndex(i) - if (item && item.implicitWidth > maxWidth) - maxWidth = item.implicitWidth - } - return maxWidth - } - interactive: itemsView.count > maxVisibleItems + implicitHeight: itemsView.count > 0 ? Math.min(contentHeight, maxVisibleItems * control._rowHeight) : 0 + implicitWidth: itemMaxWidth + interactive: itemsView.contentHeight > itemsView.height ScrollIndicator.vertical: ScrollIndicator { } highlight: HighlightPanel { visible: false // TODO listview's highlight is confict with Item's highlight. @@ -81,16 +84,34 @@ FocusScope { highlightMoveDuration: -1 highlightMoveVelocity: 400 - onCountChanged: refreshContentItemWidth() + Connections { + target: itemsView.contentItem + function onChildrenChanged() { Qt.callLater(itemsView.refreshContentItemWidth) } + } + + onCountChanged: { + itemMaxWidth = 0 + control._measuredRowHeight = 0 + refreshContentItemWidth() + } + + onContentHeightChanged: if (control._measuredRowHeight <= 0) refreshContentItemWidth() + onWidthChanged: refreshContentItemWidth() function refreshContentItemWidth() { + var maxWidth = itemMaxWidth for (var i = 0; i < itemsView.count; ++i) { var item = itemsView.itemAtIndex(i) - if (item) { - item.width = itemsView.width - } + if (!item || !item.visible) + continue + item.width = itemsView.width + if (control._measuredRowHeight <= 0 && item.height > 0) + control._measuredRowHeight = item.height + if (item.implicitWidth > maxWidth) + maxWidth = item.implicitWidth } + itemMaxWidth = maxWidth } } diff --git a/qt6/src/qml/ComboBox.qml b/qt6/src/qml/ComboBox.qml index 34bfc4d0d..430ef2c1c 100644 --- a/qt6/src/qml/ComboBox.qml +++ b/qt6/src/qml/ComboBox.qml @@ -35,7 +35,6 @@ T.ComboBox { bottomPadding: control.flat ? 0 : padding delegate: MenuItem { - implicitWidth: Math.max(DS.Style.control.implicitWidth(control), popup.implicitWidth - DS.Style.popup.margin * 2) useIndicatorPadding: true text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null @@ -203,7 +202,7 @@ T.ComboBox { leftMargin: DS.Style.popup.margin rightMargin: DS.Style.popup.margin palette: control.palette - implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width + implicitWidth: control.flat ? Math.max(contentItem.implicitWidth + leftPadding + rightPadding, control.width) : control.width // 60 is a temporary viewport so the list can realize one row and be measured. implicitHeight: (contentItem.sizedHeight > 0 ? contentItem.sizedHeight : 2 * DS.Style.arrowListView.itemHeight) + topPadding + bottomPadding diff --git a/qt6/src/qml/DialogWindow.qml b/qt6/src/qml/DialogWindow.qml index 5e5b899e8..fce494ee4 100644 --- a/qt6/src/qml/DialogWindow.qml +++ b/qt6/src/qml/DialogWindow.qml @@ -21,9 +21,10 @@ Window { D.DWindow.wmWindowTypes: D.WindowManagerHelper.DialogType flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.MSWindowsFixedSizeDialogHint D.ColorSelector.family: D.Palette.CrystalColor - color: "transparent" - height: content.height - width: content.width + property bool enableBehindWindowBlur: true + color: enableBehindWindowBlur ? "transparent" : palette.base + height: content.implicitHeight + width: content.implicitWidth property alias header: titleBar.sourceComponent property string icon @@ -33,27 +34,34 @@ Window { property real rightPadding: DS.Style.dialogWindow.contentHMargin property real topPadding: title === "" ? 0 : DS.Style.dialogWindow.contentVMargin - D.StyledBehindWindowBlur { - control: control + Loader { anchors.fill: parent - blendColor: { - if (valid) { + active: control.enableBehindWindowBlur + sourceComponent: D.StyledBehindWindowBlur { + control: Window.window + anchors.fill: parent + blendColor: { + if (valid) { + return DS.Style.control.selectColor(undefined, + Qt.rgba(235 / 255.0, 235 / 255.0, 235 / 255.0, 0.6), + Qt.rgba(10 / 255.0, 10 / 255.0, 10 / 255.0, 85 / 255.0)) + } return DS.Style.control.selectColor(undefined, - Qt.rgba(235 / 255.0, 235 / 255.0, 235 / 255.0, 0.6), - Qt.rgba(10 / 255.0, 10 / 255.0, 10 / 255.0, 85 / 255.0)) + DS.Style.behindWindowBlur.lightNoBlurColor, + DS.Style.behindWindowBlur.darkNoBlurColor) } - return DS.Style.control.selectColor(undefined, - DS.Style.behindWindowBlur.lightNoBlurColor, - DS.Style.behindWindowBlur.darkNoBlurColor) } } Item { id: content + anchors.fill: parent + implicitWidth: layout.implicitWidth + implicitHeight: layout.implicitHeight palette: control.active ? D.DTK.palette : D.DTK.inactivePalette - implicitHeight: childrenRect.height ColumnLayout { id: layout + anchors.fill: parent spacing: 0 Loader { @@ -67,6 +75,7 @@ Window { Loader { active: title !== "" + visible: active Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter sourceComponent: Component { @@ -82,6 +91,7 @@ Window { Item { id: contentLoader Layout.fillWidth: true + Layout.fillHeight: true Layout.preferredHeight: childrenRect.height Layout.leftMargin: control.leftPadding Layout.rightMargin: control.rightPadding diff --git a/qt6/src/qml/Menu.qml b/qt6/src/qml/Menu.qml index 73dcab34f..204e160cb 100644 --- a/qt6/src/qml/Menu.qml +++ b/qt6/src/qml/Menu.qml @@ -42,8 +42,17 @@ T.Menu { contentItem: FocusScope { // QTBUG-99897 focus doesn't be clear. + // Handle keys even before a menu item is selected. + focus: true implicitWidth: viewLayout.implicitWidth implicitHeight: viewLayout.implicitHeight + + // Match QWidget menus with SH_MenuBar_AltKeyNavigation disabled. + Keys.onPressed: function(event) { + if (event.key === Qt.Key_Alt) + event.accepted = true + } + ColumnLayout { id: viewLayout spacing: 0 diff --git a/qt6/src/qml/TextField.qml b/qt6/src/qml/TextField.qml index 319ea3352..d069c9eb3 100644 --- a/qt6/src/qml/TextField.qml +++ b/qt6/src/qml/TextField.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -58,16 +58,15 @@ T.TextField { implicitHeight: DS.Style.edit.textFieldHeight } - MouseArea { - anchors.fill: parent + TapHandler { acceptedButtons: Qt.RightButton - onClicked: function (mouse) { - var point = Qt.point(mouse.x, mouse.y) - if (Window.window && Window.window.width > Screen.desktopAvailableWidth) { + onTapped: function (eventPoint) { + var point = Qt.point(eventPoint.position.x, eventPoint.position.y) + if (control.Window.window && control.Window.window.width > Screen.desktopAvailableWidth) { point.x = control.mapFromGlobal(Screen.desktopAvailableWidth - contextMenu.width).x } - if (Window.window && Window.window.height > Screen.desktopAvailableHeight) { + if (control.Window.window && control.Window.window.height > Screen.desktopAvailableHeight) { point.y = control.mapFromGlobal(0, Screen.desktopAvailableHeight - contextMenu.height).y } contextMenu.popup(point.x, point.y) diff --git a/qt6/src/qml/settings/SettingsDialog.qml b/qt6/src/qml/settings/SettingsDialog.qml index e11726df0..d54dab909 100644 --- a/qt6/src/qml/settings/SettingsDialog.qml +++ b/qt6/src/qml/settings/SettingsDialog.qml @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick +import QtQuick.Layouts import org.deepin.dtk 1.0 as D import org.deepin.dtk.style 1.0 as DS import org.deepin.dtk.settings 1.0 as Settings @@ -10,6 +11,7 @@ import org.deepin.dtk 1.0 DialogWindow { id: control + enableBehindWindowBlur: false property list groups property QtObject config @@ -28,60 +30,74 @@ DialogWindow { property alias navigationView: navigationView property alias contentView: contentView - ScrollView { - id: navigationBg - clip: true - width: DS.Style.settings.navigation.width - background: Rectangle { - anchors.fill: parent - color: palette.base - } + RowLayout { + anchors.fill: parent + spacing: 0 - ListView { - id: navigationView - model: container.navigationModel - leftMargin: DS.Style.settings.navigation.margin - rightMargin: DS.Style.settings.navigation.margin - currentIndex: 0 - onCurrentIndexChanged: { - contentView.currentIndex = currentIndex - } - } - } + ScrollView { + id: navigationBg + clip: true + Layout.preferredWidth: DS.Style.settings.navigation.width + Layout.fillHeight: true - ScrollView { - id: contentBg - clip: true - anchors { - right: parent.right - left: navigationBg.right - top: control.top - } - padding: DS.Style.settings.content.margin - background: Rectangle { - anchors.fill: parent - color: palette.base + ListView { + id: navigationView + clip: true + model: container.navigationModel + leftMargin: DS.Style.settings.navigation.margin + rightMargin: DS.Style.settings.navigation.margin + currentIndex: 0 + onCurrentIndexChanged: { + contentView.currentIndex = currentIndex + } + } } - ListView { - id: contentView - model: container.contentModel - highlightRangeMode: ListView.StrictlyEnforceRange - currentIndex: 0 - onCurrentIndexChanged: { - navigationView.currentIndex = currentIndex + ScrollView { + id: contentBg + Layout.fillWidth: true + Layout.fillHeight: true + leftPadding: DS.Style.settings.content.margin + rightPadding: DS.Style.settings.content.margin + topPadding: DS.Style.settings.content.margin + bottomPadding: DS.Style.settings.content.margin + background: Rectangle { + anchors.fill: parent + color: palette.window + radius: DS.Style.control.radius + Rectangle { + anchors { + fill: parent + leftMargin: contentBg.leftPadding + rightMargin: contentBg.rightPadding + topMargin: contentBg.topPadding + bottomMargin: contentBg.bottomPadding + } + color: palette.base + } } - footer: Item { - width: parent.width - height: DS.Style.settings.content.resetButtonHeight - Button { - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom - text: qsTr("Restore Defaults") + ListView { + id: contentView + model: container.contentModel + clip: true + highlightRangeMode: ListView.StrictlyEnforceRange + currentIndex: 0 + onCurrentIndexChanged: { + navigationView.currentIndex = currentIndex + } + footer: Item { + width: parent.width + height: DS.Style.settings.content.resetButtonHeight + + Button { + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + text: qsTr("Restore Defaults") - onClicked: { - settingsContainer.resetSettings(); + onClicked: { + settingsContainer.resetSettings(); + } } } } diff --git a/src/private/dbackdropnode.cpp b/src/private/dbackdropnode.cpp index 68c239dc0..6f0d6792d 100644 --- a/src/private/dbackdropnode.cpp +++ b/src/private/dbackdropnode.cpp @@ -334,9 +334,14 @@ class Q_DECL_HIDDEN RhiManager : public DataManager return m_rhi->gc; } + // renderer 的生命周期由 QSGRenderContext::invalidated 决定,见 destroyRenderer()。 + // 失效后 sync()/preprocess()/render() 一律空转,避免在已销毁的 context 上继续渲染。 void sync(const QSize &pixelSize, QSGRootNode *rootNode, const QMatrix4x4 &matrix = {}, QSGRenderer *base = nullptr, const QVector2D &dpr = {}, bool flipY = false) { + if (Q_UNLIKELY(!renderer)) + return; + Q_ASSERT(!renderer->rootNode()); if (base) { @@ -377,6 +382,9 @@ class Q_DECL_HIDDEN RhiManager : public DataManager } bool preprocess(QRhiRenderTarget *rt, qreal &oldDPR, QRhiCommandBuffer* &oldCB, QSurface *forceSurface = nullptr) { + if (Q_UNLIKELY(!renderer || !m_rhi)) + return false; + QRhiCommandBuffer *cb = nullptr; #ifndef QT_NO_OPENGL @@ -414,6 +422,9 @@ class Q_DECL_HIDDEN RhiManager : public DataManager } bool render(qreal oldDPR, QRhiCommandBuffer* &oldCB) { + if (Q_UNLIKELY(!renderer)) + return false; + Q_ASSERT(D_PRIVATE_BF_GET(*renderer, QSGRenderer_m_nodes_dont_preprocess_tag, k_m_is_rendering_bit)); rendererRender(renderer); D_PRIVATE_BF_SET(*renderer, QSGRenderer_m_nodes_dont_preprocess_tag, k_m_is_rendering_bit, false); @@ -441,7 +452,9 @@ class Q_DECL_HIDDEN RhiManager : public DataManager friend class DataManager; RhiManager(QQuickWindow *owner) - : DataManager(owner) { + : DataManager(owner) + , context(nullptr) + , renderer(nullptr) { Q_ASSERT(owner->findChildren(Qt::FindDirectChildrenOnly).size() == 1); auto oldGraphicsDevice = owner->graphicsDevice(); if (owner->rhi()->backend() == QRhi::OpenGLES2) { @@ -460,10 +473,22 @@ class Q_DECL_HIDDEN RhiManager : public DataManager context = QQuickWindowPrivate::get(owner)->context; renderer = context->createRenderer(QSGRendererInterface::RenderMode2DNoDepthBuffer); + + // QSGRenderContext 在析构前会 emit invalidated(),其 QObject 子对象 ShaderManager + // (Renderer 的 m_shaderManager 指向它,见 qsgbatchrenderer.cpp)随之先被销毁。 + // Renderer 必须在这一刻释放,不能等 RhiManager 作为 QQuickWindow 的 QObject 子对象 + // 被 deleteChildren() 清理时才 delete——那时 ~Renderer 会访问已释放的 ShaderManager。 + // Qt 自身对 QSGRhiLayer 的处理即此模式(qsgrhilayer.cpp:31-37)。 + connect(context, &QSGRenderContext::invalidated, this, &RhiManager::destroyRenderer, Qt::DirectConnection); } ~RhiManager() { + destroyRenderer(); + } + + void destroyRenderer() { delete renderer; + renderer = nullptr; } static bool check() { diff --git a/src/private/dquickcontrolpalette.cpp b/src/private/dquickcontrolpalette.cpp index a8ea3dcc0..50c42b5be 100644 --- a/src/private/dquickcontrolpalette.cpp +++ b/src/private/dquickcontrolpalette.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include #endif @@ -458,6 +459,7 @@ void DQuickControlColorSelector::setControl(QQuickItem *newControl) return; // Clean for old + disconnect(m_controlPaletteConnection); if (m_control) { m_control->disconnect(this); if (auto w = m_control->window()) @@ -469,14 +471,16 @@ void DQuickControlColorSelector::setControl(QQuickItem *newControl) if (m_control) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) auto palette = m_control->property("palette").value(); - connect(palette, &QQuickPalette::changed, this, &DQuickControlColorSelector::updateControlTheme); + if (palette) + m_controlPaletteConnection = connect(palette, &QQuickPalette::changed, + this, &DQuickControlColorSelector::scheduleControlThemeUpdate); #endif connect(m_control, &QObject::destroyed, this, [this] { m_controlWindow = nullptr; m_control = nullptr; }); if (m_control->metaObject()->indexOfSignal("paletteChanged()") != -1) { - connect(m_control, SIGNAL(paletteChanged()), this, SLOT(updateControlTheme())); + connect(m_control, SIGNAL(paletteChanged()), this, SLOT(scheduleControlThemeUpdate())); } if (m_control->metaObject()->indexOfSignal("hoveredChanged()") != -1) { connect(m_control, SIGNAL(hoveredChanged()), this, SLOT(updateControlState())); @@ -1010,6 +1014,20 @@ void DQuickControlColorSelector::updateFamilyForChildrenRecu(QQuickItem *parent) } } +void DQuickControlColorSelector::scheduleControlThemeUpdate() +{ + if (m_controlThemeUpdatePending) + return; + + m_controlThemeUpdatePending = true; + // Palette changes can originate from a binding to one of our colors. + // Wait until that binding has finished before notifying it again. + QMetaObject::invokeMethod(this, [this] { + m_controlThemeUpdatePending = false; + updateControlTheme(); + }, Qt::QueuedConnection); +} + void DQuickControlColorSelector::updateControlTheme() { if (!m_control) diff --git a/src/private/dquickcontrolpalette_p.h b/src/private/dquickcontrolpalette_p.h index fb1631989..49bf8d8af 100644 --- a/src/private/dquickcontrolpalette_p.h +++ b/src/private/dquickcontrolpalette_p.h @@ -352,6 +352,7 @@ class DQuickControlColorSelector : public QObject QByteArray findPalettePropertyName(const DQuickControlPalette *palette) const; void clearAndInheritParentProperties(); + Q_SLOT void scheduleControlThemeUpdate(); Q_SLOT void updateControlTheme(); Q_SLOT bool updateControlState(); Q_SLOT void updateAllColorProperties(); @@ -371,6 +372,8 @@ class DQuickControlColorSelector : public QObject void setFamilyPropertyParent(DQuickControlColorSelector *parent); QPointer m_control; + QMetaObject::Connection m_controlPaletteConnection; + bool m_controlThemeUpdatePending = false; QPointer m_controlWindow; QPointer m_superColorSelector; QPointer m_parentOfFamilyProperty; diff --git a/src/private/dquickiconimage.cpp b/src/private/dquickiconimage.cpp index e7cfb43f1..a49fc5556 100644 --- a/src/private/dquickiconimage.cpp +++ b/src/private/dquickiconimage.cpp @@ -213,6 +213,9 @@ void DQuickIconImage::setName(const QString &name) if (name.startsWith("data:image/")) { d->iconType = DQuickIconImagePrivate::Base64Data; + // Cancel pending URL loads and prevent sourceSize changes from + // reloading the previous icon over the image set by updateBase64Image(). + setSource(QUrl()); } else if (QQmlFile::isLocalFile(name)) { QUrl url(name); diff --git a/tests/ut_colorselector.cpp b/tests/ut_colorselector.cpp index 3a7547ebe..ad970e22b 100644 --- a/tests/ut_colorselector.cpp +++ b/tests/ut_colorselector.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -8,6 +8,13 @@ #include #include #include +#include +#include +#include + +#include "dquickcontrolpalette_p.h" + +DQUICK_USE_NAMESPACE class ut_ColorSelector : public ::testing::Test { @@ -27,6 +34,10 @@ void ut_ColorSelector::TearDown() TEST_F(ut_ColorSelector, getColorFromProperty) { ControlHelper helper("qrc:/qml/ColorSelector_GetColorFromProperty.qml"); + const auto cleanup = qScopeGuard([&helper] { + delete helper.object; + helper.object = nullptr; + }); ASSERT_TRUE(helper.object); auto listView = helper.object->property("view").value(); @@ -41,7 +52,128 @@ TEST_F(ut_ColorSelector, getColorFromProperty) QQmlEngine &engine = helper.engine; engine.globalObject().setProperty("background", engine.newQObject(background)); - ThemeTypeGuard themeGurad(DGuiApplicationHelper::LightType); - Q_UNUSED(themeGurad); + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::white))); + EXPECT_TRUE(QTest::qWaitFor([&] { + return background->property("color") + == engine.evaluate("background.color1.normal.common.color()").toVariant(); + })); ASSERT_EQ(background->property("color"), engine.evaluate("background.color1.normal.common.color()").toVariant()); } + +// Use a template control to exercise palette feedback without unrelated style +// assets. The palette is both an input and an output of the color selector. +static const char paletteFeedbackQml[] = +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + "import QtQuick\nimport QtQuick.Templates as T\n" +#else + "import QtQuick 2.11\nimport QtQuick.Templates 2.4 as T\n" +#endif +R"( +import org.deepin.dtk 1.0 as D + +T.Button { + property D.Palette textColor: D.Palette { + normal: ("red") + normalDark: ("blue") + } + palette.window: "white" + palette.windowText: D.ColorSelector.textColor +} +)"; + +TEST_F(ut_ColorSelector, paletteUpdatesAreDeferredAndCoalesced) +{ + QList warnings; + ControlHelper helper; + QObject::connect(&helper.engine, &QQmlEngine::warnings, &helper.engine, + [&warnings](const QList &errors) { warnings.append(errors); }); + ASSERT_TRUE(helper.setData(paletteFeedbackQml)); + const auto cleanup = qScopeGuard([&helper] { + delete helper.object; + helper.object = nullptr; + }); + auto selector = qobject_cast( + qmlAttachedPropertiesObject(helper.object)); + ASSERT_NE(selector, nullptr); + QCoreApplication::processEvents(); + QSignalSpy themeChanges(selector, &DQuickControlColorSelector::controlThemeChanged); + QSignalSpy colorChanges(selector, &DQuickControlColorSelector::colorPropertyChanged); + + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::black))); + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::white))); + EXPECT_EQ(themeChanges.count(), 0); + QCoreApplication::processEvents(); + EXPECT_EQ(themeChanges.count(), 0); + EXPECT_EQ(colorChanges.count(), 0); + + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::black))); + EXPECT_EQ(themeChanges.count(), 0); + QCoreApplication::processEvents(); + EXPECT_EQ(themeChanges.count(), 1); + EXPECT_EQ(QQmlProperty::read(helper.object, "palette.windowText").value(), QColor(Qt::blue)); + + // The palette writeback must settle rather than continuously queue updates. + const int settledChanges = colorChanges.count(); + for (int i = 0; i < 5; ++i) + QCoreApplication::processEvents(); + EXPECT_EQ(colorChanges.count(), settledChanges); + EXPECT_FALSE(selector->m_controlThemeUpdatePending); + for (const auto &warning : warnings) + EXPECT_FALSE(warning.description().contains("Binding loop")) << warning.toString().toStdString(); +} + +TEST_F(ut_ColorSelector, destroyWithPendingPaletteUpdate) +{ + ControlHelper helper; + ASSERT_TRUE(helper.setData(paletteFeedbackQml)); + QPointer selector = qmlAttachedPropertiesObject(helper.object); + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::black))); + delete helper.object; + helper.object = nullptr; + EXPECT_TRUE(selector.isNull()); + QCoreApplication::processEvents(); +} + +TEST_F(ut_ColorSelector, styledControlsPaletteFeedback) +{ + for (const QByteArray &type : {QByteArray("Button"), QByteArray("ToolButton"), QByteArray("MenuItem")}) { + SCOPED_TRACE(type.constData()); + QList warnings; + ControlHelper helper; + QObject::connect(&helper.engine, &QQmlEngine::warnings, &helper.engine, + [&warnings](const QList &errors) { warnings.append(errors); }); + ASSERT_TRUE(helper.setData("import QtQuick 2.11\nimport org.deepin.dtk 1.0 as D\nD." + + type + " { text: \"Palette feedback\" }")); + const auto cleanup = qScopeGuard([&helper] { + delete helper.object; + helper.object = nullptr; + }); + auto selector = qobject_cast( + qmlAttachedPropertiesObject(helper.object)); + ASSERT_NE(selector, nullptr); + QSignalSpy changes(selector, &DQuickControlColorSelector::colorPropertyChanged); + for (bool dark : {false, true}) { + ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", + QColor(dark ? Qt::black : Qt::white))); + for (bool inactive : {true, false}) { + selector->setInactived(inactive); + for (int state = 0; state < 5; ++state) { + selector->setHovered(state == 1); + selector->setPressed(state == 2); + helper.object->setEnabled(state != 3); + helper.object->setProperty("checked", state == 4); + for (int i = 0; i < 5; ++i) + QCoreApplication::processEvents(); + EXPECT_EQ(QQmlProperty::read(helper.object, "palette.windowText").value(), + selector->property("textColor").value()); + const int settledChanges = changes.count(); + QCoreApplication::processEvents(); + EXPECT_EQ(changes.count(), settledChanges); + EXPECT_FALSE(selector->m_controlThemeUpdatePending); + } + } + } + for (const auto &warning : warnings) + EXPECT_FALSE(warning.description().contains("Binding loop")) << warning.toString().toStdString(); + } +} diff --git a/tests/ut_dquickinwindowblur.cpp b/tests/ut_dquickinwindowblur.cpp index 3ae124803..9dc522c4b 100644 --- a/tests/ut_dquickinwindowblur.cpp +++ b/tests/ut_dquickinwindowblur.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -9,6 +9,11 @@ #include #include "dquickinwindowblur_p.h" +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +// 回归用例需要访问 BackdropBlitter(Qt6 下 InWindowBlur 的内部实现) +# include "dquickbackdropblitter_p.h" +#endif +#include DQUICK_USE_NAMESPACE TEST(ut_DQuickInWindowBlur, properties) @@ -29,3 +34,51 @@ TEST(ut_DQuickInWindowBlur, properties) // don't be blured area EXPECT_NE(img.pixelColor(QPoint(90, 90)), TestUtil::simpleImage->pixelColor(QPoint(90, 90))); } + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +// 回归:窗口销毁时 Renderer 的生命周期必须早于 QSGRenderContext(及其子对象 +// ShaderManager)的销毁。修复前 RhiManager 在 QObject 子对象清理阶段才 delete +// renderer,~Renderer 访问已释放的 ShaderManager 必然 SIGSEGV(QSGBatchRenderer +// ::destroyGraphicsResources → ShaderManager::clearCachedRendererData,见 +// dbackdropnode.cpp RhiManager::~RhiManager)。本用例在 RHI 渲染路径上先渲染一帧、 +// 再随窗口销毁触发 invalidated(),修复前进程崩溃,修复后正常退出。 +// 仅 Qt6 有效:Qt5 的 InWindowBlur 走 DQuickInWindowBlur C++ 类,不创建 +// RhiManager,本用例场景在 Qt5 不存在。 +TEST(ut_DQuickInWindowBlur, destroyWithBackdropNodeOnRhi) +{ + TEST_OFFSCREEN_SKIP(); + + // D.InWindowBlur 在 Qt6 解析为 overridable QML(内含 D.BackdropBlitter), + // 该元素在 updatePaintNode 中创建 DBackdropNode(RhiNode)并建立 RhiManager。 + // 必须确认 node 确实被创建、且启用 InWindowBlur 场景(非软件渲染、非被 + // DTK_DISABLE_INWINDOWBLUR 关闭),否则本用例什么都没测到。 + if (QQuickWindow::sceneGraphBackend() == QLatin1String("software")) + GTEST_SKIP_("RhiManager 只在 RHI 渲染路径创建,软件渲染不适用本用例"); + + QuickViewHelper<> helper("qrc:/qml/DQuickInWindowBlur.qml"); + ASSERT_TRUE(helper.object); + + // Qt6 下 D.InWindowBlur 是 overridable QML 类型(内含 D.BackdropBlitter), + // 不再是 C++ 的 DQuickInWindowBlur;直接找 BackdropBlitter 实例。 + auto blurItem = helper.object->findChild(); + if (!blurItem) + GTEST_SKIP_("Qt6 InWindowBlur 未解析到 BackdropBlitter,环境不支持"); + if (!blurItem->blitterEnabled()) + GTEST_SKIP_("InWindowBlur 被禁用(DTK_DISABLE_INWINDOWBLUR 或 DConfig)"); + + // 等真实渲染帧而非固定延时:RhiManager/Renderer 在渲染线程同步时建立, + // 以 afterRendering(每帧从渲染线程发出、跨线程投递到主线程)作为"至少 + // 完成一帧"的信号。固定 qWait 在慢机器/高负载下可能首帧未完成就销毁, + // 测试静默"假通过"(未建立 RhiManager 就销毁,什么都没测到)。 + QQuickWindow *window = helper.view.data(); + QSignalSpy renderSpy(window, &QQuickWindow::afterRendering); + window->update(); // 若首帧已错过,强制再出一帧 + if (!renderSpy.wait(3000)) + GTEST_SKIP_("3s 内未等到渲染帧,无法确认 RhiManager 已建立,跳过本用例"); + + // 销毁窗口:走 QQuickWindow::~QQuickWindow → windowDestroyed → context + // invalidate() → delete;随后 QObject::deleteChildren 才轮到 RhiManager。 + // 修复前此行即 SIGSEGV。 + helper.clear(); +} +#endif // QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)