Skip to content

sync: from linuxdeepin/dtkdeclarative#303

Merged
18202781743 merged 1 commit intomasterfrom
sync-pr-530-nosync
Sep 22, 2025
Merged

sync: from linuxdeepin/dtkdeclarative#303
18202781743 merged 1 commit intomasterfrom
sync-pr-530-nosync

Conversation

@deepin-ci-robot
Copy link
Contributor

@deepin-ci-robot deepin-ci-robot commented Sep 22, 2025

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#530

Summary by Sourcery

Enhancements:

  • Apply an inactive mask blend to control colors when in InactiveState with UseInactiveColorGroup enabled, using theme-specific alpha values.

Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#530
@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

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

@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

这段代码是关于颜色选择的逻辑,我来分析一下它的语法逻辑、代码质量、性能和安全性:

  1. 语法逻辑:
  • 代码逻辑基本清晰,首先处理颜色的反转(当需要反转时),然后处理非活动状态的颜色。
  • 使用了条件判断来区分不同的状态和主题。
  • 颜色混合逻辑使用了DGuiApplicationHelper的blendColor方法,这看起来是合理的。
  1. 代码质量:
  • 代码注释清晰,解释了代码的用途和参考来源(dtkgui的generatePaletteColor_helper)。
  • 使用了静态常量useInactiveColor来避免重复调用DGuiApplicationHelper::testAttribute,这是一个好的优化。
  • 变量命名清晰,如inactiveMaskColor、windowColor等。
  1. 性能:
  • 使用static const来缓存useInactiveColor的值,避免了每次调用都进行属性检查,这是一个好的性能优化。
  • 颜色混合操作可能会涉及一些计算,但对于现代计算机来说,这种计算开销很小。
  1. 安全性:
  • 代码使用了Qt框架提供的颜色处理方法,这些方法已经过充分测试,应该是安全的。
  • 颜色值的处理使用了Qt的QColor类,可以确保颜色值在有效范围内。

改进建议:

  1. 可以考虑将颜色混合的alpha值(0.6和0.4)定义为命名常量,以提高代码的可读性和可维护性。例如:
static const qreal DARK_INACTIVE_ALPHA = 0.6;
static const qreal LIGHT_INACTIVE_ALPHA = 0.4;
  1. 可以考虑添加一些错误处理或日志记录,以便在颜色处理过程中出现问题时能够更容易地调试。

  2. 如果这段代码会在性能敏感的场景下频繁调用,可以考虑将颜色混合的结果缓存起来,特别是对于那些频繁使用的颜色组合。

  3. 可以考虑添加一些单元测试,以确保颜色处理逻辑的正确性,特别是对于不同的主题和状态组合。

  4. 如果DGuiApplicationHelper::standardPalette可能会返回无效的调色板,应该添加检查以确保调色板的有效性。

总体而言,这段代码质量良好,逻辑清晰,并且已经考虑了一些性能优化。上述建议主要是为了进一步提高代码的可维护性和健壮性。

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 22, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This pull request synchronizes upstream changes by introducing inactive-state color blending in the DQuickControlColorSelector::getColorOf method, allowing controls marked inactive to display a mask based on the window color and theme.

Sequence diagram for inactive state color blending in getColorOf

sequenceDiagram
    participant Selector as DQuickControlColorSelector
    participant Helper as DGuiApplicationHelper
    participant State as DQMLGlobalObject::ControlState
    participant Palette as QPalette
    Note over Selector: getColorOf called
    Selector->Helper: testAttribute(UseInactiveColorGroup)
    alt UseInactiveColorGroup is true and State is InactiveState
        Selector->Helper: standardPalette(State.controlTheme)
        Helper->Palette: get Window color
        Palette-->>Selector: windowColor
        Selector->Palette: setAlphaF (0.6 or 0.4 based on theme)
        Selector->Helper: blendColor(colorValue, inactiveMaskColor)
        Helper-->>Selector: blendedColor
    end
    Selector-->>Caller: colorValue
Loading

Class diagram for updated DQuickControlColorSelector::getColorOf logic

classDiagram
    class DQuickControlColorSelector {
        +QColor getColorOf(const DQuickControlPalette *palette, const DQMLGlobalObject::ControlState *state)
    }
    class DGuiApplicationHelper {
        +static bool testAttribute(Attribute)
        +static QPalette standardPalette(Theme)
        +static QColor blendColor(QColor, QColor)
        UseInactiveColorGroup
        DarkType
    }
    class DQMLGlobalObject {
        InactiveState
        ControlState
    }
    class QPalette {
        +QColor color(ColorRole)
        Window
    }
    DQuickControlColorSelector --> DGuiApplicationHelper : uses
    DQuickControlColorSelector --> DQMLGlobalObject : uses
    DQuickControlColorSelector --> QPalette : uses
Loading

File-Level Changes

Change Details Files
Add inactive-state color blending in getColorOf
  • Check UseInactiveColorGroup attribute
  • Detect DQMLGlobalObject::InactiveState
  • Obtain standard palette and window color
  • Set mask alpha based on Light/Dark theme
  • Blend original color with inactive mask
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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/private/dquickcontrolpalette.cpp:846` </location>
<code_context>
     }

+    // items with inactive state should use inactive color, it likes dtkgui's generatePaletteColor_helper.
+    static const auto useInactiveColor = DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::UseInactiveColorGroup);
+    if (useInactiveColor && state->controlState == DQMLGlobalObject::InactiveState) {
+        const auto &palette = DGuiApplicationHelper::standardPalette(state->controlTheme);
+        const auto &windowColor = palette.color(QPalette::Window);
</code_context>

<issue_to_address>
**suggestion:** Consider whether static const is appropriate for useInactiveColor.

If the application's attribute can change at runtime, use a local variable instead to ensure the value is always current.

```suggestion
    const auto useInactiveColor = DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::UseInactiveColorGroup);
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

// items with inactive state should use inactive color, it likes dtkgui's generatePaletteColor_helper.
static const auto useInactiveColor = DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::UseInactiveColorGroup);
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider whether static const is appropriate for useInactiveColor.

If the application's attribute can change at runtime, use a local variable instead to ensure the value is always current.

Suggested change
static const auto useInactiveColor = DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::UseInactiveColorGroup);
const auto useInactiveColor = DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::UseInactiveColorGroup);

@18202781743 18202781743 merged commit c62b45a into master Sep 22, 2025
14 of 16 checks passed
@18202781743 18202781743 deleted the sync-pr-530-nosync branch September 22, 2025 10:18
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.

2 participants