Skip to content

Commit

Permalink
Fix adjusting select geometry before exporting from gui
Browse files Browse the repository at this point in the history
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<int>(selection.width() * scale))
                            .arg(static_cast<int>(selection.height() * scale))
                            .arg(static_cast<int>(selection.left() * scale))
    -                       .arg(static_cast<int>(selection.top() * scale));
    +                       .arg(static_cast<int>(selection.top() * scale))
    +                       .arg(static_cast<int>(final_geometry.width() * scale))
    +                       .arg(static_cast<int>(final_geometry.height() * scale))
    +                       .arg(static_cast<int>(final_geometry.left() * scale))
    +                       .arg(static_cast<int>(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
  • Loading branch information
toofar committed Dec 28, 2023
1 parent e118894 commit 6347418
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6347418

Please sign in to comment.