Skip to content

feat: add icon scaling with keyboard shortcuts#653

Merged
wjyrich merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-289529
Sep 29, 2025
Merged

feat: add icon scaling with keyboard shortcuts#653
wjyrich merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-289529

Conversation

@wjyrich

@wjyrich wjyrich commented Sep 28, 2025

Copy link
Copy Markdown
Contributor
  1. Added icon scaling functionality with Ctrl++/Ctrl+= to zoom in and Ctrl+- to zoom out
  2. Implemented smooth scaling animation with 200ms duration and easing
  3. Set scaling limits between 0.5x and 1.0x with 0.1x step increments
  4. Updated IconItemDelegate to support iconScaleFactor property for consistent scaling
  5. Added transformOrigin: Item.Center to maintain icon positioning during scaling

feat: 添加图标缩放功能和键盘快捷键

  1. 添加图标缩放功能,支持 Ctrl++/Ctrl+= 放大和 Ctrl+- 缩小
  2. 实现平滑缩放动画,持续时间为200毫秒并带有缓动效果
  3. 设置缩放限制在0.5倍到1.0倍之间,每次调整0.1倍
  4. 更新IconItemDelegate以支持iconScaleFactor属性,确保缩放一致性
  5. 添加transformOrigin: Item.Center以在缩放过程中保持图标定位

Pms: BUG-289529

Summary by Sourcery

Introduce interactive icon scaling with keyboard zoom shortcuts, animated transitions, and consistent delegate support

New Features:

  • Add keyboard shortcuts (Ctrl++/Ctrl+= to zoom in and Ctrl+- to zoom out) for icon scaling
  • Implement smooth icon scaling animation with 200ms duration and easing
  • Enforce scaling limits between 0.5x and 1.0x with 0.1x increments

Enhancements:

  • Expose iconScaleFactor in IconItemDelegate and apply it to icon rendering
  • Set transform origin to center to preserve icon positioning during scaling

@sourcery-ai

sourcery-ai Bot commented Sep 28, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces interactive icon scaling by adding an animated iconScaleFactor property, keyboard shortcuts to adjust the scale within set bounds, and propagating the scale factor into the icon delegate to ensure consistent, centered scaling across all icons.

Class diagram for updated icon scaling properties

classDiagram
    class FullscreenFrame {
        +iconScaleFactor: real
    }
    class IconItemDelegate {
        +iconScaleFactor: real
    }
    FullscreenFrame "1" --> "*" IconItemDelegate : iconScaleFactor
Loading

File-Level Changes

Change Details Files
Add iconScaleFactor property with smooth scaling animation
  • Define root-level iconScaleFactor property
  • Attach Behavior with 200ms NumberAnimation and OutQuad easing
qml/FullscreenFrame.qml
Implement keyboard shortcuts for zooming
  • Add Shortcut for Ctrl++/Ctrl+= to increase iconScaleFactor with upper clamp at 1.0
  • Add Shortcut for Ctrl+- to decrease iconScaleFactor with lower clamp at 0.5
qml/FullscreenFrame.qml
Propagate and apply scale factor in icon items
  • Pass iconScaleFactor and set transformOrigin to Item.Center on icon instances
  • Introduce iconScaleFactor property in IconItemDelegate
  • Multiply existing scale calculations by iconScaleFactor
qml/FullscreenFrame.qml
qml/IconItemDelegate.qml

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 there - I've reviewed your changes and they look great!


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.

Comment thread qml/FullscreenFrame.qml Outdated
1. Added icon scaling functionality with Ctrl++/Ctrl+= to zoom in and
Ctrl+- to zoom out
2. Implemented smooth scaling animation with 200ms duration and easing
3. Set scaling limits between 0.5x and 1.0x with 0.1x step increments
4. Updated IconItemDelegate to support iconScaleFactor property for
consistent scaling
5. Added transformOrigin: Item.Center to maintain icon positioning
during scaling

feat: 添加图标缩放功能和键盘快捷键

1. 添加图标缩放功能,支持 Ctrl++/Ctrl+= 放大和 Ctrl+- 缩小
2. 实现平滑缩放动画,持续时间为200毫秒并带有缓动效果
3. 设置缩放限制在0.5倍到1.0倍之间,每次调整0.1倍
4. 更新IconItemDelegate以支持iconScaleFactor属性,确保缩放一致性
5. 添加transformOrigin: Item.Center以在缩放过程中保持图标定位

Pms: BUG-289529
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见

总体评价

