From 4676b6b0669b371e6ce455e6929e887192dbc9cd Mon Sep 17 00:00:00 2001 From: toofar Date: Fri, 29 Dec 2023 11:54:08 +1300 Subject: [PATCH] Fix adjusting selection geometry when 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 ;) This error has the following implications 1) causing the pin widget to shift a little from where the selection was 2) causing the reported geometry to not match the pixmap size, which didn't have much effect unless you wanted to use the geometry later (for example for allowing editing pins). I guess the pin widget got its size from the pixmap or something and that's why it wasn't huge? 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 (which causes monitor two to have a negative offset) * pin a selection and watch the pinned window shift a bit from where the selection was; or * 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 {