Skip to content

fix: fall back to standard palette for typed colors without control - #722

Open
Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3
Open

Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3

Conversation

@Ivy233

@Ivy233 Ivy233 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

DQuickControlColorSelector::getColorOfColor() left the color invalid when a typed color (e.g. D.Color.Highlight used by HighlightPanel's backgroundColor) was resolved without any QQuickControl ancestor -- popup/window contexts such as Menu/ArrowListView highlights, or a window-level attached selector. The default-constructed invalid QColor has alpha 255, so HighlightPanel rendered as an opaque black block, and every read of the property printed
"ColorSelector: The ... is an invalid color on ...".

Fall back to DGuiApplicationHelper::standardPalette() of the current theme, consistent with the inactive-blend branch just below. Verified with a minimal QML scene (HighlightPanel under a plain Item): before, 5 warnings and backgroundColor invalid (#000000); after, no warning and a valid highlight color (#024cca).

修复:无 Control 祖先时类型化颜色回退到标准调色板

DQuickControlColorSelector::getColorOfColor() 在类型化颜色(如 HighlightPanel 的 backgroundColor 使用的 D.Color.Highlight)于无 QQuickControl 祖先的上下文(Menu/ArrowListView 高亮等 popup/window 场景,或窗口级附加 selector)解析时返回无效颜色。默认构造的无效
QColor alpha 为 255,导致 HighlightPanel 被画成不透明黑块,且每次
读取属性都打印 "ColorSelector: The ... is an invalid color on ..."。

回退到当前主题的 DGuiApplicationHelper::standardPalette(),与下方 inactive 混色分支保持一致。已用最小 QML 场景(HighlightPanel 挂在
纯 Item 下)验证:修复前 5 条告警且 backgroundColor 无效(#000000), 修复后无告警且返回有效高亮色(#024cca)。

PMS: TASK-394335

Summary by Sourcery

Prevent invalid typed-color resolution in popup and window-level highlight contexts by using the current theme’s standard palette as a fallback.

Bug Fixes:

  • Ensure typed colors resolve to a valid theme color when no QQuickControl ancestor is available, preventing invalid-color warnings and opaque black rendering.
  • Keep menu and arrow-list highlights within a Control context so their typed colors resolve correctly.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Typed colors now resolve through the current theme’s standard application palette when no QQuickControl ancestor is available, preserving control-specific behavior otherwise and preventing invalid color results in popup/window contexts.

Flow diagram for typed color palette fallback

flowchart TD
    A[Resolve target color] --> B{"targetColor.isTypedColor()"}
    B -- No --> C["targetColor.color()"]
    B -- Yes --> D{m_control available?}
    D -- Yes --> E["targetColor.toColor(_d_getControlPalette(m_control))"]
    D -- No --> F["targetColor.toColor(DGuiApplicationHelper::standardPalette(state->controlTheme))"]
    C --> G[Return valid QColor]
    E --> G
    F --> G
Loading

File-Level Changes

Change Details Files
Add a standard-palette fallback when resolving typed colors without a control ancestor.
  • Continue using the control-specific palette when a control is available.
  • Use the current theme’s application-wide standard palette for popup, window, and other control-less contexts.
  • Prevent invalid colors, opaque black rendering, and repeated invalid-color warnings.
src/private/dquickcontrolpalette.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.51
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #723

@Ivy233
Ivy233 force-pushed the fix/dde-shell-warning-batch3 branch from 7d93864 to 1b23d50 Compare October 21, 2026 05:41
interactive: itemsView.count > maxVisibleItems
ScrollIndicator.vertical: ScrollIndicator { }
highlight: HighlightPanel {
highlight: Control {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接把HighlightPanel的根从Item改成Control是不是也可以,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里先确认一下“根”指哪个对象:

如果指 HighlightPanel.qml 的根(当前是 Item),不建议直接改成 Control。ColorSelector::findAndSetControlParent() 是从元素自身开始找第一个 Control 的,根改成 Control 后会停在自身;MenuItem / ItemDelegate / NavigationTitle 这些把 HighlightPanel 当 background 的场景就不再继承宿主 Control 的 hovered / pressed / disabled 状态。FlowStyle 里 highlightPanel.background 定义了 hovered 变体,本地最小 QML 对比同一个 hovered 宿主下,Item 根是 Hovered / #4099d0,Control 根变成 Normal / #308cc6,会有可见的 hover 高亮色变化。

如果指 ArrowListView.qml 的根 FocusScope,也不建议改:Control 不继承 FocusScope,键盘焦点/导航语义会变;Menu.qml 的根是 T.Menu / Popup,更无法改成 Control。

所以当前只在 Menu / ArrowListView 的 ListView.highlight 外包一层 Control,作用域最小;C++ 的 standardPalette 回退继续覆盖独立/窗口级无 Control 场景。若希望减少改动,可以只保留 C++ 回退、去掉这两处包裹,但不建议改公共组件的根类型。

DQuickControlColorSelector::getColorOf() left the color invalid when a
typed color (e.g. D.Color.Highlight used by HighlightPanel's
backgroundColor) was resolved without any QQuickControl ancestor --
popup/window contexts such as Menu/ArrowListView highlights, or a
window-level attached selector. The default-constructed invalid QColor
has alpha 255, so HighlightPanel rendered as an opaque black block, and
every read of the property printed
"ColorSelector: The ... is an invalid color on ...".

Fall back to DGuiApplicationHelper::standardPalette() of the current
theme, consistent with the inactive-blend branch just below. Verified
with a minimal QML scene (HighlightPanel under a plain Item): before,
5 warnings and backgroundColor invalid (#000000); after, no warning
and a valid highlight color (#024cca).

Also wrap the ListView.highlight HighlightPanel in a Control in the Qt6
Menu/ArrowListView components (qt6/src/qml/Menu.qml and
qt6/src/qml/ArrowListView.qml). This gives dtk's own highlight the
QQuickControl ancestor that ColorSelector expects, without changing the
highlight geometry or z-order. The standard-palette fallback above still
covers other control-less contexts (standalone HighlightPanel,
window-level selectors).

修复:无 Control 祖先时类型化颜色回退到标准调色板

DQuickControlColorSelector::getColorOf() 在类型化颜色(如
HighlightPanel 的 backgroundColor 使用的 D.Color.Highlight)于无
QQuickControl 祖先的上下文(Menu/ArrowListView 高亮等 popup/window
场景,或窗口级附加 selector)解析时返回无效颜色。默认构造的无效
QColor alpha 为 255,导致 HighlightPanel 被画成不透明黑块,且每次
读取属性都打印 "ColorSelector: The ... is an invalid color on ..."。

回退到当前主题的 DGuiApplicationHelper::standardPalette(),与下方
inactive 混色分支保持一致。已用最小 QML 场景(HighlightPanel 挂在
纯 Item 下)验证:修复前 5 条告警且 backgroundColor 无效(#000000),
修复后无告警且返回有效高亮色(#024cca)。

同时将 Qt6 Menu/ArrowListView 的 ListView.highlight 用 Control 包裹
(qt6/src/qml/Menu.qml、qt6/src/qml/ArrowListView.qml),为
HighlightPanel 提供 ColorSelector 期望的 QQuickControl 祖先,不改变
高亮的几何与 z 序;上述标准调色板回退继续覆盖其他无 Control 场景
(独立 HighlightPanel、窗口级 selector)。

PMS: TASK-394335
@Ivy233
Ivy233 force-pushed the fix/dde-shell-warning-batch3 branch from 1b23d50 to 0064daf Compare October 21, 2026 09:09
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了无 Control 父级链时类型化颜色无法解析的问题,通过在 QML 层将 HighlightPanel 包装为 Control 的 contentItem,并在 C++ 层添加标准调色板回退逻辑,方案合理且实现正确。四维度均无问题,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ["可选:修正预存 TODO 注释中的拼写错误 'confict' -> 'conflict'(ArrowListView.qml 第11行、Menu.qml 第43行),虽非本次引入但可在后续清理。"]


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 当前实现已正确,无需修改。以下为本次修复的核心逻辑参考: // dquickcontrolpalette.cpp - getColorOf() 中的回退逻辑 if (targetColor.isTypedColor()) {
    if (m_control)
        colorValue = targetColor.toColor(_d_getControlPalette(m_control));
    else
        // no control in the parent chain: fall back to standard palette
        colorValue = targetColor.toColor(DGuiApplicationHelper::standardPalette(state->controlTheme));
} else {
    colorValue = targetColor.color();
}

本报告由 AI 代码审查工具自动生成

@Ivy233
Ivy233 requested a review from 18202781743 October 21, 2026 09:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants