From a8bb555c127e19e5942b3fec162256b89d1e62f7 Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Thu, 17 May 2018 22:14:02 +0200 Subject: [PATCH] Fix negative selection geometry bug normalize only swaps the sides if width() or height() is < 0, but we need it to happen when it is <=0 because with QRect's normalized method we get negative geometry and that causes a bug when we position the buttons. --- src/widgets/capture/capturewidget.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 736ca827..c891d13c 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -439,10 +439,22 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent *e) { // of a new one. if (!m_buttonHandler->isVisible() && m_selection->isVisible()) { // Don't go outside - m_selection->setGeometry(m_selection->geometry().intersected(rect())); - m_context.selection = m_selection->geometry(); // TODO remove? + QRect newGeometry = m_selection->geometry().intersected(rect()); + // normalize + if (newGeometry.width() <= 0) { + int left = newGeometry.left(); + newGeometry.setLeft(newGeometry.right()); + newGeometry.setRight(left); + } + if (newGeometry.height() <= 0) { + int top = newGeometry.top(); + newGeometry.setTop(newGeometry.bottom()); + newGeometry.setBottom(top); + } + m_selection->setGeometry(newGeometry); + m_context.selection = newGeometry; updateSizeIndicator(); - m_buttonHandler->updatePosition(m_selection->geometry()); + m_buttonHandler->updatePosition(newGeometry); m_buttonHandler->show(); } m_mouseIsClicked = false;