Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 47 additions & 43 deletions src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,8 @@ void MainWindow::updateToolBarPos()
qCDebug(dsrApp) << "正在初始化工具栏...";
m_toolBar->initToolBar(this, isHideToolBar);
m_toolBar->setRecordLaunchMode(m_functionType);
if (m_toolBar->layout())
m_toolBar->layout()->activate();
// m_toolBar->setIsZhaoxinPlatform(m_isZhaoxin);
m_toolBar->setScrollShotDisabled(!m_wmHelper->hasBlurWindow());

Expand Down Expand Up @@ -4809,23 +4811,23 @@ void MainWindow::paintEvent(QPaintEvent *event)
m_backgroundPixmap.setDevicePixelRatio(m_pixelRatio);
painter.drawPixmap(backgroundRect, m_backgroundPixmap);
} else if (status::record == m_functionType || status::scrollshot == m_functionType) {
// 录屏/滚动截图模式:只在工具栏区域绘制背景
// 不全屏绘制,避免影响鼠标穿透
// 录屏/滚动截图模式:只在模糊面板精确圆角区域绘制背景截图,供 InWidgetBlend 模糊采样。
// 使用 ToolBarWidget/SideBarWidget 的 contentsRect 配合 DFloatingWidget 圆角半径(18)
// 裁剪,避免脏截图在阴影区域和圆角外泄漏。
if (m_toolBar && m_toolBar->isVisible()) {
QRegion clipRegion;
QRect toolBarRect = m_toolBar->geometry();
toolBarRect.adjust(-20, -20, 20, 20);
clipRegion += toolBarRect;
// 二级工具栏(如AI助手面板)也需要背景模糊效果
QPainterPath clipPath;
QRect innerRect = m_toolBar->getInnerWidgetRect();
innerRect.translate(m_toolBar->pos());
clipPath.addRoundedRect(innerRect, 18, 18);
if (m_sideBar && m_sideBar->isVisible()) {
QRect sideBarRect = m_sideBar->geometry();
sideBarRect.adjust(-20, -20, 20, 20);
clipRegion += sideBarRect;
QRect sideInner = m_sideBar->getInnerWidgetRect();
sideInner.translate(m_sideBar->pos());
clipPath.addRoundedRect(sideInner, 18, 18);
}

painter.setRenderHint(QPainter::Antialiasing, true);
m_backgroundPixmap.setDevicePixelRatio(m_pixelRatio);
painter.setClipRegion(clipRegion);
painter.setClipPath(clipPath);
painter.drawPixmap(backgroundRect, m_backgroundPixmap);
painter.setClipping(false);
}
Expand Down Expand Up @@ -5106,17 +5108,9 @@ int MainWindow::mouseReleaseEF(QMouseEvent *mouseEvent, bool &needRepaint)
if (!m_isShapesWidgetExist) {
// 未打开截图形状编辑界面
if (mouseEvent->button() == Qt::LeftButton) {
// 滚动截图的图片大小提示更新,不会使用此方法
if (status::scrollshot != m_functionType) {
m_sizeTips->updateTips(QPoint(recordX, recordY), QSize(recordWidth, recordHeight));
}
if (!isFirstReleaseButton) {
isFirstReleaseButton = true;
updateCursor(mouseEvent);
updateToolBarPos();
if (status::shot == m_functionType && m_sideBar->isVisible()) {
updateSideBarPos();
}
m_zoomIndicator->hideMagnifier();
if (!isFirstDrag) {
for (auto it = windowRects.rbegin(); it != windowRects.rend(); ++it) {
Expand All @@ -5128,32 +5122,42 @@ int MainWindow::mouseReleaseEF(QMouseEvent *mouseEvent, bool &needRepaint)
}
}

// 先调整选区最小尺寸和边界,再更新工具栏位置
// 使用 m_backgroundRect(逻辑大小)做边界检查,
// rootWindowRect 在高DPI下是物理像素,与 recordX/Y 坐标系不一致
if (status::record == m_functionType) {
// Make sure record area not too small.
recordWidth = recordWidth < RECORD_MIN_SIZE ? RECORD_MIN_SIZE : recordWidth;
recordHeight = recordHeight < RECORD_MIN_HEIGHT ? RECORD_MIN_HEIGHT : recordHeight;

if (recordX + recordWidth > rootWindowRect.width()) {
recordX = rootWindowRect.width() - recordWidth;
if (recordX + recordWidth > m_backgroundRect.width()) {
recordX = m_backgroundRect.width() - recordWidth;
}

if (recordY + recordHeight > rootWindowRect.height()) {
recordY = rootWindowRect.height() - recordHeight;
if (recordY + recordHeight > m_backgroundRect.height()) {
recordY = m_backgroundRect.height() - recordHeight;
}
if (recordX < 0) recordX = 0;
if (recordY < 0) recordY = 0;
}

else if (status::shot == m_functionType) {
// Make sure record area not too small.
recordWidth = recordWidth < RECORD_MIN_SHOT_SIZE ? RECORD_MIN_SHOT_SIZE : recordWidth;
recordHeight = recordHeight < RECORD_MIN_SHOT_SIZE ? RECORD_MIN_SHOT_SIZE : recordHeight;

if (recordX + recordWidth > rootWindowRect.width()) {
recordX = rootWindowRect.width() - recordWidth;
if (recordX + recordWidth > m_backgroundRect.width()) {
recordX = m_backgroundRect.width() - recordWidth;
}

if (recordY + recordHeight > rootWindowRect.height()) {
recordY = rootWindowRect.height() - recordHeight;
if (recordY + recordHeight > m_backgroundRect.height()) {
recordY = m_backgroundRect.height() - recordHeight;
}
if (recordX < 0) recordX = 0;
if (recordY < 0) recordY = 0;
}

// 尺寸调整完成后更新提示和工具栏位置
if (status::scrollshot != m_functionType) {
m_sizeTips->updateTips(QPoint(recordX, recordY), QSize(recordWidth, recordHeight));
}
// showRecordButton();
updateToolBarPos();
Expand Down Expand Up @@ -5294,9 +5298,9 @@ int MainWindow::mouseMoveEF(QMouseEvent *mouseEvent, bool &needRepaint)
if (recordButtonStatus == RECORD_BUTTON_NORMAL && dragRecordX >= 0 && dragRecordY >= 0) {
if (dragAction == ACTION_MOVE) {
recordX = std::max(
std::min(dragRecordX + mouseEvent->x() - dragStartX, rootWindowRect.width() - recordWidth), 0);
std::min(dragRecordX + mouseEvent->x() - dragStartX, m_backgroundRect.width() - recordWidth), 0);
recordY = std::max(
std::min(dragRecordY + mouseEvent->y() - dragStartY, rootWindowRect.height() - recordHeight), 0);
std::min(dragRecordY + mouseEvent->y() - dragStartY, m_backgroundRect.height() - recordHeight), 0);
} else if (dragAction == ACTION_RESIZE_TOP_LEFT) {
resizeTop(mouseEvent);
resizeLeft(mouseEvent);
Expand Down Expand Up @@ -5767,15 +5771,15 @@ int MainWindow::keyPressEF(QKeyEvent *keyEvent, bool &needRepaint)

needRepaint = true;
} else if (keyEvent->key() == Qt::Key_Right || keyEvent->key() == Qt::Key_D) {
recordX = std::min(rootWindowRect.width() - recordWidth, recordX + 1);
recordX = std::min(m_backgroundRect.width() - recordWidth, recordX + 1);

needRepaint = true;
} else if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_W) {
recordY = std::max(0, recordY - 1);

needRepaint = true;
} else if (keyEvent->key() == Qt::Key_Down || keyEvent->key() == Qt::Key_S) {
recordY = std::min(rootWindowRect.height() - recordHeight, recordY + 1);
recordY = std::min(m_backgroundRect.height() - recordHeight, recordY + 1);

needRepaint = true;
}
Expand Down Expand Up @@ -7061,24 +7065,24 @@ void MainWindow::resizeTop(QMouseEvent *mouseEvent)
if (status::record == m_functionType) {
int offsetY = mouseEvent->y() - dragStartY;
recordY = std::max(std::min(dragRecordY + offsetY, dragRecordY + dragRecordHeight - RECORD_MIN_HEIGHT), 1);
recordHeight = std::max(std::min(dragRecordHeight - offsetY, rootWindowRect.height()), RECORD_MIN_HEIGHT);
recordHeight = std::max(std::min(dragRecordHeight - offsetY, m_backgroundRect.height()), RECORD_MIN_HEIGHT);
}

else if (status::shot == m_functionType) {
int offsetY = mouseEvent->y() - dragStartY;
recordY = std::max(std::min(dragRecordY + offsetY, dragRecordY + dragRecordHeight - RECORD_MIN_SHOT_SIZE), 1);
recordHeight = std::max(std::min(dragRecordHeight - offsetY, rootWindowRect.height()), RECORD_MIN_SHOT_SIZE);
recordHeight = std::max(std::min(dragRecordHeight - offsetY, m_backgroundRect.height()), RECORD_MIN_SHOT_SIZE);
}
}

void MainWindow::resizeBottom(QMouseEvent *mouseEvent)
{
if (status::record == m_functionType) {
int offsetY = mouseEvent->y() - dragStartY;
recordHeight = std::max(std::min(dragRecordHeight + offsetY, rootWindowRect.height()), RECORD_MIN_HEIGHT);
recordHeight = std::max(std::min(dragRecordHeight + offsetY, m_backgroundRect.height()), RECORD_MIN_HEIGHT);
} else if (status::shot == m_functionType) {
int offsetY = mouseEvent->y() - dragStartY;
recordHeight = std::max(std::min(dragRecordHeight + offsetY, rootWindowRect.height()), RECORD_MIN_SHOT_SIZE);
recordHeight = std::max(std::min(dragRecordHeight + offsetY, m_backgroundRect.height()), RECORD_MIN_SHOT_SIZE);
}
}

Expand All @@ -7087,22 +7091,22 @@ void MainWindow::resizeLeft(QMouseEvent *mouseEvent)
if (status::record == m_functionType) {
int offsetX = mouseEvent->x() - dragStartX;
recordX = std::max(std::min(dragRecordX + offsetX, dragRecordX + dragRecordWidth - RECORD_MIN_SIZE), 1);
recordWidth = std::max(std::min(dragRecordWidth - offsetX, rootWindowRect.width()), RECORD_MIN_SIZE);
recordWidth = std::max(std::min(dragRecordWidth - offsetX, m_backgroundRect.width()), RECORD_MIN_SIZE);
} else if (m_functionType == 1) {
int offsetX = mouseEvent->x() - dragStartX;
recordX = std::max(std::min(dragRecordX + offsetX, dragRecordX + dragRecordWidth - RECORD_MIN_SHOT_SIZE), 1);
recordWidth = std::max(std::min(dragRecordWidth - offsetX, rootWindowRect.width()), RECORD_MIN_SHOT_SIZE);
recordWidth = std::max(std::min(dragRecordWidth - offsetX, m_backgroundRect.width()), RECORD_MIN_SHOT_SIZE);
}
}

void MainWindow::resizeRight(QMouseEvent *mouseEvent)
{
if (status::record == m_functionType) {
int offsetX = mouseEvent->x() - dragStartX;
recordWidth = std::max(std::min(dragRecordWidth + offsetX, rootWindowRect.width()), RECORD_MIN_SIZE);
recordWidth = std::max(std::min(dragRecordWidth + offsetX, m_backgroundRect.width()), RECORD_MIN_SIZE);
} else if (status::shot == m_functionType) {
int offsetX = mouseEvent->x() - dragStartX;
recordWidth = std::max(std::min(dragRecordWidth + offsetX, rootWindowRect.width()), RECORD_MIN_SHOT_SIZE);
recordWidth = std::max(std::min(dragRecordWidth + offsetX, m_backgroundRect.width()), RECORD_MIN_SHOT_SIZE);
}
}

Expand Down Expand Up @@ -7491,8 +7495,8 @@ void MainWindow::adjustLayout(QVBoxLayout *layout, int layoutWidth, int layoutHe
layout->setContentsMargins(
recordX,
recordY,
rootWindowRect.width() - recordX - recordWidth,
rootWindowRect.height() - recordY - recordHeight);
m_backgroundRect.width() - recordX - recordWidth,
m_backgroundRect.height() - recordY - recordHeight);
}

void MainWindow::initShapeWidget(QString type)
Expand Down
8 changes: 8 additions & 0 deletions src/widgets/sidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ void SideBar::hideWidget(){
m_sidebarWidget->hide();
}

QRect SideBar::getInnerWidgetRect() const
{
if (!m_sidebarWidget)
return rect();
QRect cr = m_sidebarWidget->contentsRect();
return QRect(m_sidebarWidget->mapTo(const_cast<SideBar *>(this), cr.topLeft()), cr.size());
}

void SideBar::initSideBar(MainWindow *pmainWindow)
{
qCDebug(dsrApp) << "SideBar::initSideBar called.";
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/sidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class SideBar : public DLabel
void showWidget();
void hideWidget();

/**
* @brief getInnerWidgetRect 获取 SideBarWidget 的 contentsRect(模糊面板区域)
* 在 SideBar 坐标系下的位置
*/
QRect getInnerWidgetRect() const;

signals:
void heightChanged();
void buttonChecked(QString shape);
Expand Down
9 changes: 9 additions & 0 deletions src/widgets/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ void ToolBar::paintEvent(QPaintEvent *e)
DLabel::paintEvent(e);
}

QRect ToolBar::getInnerWidgetRect() const
{
if (!m_toolbarWidget)
return rect();
// 返回 ToolBarWidget 的 contentsRect 在 ToolBar 坐标系下的位置
QRect cr = m_toolbarWidget->contentsRect();
return QRect(m_toolbarWidget->mapTo(const_cast<ToolBar *>(this), cr.topLeft()), cr.size());
}

#if (QT_VERSION_MAJOR == 5)
void ToolBar::enterEvent(QEvent *e)
{
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class ToolBar : public DLabel
* @return
*/
QRect getShotOptionRect();

/**
* @brief getInnerWidgetRect 获取 ToolBarWidget 的 contentsRect(模糊面板区域)
* 在 ToolBar 坐标系下的位置
*/
QRect getInnerWidgetRect() const;
signals:
void buttonChecked(QString shape);
void currentFunctionToMain(QString shapeType);
Expand Down
Loading