Commit e2f1ecf0 authored by Damien de Lemeny's avatar Damien de Lemeny

Clean global origin workaround

KisToolProxy::forwardEvent had an ugly workaround parameter to get the
origin coordinates of the canvas converted to global coordinates. Better
have KisToolProxy creating that origin instead of passing it around.

REWIEW:121226
parent 9dddc5fe
......@@ -29,6 +29,12 @@ KisToolProxy::KisToolProxy(KoCanvasBase *canvas, QObject *parent)
{
}
QPointF KisToolProxy::tabletToDocument(const QPointF &globalPos)
{
const QPointF pos = globalPos - canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0));
return widgetToDocument(pos);
}
QPointF KisToolProxy::widgetToDocument(const QPointF &widgetPoint) const
{
KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
......@@ -71,16 +77,10 @@ KoPointerEvent KisToolProxy::convertEventToPointerEvent(QEvent *event, const QPo
return KoPointerEvent(&fakeEvent, QPointF());
}
QPointF KisToolProxy::tabletToDocument(const QPointF &globalPos, const QPoint &canvasOriginWorkaround)
{
const QPointF pos = globalPos - canvasOriginWorkaround;
return widgetToDocument(pos);
}
void KisToolProxy::forwardMouseHoverEvent(QMouseEvent *mouseEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround)
void KisToolProxy::forwardMouseHoverEvent(QMouseEvent *mouseEvent, QTabletEvent *lastTabletEvent)
{
if (lastTabletEvent) {
QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos());
this->tabletEvent(lastTabletEvent, docPoint);
} else {
KIS_ASSERT_RECOVER_RETURN(mouseEvent->type() == QEvent::MouseMove);
......@@ -89,7 +89,7 @@ void KisToolProxy::forwardMouseHoverEvent(QMouseEvent *mouseEvent, QTabletEvent
}
}
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround)
bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent)
{
bool retval = true;
......@@ -98,7 +98,7 @@ bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, Q
QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
if (tabletEvent) {
QPointF docPoint = tabletToDocument(tabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
QPointF docPoint = tabletToDocument(tabletEvent->hiResGlobalPos());
tabletEvent->accept();
this->tabletEvent(tabletEvent, docPoint);
forwardToTool(state, action, tabletEvent, docPoint);
......@@ -113,7 +113,7 @@ bool KisToolProxy::forwardEvent(ActionState state, KisTool::ToolAction action, Q
}
} else if (mouseEvent) {
if (lastTabletEvent) {
QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos(), canvasOriginWorkaround);
QPointF docPoint = tabletToDocument(lastTabletEvent->hiResGlobalPos());
lastTabletEvent->accept();
this->tabletEvent(lastTabletEvent, docPoint);
forwardToTool(state, action, lastTabletEvent, docPoint);
......
......@@ -35,14 +35,14 @@ public:
public:
KisToolProxy(KoCanvasBase *canvas, QObject *parent = 0);
void forwardMouseHoverEvent(QMouseEvent *mouseEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround);
void forwardMouseHoverEvent(QMouseEvent *mouseEvent, QTabletEvent *lastTabletEvent);
/**
* Forwards the event to the active tool and returns true if the
* event 'was not ignored'. That is by default the event is
* considered accepted, but the tool can explicitly ignore it.
*/
bool forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent, const QPoint &canvasOriginWorkaround);
bool forwardEvent(ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent, QTabletEvent *lastTabletEvent);
bool primaryActionSupportsHiResEvents() const;
void setActiveTool(KoToolBase *tool);
......@@ -52,7 +52,7 @@ public:
private:
KoPointerEvent convertEventToPointerEvent(QEvent *event, const QPointF &docPoint, bool *result);
QPointF tabletToDocument(const QPointF &globalPos, const QPoint &canvasOriginWorkaround);
QPointF tabletToDocument(const QPointF &globalPos);
void forwardToTool(ActionState state, KisTool::ToolAction action, QEvent *event, const QPointF &docPoint);
protected:
......
......@@ -114,8 +114,7 @@ void KisAlternateInvocationAction::begin(int shortcut, QEvent *event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::BEGIN, m_d->savedAction, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
}
void KisAlternateInvocationAction::end(QEvent *event)
......@@ -139,8 +138,7 @@ void KisAlternateInvocationAction::end(QEvent *event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::END, m_d->savedAction, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
KisAbstractInputAction::end(event);
}
......@@ -165,7 +163,6 @@ void KisAlternateInvocationAction::inputEvent(QEvent* event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::CONTINUE, m_d->savedAction, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
}
}
......@@ -67,8 +67,7 @@ void KisChangePrimarySettingAction::begin(int shortcut, QEvent *event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::BEGIN, KisTool::AlternateChangeSize, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
}
}
......@@ -80,8 +79,7 @@ void KisChangePrimarySettingAction::end(QEvent *event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::END, KisTool::AlternateChangeSize, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
}
KisAbstractInputAction::end(event);
......@@ -96,7 +94,6 @@ void KisChangePrimarySettingAction::inputEvent(QEvent* event)
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::CONTINUE, KisTool::AlternateChangeSize, &targetEvent, event,
inputManager()->lastTabletEvent(),
inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
inputManager()->lastTabletEvent());
}
}
......@@ -556,7 +556,7 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (!d->matcher.mouseMoved(mouseEvent)) {
//Update the current tool so things like the brush outline gets updated.
d->toolProxy->forwardMouseHoverEvent(mouseEvent, lastTabletEvent(), canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
d->toolProxy->forwardMouseHoverEvent(mouseEvent, lastTabletEvent());
}
retval = true;
event->setAccepted(retval);
......
......@@ -97,12 +97,10 @@ bool KisToolInvocationAction::canIgnoreModifiers() const
void KisToolInvocationAction::begin(int shortcut, QEvent *event)
{
if (shortcut == ActivateShortcut || shortcut == LineToolShortcut) {
QPoint workaround = inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0));
d->active =
inputManager()->toolProxy()->forwardEvent(
KisToolProxy::BEGIN, KisTool::Primary, event, event,
inputManager()->lastTabletEvent(),
workaround);
inputManager()->lastTabletEvent());
} else if (shortcut == ConfirmShortcut) {
QKeyEvent pressEvent(QEvent::KeyPress, Qt::Key_Return, 0);
inputManager()->toolProxy()->keyPressEvent(&pressEvent);
......@@ -129,11 +127,9 @@ void KisToolInvocationAction::begin(int shortcut, QEvent *event)
void KisToolInvocationAction::end(QEvent *event)
{
if (d->active) {
QPoint workaround = inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0));
inputManager()->toolProxy()->
forwardEvent(KisToolProxy::END, KisTool::Primary, event, event,
inputManager()->lastTabletEvent(),
workaround);
inputManager()->lastTabletEvent());
d->active = false;
}
......@@ -145,11 +141,10 @@ void KisToolInvocationAction::inputEvent(QEvent* event)
{
if (!d->active) return;
QPoint workaround = inputManager()->canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0));
inputManager()->toolProxy()->
forwardEvent(KisToolProxy::CONTINUE, KisTool::Primary, event, event,
inputManager()->lastTabletEvent(), workaround);
inputManager()->lastTabletEvent());
}
void KisToolInvocationAction::processUnhandledEvent(QEvent* event)
......
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