Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the toolbar incorrect coordinate position display #501

Merged
merged 1 commit into from
Jul 12, 2024
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
158 changes: 158 additions & 0 deletions src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,6 +2406,14 @@
//快捷全屏录制不需要显示工具栏
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) {
add-uos marked this conversation as resolved.
Show resolved Hide resolved
QPoint correctPoint = getTwoScreenIntersectPos(toolbarPoint);
if(toolbarPoint != correctPoint){
toolbarPoint = correctPoint;

Check warning on line 2413 in src/main_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The statement 'if (toolbarPoint!=correctPoint) toolbarPoint=correctPoint' is logically equivalent to 'toolbarPoint=correctPoint'.
}
}

m_toolBar->showAt(toolbarPoint);
//qDebug() << "==================2=================";
}
Expand Down Expand Up @@ -2708,8 +2716,158 @@
m_cameraWidget->setRecordRect(recordX, recordY, recordWidth, recordHeight);
}
}

QPoint MainWindow::getTwoScreenIntersectPos(QPoint rawPos)
{
// 1. fix the error screen list
QList<ScreenInfo> tmp_screenInfo;
QPoint toolbarPoint = rawPos;

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();
}

// 3. screen-1 intersect screen-2
if (area_1 != 0 && area_2 != 0 && is_inScreen1 && is_inScreen2) {
int x = toolbarPoint.x(), y = toolbarPoint.y();

Check warning on line 2755 in src/main_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'x'. The initialized value is overwritten before it is read.
int type = 0;
if (intersectRect_1.x() < intersectRect_2.x() && intersectRect_1.y() < intersectRect_2.y()) {
type = 1;
} else if (intersectRect_1.x() < intersectRect_2.x() && intersectRect_1.y() > intersectRect_2.y()) {
type = 2;
} else {
type = 0;
}

if (area_1 > area_2) { // screen1
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) {
}

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
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();

Check warning on line 2819 in src/main_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'y'. The initialized value is overwritten before it is read.

if (intersectRect_1.x() == tmp_screenInfo.at(0).x || intersectRect_1.x() < m_toolBar->width()) {
x = intersectRect_1.x() + SIDEBAR_X_SPACING;
}

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;
}

if (intersectRect_1.y() == tmp_screenInfo.at(0).y) {
y = intersectRect_1.y() + intersectRect_1.height();
} 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();
} else {
y = recordY + recordHeight;
}

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();

Check warning on line 2844 in src/main_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Redundant initialization for 'y'. The initialized value is overwritten before it is read.
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;
}

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;
}

if (intersectRect_2.y() == tmp_screenInfo.at(1).y) {
y = intersectRect_2.y() + intersectRect_2.height();
} 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();
} else {
y = recordY + recordHeight;
}

toolbarPoint.setX(x);
toolbarPoint.setY(y);
}

return toolbarPoint;

}
//切换截图功能或者录屏功能
void MainWindow::changeFunctionButton(QString type)

Check warning on line 2870 in src/main_window.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'type' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
if (type == "record") {
if (status::record == m_functionType) {
Expand Down
4 changes: 4 additions & 0 deletions src/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ public slots:
//void updateRecordButtonPos();
//void updateShotButtonPos();
void updateCameraWidgetPos();
/**
* @brief 多屏幕错位时修正工具栏坐标
*/
QPoint getTwoScreenIntersectPos(QPoint rawPos);
/**
* @brief 切换截图功能或者录屏功能
* @param shapeType : "record" or "shot"
Expand Down
Loading