Skip to content

fix: avoid quick panel placeholder not aligned to center on startup#1564

Merged
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:pms-bug-283031
Apr 22, 2026
Merged

fix: avoid quick panel placeholder not aligned to center on startup#1564
BLumia merged 1 commit into
linuxdeepin:masterfrom
BLumia:pms-bug-283031

Conversation

@BLumia
Copy link
Copy Markdown
Member

@BLumia BLumia commented Apr 21, 2026

把Grid替换为GridLayout来使用布局特性,使托盘上的快捷面板部件内的元素始终可以居中,避免托盘插件未就绪时,元素偏离中心显示.

@BLumia BLumia requested review from 18202781743 and wjyrich April 21, 2026 08:38
Copy link
Copy Markdown

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

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

Please try again later or upgrade to continue using Sourcery

wjyrich
wjyrich previously approved these changes Apr 22, 2026
把Grid替换为GridLayout来使用布局特性,使托盘上的快捷面板部件内的元素
始终可以居中,避免托盘插件未就绪时,元素偏离中心显示.

PMS: BUG-283031
Log:
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码主要对托盘区域的UI布局进行了调整,涉及尺寸修改和布局容器的替换。以下是对语法逻辑、代码质量、性能和安全的详细审查及改进意见:

1. 语法与逻辑审查

  • ShellSurfaceItemProxy.qml:

    • 逻辑: 修改了 implicitWidthimplicitHeight 的默认回退值从 1016
    • 分析: 这是一个合理的调整。通常 UI 组件的最小点击区域或占位尺寸建议不小于 16x16 或 32x32 像素,以符合人机工程学标准。如果 shellSurface 为空,10像素的尺寸过小,可能导致视觉异常或难以点击。增加至 16 像素能改善空状态下的视觉效果。
  • PanelTrayItem.qml:

    • 逻辑: 将 contentItem 的容器从 Grid 替换为 GridLayout
    • 分析: 这是一个破坏性逻辑上可能有问题的变更。
      • Grid: rows: root.useColumnLayout ? 2 : 1 意味着如果不使用列布局(即行布局),行数为1,所有子元素横向排列。如果使用列布局,行数为2,这意味着它强制布局为2行。
      • GridLayout: flow: root.useColumnLayout ? GridLayout.TopToBottom : GridLayout.LeftToRightflow 属性控制的是填充顺序(先填满行还是先填满列),但不限制行数或列数
      • 后果: 原代码逻辑暗示布局是固定的(要么横向一排,要么纵向两排)。新代码使用 flow 后,如果子元素数量变化,布局可能会变得不可预测(例如纵向排列时可能会超过2行,或者横向排列时超过1行)。
      • 建议: 需要确认业务逻辑是否允许子元素数量变化。如果必须保持原来的"1行或2行"的限制,应继续使用 Grid 或者在 GridLayout 中显式设置 columnsrows 属性。
    • 逻辑: 移除了 quickpanelPlaceholder 的显式宽高设置,改为使用 padding
    • 分析: 原代码逻辑是:如果 placeholder 未激活,quickpanelPlaceholder 的大小固定为 16 + itemMargins。现在改为依赖 paddingcontentItem (DciIcon) 的 sourceSize (16x16) 来撑开大小。这种写法更符合 QML 的声明式布局习惯,只要 DciIcon 能正确渲染,尺寸计算是准确的。

2. 代码质量

  • 可维护性:
    • PanelTrayItem.qml 中,GridGridLayout 的切换改变了布局的核心行为。建议在注释中说明为什么要使用 flow 而不是固定 rows/columns,以及是否预期了子元素数量的变化。
  • 一致性:
    • ShellSurfaceItemProxy.qml 中的默认尺寸 16PanelTrayItem.qmlDciIconsourceSize: Qt.size(16, 16) 保持了一致,这是一个好的信号,表明系统对空状态或图标的最小尺寸有了统一标准。

3. 性能

  • 布局开销:
    • GridLayout 相比 Grid 计算稍微复杂一些,因为它需要处理更复杂的对齐和跨度。但在托盘这种子元素极少(通常只有1-2个)的场景下,性能差异可以忽略不计。
  • 绑定:
    • Layout.alignment: Qt.AlignCenter 的引入是合理的,确保了元素在布局单元格内的居中,视觉上更美观。

4. 安全性

  • 此处无明显的安全性风险,主要涉及 UI 渲染逻辑。

总结与改进建议

这段代码的主要问题集中在 PanelTrayItem.qmlGridGridLayout 的变更,这改变了布局的约束逻辑。

建议修改如下:

如果业务逻辑上需要严格保持原来的"横向1行"或"纵向2行"的布局结构,建议显式指定 rowscolumns,而不是仅依赖 flow

修改后的代码建议 (针对 PanelTrayItem.qml):

    contentItem: GridLayout {
        // 根据布局方向设置行数或列数,以保持原有逻辑
        rows: root.useColumnLayout ? 2 : 1
        columns: root.useColumnLayout ? 1 : 2 // 或者根据子元素数量动态设置
        
        // 如果确实希望使用 flow (即不限制行/列数),请保留原代码的 flow
        // flow: root.useColumnLayout ? GridLayout.TopToBottom : GridLayout.LeftToRight
        
        rowSpacing: 0
        columnSpacing: 0

        Loader {
            id: placeholder
            Layout.alignment: Qt.AlignCenter
            Layout.fillHeight: true // 可选:是否填充高度
            Layout.fillWidth: true  // 可选:是否填充宽度
            active: root.shellSurface
            visible: active
            sourceComponent: TrayItemSurface {
                // ...
            }
        }
        Control {
            id: quickpanelPlaceholder
            Layout.alignment: Qt.AlignCenter
            padding: itemMargins
            // ...
        }
    }

具体建议:

  1. 明确布局约束: 如果原代码 rows: 2 是为了确保只有两个元素上下排列,那么在 GridLayout 中应该保留 rows: root.useColumnLayout ? 2 : 1,或者设置 columns: root.useColumnLayout ? 1 : 2。不要仅依赖 flow,除非你希望布局是流式的。
  2. 填充属性: 考虑为 Loader 添加 Layout.fillHeightLayout.fillWidth(如果需要),以确保 TrayItemSurface 能够正确填充分配给它的空间。

结论:
ShellSurfaceItemProxy.qml 的修改是好的。PanelTrayItem.qml 的修改在语法上没问题,但在逻辑上可能改变了布局行为(从固定行数变为流式布局)。请务必确认这是预期行为,否则建议显式添加 rowscolumns 属性以维持原有的布局约束。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, wjyrich

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

@BLumia BLumia merged commit c1cb16a into linuxdeepin:master Apr 22, 2026
9 of 12 checks passed
@BLumia BLumia deleted the pms-bug-283031 branch April 22, 2026 03:06
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