Commit 48135195 authored by Michael Abrahams's avatar Michael Abrahams

Right click to undo last path point.

Summary: The path tool and select path tool will install an event filter to inctercept right click events and right double click events.

Reviewers: dkazakov, rempt

Differential Revision: https://phabricator.kde.org/D243
parent abb8f88e
......@@ -50,6 +50,21 @@ void KisToolPath::mousePressEvent(KoPointerEvent *event)
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<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::RightButton) {
localTool()->removeLastPoint();
return true;
}
}
return false;
}
void KisToolPath::beginAlternateAction(KoPointerEvent *event, AlternateAction action) {
Q_UNUSED(action)
mousePressEvent(event);
......
......@@ -42,6 +42,7 @@ public:
using KoCreatePathTool::endPathWithoutLastPoint;
using KoCreatePathTool::endPath;
using KoCreatePathTool::cancelPath;
using KoCreatePathTool::removeLastPoint;
private:
KisToolPath* const m_parentTool;
......@@ -61,6 +62,7 @@ public:
virtual QList< QPointer<QWidget> > 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);
......
......@@ -55,6 +55,20 @@ void KisToolSelectPath::mousePressEvent(KoPointerEvent* event)
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<QMouseEvent*>(event);
if (mouseEvent->button() == Qt::RightButton) {
localTool()->removeLastPoint();
return true;
}
}
return false;
}
QList<QPointer<QWidget> > KisToolSelectPath::createOptionWidgets()
{
QList<QPointer<QWidget> > widgetsList =
......
......@@ -41,6 +41,7 @@ public:
using KoCreatePathTool::endPathWithoutLastPoint;
using KoCreatePathTool::endPath;
using KoCreatePathTool::cancelPath;
using KoCreatePathTool::removeLastPoint;
private:
KisToolSelectPath* const m_selectionTool;
......@@ -72,6 +73,7 @@ class KisToolSelectPath : public SelectionActionHandler<KisDelegatedSelectPathWr
public:
KisToolSelectPath(KoCanvasBase * canvas);
void mousePressEvent(KoPointerEvent* event);
bool eventFilter(QObject *obj, QEvent *event);
protected:
void requestStrokeCancellation();
......
......@@ -24,6 +24,8 @@
#include <QPointer>
#include "input/kis_input_manager.h"
#include "canvas/kis_canvas2.h"
#include "kis_delegated_tool_policies.h"
......@@ -48,12 +50,22 @@ public:
BaseClass::activate(toolActivation, shapes);
m_localTool->activate(toolActivation, shapes);
ActivationPolicy::onActivate(BaseClass::canvas());
KisInputManager *inputManager = (static_cast<KisCanvas2*>(BaseClass::canvas()))->globalInputManager();
if (inputManager) {
inputManager->attachPriorityEventFilter(this);
}
}
void deactivate()
{
m_localTool->deactivate();
BaseClass::deactivate();
KisInputManager *inputManager = (static_cast<KisCanvas2*>(BaseClass::canvas()))->globalInputManager();
if (inputManager) {
inputManager->detachPriorityEventFilter(this);
}
}
void mousePressEvent(KoPointerEvent *event)
......
......@@ -125,11 +125,17 @@ void KoCreatePathTool::mousePressEvent(KoPointerEvent *event)
{
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 @@ void KoCreatePathTool::cancelPath()
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<KoShape*> &)
{
Q_D(KoCreatePathTool);
......
......@@ -95,6 +95,7 @@ protected:
void endPath();
void endPathWithoutLastPoint();
void cancelPath();
void removeLastPoint();
/// reimplemented
virtual QList<QPointer<QWidget> > createOptionWidgets();
......
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