Skip to content

feat: implement custom PageButton for calendar navigation#337

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

feat: implement custom PageButton for calendar navigation#337
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
wjyrich:fix-bug-321969

Conversation

@wjyrich

@wjyrich wjyrich commented Jul 11, 2025

Copy link
Copy Markdown
Contributor
  1. Added new PageButton class inheriting from QFrame with hover/press visual states
  2. Replaced DToolButton with PageButton for next/previous navigation in calendar
  3. Implemented custom painting with rounded corners and hover effects
  4. Added proper event handling for mouse interactions
  5. Centralized icon positioning and styling
  6. Simplified button sizing by moving fixed dimensions to PageButton class

The change was made to provide more consistent and visually appealing navigation buttons in the calendar widget, with better hover/pressed state feedback compared to the standard DToolButton. The custom implementation allows for more control over the visual appearance and behavior.

feat: 为日历导航实现自定义 PageButton

  1. 新增继承自 QFrame 的 PageButton 类,带有悬停/按下视觉状态
  2. 在日历导航中用 PageButton 替换 DToolButton
  3. 实现自定义绘制,包括圆角和悬停效果
  4. 添加了适当的鼠标交互事件处理
  5. 集中处理图标位置和样式
  6. 通过将固定尺寸移至 PageButton 类简化按钮尺寸设置

此变更为日历组件提供了更一致且视觉上更吸引人的导航按钮,相比标准
DToolButton 提供了更好的悬停/按下状态反馈。自定义实现可以更好地控制视觉
外观和行为。

Pms: BUG-321969

Summary by Sourcery

Implement a new PageButton widget to replace DToolButton in calendar navigation, providing consistent sizing, centralized styling, and enhanced hover and press states.

New Features:

  • Introduce PageButton component with hover and press visual feedback

Enhancements:

  • Replace calendar navigation DToolButtons with PageButton and centralize sizing and icon styling
  • Implement custom painting for rounded corners and hover effects
  • Add mouse event handling to PageButton for press and click interactions

@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 11, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR replaces the standard DToolButton-based calendar navigation with a new custom PageButton QFrame subclass featuring hover/press visual states, custom painting with rounded corners, centralized icon styling/positioning, and consolidated sizing, then updates SidebarCalendarWidget to use PageButton and connect its clicked signal.

Class diagram for new PageButton and SidebarCalendarWidget changes

classDiagram
    class QFrame
    class PageButton {
        +PageButton(QWidget *parent)
        +~PageButton()
        +void setIcon(const QIcon &icon)
        +signal void clicked()
        -void initUI()
        -bool m_hover
        -bool m_mousePress
        -CommonIconButton *m_iconButton
        +bool event(QEvent* e)
        +void paintEvent(QPaintEvent* e)
        +void mousePressEvent(QMouseEvent* event)
        +void mouseReleaseEvent(QMouseEvent* event)
    }
    PageButton --|> QFrame
    class SidebarCalendarWidget {
        -PageButton* m_nextPage
        -PageButton* m_previousPage
        ...
    }
Loading

File-Level Changes

Change Details Files
Introduced PageButton component for custom navigation
  • Created PageButton subclass inheriting from QFrame
  • Implemented initUI, custom paintEvent, event handling, mousePress/Release for hover and press feedback
  • Centralized fixed dimensions, icon positioning, and styling via CommonIconButton
plugins/dde-dock/datetime/calendar/pagebutton.h
plugins/dde-dock/datetime/calendar/pagebutton.cpp
Replaced DToolButton with PageButton in SidebarCalendarWidget
  • Swapped m_nextPage and m_previousPage from DToolButton to PageButton
  • Removed manual iconSize and fixedSize settings from calendar widget
  • Updated signal connections to use PageButton::clicked
plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.cpp
plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.h

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 - here's some feedback:

  • Implement keyboard focus and key event handling (e.g. Space/Enter) in PageButton to support accessibility.
  • Remove the empty PageButton destructor or mark it as = default to avoid redundant code.
  • Extract hardcoded size and corner‐radius values into named constants or style metrics for better maintainability and theming.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Implement keyboard focus and key event handling (e.g. Space/Enter) in PageButton to support accessibility.
- Remove the empty PageButton destructor or mark it as = default to avoid redundant code.
- Extract hardcoded size and corner‐radius values into named constants or style metrics for better maintainability and theming.

## Individual Comments

### Comment 1
<location> `plugins/dde-dock/datetime/calendar/pagebutton.cpp:91` </location>
<code_context>
+        m_mousePress = true;
+        update();
+    }
+    QWidget::mousePressEvent(event);
+}
+
</code_context>

<issue_to_address>
Base class mouse event should call QFrame::mousePressEvent.