这个代码变更实现了桌面图标缩放功能,允许用户通过快捷键调整全屏模式下应用图标的缩放比例。代码结构清晰,实现合理,但有一些可以改进的地方。

具体改进建议

1. 代码质量

  1. 命名一致性

    • desktopintegration.h 中使用了 scaleFactoriconScaleFactor 两个相似但不同的属性,容易引起混淆。建议统一命名风格,比如 iconScalewindowScale
  2. 代码重复

    • FullscreenFrame.qml 中,两个快捷键处理逻辑非常相似,可以考虑抽取为一个通用方法。
  3. 注释完善

    • setIconScaleFactor 方法中的注释可以更详细,说明缩放因子的有效范围和意义。

2. 代码性能

  1. DConfig 创建

    • setIconScaleFactor 中每次都创建新的 DConfig 实例,可以考虑复用已有的实例,或者将 DConfig 实例作为成员变量保存。
  2. 动画性能

    • FullscreenFrame.qml 中添加了缩放动画,但没有考虑性能影响。建议添加 enabled 属性控制动画的开启/关闭,特别是对于低性能设备。

3. 代码安全

  1. 输入验证

    • setIconScaleFactor 方法没有对输入的 factor 参数进行范围验证,虽然在使用时有上下限检查,但在方法内部也应该添加验证。
  2. 并发访问

    • m_iconScaleFactor 是一个公共可访问的属性,在多线程环境下可能存在并发访问问题。建议添加适当的同步机制。

4. 功能完善

  1. 缩放限制

    • 当前缩放范围是 0.5 到 1.0,这个限制应该作为常量定义,而不是硬编码在多个地方。
  2. 用户反馈

    • 当用户使用快捷键调整缩放比例时,可以考虑添加视觉反馈,比如临时显示当前缩放比例。
  3. 配置持久化

    • 虽然 DConfig 会保存设置,但可以考虑添加手动保存的选项,确保用户设置的及时保存。

修改建议代码示例

// desktopintegration.h 中添加常量定义
static constexpr qreal MIN_ICON_SCALE_FACTOR = 0.5;
static constexpr qreal MAX_ICON_SCALE_FACTOR = 1.0;
static constexpr qreal ICON_SCALE_FACTOR_STEP = 0.1;

// 改进后的 setIconScaleFactor 方法
void DesktopIntegration::setIconScaleFactor(qreal factor)
{
    // 参数验证
    if (factor < MIN_ICON_SCALE_FACTOR || factor > MAX_ICON_SCALE_FACTOR) {
        qCWarning(logDesktopIntegration) << "Invalid icon scale factor:" << factor;
        return;
    }
    
    if (qFuzzyCompare(m_iconScaleFactor, factor)) {
        return;
    }
    
    m_iconScaleFactor = factor;
    
    // 保存到 dconfig
    QScopedPointer<DConfig> dconfig(DConfig::create("org.deepin.dde.shell", "org.deepin.ds.launchpad"));
    if (dconfig->isValid()) {
        dconfig->setValue("iconScaleFactor", factor);
        qCInfo(logDesktopIntegration) << "Icon scale factor saved:" << factor;
    }
    
    emit iconScaleFactorChanged();
}
// FullscreenFrame.qml 中抽取的通用方法
function adjustIconScale(increase) {
    var newValue = increase 
        ? Math.min(DesktopIntegration.iconScaleFactor + ICON_SCALE_FACTOR_STEP, MAX_ICON_SCALE_FACTOR)
        : Math.max(DesktopIntegration.iconScaleFactor - ICON_SCALE_FACTOR_STEP, MIN_ICON_SCALE_FACTOR);
    
    if (newValue !== DesktopIntegration.iconScaleFactor) {
        DesktopIntegration.iconScaleFactor = newValue;
        showScaleIndicator(newValue); // 添加视觉反馈
    }
}

// 快捷键处理
Shortcut {
    context: Qt.ApplicationShortcut
    sequences: ["Ctrl++", "Ctrl+="]
    onActivated: adjustIconScale(true)
}

Shortcut {
    context: Qt.ApplicationShortcut
    sequences: ["Ctrl+-"]
    onActivated: adjustIconScale(false)
}

总结

这个功能实现整体上是合理的,主要改进方向是提高代码质量、性能和安全性,同时增强用户体验。通过添加适当的常量定义、输入验证、减少代码重复和优化性能,可以使代码更加健壮和可维护。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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

@wjyrich wjyrich merged commit 0f703a4 into linuxdeepin:master Sep 29, 2025
10 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