diff --git a/src/widgets/capture/capturetoolobjects.cpp b/src/widgets/capture/capturetoolobjects.cpp index bd9b76a500..cd3e3d6a48 100644 --- a/src/widgets/capture/capturetoolobjects.cpp +++ b/src/widgets/capture/capturetoolobjects.cpp @@ -55,6 +55,9 @@ int CaptureToolObjects::find(const QPoint& pos, const QSize& captureSize) if (m_captureToolObjects.empty()) { return -1; } + if (!QRect(QPoint(0, 0), captureSize).contains(pos)) { + return -1; + } QPixmap pixmap(captureSize); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); @@ -148,4 +151,4 @@ CaptureToolObjects& CaptureToolObjects::operator=( count++; } return *this; -} \ No newline at end of file +} diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index f58ddecfd0..7ab244508d 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -153,7 +153,7 @@ CaptureWidget::CaptureWidget(uint id, } } move(topLeft); - resize(pixmap().size()); + resize(m_context.screenshot.size()); } else if (windowMode == CaptureWindowMode::FullScreenCurrent) { // Emulate fullscreen mode // setWindowFlags(Qt::WindowStaysOnTopHint |f @@ -485,7 +485,7 @@ int CaptureWidget::selectToolItemAtPos(const QPoint& pos) auto toolItem = activeToolObject(); if (!toolItem || (toolItem && !toolItem->selectionRect().contains(capturePoint))) { - activeLayerIndex = m_captureToolObjects.find(capturePoint, size()); + activeLayerIndex = m_captureToolObjects.find(capturePoint, m_context.screenshot.size()); int thickness_old = m_context.thickness; m_panel->setActiveLayer(activeLayerIndex); drawObjectSelection(); @@ -552,6 +552,8 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e) m_dragStartPoint = e->pos(); m_initialOffset = m_viewOffset; updateViewTransform(); + updateCursor(); + return; } // Commit current tool if it has edit widget and mouse click is outside @@ -591,6 +593,7 @@ void CaptureWidget::mouseDoubleClickEvent(QMouseEvent* event) void CaptureWidget::mouseMoveEvent(QMouseEvent* e) { m_context.mousePos = widgetToCapturePoint(e->pos()); + auto scrollWidgetPos = scrollWidgetPoint(e->pos()); // position relative to ScrollArea::widget bool symmetryMod = qApp->keyboardModifiers() & Qt::ShiftModifier; // Repaint to ensure that preview is displayed at correct position @@ -682,23 +685,22 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e) } } } else if (!m_movingSelection && - (!m_selection->geometry().contains(e->pos()) || + (!m_selection->geometry().contains(scrollWidgetPos) || m_newSelection)) { m_newSelection = true; // Drawing a new selection + auto captureStartPoint = widgetToCapturePoint(m_dragStartPoint); inputRect = symmetryMod - ? QRect(m_dragStartPoint * 2 - m_context.mousePos, + ? QRect(captureStartPoint * 2 - m_context.mousePos, m_context.mousePos) - : QRect(m_dragStartPoint, m_context.mousePos); + : QRect(captureStartPoint, m_context.mousePos); } else if (m_mouseOverHandle == SelectionWidget::NO_SIDE) { // Moving the whole selection m_movingSelection = true; if (m_adjustmentButtonPressed || activeToolObject().isNull()) { - setCursor(Qt::OpenHandCursor); + widget()->setCursor(Qt::OpenHandCursor); QRect initialRect = m_selection->savedGeometry().normalized(); - QPoint newTopLeft = - initialRect.topLeft() + (e->pos() - m_dragStartPoint); - inputRect = QRect(newTopLeft, initialRect.size()); + inputRect = initialRect.translated((e->pos() - m_dragStartPoint) * m_viewScale); } else { return; } @@ -773,7 +775,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e) // Try to select existing tool if it was in the selection area // but need to select another one m_panel->setActiveLayer(m_captureToolObjects.find( - widgetToCapturePoint(e->pos()), size())); + widgetToCapturePoint(e->pos()), m_context.screenshot.size())); } drawToolsData(true, true); } @@ -785,19 +787,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e) // Don't go outside QRect newGeometry = m_selection->captureGeomtry().intersected( - m_context.screenshot.rect()); - newGeometry.normalized(); - // 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_context.screenshot.rect()).normalized(); m_selection->setCaptureGeometry(newGeometry); m_context.selection = newGeometry; // extendedRect(&newGeometry); //TODO: cleanup diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index 4e617cd3b1..7315c1d7ac 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -197,7 +197,7 @@ private slots: HoverEventFilter* m_eventFilter; SelectionWidget* m_selection; - QPoint m_dragStartPoint; + QPoint m_dragStartPoint; // widget coordinates SelectionWidget::SideType m_mouseOverHandle; uint m_id; @@ -212,7 +212,7 @@ private slots: bool m_existingObjectIsChanged; // For start moving after more than X offset - QPoint m_startMovePos; + QPoint m_startMovePos; // widget coordinates bool m_startMove; QTransform m_viewTransform; // window to capture transform