Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit aa3a3d61 authored by Nabil Maghfur Usman's avatar Nabil Maghfur Usman Committed by Dmitry Kazakov

Allow shift snapping when placing and dragging assistant handles

Shift snapping assistant handles only worked after
the assistant has been created, by click-dragging
the handles. This change allows the user to hold
shift to snap handles when the assistant hasn't
been completed.

This change addresses bug 406204, except that Shift
can still only be held after the user starts
click-dragging the assistant's handles.

BUG:406204
parent 3be762c2
......@@ -271,11 +271,12 @@ void KisAssistantTool::beginPrimaryAction(KoPointerEvent *event)
} else if (m_handleDrag && assistant->handles().size()>2 && (assistant->id() == "ellipse" ||
assistant->id() == "concentric ellipse" ||
assistant->id() == "fisheye-point")){
m_snapIsRadial = false;
if (m_handleDrag == assistant->handles()[0]) {
m_dragStart = *assistant->handles()[1];
m_snapIsRadial = false;
} else if (m_handleDrag == assistant->handles()[1]) {
m_dragStart = *assistant->handles()[0];
m_snapIsRadial = false;
} else if (m_handleDrag == assistant->handles()[2]) {
m_dragStart = assistant->getEditorPosition();
m_radius = QLineF(m_dragStart, *assistant->handles()[0]);
......@@ -376,15 +377,10 @@ void KisAssistantTool::continuePrimaryAction(KoPointerEvent *event)
if (m_handleDrag) {
*m_handleDrag = event->point;
//ported from the gradient tool... we need to think about this more in the future.
if (event->modifiers() == Qt::ShiftModifier && m_snapIsRadial) {
QLineF dragRadius = QLineF(m_dragStart, event->point);
dragRadius.setLength(m_radius.length());
*m_handleDrag = dragRadius.p2();
} else if (event->modifiers() == Qt::ShiftModifier ) {
QPointF move = snapToClosestAxis(event->point - m_dragStart);
*m_handleDrag = m_dragStart + move;
} else {
KisPaintingAssistantSP selectedAssistant = m_canvas->paintingAssistantsDecoration()->selectedAssistant();
if (!snap(event)) {
*m_handleDrag = canvasDecoration->snapToGuide(event, QPointF(), false);
}
m_handleDrag->uncache();
......@@ -408,7 +404,7 @@ void KisAssistantTool::continuePrimaryAction(KoPointerEvent *event)
m_canvas->updateCanvas();
} else if (m_assistantDrag) {
QPointF newAdjustment = canvasDecoration->snapToGuide(event, QPointF(), false) - m_cursorStart;
if (event->modifiers() == Qt::ShiftModifier ) {
if (event->modifiers() & Qt::ShiftModifier ) {
newAdjustment = snapToClosestAxis(newAdjustment);
}
Q_FOREACH (KisPaintingAssistantHandleSP handle, m_assistantDrag->handles()) {
......@@ -658,7 +654,11 @@ void KisAssistantTool::slotChangeVanishingPointAngle(double value)
void KisAssistantTool::mouseMoveEvent(KoPointerEvent *event)
{
if (m_newAssistant && m_internalMode == MODE_CREATION) {
*m_newAssistant->handles().back() = event->point;
KisPaintingAssistantHandleSP new_handle = m_newAssistant->handles().back();
if (!snap(event)) {
*new_handle = event->point;
}
} else if (m_newAssistant && m_internalMode == MODE_DRAGGING_TRANSLATING_TWONODES) {
QPointF translate = event->point - m_dragEnd;
......@@ -1135,3 +1135,101 @@ void KisAssistantTool::slotCustomOpacityChanged()
m_canvas->paintingAssistantsDecoration()->uncache();
m_canvas->canvasWidget()->update();
}
void KisAssistantTool::beginAlternateAction(KoPointerEvent *event, AlternateAction action)
{
Q_UNUSED(action);
setMode(KisTool::PAINT_MODE);
if (m_newAssistant && m_internalMode == MODE_CREATION) {
KisPaintingAssistantsDecorationSP canvasDecoration = m_canvas->paintingAssistantsDecoration();
*m_newAssistant->handles().back() = event->point;
if (!snap(event)) {
*m_newAssistant->handles().back() = canvasDecoration->snapToGuide(event, QPointF(), false);
}
if (m_newAssistant->handles().size() == m_newAssistant->numHandles()) {
addAssistant();
} else {
m_newAssistant->addHandle(new KisPaintingAssistantHandle(canvasDecoration->snapToGuide(event, QPointF(), false)), HandleType::NORMAL);
}
m_canvas->updateCanvas();
return;
}
}
void KisAssistantTool::continueAlternateAction(KoPointerEvent *event, AlternateAction action)
{
Q_UNUSED(action);
event->ignore();
}
void KisAssistantTool::endAlternateAction(KoPointerEvent *event, AlternateAction action)
{
Q_UNUSED(action);
setMode(KisTool::HOVER_MODE);
event->ignore();
m_canvas->updateCanvas();
}
bool KisAssistantTool::snap(KoPointerEvent *event)
{
if ((event->modifiers() & Qt::ShiftModifier) == false) {
return false;
} else {
if (m_handleDrag) {
if (m_snapIsRadial == true) {
QLineF dragRadius = QLineF(m_dragStart, event->point);
dragRadius.setLength(m_radius.length());
*m_handleDrag = dragRadius.p2();
} else {
QPointF snap_point = snapToClosestAxis(event->point - m_dragStart);
*m_handleDrag = m_dragStart + snap_point;
}
} else {
if (m_newAssistant && m_internalMode == MODE_CREATION) {
QList<KisPaintingAssistantHandleSP> handles = m_newAssistant->handles();
KisPaintingAssistantHandleSP handle_snap = handles.back();
// for any assistant, snap 2nd handle to x or y axis relative to first handle
if (handles.size() == 2) {
QPointF snap_point = snapToClosestAxis(event->point - *handles[0]);
*handle_snap = *handles[0] + snap_point;
} else {
bool was_snapped = false;
if (m_newAssistant->id() == "spline") {
KisPaintingAssistantHandleSP start;
handles.size() == 3 ? start = handles[0] : start = handles[1];
QPointF snap_point = snapToClosestAxis(event->point - *start);
*handle_snap = *start + snap_point;
was_snapped = true;
}
if (m_newAssistant->id() == "ellipse" ||
m_newAssistant->id() == "concentric ellipse" ||
m_newAssistant->id() == "fisheye-point") {
QPointF center = QLineF(*handles[0], *handles[1]).center();
QLineF radius = QLineF(center,*handles[0]);
QLineF dragRadius = QLineF(center, event->point);
dragRadius.setLength(radius.length());
*handle_snap = dragRadius.p2();
was_snapped = true;
}
if (m_newAssistant->id() == "perspective") {
KisPaintingAssistantHandleSP start;
handles.size() == 3 ? start = handles[1] : start = handles[2];
QPointF snap_point = snapToClosestAxis(event->point - *start);
*handle_snap = *start + snap_point;
was_snapped = true;
}
return was_snapped;
}
}
}
return true;
}
}
......@@ -68,10 +68,12 @@ public:
* hitbox regions specified to know if a click is doing any of those actions.
*/
void beginPrimaryAction(KoPointerEvent *event) override;
void beginAlternateAction(KoPointerEvent *event, AlternateAction action) override;
void continuePrimaryAction(KoPointerEvent *event) override;
void endPrimaryAction(KoPointerEvent *event) override;
void continueAlternateAction(KoPointerEvent *event, AlternateAction action) override;
void endAlternateAction(KoPointerEvent *event, AlternateAction action) override;
void mouseMoveEvent(KoPointerEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
......@@ -86,6 +88,11 @@ private:
void assistantSelected(KisPaintingAssistantSP assistant);
// Handles both shift+mouse-drag or shift+mouse-move snapping
// Returns true if snapping is successful
// This uses m_handleDrag or m_newAssistant to figure out what handle to snap and where
bool snap(KoPointerEvent *event);
public Q_SLOTS:
void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override;
void deactivate() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment