Skip to content

Commit

Permalink
Some fixes after rebase.
Browse files Browse the repository at this point in the history
* fix object selection
* don't try to select on middle click
* adjust the recent selection logic changes to match mouse coordinates used by this branch
  • Loading branch information
karliss committed Sep 6, 2021
1 parent 87f433e commit 9c65ee4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/widgets/capture/capturetoolobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -148,4 +151,4 @@ CaptureToolObjects& CaptureToolObjects::operator=(
count++;
}
return *this;
}
}
36 changes: 13 additions & 23 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/capture/capturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down

0 comments on commit 9c65ee4

Please sign in to comment.