Commit 7528f478 authored by Sharaf Zaman's avatar Sharaf Zaman Committed by Boudewijn Rempt

Add KisZoomAndRotateAction

This facilitates both rotation and zooming actions of the
canvas

Maniphest: T10784
parent 2c299f5b
......@@ -304,6 +304,7 @@ set(kritaui_LIB_SRCS
input/kis_select_layer_action.cpp
input/KisQtWidgetsTweaker.cpp
input/KisInputActionGroup.cpp
input/kis_zoom_and_rotate_action.cpp
operations/kis_operation.cpp
operations/kis_operation_configuration.cpp
......
......@@ -33,6 +33,8 @@
#include "kis_input_profile_manager.h"
#include "kis_extended_modifiers_mapper.h"
#include "kis_zoom_and_rotate_action.h"
/**
* This hungry class EventEater encapsulates event masking logic.
*
......@@ -502,7 +504,9 @@ void KisInputManager::Private::addTouchShortcut(KisAbstractInputAction* action,
{
KisTouchShortcut *shortcut = new KisTouchShortcut(action, index);
switch(gesture) {
case KisShortcutConfiguration::RotateGesture:
case KisShortcutConfiguration::PinchGesture:
shortcut = new KisTouchShortcut(new KisZoomAndRotateAction, index);
shortcut->setMinimumTouchPoints(2);
shortcut->setMaximumTouchPoints(2);
break;
......
......@@ -32,10 +32,12 @@
class KisRotateCanvasAction::Private
{
public:
Private() : angleDrift(0) {}
Private() : angleDrift(0), previousAngle(0) {}
Shortcut mode;
qreal angleDrift;
qreal previousAngle;
};
......@@ -83,6 +85,7 @@ void KisRotateCanvasAction::deactivate(int shortcut)
void KisRotateCanvasAction::begin(int shortcut, QEvent *event)
{
KisAbstractInputAction::begin(shortcut, event);
d->previousAngle = 0;
KisCanvasController *canvasController =
dynamic_cast<KisCanvasController*>(inputManager()->canvas()->canvasController());
......@@ -145,6 +148,35 @@ void KisRotateCanvasAction::inputEvent(QEvent* event)
controller->rotateCanvas(angle, widgetPos);
return;
}
case QEvent::TouchUpdate: {
QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
if (touchEvent->touchPoints().count() != 2)
break;
QPointF p0 = touchEvent->touchPoints().at(0).pos();
QPointF p1 = touchEvent->touchPoints().at(1).pos();
// high school (y2 - y1) / (x2 - x1)
QPointF slope = p1 - p0;
qreal newAngle = atan2(slope.y(), slope.x());
if (!d->previousAngle)
{
d->previousAngle = newAngle;
return;
}
qreal delta = (180 / M_PI) * (newAngle - d->previousAngle);
qDebug() << ppVar(delta);
KisCanvas2 *canvas = inputManager()->canvas();
KisCanvasController *controller = static_cast<KisCanvasController*>(canvas->canvasController());
controller->rotateCanvas(delta);
d->previousAngle = newAngle;
return;
}
default:
break;
}
......
/*
* This file is part of the KDE project
* Copyright (C) 2019 Sharaf Zaman <sharafzaz121@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <klocalizedstring.h>
#include "kis_zoom_and_rotate_action.h"
#include "kis_zoom_action.h"
#include "kis_rotate_canvas_action.h"
class KisZoomAndRotateAction::Private {
public:
Private(): zoomAction(new KisZoomAction), rotateAction(new KisRotateCanvasAction) {}
KisZoomAction *zoomAction;
KisRotateCanvasAction *rotateAction;
};
KisZoomAndRotateAction::KisZoomAndRotateAction()
: KisAbstractInputAction ("Zoom and Rotate Canvas")
, d(new Private)
{
setName(i18n("Zoom and Rotate Canvas"));
}
int KisZoomAndRotateAction::priority() const
{
return 5;
}
void KisZoomAndRotateAction::activate(int shortcut)
{
d->zoomAction->activate(shortcut);
d->rotateAction->activate(shortcut);
}
void KisZoomAndRotateAction::deactivate(int shortcut)
{
d->zoomAction->deactivate(shortcut);
d->rotateAction->deactivate(shortcut);
}
void KisZoomAndRotateAction::begin(int shortcut, QEvent *event)
{
d->zoomAction->begin(shortcut, event);
d->rotateAction->begin(shortcut, event);
}
void KisZoomAndRotateAction::cursorMoved(const QPointF &lastPos, const QPointF &pos)
{
d->zoomAction->cursorMoved(lastPos, pos);
d->rotateAction->cursorMoved(lastPos, pos);
}
void KisZoomAndRotateAction::inputEvent(QEvent *event)
{
d->zoomAction->inputEvent(event);
d->rotateAction->inputEvent(event);
}
KisInputActionGroup KisZoomAndRotateAction::inputActionGroup(int shortcut) const
{
Q_UNUSED(shortcut);
return ViewTransformActionGroup;
}
/*
* This file is part of the KDE project
* Copyright (C) 2019 Sharaf Zaman <sharafzaz121@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_ZOOM_AND_ROTATE_ACTION_H
#define KIS_ZOOM_AND_ROTATE_ACTION_H
#include "kis_abstract_input_action.h"
/**
* @brief This class merely deligates the actions to KisZoomAction
* _and_ KisRotateCanvasAction at the same time.
*/
class KisZoomAndRotateAction : public KisAbstractInputAction
{
public:
KisZoomAndRotateAction();
int priority() const override;
void activate(int shortcut) override;
void deactivate(int shortcut) override;
void begin(int shortcut, QEvent *event) override;
void cursorMoved(const QPointF &lastPos, const QPointF &pos) override;
void inputEvent(QEvent* event) override;
KisInputActionGroup inputActionGroup(int shortcut) const override;
private:
class Private;
const Private *d;
};
#endif // KIS_ZOOM_AND_ROTATE_ACTION_H
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