fix: Refine background rendering logic for toolbar in recording modes#794
Merged
deepin-bot[bot] merged 1 commit intoJan 23, 2026
Merged
fix: Refine background rendering logic for toolbar in recording modes#794deepin-bot[bot] merged 1 commit into
deepin-bot[bot] merged 1 commit into
Conversation
Updated the background rendering conditions to ensure the toolbar blur effect is applied correctly in recording and scrolling screenshot modes, enhancing visual consistency across different function types. This change improves the user experience by maintaining the intended appearance of the toolbar during various capture scenarios.
deepin pr auto review代码审查意见整体评价这段代码主要是针对 Qt6+XCB 环境下工具栏模糊效果的修复,解决了不同模式下的背景绘制问题。代码结构清晰,注释充分,但存在一些可以改进的地方。 具体问题与建议1. 代码逻辑问题问题1:
问题2:工具栏区域调整的硬编码 toolBarRect.adjust(-20, -20, 20, 20);
2. 代码质量问题问题1:重复代码
问题2:条件判断可读性
3. 性能问题问题1:不必要的渲染提示设置
问题2:频繁的几何计算
4. 安全问题问题1:空指针检查不完整
改进后的代码示例void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
// 获取背景绘制区域
QRect backgroundRect = getBackgroundRect();
// 设置设备像素比
m_backgroundPixmap.setDevicePixelRatio(m_pixelRatio);
if (isScreenCaptureMode() || !m_hasComposite) {
// 截图模式或2D模式:全屏绘制背景
painter.drawPixmap(backgroundRect, m_backgroundPixmap);
} else if (isRecordingMode()) {
// 录屏/滚动截图模式:只在工具栏区域绘制背景
if (m_toolBar && m_toolBar->isVisible()) {
QRect toolBarRect = getAdjustedToolBarRect();
painter.setClipRect(toolBarRect);
painter.drawPixmap(backgroundRect, m_backgroundPixmap);
painter.setClipping(false);
}
}
}
QRect MainWindow::getBackgroundRect() const
{
if (Utils::isQt6XcbEnv) {
return QRect(0, 0, m_backgroundRect.width(), m_backgroundRect.height());
}
return QRect(0, 0, rootWindowRect.width(), rootWindowRect.height());
}
bool MainWindow::isScreenCaptureMode() const
{
return status::shot == m_functionType;
}
bool MainWindow::isRecordingMode() const
{
return status::record == m_functionType || status::scrollshot == m_functionType;
}
QRect MainWindow::getAdjustedToolBarRect() const
{
QRect toolBarRect = m_toolBar->geometry();
const int margin = m_toolBarBackgroundMargin; // 假设这是类成员变量
toolBarRect.adjust(-margin, -margin, margin, margin);
return toolBarRect;
}总结这段代码主要解决了 Qt6+XCB 环境下的工具栏模糊问题,但可以通过减少重复代码、提高可读性和优化性能来进一步改进。建议将硬编码值提取为配置项,并确保空指针检查完整。 |
lzwind
approved these changes
Jan 23, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Member
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
a91090a
into
linuxdeepin:develop/snipe
7 of 9 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updated the background rendering conditions to ensure the toolbar blur effect is applied correctly in recording and scrolling screenshot modes, enhancing visual consistency across different function types. This change improves the user experience by maintaining the intended appearance of the toolbar during various capture scenarios.