diff --git a/krita/plugins/tools/defaulttools/kis_tool_path.h b/krita/plugins/tools/defaulttools/kis_tool_path.h --- a/krita/plugins/tools/defaulttools/kis_tool_path.h +++ b/krita/plugins/tools/defaulttools/kis_tool_path.h @@ -42,6 +42,7 @@ using KoCreatePathTool::endPathWithoutLastPoint; using KoCreatePathTool::endPath; using KoCreatePathTool::cancelPath; + using KoCreatePathTool::removeLastPoint; private: KisToolPath* const m_parentTool; @@ -61,6 +62,7 @@ virtual QList< QPointer > createOptionWidgets(); + bool eventFilter(QObject *obj, QEvent *event); void beginAlternateAction(KoPointerEvent *event, AlternateAction action); void continueAlternateAction(KoPointerEvent *event, AlternateAction action); void endAlternateAction(KoPointerEvent *event, AlternateAction action); diff --git a/krita/plugins/tools/defaulttools/kis_tool_path.cc b/krita/plugins/tools/defaulttools/kis_tool_path.cc --- a/krita/plugins/tools/defaulttools/kis_tool_path.cc +++ b/krita/plugins/tools/defaulttools/kis_tool_path.cc @@ -50,6 +50,21 @@ DelegatedPathTool::mousePressEvent(event); } +// Install an event filter to catch right-click events. +// This is the simplest way to accommodate the popup palette binding. +bool KisToolPath::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonPress || + event->type() == QEvent::MouseButtonDblClick) { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::RightButton) { + localTool()->removeLastPoint(); + return true; + } + } + return false; +} + void KisToolPath::beginAlternateAction(KoPointerEvent *event, AlternateAction action) { Q_UNUSED(action) mousePressEvent(event); diff --git a/krita/plugins/tools/selectiontools/kis_tool_select_path.h b/krita/plugins/tools/selectiontools/kis_tool_select_path.h --- a/krita/plugins/tools/selectiontools/kis_tool_select_path.h +++ b/krita/plugins/tools/selectiontools/kis_tool_select_path.h @@ -41,6 +41,7 @@ using KoCreatePathTool::endPathWithoutLastPoint; using KoCreatePathTool::endPath; using KoCreatePathTool::cancelPath; + using KoCreatePathTool::removeLastPoint; private: KisToolSelectPath* const m_selectionTool; @@ -72,6 +73,7 @@ public: KisToolSelectPath(KoCanvasBase * canvas); void mousePressEvent(KoPointerEvent* event); + bool eventFilter(QObject *obj, QEvent *event); protected: void requestStrokeCancellation(); diff --git a/krita/plugins/tools/selectiontools/kis_tool_select_path.cc b/krita/plugins/tools/selectiontools/kis_tool_select_path.cc --- a/krita/plugins/tools/selectiontools/kis_tool_select_path.cc +++ b/krita/plugins/tools/selectiontools/kis_tool_select_path.cc @@ -55,6 +55,20 @@ DelegatedSelectPathTool::mousePressEvent(event); } +// Install an event filter to catch right-click events. +bool KisToolSelectPath::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonPress || + event->type() == QEvent::MouseButtonDblClick) { + QMouseEvent *mouseEvent = static_cast(event); + if (mouseEvent->button() == Qt::RightButton) { + localTool()->removeLastPoint(); + return true; + } + } + return false; +} + QList > KisToolSelectPath::createOptionWidgets() { QList > widgetsList = diff --git a/krita/ui/tool/kis_delegated_tool.h b/krita/ui/tool/kis_delegated_tool.h --- a/krita/ui/tool/kis_delegated_tool.h +++ b/krita/ui/tool/kis_delegated_tool.h @@ -24,6 +24,8 @@ #include +#include "input/kis_input_manager.h" +#include "canvas/kis_canvas2.h" #include "kis_delegated_tool_policies.h" @@ -48,12 +50,22 @@ BaseClass::activate(toolActivation, shapes); m_localTool->activate(toolActivation, shapes); ActivationPolicy::onActivate(BaseClass::canvas()); + + KisInputManager *inputManager = (static_cast(BaseClass::canvas()))->globalInputManager(); + if (inputManager) { + inputManager->attachPriorityEventFilter(this); + } } void deactivate() { m_localTool->deactivate(); BaseClass::deactivate(); + + KisInputManager *inputManager = (static_cast(BaseClass::canvas()))->globalInputManager(); + if (inputManager) { + inputManager->detachPriorityEventFilter(this); + } } void mousePressEvent(KoPointerEvent *event) diff --git a/libs/basicflakes/tools/KoCreatePathTool.h b/libs/basicflakes/tools/KoCreatePathTool.h --- a/libs/basicflakes/tools/KoCreatePathTool.h +++ b/libs/basicflakes/tools/KoCreatePathTool.h @@ -95,6 +95,7 @@ void endPath(); void endPathWithoutLastPoint(); void cancelPath(); + void removeLastPoint(); /// reimplemented virtual QList > createOptionWidgets(); diff --git a/libs/basicflakes/tools/KoCreatePathTool.cpp b/libs/basicflakes/tools/KoCreatePathTool.cpp --- a/libs/basicflakes/tools/KoCreatePathTool.cpp +++ b/libs/basicflakes/tools/KoCreatePathTool.cpp @@ -125,11 +125,17 @@ { Q_D(KoCreatePathTool); + //Right click removes last point + if (event->button() == Qt::RightButton) { + removeLastPoint(); + return; + } + const bool isOverFirstPoint = d->shape && handleGrabRect(d->firstPoint->point()).contains(event->point); bool haveCloseModifier = (listeningToModifiers() && (event->modifiers() & Qt::ShiftModifier)); - if ((event->button() == Qt::RightButton) || ((event->button() == Qt::LeftButton) && haveCloseModifier && !isOverFirstPoint)) { + if ((event->button() == Qt::LeftButton) && haveCloseModifier && !isOverFirstPoint) { endPathWithoutLastPoint(); return; } @@ -356,6 +362,25 @@ d->cleanUp(); } +void KoCreatePathTool::removeLastPoint() +{ + Q_D(KoCreatePathTool); + + if ((d->shape)) { + KoPathPointIndex lastPointIndex = d->shape->pathPointIndex(d->activePoint); + + if (lastPointIndex.second > 1) { + lastPointIndex.second--; + delete d->shape->removePoint(lastPointIndex); + + d->hoveredPoint = 0; + + d->repaintActivePoint(); + canvas()->updateCanvas(d->shape->boundingRect()); + } + } +} + void KoCreatePathTool::activate(ToolActivation, const QSet &) { Q_D(KoCreatePathTool);