Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Nov 26, 2025

目前在 tips 控件的类型(单行/多行)变化时,若原本控件内存储的文案没有变化,则不一定会重新计算界面宽度.此提交新增了类型变化的检查.

Summary by Sourcery

Ensure tips widgets recompute and update their layout when switching between single-line and multi-line modes, and simplify Bluetooth tooltip width handling by relying on the tips widget geometry instead of manual sizing.

Bug Fixes:

  • Fix tips widgets not updating geometry when the tips type changes but the underlying text remains the same.

Enhancements:

  • Remove redundant manual width calculation for Bluetooth tooltip labels to let the tips widget manage its own sizing.

@BLumia BLumia requested a review from yixinshark November 26, 2025 10:26
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 26, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures tooltip geometry is updated when the tips widget type switches between single-line and multi-line, even if the text content is unchanged, and removes now-redundant manual width handling in the Bluetooth item.

Sequence diagram for Bluetooth tooltip refresh with updated TipsWidget

sequenceDiagram
  actor User
  participant BluetoothItem
  participant TipsWidget

  User->>BluetoothItem: hover triggers refreshTips()
  BluetoothItem->>TipsWidget: setText(tipsText)
  activate TipsWidget
  TipsWidget->>TipsWidget: compute typeChanged based on m_type
  TipsWidget->>TipsWidget: m_type = SingleLine
  alt text unchanged
    TipsWidget->>TipsWidget: updateGeometry()
    TipsWidget->>TipsWidget: update()
    TipsWidget-->>BluetoothItem: return
  else text changed
    TipsWidget->>TipsWidget: m_text = newText
    TipsWidget->>TipsWidget: updateGeometry()
    TipsWidget->>TipsWidget: update()
    TipsWidget-->>BluetoothItem: return
  end
  deactivate TipsWidget
  BluetoothItem->>BluetoothItem: m_quickPanel->setDescription(description)
  BluetoothItem-->>User: updated tooltip and quick panel shown
Loading

Class diagram for updated TipsWidget and BluetoothItem

classDiagram
  class TipsWidget {
    enum Type
    Type m_type
    QString m_text
    QStringList m_textList
    +setText(text: QString): void
    +setTextList(textList: QStringList): void
    +updateGeometry(): void
    +update(): void
  }

  class BluetoothItem {
    +refreshTips(): void
    QWidget m_tipsLabel
    QWidget m_quickPanel
  }

  BluetoothItem --> TipsWidget : uses m_tipsLabel as tooltip widget
Loading

File-Level Changes

Change Details Files
Ensure TipsWidget updates geometry when switching between single-line and multi-line modes even if text content is unchanged.
  • Track whether the widget type is changing before assigning the new type in setText and setTextList.
  • If the text (or text list) is unchanged but the type has changed, call updateGeometry() and update() before returning.
  • Preserve existing behavior when both type and text remain unchanged.
plugins/dde-dock/widgets/tipswidget.cpp
Rely on TipsWidget’s internal geometry handling instead of manually sizing the Bluetooth tooltip label.
  • Remove manual text width calculation using QFontMetrics for the Bluetooth tips label.
  • Stop setting a minimum width on the Bluetooth tips label so its size is governed by TipsWidget’s geometry updates.
plugins/dde-dock/bluetooth/bluetoothitem.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 - here's some feedback:

  • In setTextList, the typeChanged check uses m_type != TipsWidget::SingleLine, which means switching from SingleLine to MultiLine will incorrectly set typeChanged to false; compare against the new type (or the previous type) instead so type changes are detected correctly.
  • Both setText and setTextList duplicate the same typeChanged/updateGeometry()/update() logic; consider capturing the previous type once and refactoring this into a small helper or shared block to avoid divergence between the two paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `setTextList`, the `typeChanged` check uses `m_type != TipsWidget::SingleLine`, which means switching from `SingleLine` to `MultiLine` will incorrectly set `typeChanged` to `false`; compare against the new type (or the previous type) instead so type changes are detected correctly.
- Both `setText` and `setTextList` duplicate the same `typeChanged`/`updateGeometry()`/`update()` logic; consider capturing the previous type once and refactoring this into a small helper or shared block to avoid divergence between the two paths.

## Individual Comments

### Comment 1
<location> `plugins/dde-dock/widgets/tipswidget.cpp:22-25` </location>
<code_context>

 void TipsWidget::setText(const QString &text)
 {
+    bool typeChanged = m_type != TipsWidget::SingleLine;
     m_type = TipsWidget::SingleLine;
     // 如果传递的是富文本,获取富文本中的纯文本内容进行显示
</code_context>

<issue_to_address>
**issue (bug_risk):** The type change detection in setTextList compares against SingleLine instead of MultiLine, which breaks the intended geometry update logic.

In `setTextList`, `typeChanged` is computed against `TipsWidget::SingleLine`, but the new type is `TipsWidget::MultiLine`. As a result, transitions from `SingleLine` to `MultiLine` don’t trigger `updateGeometry()` / `update()` even though the type changed. This should match `setText` and use `bool typeChanged = (m_type != TipsWidget::MultiLine);` so changes to `MultiLine` are detected correctly.
</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.

wjyrich
wjyrich previously approved these changes Nov 27, 2025
目前在 tips 控件的类型(单行/多行)变化时,若原本控件内存储的文案没有
变化,则不一定会重新计算界面宽度.此提交新增了类型变化的检查.

PMS: BUG-335551
Log:
@deepin-ci-robot
Copy link

deepin pr auto review

我来分析一下这两个文件的修改:

  1. bluetoothitem.cpp 的修改:
  • 删除了手动设置标签最小宽度的代码
  • 这是一个好的改动,因为:
    • Qt 的布局系统通常会自动处理控件大小
    • 手动设置固定宽度可能会影响布局的自适应性
    • 移除这些代码可以让界面更灵活地适应不同长度的文本
  1. tipswidget.cpp 的修改:
  • 在 setText 和 setTextList 方法中添加了 typeChanged 检查
  • 当类型改变时(从单行到多行或反之),会触发更新
  • 这个改进是合理的,因为:
    • 确保了在类型改变时界面能正确更新
    • 避免了不必要的重绘和几何计算
    • 提高了代码的健壮性

建议改进:

  1. 对于 bluetoothitem.cpp:

    • 如果确实需要控制提示文本的宽度,建议使用 sizePolicy 而不是固定最小宽度
    • 可以考虑使用 setWordWrap(true) 来处理长文本
  2. 对于 tipswidget.cpp:

    • 可以考虑将 typeChanged 的检查逻辑提取为一个公共方法,避免代码重复
    • 建议添加注释说明为什么需要在 typeChanged 时更新几何和重绘
  3. 通用建议:

    • 考虑添加单元测试来验证这些改动
    • 建议添加相关的文档说明这些改动的影响

这些修改总体上是积极的,提高了代码的可维护性和界面的响应性。

@BLumia BLumia requested a review from wjyrich November 27, 2025 02:53
@deepin-ci-robot
Copy link

[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 3a97055 into linuxdeepin:master Nov 27, 2025
9 of 10 checks passed
@BLumia BLumia deleted the pms-335551 branch November 27, 2025 03:02
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