Skip to content

feat: add wheel event support for brightness and volume controls#340

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-317615
Jul 22, 2025
Merged

feat: add wheel event support for brightness and volume controls#340
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-317615

Conversation

@wjyrich

@wjyrich wjyrich commented Jul 21, 2025

Copy link
Copy Markdown
Contributor
  1. Added wheel event handling for brightness slider in BrightnessApplet
  2. Implemented wheel event handling for volume control in SoundApplet
  3. Installed event filters on relevant slider widgets to capture wheel events
  4. Adjusted brightness/volume values in steps of 2% per wheel tick
  5. Added necessary QWheelEvent includes

The changes allow users to adjust brightness and volume levels using mouse wheel directly on the dock applets, providing a more intuitive and convenient control method. This matches common UX patterns found in other desktop environments.

feat: 为亮度和音量控制添加滚轮事件支持

  1. 在 BrightnessApplet 中添加亮度滑块的滚轮事件处理
  2. 在 SoundApplet 中实现音量控制的滚轮事件处理
  3. 在相关滑块部件上安装事件过滤器以捕获滚轮事件
  4. 每次滚轮滚动调整亮度/音量2%
  5. 添加必要的 QWheelEvent 头文件

这些修改允许用户直接在dock应用上使用鼠标滚轮调整亮度和音量级别,提供了更
直观和方便的控制方式。这与其他桌面环境中常见的用户体验模式相匹配。

Pms: BUG-317615

Summary by Sourcery

Add mouse wheel support to brightness and volume sliders in dock applets to allow 2% incremental adjustments per wheel tick.

New Features:

  • Enable adjusting screen brightness using the mouse wheel on the brightness applet’s slider
  • Enable adjusting volume using the mouse wheel on the sound applet’s slider

Enhancements:

  • Install event filters on slider widgets and handle QWheelEvent to change values in 2% steps per wheel notch
  • Include QWheelEvent headers to support wheel event handling

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2025

Copy link
Copy Markdown

Reviewer's Guide

Introduces mouse wheel event handling in the brightness and sound applets by installing event filters on slider widgets, processing QWheelEvent in eventFilter overrides, and adjusting values in 2% increments.

Sequence diagram for handling mouse wheel event on brightness slider

sequenceDiagram
    actor User
    participant BrightnessSlider as Brightness Slider
    participant BrightnessApplet
    participant BrightnessController
    User->>BrightnessSlider: Scroll mouse wheel
    BrightnessSlider->>BrightnessApplet: eventFilter(QWheelEvent)
    BrightnessApplet->>BrightnessSlider: updateSliderValue(newValue)
    BrightnessApplet->>BrightnessController: setMonitorBrightness(newValue)
Loading

Sequence diagram for handling mouse wheel event on volume slider

sequenceDiagram
    actor User
    participant VolumeSlider as Volume Slider
    participant SoundApplet
    participant SoundController
    User->>VolumeSlider: Scroll mouse wheel
    VolumeSlider->>SoundApplet: eventFilter(QWheelEvent)
    SoundApplet->>VolumeSlider: setValue(newValue)
    SoundApplet->>SoundController: SetVolume(newValue)
Loading

Class diagram for updated event filter handling in BrightnessApplet and SoundApplet

classDiagram
    class BrightnessApplet {
        +bool eventFilter(QObject *watcher, QEvent *event) override
    }
    class SoundApplet {
        +bool eventFilter(QObject *watcher, QEvent *event) override
    }
    BrightnessApplet --|> QWidget
    SoundApplet --|> QWidget
Loading

File-Level Changes

Change Details Files
Wheel event support for brightness control
  • Include QWheelEvent header in brightnessapplet.cpp
  • Install event filter on each brightness slider
  • Override eventFilter in BrightnessApplet to catch QEvent::Wheel
  • Adjust brightness by ±2% per wheel tick using qBound and BrightnessController
plugins/dde-dock/brightness/brightnessapplet.cpp
plugins/dde-dock/brightness/brightnessapplet.h
Wheel event support for volume control
  • Include QWheelEvent and QApplication headers in soundapplet.cpp
  • Install event filter on volume slider container and slider
  • Extend eventFilter in SoundApplet to handle QEvent::Wheel
  • Adjust volume by ±2% per wheel tick via SoundController
plugins/dde-dock/sound/soundapplet.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

@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 @wjyrich - 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> `plugins/dde-dock/sound/soundapplet.cpp:363` </location>
<code_context>
+            int currentValue = m_volumeSlider->value();
+            int newValue = qBound(m_volumeSlider->minimum(), currentValue + delta, m_volumeSlider->maximum());
+            m_volumeSlider->setValue(newValue);
+            SoundController::ref().SetVolume(newValue * 0.01, true);
+            
+            event->accept();
</code_context>

