From 63474185097a79e52c24ae55a62fb2e5ab86d065 Mon Sep 17 00:00:00 2001 From: toofar Date: Fri, 29 Dec 2023 11:54:08 +1300 Subject: [PATCH] Fix adjusting select geometry before exporting from gui The docs for `setTopLeft()` say "Set the top-left corner of the rectangle to the given position. May change the size, but will never change the bottom-right corner of the rectangle." For some reason on windows when calling `setTopLeft()` here when the widget is at an offset it is moving the top left of the rect but not keeping the size the same. I believe all we want to do here is move the rect, so this commit changes this adjustment to definitively do that. There are various instances of `move()`, `moveTo()` and `moveTopLeft()` in the codebase, and only one other if `setTopLeft()`. I picked `moveTopLeft()` because it makes the diff smaller ;) You can reproduce this like so: * have a windows machine with two monitors * change the display settings so monitor one is to the right of monitor two * observe this modified geometry somehow, like this patch which changes the size measurement painted on the selection widget to include the modified geometry alongside the original one: diff --git c/src/widgets/capture/capturewidget.cpp w/src/widgets/capture/capturewidget.cpp index 49ebff9720a0..16c7d04dbed6 100644 --- c/src/widgets/capture/capturewidget.cpp +++ w/src/widgets/capture/capturewidget.cpp @@ -551,11 +633,18 @@ void CaptureWidget::paintEvent(QPaintEvent* paintEvent) QRect xybox; QFontMetrics fm = painter.fontMetrics(); - QString xy = QString("%1x%2+%3+%4") + QRect final_geometry(m_context.selection); + final_geometry.setTopLeft(final_geometry.topLeft() + m_context.widgetOffset); + QString xy = QString("%1x%2+%3+%4\n%5x%6+%7+%8") .arg(static_cast(selection.width() * scale)) .arg(static_cast(selection.height() * scale)) .arg(static_cast(selection.left() * scale)) - .arg(static_cast(selection.top() * scale)); + .arg(static_cast(selection.top() * scale)) + .arg(static_cast(final_geometry.width() * scale)) + .arg(static_cast(final_geometry.height() * scale)) + .arg(static_cast(final_geometry.left() * scale)) + .arg(static_cast(final_geometry.top() * scale)) + ; xybox = fm.boundingRect(xy); // the small numbers here are just margins so the text doesn't https://doc.qt.io/qt-6/qrect.html#setTopLeft --- src/widgets/capture/capturewidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 3442c4144b..312971ee67 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -200,7 +200,7 @@ CaptureWidget::~CaptureWidget() auto lastRegion = m_selection->geometry(); setLastRegion(lastRegion); QRect geometry(m_context.selection); - geometry.setTopLeft(geometry.topLeft() + m_context.widgetOffset); + geometry.moveTopLeft(geometry.topLeft() + m_context.widgetOffset); Flameshot::instance()->exportCapture( pixmap(), geometry, m_context.request); } else {