From 36e126cd2a545f5eab0304a9be7c6f56095b4ee8 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Fri, 12 Jul 2024 09:11:39 +0800 Subject: [PATCH] fix: the incorrect coordinate position display the incorrect coordinate position display Log: the incorrect coordinate position display Bug: https://pms.uniontech.com/bug-view-261623.html --- src/main_window.cpp | 164 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/src/main_window.cpp b/src/main_window.cpp index 1074a3e2..293b9075 100755 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -2406,6 +2406,170 @@ void MainWindow::updateToolBarPos() //快捷全屏录制不需要显示工具栏 if(m_isFullScreenRecord) return; m_toolbarLastPoint = toolbarPoint; + // handel the screen misaligned + if (m_screenInfo.size() == 2 && m_screenInfo.at(0).y != m_screenInfo.at(1).y && m_screenInfo.at(0).x != m_screenInfo.at(1).x) { + + // 1. fix the error screen list + QList tmp_screenInfo; + + if (m_screenInfo.at(0).x == 0) { + tmp_screenInfo.append(m_screenInfo.at(0)); + tmp_screenInfo.append(m_screenInfo.at(1)); + } else { + tmp_screenInfo.append(m_screenInfo.at(1)); + tmp_screenInfo.append(m_screenInfo.at(0)); + } + + // 2. get the cross area + double area_1 = 0, area_2 = 0; + bool is_inScreen1 = false, is_inScreen2 = false; + QRect intersectRect_1, intersectRect_2; + QRect screen_1(tmp_screenInfo.at(0).x, tmp_screenInfo.at(0).y, tmp_screenInfo.at(0).width, tmp_screenInfo.at(0).height); + QRect screen_2(tmp_screenInfo.at(1).x, tmp_screenInfo.at(1).y, tmp_screenInfo.at(1).width, tmp_screenInfo.at(1).height); + + if (is_inScreen1 = QRect(recordX, recordY, recordWidth, recordHeight).intersects(screen_1)) { + intersectRect_1 = QRect(recordX, recordY, recordWidth, recordHeight).intersected(QRect(tmp_screenInfo.at(0).x, tmp_screenInfo.at(0).y, tmp_screenInfo.at(0).width, tmp_screenInfo.at(0).height)); + area_1 = intersectRect_1.width() * intersectRect_1.height(); + } + + if (is_inScreen2 = QRect(recordX, recordY, recordWidth, recordHeight).intersects(screen_2)) { + intersectRect_2 = QRect(recordX, recordY, recordWidth, recordHeight).intersected(QRect(tmp_screenInfo.at(1).x, tmp_screenInfo.at(1).y, tmp_screenInfo.at(1).width, tmp_screenInfo.at(1).height)); + area_2 = intersectRect_2.width() * intersectRect_2.height(); + } + + qDebug() << "record rect: " << QRect(dragRecordX, dragRecordY, dragRecordWidth, dragRecordHeight); + qDebug() << "intersect rect: " << intersectRect_1 << intersectRect_2; + qDebug() << "screen rect: " << screen_1 << screen_2; + qDebug() << "is intersect corss : " << is_inScreen1 << is_inScreen2; + qDebug() << "tarbar size : " << m_toolBar->size(); + + // 3. screen-1 intersect screen-2 + if (area_1 != 0 && area_2 != 0 && is_inScreen1 && is_inScreen2) { + int x = toolbarPoint.x(), y = toolbarPoint.y(); + int type = 0; + if (intersectRect_1.x() < intersectRect_2.x() && intersectRect_1.y() < intersectRect_2.y()) { + qDebug() << "west->south direction"; + type = 1; + } else if (intersectRect_1.x() < intersectRect_2.x() && intersectRect_1.y() > intersectRect_2.y()) { + qDebug() << "west-worth direction"; + type = 2; + } else { + qDebug() << "w-line"; + type = 0; + } + + if (area_1 > area_2) { // screen1 + qDebug() << "screen 1 larger"; + x = tmp_screenInfo.at(0).x + tmp_screenInfo.at(0).width - m_toolBar->width() - SIDEBAR_X_SPACING; + if (type == 1) { + if (intersectRect_1.y() < m_toolBar->height()) { + y = intersectRect_1.y() + intersectRect_1.height(); + } else { + y = intersectRect_1.y() - m_toolBar->height(); + } + } + if (type == 2) { + y = intersectRect_1.y() + intersectRect_1.height(); + } + if (type == 0) { + if (intersectRect_1.x() + intersectRect_1.width() == tmp_screenInfo.at(0).x + tmp_screenInfo.at(0).width) { + qDebug() << "cross-1 out right x" << x << intersectRect_1.x() << tmp_screenInfo.at(0).width; + } + + if (intersectRect_1.y() <= tmp_screenInfo.at(0).y) { + y = intersectRect_1.y() + intersectRect_1.height(); + } else { + if (intersectRect_1.y() - tmp_screenInfo.at(0).y > m_toolBar->height() && intersectRect_1.y() + intersectRect_1.height() + m_toolBar->height() > tmp_screenInfo.at(1).y + tmp_screenInfo.at(1).height) { + y = intersectRect_1.y() - m_toolBar->height(); + } + } + } + } else { // screen2 + qDebug() << "screen 2 larger"; + x = intersectRect_2.x() + SIDEBAR_X_SPACING; + if (type == 1) { + y = intersectRect_2.y() + intersectRect_2.height(); + } + if (type == 2) { + if (intersectRect_2.y() < m_toolBar->height()) { + y = intersectRect_2.y() + intersectRect_2.height(); + } else { + y = intersectRect_2.y() - m_toolBar->height(); + } + } + if (type == 0) { + if (intersectRect_2.y() < m_toolBar->height()) { + y = intersectRect_2.y() + intersectRect_2.height(); + } else { + if (intersectRect_2.y() + intersectRect_2.height() + m_toolBar->height() > tmp_screenInfo.at(1).y + tmp_screenInfo.at(1).height) { + y = intersectRect_2.y() - m_toolBar->height(); + } + } + } + } + + toolbarPoint.setX(x); + toolbarPoint.setY(y); + } + + // 4. screen-1 + if (area_1 != 0 && area_2 == 0 && is_inScreen1 && !is_inScreen2 && area_1 != recordWidth * recordHeight) { + int x = toolbarPoint.x(), y = toolbarPoint.y(); + + if (intersectRect_1.x() == tmp_screenInfo.at(0).x || intersectRect_1.x() < m_toolBar->width()) { + x = intersectRect_1.x() + SIDEBAR_X_SPACING; + qDebug() << "screen-1 out left x"; + } + + if (intersectRect_1.x() + intersectRect_1.width() == tmp_screenInfo.at(0).x + tmp_screenInfo.at(0).width) { + x = tmp_screenInfo.at(0).x + tmp_screenInfo.at(0).width - m_toolBar->width() - SIDEBAR_X_SPACING; + qDebug() << "screen-1 out right x" << x << intersectRect_1.x() << tmp_screenInfo.at(0).width; + } + + if (intersectRect_1.y() == tmp_screenInfo.at(0).y) { + y = intersectRect_1.y() + intersectRect_1.height(); + qDebug() << "screen-1 out top y"; + } else if (intersectRect_1.y() + intersectRect_1.height() == tmp_screenInfo.at(0).y + tmp_screenInfo.at(0).height || intersectRect_1.y() + intersectRect_1.height() + m_toolBar->height() >= tmp_screenInfo.at(0).y + tmp_screenInfo.at(0).height) { + y = intersectRect_1.y() - m_toolBar->height(); + qDebug() << "screen-1 out bottom y"; + } else { + y = recordY + recordHeight; + qDebug() << "screen-1 normal y"; + } + + toolbarPoint.setX(x); + toolbarPoint.setY(y); + } + + // 5. screen-2 + if (area_1 == 0 && area_2 != 0 && !is_inScreen1 && is_inScreen2 && area_2 != recordWidth * recordHeight) { + int x = toolbarPoint.x(), y = toolbarPoint.y(); + if (intersectRect_2.x() == tmp_screenInfo.at(1).x || mapToGlobal(m_toolBar->pos()).x() < tmp_screenInfo.at(1).x) { + x = intersectRect_2.x() + SIDEBAR_X_SPACING; + qDebug() << "screen-2 out left x"; + } + + if (intersectRect_2.x() + intersectRect_2.width() == tmp_screenInfo.at(1).x + tmp_screenInfo.at(1).width) { + x = tmp_screenInfo.at(1).x + tmp_screenInfo.at(1).width - m_toolBar->width() - SIDEBAR_X_SPACING; + qDebug() << "screen-2 out right x" << x << intersectRect_2.x() << tmp_screenInfo.at(1).width; + } + + if (intersectRect_2.y() == tmp_screenInfo.at(1).y) { + y = intersectRect_2.y() + intersectRect_2.height(); + qDebug() << "screen-2 out top y"; + } else if (intersectRect_2.y() + intersectRect_2.height() == tmp_screenInfo.at(1).y + tmp_screenInfo.at(1).height || intersectRect_2.y() + intersectRect_2.height() + m_toolBar->height() >= tmp_screenInfo.at(1).y + tmp_screenInfo.at(1).height) { + y = intersectRect_2.y() - m_toolBar->height(); + qDebug() << "screen-2 out bottom y"; + } else { + y = recordY + recordHeight; + qDebug() << "screen-2 normal y"; + } + + toolbarPoint.setX(x); + toolbarPoint.setY(y); + } + } + m_toolBar->showAt(toolbarPoint); //qDebug() << "==================2================="; }