<issue_to_address>
Multiplying by 0.01 assumes slider range is 0-100.

If the slider range changes, this calculation may produce incorrect results. Use the slider's min and max values for scaling instead.
</issue_to_address>

### Comment 2
<location> `plugins/dde-dock/sound/soundapplet.cpp:92` </location>
<code_context>
     m_listView->installEventFilter(this);
+    
+    // 安装事件过滤器,以便处理滚轮事件
+    m_sliderContainer->installEventFilter(this);
+    m_volumeSlider->slider()->installEventFilter(this);

     // sound setting button
</code_context>

<issue_to_address>
Installing event filters on both container and slider may cause duplicate event handling.

Check that wheel events are not processed twice due to filters on both the container and the slider, as this could cause unintended side effects.
</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.

Comment thread plugins/dde-dock/sound/soundapplet.cpp Outdated
SoundController::ref().SetVolume(newValue * 0.01, true);

event->accept();
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Multiplying by 0.01 assumes slider range is 0-100.

If the slider range changes, this calculation may produce incorrect results. Use the slider's min and max values for scaling instead.

Comment on lines 92 to 93
// sound setting button
m_settingButton->setAutoShowPage(true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Installing event filters on both container and slider may cause duplicate event handling.

Check that wheel events are not processed twice due to filters on both the container and the slider, as this could cause unintended side effects.

Comment thread plugins/dde-dock/sound/soundapplet.cpp Outdated
1. Added wheel event handling for brightness slider in BrightnessApplet
2. Implemented wheel event handling for volume control in SoundApplet
3. Installed event filters on relevant slider widgets to capture wheel
events
4. Adjusted brightness/volume values in steps of 2% per wheel tick
5. Added necessary QWheelEvent includes

The changes allow users to adjust brightness and volume levels using
mouse wheel directly on the dock applets, providing a more intuitive
and convenient control method. This matches common UX patterns found in
other desktop environments.

feat: 为亮度和音量控制添加滚轮事件支持

1. 在 BrightnessApplet 中添加亮度滑块的滚轮事件处理
2. 在 SoundApplet 中实现音量控制的滚轮事件处理
3. 在相关滑块部件上安装事件过滤器以捕获滚轮事件
4. 每次滚轮滚动调整亮度/音量2%
5. 添加必要的 QWheelEvent 头文件

这些修改允许用户直接在dock应用上使用鼠标滚轮调整亮度和音量级别,提供了更
直观和方便的控制方式。这与其他桌面环境中常见的用户体验模式相匹配。

Pms: BUG-317615
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. brightnessapplet.cpp文件中,新增了dSlider->setMouseWheelEnabled(true);这行代码,但没有对应的注释说明为什么需要启用鼠标滚轮功能。建议添加注释说明这一改动的原因。

  2. dockslider.cpp文件中,setMouseWheelEnabled(true);这行代码被移动到了构造函数中,但没有检查是否已经设置了鼠标滚轮功能。如果setMouseWheelEnabled被多次调用,可能会导致功能被覆盖。建议在设置之前检查是否已经启用了鼠标滚轮功能。

  3. 代码中没有错误处理或异常捕获机制。如果BrightnessModel::ref().minBrightness()BrightnessModel::ref().maxBrightness()返回无效值,可能会导致程序崩溃。建议添加错误处理逻辑,确保程序的健壮性。

  4. 代码中使用了硬编码的值,如SLIDER_ITEM_HEIGHT100。建议将这些值定义为常量,以提高代码的可读性和可维护性。

  5. dockslider.cpp文件中,m_timer的初始化应该放在构造函数中,而不是在类定义中。这样可以确保m_timer在使用之前已经被正确初始化。

  6. dockslider.cpp文件中,setPageStep(50);这行代码被注释掉了,但没有说明原因。如果这行代码是必要的,应该取消注释。如果不是必要的,应该删除这行代码。

  7. 代码中没有使用delete关键字释放动态分配的内存。在brightnessapplet.cpp文件中,containerdSlider是动态分配的,应该在适当的时候释放内存,以避免内存泄漏。

  8. 代码中没有使用new关键字创建的对象,应该在适当的时候使用delete关键字释放内存。例如,new DSlider()应该在使用完毕后使用delete释放内存。

综上所述,建议在代码中添加适当的注释,检查并修复潜在的错误,以及确保动态分配的内存被正确释放。

@wjyrich

wjyrich commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot deepin-bot Bot merged commit 3786740 into linuxdeepin:master Jul 22, 2025
9 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