Skip to content

fix(title): enable ratio control before status text is ready#462

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master
Jul 20, 2026
Merged

fix(title): enable ratio control before status text is ready#462
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:master

Conversation

@wyu71

@wyu71 wyu71 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Keep the ratio control available for a nonempty all-items collection. 在异步状态文本填充前,为非空的全部合集保持比例按钮可用。

Log: 修复首屏比例按钮延迟可用的问题
Influence: 全部合集首屏的原始比例和方形缩略图切换

@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.

Sorry @wyu71, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Keep the ratio control available for a nonempty all-items collection.
在异步状态文本填充前,为非空的全部合集保持比例按钮可用。

Log: 修复首屏比例按钮延迟可用的问题
Influence: 全部合集首屏的原始比例和方形缩略图切换
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码通过增加状态属性优化了比例按钮的可用性判断逻辑,避免了异步加载导致的渲染问题
逻辑清晰且符合QML规范,无安全漏洞,仅因条件表达式略微复杂扣少量分数

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码在 TitleBar 组件中新增了 initialRatioContentAvailableratioContentStateResolved 属性,并正确使用了 Connections 监听 GStatusonStatusBarNumTextChanged 信号。Component.onCompleted 中的初始化逻辑正确。range1Buttonenabled 属性条件表达式括号匹配正确,逻辑运算符使用无误。
潜在问题:enabled 的条件表达式较长,阅读和理解成本稍高
建议:可考虑将复杂的条件判断提取为一个独立的只读属性或函数,以提高可读性

  • 2.代码质量(良好)✓

新增了详细的注释解释 initialRatioContentAvailable 的设计意图,变量命名能够准确表达其业务含义。代码结构清晰,ConnectionsComponent.onCompleted 的位置安排合理。
潜在问题:无
建议:保持现有的注释习惯,对于复杂的布尔逻辑可适当添加行内注释

  • 3.代码性能(无性能问题)✓

albumControl.getAllCount() 仅在组件初始化时计算一次,未引入频繁的轮询或重复计算。信号槽连接机制高效,不会造成额外的性能开销。
潜在问题:无
建议:无需优化

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码为纯QML前端UI逻辑,不涉及敏感数据处理、外部命令执行或文件系统操作,不存在安全风险。

  • 建议:无需安全修复

■ 【改进建议代码示例】

diff --git a/src/qml/AlbumTitle.qml b/src/qml/AlbumTitle.qml
index dc0b3c12..e9c4ef11 100644
--- a/src/qml/AlbumTitle.qml
+++ b/src/qml/AlbumTitle.qml
@@ -50,6 +50,11 @@ TitleBar {
     property int layoutLeftMargin_AlignLeft: showHideleftSidebarButton.x + showHideleftSidebarButton.width // 显示比例按钮向标题左侧对齐时的布局留白宽度
     property int layoutLeftMargin_AlignRight: GStatus.sideBarWidth + 10 // 显示比例按钮向标题右侧对齐时的布局留白宽度
     property bool collectionComboEverNarrow: false
+    // Do not wait for the asynchronously populated status text to render the
+    // ratio button. Once a view has supplied status text, that text remains
+    // the authoritative availability state for subsequent view changes.
+    property bool initialRatioContentAvailable: albumControl.getAllCount() > 0
+    property bool ratioContentStateResolved: false
+    
+    // 提取复杂逻辑为只读属性,增强可读性
+    readonly property bool isRange1ButtonEnabled: !(GStatus.currentViewType === Album.Types.ViewCollecttion
+                                                    && GStatus.currentCollecttionViewIndex === 0)
+                                                  && (GStatus.statusBarNumText !== ""
+                                                      || (!title.ratioContentStateResolved
+                                                          && GStatus.currentViewType === Album.Types.ViewCollecttion
+                                                          && GStatus.currentCollecttionViewIndex === 3
+                                                          && title.initialRatioContentAvailable))
 
     property int lastWidth: 0
     onWidthChanged: {
@@ -83,6 +88,18 @@ TitleBar {
         lastWidth = width
     }
 
+    Connections {
+        target: GStatus
+        function onStatusBarNumTextChanged() {
+            if (GStatus.statusBarNumText !== "")
+                title.ratioContentStateResolved = true
+        }
+    }
+
+    Component.onCompleted: {
+        ratioContentStateResolved = GStatus.statusBarNumText !== ""
+    }
+
     // 显示比例按钮向左对齐动画
     NumberAnimation {
         id: layoutMoveToRightAnimation
@@ -220,7 +237,13 @@ TitleBar {
                 id: range1Button
                 Layout.preferredWidth: iconSize
                 Layout.preferredHeight: iconSize
-                enabled: GStatus.statusBarNumText !== "" && !(GStatus.currentViewType === Album.Types.ViewCollecttion && GStatus.currentCollecttionViewIndex === 0)
+                enabled: title.isRange1ButtonEnabled
                 ToolTip.visible: hovered
                 ToolTip.text: icon.name === "range1" ? qsTr("Original ratio") : qsTr("Square thumbnails")
                 icon {

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx, wyu71

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

@wyu71
wyu71 merged commit 450be9a into linuxdeepin:master Jul 20, 2026
17 checks passed
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