Call QFrame::mousePressEvent(event) here to maintain proper event handling and consistency with the base class.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    QWidget::mousePressEvent(event);
=======
    QFrame::mousePressEvent(event);
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `plugins/dde-dock/datetime/calendar/pagebutton.cpp:105` </location>
<code_context>
+        Q_EMIT clicked();
+    }
+
+    QWidget::mouseReleaseEvent(event);
+} 
\ No newline at end of file
</code_context>

<issue_to_address>
Base class mouse event should call QFrame::mouseReleaseEvent.

Use QFrame::mouseReleaseEvent(event) instead of QWidget to ensure proper event handling.
</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/datetime/calendar/pagebutton.cpp
Comment thread plugins/dde-dock/datetime/calendar/pagebutton.cpp
Comment thread plugins/dde-dock/datetime/calendar/pagebutton.cpp Outdated
Comment thread plugins/dde-dock/datetime/calendar/pagebutton.h Outdated
Comment thread plugins/dde-dock/datetime/calendar/pagebutton.cpp Outdated
p.setBrush(bgColor);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect(), 8, 8);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这个圆角值从哪儿来的?可以参照下ToolButton的值,

1. Added new PageButton class inheriting from QFrame with hover/press
visual states
2. Replaced DToolButton with PageButton for next/previous navigation
in calendar
3. Implemented custom painting with rounded corners and hover effects
4. Added proper event handling for mouse interactions
5. Centralized icon positioning and styling
6. Simplified button sizing by moving fixed dimensions to PageButton
class

The change was made to provide more consistent and visually appealing
navigation buttons in the calendar widget, with better hover/pressed
state feedback compared to the standard DToolButton. The custom
implementation allows for more control over the visual appearance and
behavior.

feat: 为日历导航实现自定义 PageButton

1. 新增继承自 QFrame 的 PageButton 类,带有悬停/按下视觉状态
2. 在日历导航中用 PageButton 替换 DToolButton
3. 实现自定义绘制,包括圆角和悬停效果
4. 添加了适当的鼠标交互事件处理
5. 集中处理图标位置和样式
6. 通过将固定尺寸移至 PageButton 类简化按钮尺寸设置

此变更为日历组件提供了更一致且视觉上更吸引人的导航按钮,相比标准
DToolButton 提供了更好的悬停/按下状态反馈。自定义实现可以更好地控制视觉
外观和行为。

Pms: BUG-321969
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. 文件头注释:在pagebutton.cpppagebutton.h文件头部的注释中,版权声明和许可证标识应该放在文件的最顶部,而不是在版权声明和许可证标识之间留有空行。建议格式如下:

    // SPDX-FileCopyrightText: 2019 - 2025 UnionTech Software Technology Co., Ltd.
    //
    // SPDX-License-Identifier: LGPL-3.0-or-later
  2. 构造函数和析构函数PageButton类的构造函数和析构函数中,没有对成员变量进行任何初始化或清理操作,这是合理的,因为它们是默认构造函数和析构函数。但是,如果以后需要添加更多的成员变量,应该在这里进行初始化。

  3. initUI函数initUI函数中创建的QHBoxLayout对象没有在类中声明,这可能会导致内存泄漏。应该将hLayout声明为类的成员变量,以便在析构函数中正确释放内存。

  4. setIcon函数setIcon函数中的m_iconButton->setIcon(icon, Qt::black, Qt::white);调用可能不正确,因为CommonIconButton类可能没有这样的构造函数。应该检查CommonIconButton类的定义,确保setIcon函数的参数是正确的。

  5. event函数event函数中的update()调用应该在m_hoverm_mousePress状态改变时进行,而不是在switch语句的每个分支中都调用。可以将update()调用移到default分支中。

  6. paintEvent函数paintEvent函数中的Q_UNUSED(e)宏没有实际用途,应该移除。

  7. mousePressEventmouseReleaseEvent函数mousePressEventmouseReleaseEvent函数中的update()调用应该在m_mousePress状态改变时进行,而不是在if语句的每个分支中都调用。可以将update()调用移到if语句的外部。

  8. SidebarCalendarWidget类的修改:在SidebarCalendarWidget类中,将DToolButton替换为PageButton是一个好的做法,因为PageButton类提供了更多的功能。但是,应该确保PageButton类已经实现了所有DToolButton类的方法和信号。

  9. SidebarCalendarWidget类的initView函数initView函数中的注释//日期按钮区域控件//按钮布局应该移到成员变量声明之前,以便更好地描述成员变量的用途。

  10. SidebarCalendarWidget类的initConnection函数initConnection函数中的注释// connect(m_manager, &CalendarManager::sidebarFirstDayChanged, this, &SidebarCalendarWidget::onFirstDayChanged);应该移到connect语句之前,以便更好地描述连接的用途。

以上是代码审查的一些主要意见,希望对你有所帮助。

@wjyrich

wjyrich commented Jul 16, 2025

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 16, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 3ced55a into linuxdeepin:master Jul 16, 2025
7 of 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