diff --git a/libs/ui/input/kis_abstract_input_action.cpp b/libs/ui/input/kis_abstract_input_action.cpp index 561d327436..030dc4dae4 100644 --- a/libs/ui/input/kis_abstract_input_action.cpp +++ b/libs/ui/input/kis_abstract_input_action.cpp @@ -1,223 +1,232 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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 "kis_abstract_input_action.h" #include #include #include #include class Q_DECL_HIDDEN KisAbstractInputAction::Private { public: QString id; QString name; QString description; QHash indexes; QPointF lastCursorPosition; + QPointF startCursorPosition; static KisInputManager *inputManager; }; KisInputManager *KisAbstractInputAction::Private::inputManager = 0; KisAbstractInputAction::KisAbstractInputAction(const QString &id) : d(new Private) { d->id = id; d->indexes.insert(i18n("Activate"), 0); } KisAbstractInputAction::~KisAbstractInputAction() { delete d; } void KisAbstractInputAction::activate(int shortcut) { Q_UNUSED(shortcut); } void KisAbstractInputAction::deactivate(int shortcut) { Q_UNUSED(shortcut); } void KisAbstractInputAction::begin(int shortcut, QEvent *event) { Q_UNUSED(shortcut); if (event) { d->lastCursorPosition = eventPosF(event); + d->startCursorPosition = d->lastCursorPosition; } } void KisAbstractInputAction::inputEvent(QEvent *event) { if (event) { QPointF newPosition = eventPosF(event); cursorMoved(d->lastCursorPosition, newPosition); + cursorMovedAbsolute(d->startCursorPosition, newPosition); d->lastCursorPosition = newPosition; } } void KisAbstractInputAction::end(QEvent *event) { Q_UNUSED(event); } void KisAbstractInputAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) { Q_UNUSED(lastPos); Q_UNUSED(pos); } +void KisAbstractInputAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) +{ + Q_UNUSED(startPos); + Q_UNUSED(pos); +} + bool KisAbstractInputAction::supportsHiResInputEvents() const { return false; } KisInputActionGroup KisAbstractInputAction::inputActionGroup(int shortcut) const { Q_UNUSED(shortcut); return ModifyingActionGroup; } KisInputManager* KisAbstractInputAction::inputManager() const { return Private::inputManager; } QString KisAbstractInputAction::name() const { return d->name; } QString KisAbstractInputAction::description() const { return d->description; } int KisAbstractInputAction::priority() const { return 0; } bool KisAbstractInputAction::canIgnoreModifiers() const { return false; } QHash< QString, int > KisAbstractInputAction::shortcutIndexes() const { return d->indexes; } QString KisAbstractInputAction::id() const { return d->id; } void KisAbstractInputAction::setName(const QString &name) { d->name = name; } void KisAbstractInputAction::setDescription(const QString &description) { d->description = description; } void KisAbstractInputAction::setShortcutIndexes(const QHash< QString, int > &indexes) { d->indexes = indexes; } void KisAbstractInputAction::setInputManager(KisInputManager *manager) { Private::inputManager = manager; } bool KisAbstractInputAction::isShortcutRequired(int shortcut) const { Q_UNUSED(shortcut); return false; } QPoint KisAbstractInputAction::eventPos(const QEvent *event) { if(!event) { return QPoint(); } switch (event->type()) { case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: return static_cast(event)->pos(); case QEvent::TabletMove: case QEvent::TabletPress: case QEvent::TabletRelease: return static_cast(event)->pos(); case QEvent::Wheel: return static_cast(event)->pos(); case QEvent::NativeGesture: return static_cast(event)->pos(); default: warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); return QPoint(); } } QPointF KisAbstractInputAction::eventPosF(const QEvent *event) { switch (event->type()) { case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: return static_cast(event)->localPos(); case QEvent::TabletMove: case QEvent::TabletPress: case QEvent::TabletRelease: return static_cast(event)->posF(); case QEvent::Wheel: return static_cast(event)->posF(); case QEvent::NativeGesture: return QPointF(static_cast(event)->pos()); default: warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type(); return QPointF(); } } bool KisAbstractInputAction::isAvailable() const { return true; } diff --git a/libs/ui/input/kis_abstract_input_action.h b/libs/ui/input/kis_abstract_input_action.h index 539b77fca1..20699f2864 100644 --- a/libs/ui/input/kis_abstract_input_action.h +++ b/libs/ui/input/kis_abstract_input_action.h @@ -1,230 +1,231 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_ABSTRACT_INPUT_ACTION_H #define KIS_ABSTRACT_INPUT_ACTION_H #include #include #include "kritaui_export.h" #include "KisInputActionGroup.h" class QPointF; class QEvent; class KisInputManager; /** * \brief Abstract base class for input actions. * * Input actions represent actions to be performed when interacting * with the canvas. They are managed by KisInputManager and activated * when KisKeyShortcut or KisStrokeShortcut detects it matches a certain * set of inputs. * * The begin() method uses an index for the type of behaviour to activate. * This index can be used to trigger behaviour when different events occur. * * The events can be of two types: * 1) Key events. The input manager calls begin() and end() sequentially * with an \p index parameter to begin() representing the type of * action that should be performed. The \p event parameter of both * calls in null. * 2) Stroke events. The input manager calls begin() and end() on the * corresponding mouse down and up events. The \p event parameter * will be of QMouseEvent type, representing the event happened. * All the mouse move events between begin() and end() will be * redirected to the inputEvent() method. */ class KRITAUI_EXPORT KisAbstractInputAction { public: /** * Constructor. * * \param manager The InputManager this action belongs to. */ explicit KisAbstractInputAction(const QString &id); /** * Destructor. */ virtual ~KisAbstractInputAction(); /** * The method is called when the action is yet to be started, * that is, e.g. the user has pressed all the modifiers for the * action but hasn't started painting yet. This method is a right * place to show the user what is going to happen, e.g. change the * cursor. */ virtual void activate(int shortcut); /** * The method is called when the action is not a candidate for * the starting anymore. The action should revert everything that * was done in activate() method. * * \see activate() */ virtual void deactivate(int shortcut); /** * Begin the action. * * \param shortcut The index of the behaviour to trigger. * \param event The mouse event that has triggered this action. * Is null for keyboard-activated actions. */ virtual void begin(int shortcut, QEvent *event); /** * End the action. * \param event The mouse event that has finished this action. * Is null for keyboard-activated actions. */ virtual void end(QEvent *event); /** * Process an input event. * * By default handles MouseMove events and passes the data to * a convenience cursorMoved() method * * \param event An event to process. */ virtual void inputEvent(QEvent* event); /** * Returns true if the action can handle HiRes flow of move events * which is generated by the tablet. If the function returns * false, some of the events will be dropped or postponed. For * most of the actions in Krita (except of real painting) it is * perfectly acceptable, so 'false' is the default value. */ virtual bool supportsHiResInputEvents() const; /** * \return the group of the action the specified \p shortcut belongs to */ virtual KisInputActionGroup inputActionGroup(int shortcut) const; /** * The indexes of shortcut behaviours available. */ virtual QHash shortcutIndexes() const; /** * The id of this action. */ virtual QString id() const; /** * The translated name of this action. */ virtual QString name() const; /** * A short description of this action. */ virtual QString description() const; /** * The priority for this action. * * Priority determines how "important" the action is and is used * to resolve conflicts when multiple actions can be activated. */ virtual int priority() const; /** * Returns true if an action can run with any modifiers pressed * (the shortcut's modifiers list must be empty for that). That is * used for making one type of actions default one. */ virtual bool canIgnoreModifiers() const; /** * Return true when the specified shortcut is required for basic * user interaction. This is used by the configuration system to * prevent basic actions like painting from being removed. * * \param shortcut The shortcut index to check. * \return True if the shortcut is required, false if not. */ virtual bool isShortcutRequired(int shortcut) const; /** * Some of the actions are available in particular situations * only. E.g. switch frame action is available iff a animated * layer is selected. If isAvailable() returns true then the * action will *not* be triggered by the shortcut matcher. */ virtual bool isAvailable() const; protected: /** * The input manager this action belongs to. */ KisInputManager *inputManager() const; /** * Set the name of this action. * * \param name The new name. */ void setName(const QString &name); /** * Set the description of this action. * * \param description The new description. */ void setDescription(const QString &description); /** * Set the available indexes of shortcut behaviours. * * \param indexes The new indexes. */ void setShortcutIndexes(const QHash &indexes); /** * Convenience method for handling cursor movement for tablet, mouse and touch. * The default implementation of inputEvent calls this function. */ virtual void cursorMoved(const QPointF &lastPos, const QPointF &pos); + virtual void cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos); /** * Convenience method to extract the position from a cursor movement event. * * \param event A mouse or tablet event. */ QPoint eventPos(const QEvent *event); /** * Convenience method to extract the floating point position from a * cursor movement event. * * \param event A mouse or tablet event. */ QPointF eventPosF(const QEvent *event); private: friend class KisInputManager; static void setInputManager(KisInputManager *manager); class Private; Private * const d; }; #endif // KIS_ABSTRACT_INPUT_ACTION_H diff --git a/libs/ui/input/kis_gamma_exposure_action.cpp b/libs/ui/input/kis_gamma_exposure_action.cpp index fd6e0bad0b..d14f333bdf 100644 --- a/libs/ui/input/kis_gamma_exposure_action.cpp +++ b/libs/ui/input/kis_gamma_exposure_action.cpp @@ -1,199 +1,199 @@ /* * Copyright (c) 2014 Dmitry Kazakov * * 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 "kis_gamma_exposure_action.h" #include #include #include #include #include "kis_cursor.h" #include "KisViewManager.h" #include "kis_input_manager.h" #include "krita_utils.h" #include "kis_exposure_gamma_correction_interface.h" class KisGammaExposureAction::Private { public: Private(KisGammaExposureAction *qq) : q(qq), baseExposure(0.0), baseGamma(0.0) {} KisGammaExposureAction *q; Shortcuts mode; qreal baseExposure; qreal baseGamma; void addExposure(qreal diff); void addGamma(qreal diff); }; void KisGammaExposureAction::Private::addExposure(qreal diff) { KisExposureGammaCorrectionInterface *interface = q->inputManager()->canvas()->exposureGammaCorrectionInterface(); if (!interface->canChangeExposureAndGamma()) return; interface->setCurrentExposure(interface->currentExposure() + diff); } void KisGammaExposureAction::Private::addGamma(qreal diff) { KisExposureGammaCorrectionInterface *interface = q->inputManager()->canvas()->exposureGammaCorrectionInterface(); if (!interface->canChangeExposureAndGamma()) return; interface->setCurrentGamma(interface->currentGamma() + diff); } KisGammaExposureAction::KisGammaExposureAction() : KisAbstractInputAction("Exposure or Gamma") , d(new Private(this)) { setName(i18n("Exposure and Gamma")); setDescription(i18n("The Exposure and Gamma action changes the display mode of the canvas.")); QHash< QString, int > shortcuts; shortcuts.insert(i18n("Exposure Mode"), ExposureShortcut); shortcuts.insert(i18n("Gamma Mode"), GammaShortcut); shortcuts.insert(i18n("Exposure +0.5"), AddExposure05Shortcut); shortcuts.insert(i18n("Exposure -0.5"), RemoveExposure05Shortcut); shortcuts.insert(i18n("Gamma +0.5"), AddGamma05Shortcut); shortcuts.insert(i18n("Gamma -0.5"), RemoveGamma05Shortcut); shortcuts.insert(i18n("Exposure +0.2"), AddExposure02Shortcut); shortcuts.insert(i18n("Exposure -0.2"), RemoveExposure02Shortcut); shortcuts.insert(i18n("Gamma +0.2"), AddGamma02Shortcut); shortcuts.insert(i18n("Gamma -0.2"), RemoveGamma02Shortcut); shortcuts.insert(i18n("Reset Exposure and Gamma"), ResetExposureAndGammaShortcut); setShortcutIndexes(shortcuts); } KisGammaExposureAction::~KisGammaExposureAction() { delete d; } int KisGammaExposureAction::priority() const { return 5; } void KisGammaExposureAction::activate(int shortcut) { if (shortcut == ExposureShortcut) { QApplication::setOverrideCursor(KisCursor::changeExposureCursor()); } else /* if (shortcut == GammaShortcut) */ { QApplication::setOverrideCursor(KisCursor::changeGammaCursor()); } } void KisGammaExposureAction::deactivate(int shortcut) { Q_UNUSED(shortcut); QApplication::restoreOverrideCursor(); } void KisGammaExposureAction::begin(int shortcut, QEvent *event) { KisAbstractInputAction::begin(shortcut, event); KisExposureGammaCorrectionInterface *interface = inputManager()->canvas()->exposureGammaCorrectionInterface(); switch(shortcut) { case ExposureShortcut: d->baseExposure = interface->currentExposure(); d->mode = (Shortcuts)shortcut; break; case GammaShortcut: d->baseGamma = interface->currentGamma(); d->mode = (Shortcuts)shortcut; break; case AddExposure05Shortcut: d->addExposure(0.5); break; case RemoveExposure05Shortcut: d->addExposure(-0.5); break; case AddGamma05Shortcut: d->addGamma(0.5); break; case RemoveGamma05Shortcut: d->addGamma(-0.5); break; case AddExposure02Shortcut: d->addExposure(0.2); break; case RemoveExposure02Shortcut: d->addExposure(-0.2); break; case AddGamma02Shortcut: d->addGamma(0.2); break; case RemoveGamma02Shortcut: d->addGamma(-0.2); break; case ResetExposureAndGammaShortcut: { KisExposureGammaCorrectionInterface *interface = inputManager()->canvas()->exposureGammaCorrectionInterface(); if (!interface->canChangeExposureAndGamma()) break; interface->setCurrentGamma(1.0); interface->setCurrentExposure(0.0); break; } } } -void KisGammaExposureAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) +void KisGammaExposureAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { - QPointF diff = -(pos - lastPos); + QPointF diff = -(pos - startPos); const int step = 200; KisExposureGammaCorrectionInterface *interface = inputManager()->canvas()->exposureGammaCorrectionInterface(); if (!interface->canChangeExposureAndGamma()) return; if (d->mode == ExposureShortcut) { - d->baseExposure += qreal(diff.y()) / step; - interface->setCurrentExposure(d->baseExposure); + const qreal currentExposure = d->baseExposure + qreal(diff.y()) / step; + interface->setCurrentExposure(currentExposure); } else if (d->mode == GammaShortcut) { - d->baseGamma += qreal(diff.y()) / step; - interface->setCurrentGamma(d->baseGamma); + const qreal currentGamma = d->baseExposure + qreal(diff.y()) / step; + interface->setCurrentGamma(currentGamma); } } bool KisGammaExposureAction::isShortcutRequired(int shortcut) const { Q_UNUSED(shortcut); return false; } diff --git a/libs/ui/input/kis_gamma_exposure_action.h b/libs/ui/input/kis_gamma_exposure_action.h index 3aa46f1c15..38c15b2f2e 100644 --- a/libs/ui/input/kis_gamma_exposure_action.h +++ b/libs/ui/input/kis_gamma_exposure_action.h @@ -1,62 +1,62 @@ /* * Copyright (c) 2014 Dmitry Kazakov * * 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_GAMMA_EXPOSURE_ACTION_H #define __KIS_GAMMA_EXPOSURE_ACTION_H #include "kis_abstract_input_action.h" class KisGammaExposureAction : public KisAbstractInputAction { public: /** * The different behaviours for this action. */ enum Shortcuts { ExposureShortcut, GammaShortcut, AddExposure05Shortcut, RemoveExposure05Shortcut, AddGamma05Shortcut, RemoveGamma05Shortcut, AddExposure02Shortcut, RemoveExposure02Shortcut, AddGamma02Shortcut, RemoveGamma02Shortcut, ResetExposureAndGammaShortcut }; explicit KisGammaExposureAction(); ~KisGammaExposureAction() override; int priority() const override; void activate(int shortcut) override; void deactivate(int shortcut) override; void begin(int shortcut, QEvent *event = 0) override; - void cursorMoved(const QPointF &lastPos, const QPointF &pos) override; + void cursorMovedAbsolute(const QPointF &lastPos, const QPointF &pos) override; bool isShortcutRequired(int shortcut) const override; private: class Private; Private * const d; }; #endif /* __KIS_GAMMA_EXPOSURE_ACTION_H */ diff --git a/libs/ui/input/kis_pan_action.cpp b/libs/ui/input/kis_pan_action.cpp index 325c2c4fd6..18eec430ff 100644 --- a/libs/ui/input/kis_pan_action.cpp +++ b/libs/ui/input/kis_pan_action.cpp @@ -1,203 +1,205 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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 "kis_pan_action.h" #include #include #include #include #include #include #include #include "kis_input_manager.h" class KisPanAction::Private { public: Private() : panDistance(10) { } QPointF averagePoint( QTouchEvent* event ); const int panDistance; QPointF lastPosition; + QPointF originalPreferredCenter; }; KisPanAction::KisPanAction() : KisAbstractInputAction("Pan Canvas") , d(new Private) { setName(i18n("Pan Canvas")); setDescription(i18n("The Pan Canvas action pans the canvas.")); QHash shortcuts; shortcuts.insert(i18n("Pan Mode"), PanModeShortcut); shortcuts.insert(i18n("Pan Left"), PanLeftShortcut); shortcuts.insert(i18n("Pan Right"), PanRightShortcut); shortcuts.insert(i18n("Pan Up"), PanUpShortcut); shortcuts.insert(i18n("Pan Down"), PanDownShortcut); setShortcutIndexes(shortcuts); } KisPanAction::~KisPanAction() { delete d; } int KisPanAction::priority() const { return 5; } void KisPanAction::activate(int shortcut) { Q_UNUSED(shortcut); QApplication::setOverrideCursor(Qt::OpenHandCursor); } void KisPanAction::deactivate(int shortcut) { Q_UNUSED(shortcut); QApplication::restoreOverrideCursor(); } void KisPanAction::begin(int shortcut, QEvent *event) { KisAbstractInputAction::begin(shortcut, event); bool overrideCursor = true; switch (shortcut) { case PanModeShortcut: { QTouchEvent *tevent = dynamic_cast(event); if (tevent) { d->lastPosition = d->averagePoint(tevent); break; } // Some QT wheel events are actually be touch pad pan events. From the QT docs: // "Wheel events are generated for both mouse wheels and trackpad scroll gestures." QWheelEvent *wheelEvent = dynamic_cast(event); if (wheelEvent) { inputManager()->canvas()->canvasController()->pan(-wheelEvent->pixelDelta()); overrideCursor = false; break; } + d->originalPreferredCenter = inputManager()->canvas()->canvasController()->preferredCenter(); + break; } case PanLeftShortcut: inputManager()->canvas()->canvasController()->pan(QPoint(d->panDistance, 0)); break; case PanRightShortcut: inputManager()->canvas()->canvasController()->pan(QPoint(-d->panDistance, 0)); break; case PanUpShortcut: inputManager()->canvas()->canvasController()->pan(QPoint(0, d->panDistance)); break; case PanDownShortcut: inputManager()->canvas()->canvasController()->pan(QPoint(0, -d->panDistance)); break; } if (overrideCursor) { QApplication::setOverrideCursor(Qt::ClosedHandCursor); } } void KisPanAction::end(QEvent *event) { QApplication::restoreOverrideCursor(); KisAbstractInputAction::end(event); } void KisPanAction::inputEvent(QEvent *event) { switch (event->type()) { case QEvent::Gesture: { QGestureEvent *gevent = static_cast(event); if (gevent->activeGestures().at(0)->gestureType() == Qt::PanGesture) { QPanGesture *pan = static_cast(gevent->activeGestures().at(0)); inputManager()->canvas()->canvasController()->pan(-pan->delta().toPoint() * 0.2); } return; } case QEvent::TouchUpdate: { QTouchEvent *tevent = static_cast(event); QPointF newPos = d->averagePoint(tevent); QPointF delta = newPos - d->lastPosition; // If this is enormously large, then we are likely in the process of ending the gesture, // with fingers being lifted one by one from the perspective of our very speedy operations, // and as such, ignore those big jumps. if(delta.manhattanLength() < 50) { inputManager()->canvas()->canvasController()->pan(-delta.toPoint()); d->lastPosition = newPos; } return; } default: break; } KisAbstractInputAction::inputEvent(event); } -void KisPanAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) +void KisPanAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { - QPointF relMovement = -(pos - lastPos); - inputManager()->canvas()->canvasController()->pan(relMovement.toPoint()); + inputManager()->canvas()->canvasController()->setPreferredCenter(-pos + startPos + d->originalPreferredCenter); } QPointF KisPanAction::Private::averagePoint( QTouchEvent* event ) { QPointF result; int count = 0; Q_FOREACH ( QTouchEvent::TouchPoint point, event->touchPoints() ) { if( point.state() != Qt::TouchPointReleased ) { result += point.screenPos(); count++; } } if( count > 0 ) { return result / count; } else { return QPointF(); } } bool KisPanAction::isShortcutRequired(int shortcut) const { return shortcut == PanModeShortcut; } KisInputActionGroup KisPanAction::inputActionGroup(int shortcut) const { Q_UNUSED(shortcut); return ViewTransformActionGroup; } bool KisPanAction::supportsHiResInputEvents() const { return true; } diff --git a/libs/ui/input/kis_pan_action.h b/libs/ui/input/kis_pan_action.h index af3f4aacd8..20d251167b 100644 --- a/libs/ui/input/kis_pan_action.h +++ b/libs/ui/input/kis_pan_action.h @@ -1,67 +1,67 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_PAN_ACTION_H #define KIS_PAN_ACTION_H #include "kis_abstract_input_action.h" /** * \brief Pan Canvas implementation of KisAbstractInputAction. * * The Pan Canvas action pans the canvas. */ class KisPanAction : public KisAbstractInputAction { public: /** * The different behaviours for this action. */ enum Shortcut { PanModeShortcut, ///< Toggle the pan mode. PanLeftShortcut, ///< Pan left by a fixed amount. PanRightShortcut, ///< Pan right by a fixed amount. PanUpShortcut, ///< Pan up by a fixed amount. PanDownShortcut ///< Pan down by a fixed amount. }; explicit KisPanAction(); ~KisPanAction() override; int priority() const override; void activate(int shortcut) override; void deactivate(int shortcut) override; void begin(int shortcut, QEvent *event) override; void end(QEvent *event) override; void inputEvent(QEvent* event) override; - void cursorMoved(const QPointF &lastPos, const QPointF &pos) override; + void cursorMovedAbsolute(const QPointF &lastPos, const QPointF &pos) override; bool isShortcutRequired(int shortcut) const override; KisInputActionGroup inputActionGroup(int shortcut) const override; bool supportsHiResInputEvents() const; private: class Private; Private * const d; }; #endif // KIS_PAN_ACTION_H diff --git a/libs/ui/input/kis_rotate_canvas_action.cpp b/libs/ui/input/kis_rotate_canvas_action.cpp index 57075b91eb..0f4c29fc8a 100644 --- a/libs/ui/input/kis_rotate_canvas_action.cpp +++ b/libs/ui/input/kis_rotate_canvas_action.cpp @@ -1,194 +1,192 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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 "kis_rotate_canvas_action.h" #include #include #include #include "kis_cursor.h" #include "kis_canvas_controller.h" #include #include "kis_input_manager.h" #include class KisRotateCanvasAction::Private { public: - Private() : angleDrift(0), previousAngle(0) {} + Private() : previousAngle(0) {} Shortcut mode; - qreal angleDrift; qreal previousAngle; + qreal startRotation; + qreal previousRotation; }; KisRotateCanvasAction::KisRotateCanvasAction() : KisAbstractInputAction("Rotate Canvas") , d(new Private()) { setName(i18n("Rotate Canvas")); setDescription(i18n("The Rotate Canvas action rotates the canvas.")); QHash shortcuts; shortcuts.insert(i18n("Rotate Mode"), RotateModeShortcut); shortcuts.insert(i18n("Discrete Rotate Mode"), DiscreteRotateModeShortcut); shortcuts.insert(i18n("Rotate Left"), RotateLeftShortcut); shortcuts.insert(i18n("Rotate Right"), RotateRightShortcut); shortcuts.insert(i18n("Reset Rotation"), RotateResetShortcut); setShortcutIndexes(shortcuts); } KisRotateCanvasAction::~KisRotateCanvasAction() { delete d; } int KisRotateCanvasAction::priority() const { return 3; } void KisRotateCanvasAction::activate(int shortcut) { if (shortcut == DiscreteRotateModeShortcut) { QApplication::setOverrideCursor(KisCursor::rotateCanvasDiscreteCursor()); } else /* if (shortcut == SmoothRotateModeShortcut) */ { QApplication::setOverrideCursor(KisCursor::rotateCanvasSmoothCursor()); } } void KisRotateCanvasAction::deactivate(int shortcut) { Q_UNUSED(shortcut); QApplication::restoreOverrideCursor(); } void KisRotateCanvasAction::begin(int shortcut, QEvent *event) { KisAbstractInputAction::begin(shortcut, event); d->previousAngle = 0; KisCanvasController *canvasController = dynamic_cast(inputManager()->canvas()->canvasController()); switch(shortcut) { case RotateModeShortcut: - d->mode = (Shortcut)shortcut; - break; case DiscreteRotateModeShortcut: d->mode = (Shortcut)shortcut; - d->angleDrift = 0; + d->startRotation = inputManager()->canvas()->rotationAngle(); + d->previousRotation = 0; break; case RotateLeftShortcut: canvasController->rotateCanvasLeft15(); break; case RotateRightShortcut: canvasController->rotateCanvasRight15(); break; case RotateResetShortcut: canvasController->resetCanvasRotation(); break; } } -void KisRotateCanvasAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) +void KisRotateCanvasAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { const KisCoordinatesConverter *converter = inputManager()->canvas()->coordinatesConverter(); - QPointF centerPoint = converter->flakeToWidget(converter->flakeCenterPoint()); - QPointF oldPoint = lastPos - centerPoint; - QPointF newPoint = pos - centerPoint; + const QPointF centerPoint = converter->flakeToWidget(converter->flakeCenterPoint()); + const QPointF startPoint = startPos - centerPoint; + const QPointF newPoint = pos - centerPoint; - qreal oldAngle = atan2(oldPoint.y(), oldPoint.x()); - qreal newAngle = atan2(newPoint.y(), newPoint.x()); + const qreal oldAngle = atan2(startPoint.y(), startPoint.x()); + const qreal newAngle = atan2(newPoint.y(), newPoint.x()); - qreal angle = (180 / M_PI) * (newAngle - oldAngle); + qreal newRotation = (180 / M_PI) * (newAngle - oldAngle); if (d->mode == DiscreteRotateModeShortcut) { const qreal angleStep = 15; - qreal initialAngle = inputManager()->canvas()->rotationAngle(); - qreal roundedAngle = qRound((initialAngle + angle + d->angleDrift) / angleStep) * angleStep - initialAngle; - d->angleDrift += angle - roundedAngle; - angle = roundedAngle; + newRotation = qRound(newRotation / angleStep) * angleStep; } KisCanvasController *canvasController = dynamic_cast(inputManager()->canvas()->canvasController()); - canvasController->rotateCanvas(angle); + canvasController->rotateCanvas(newRotation - d->previousRotation); + d->previousRotation = newRotation; } void KisRotateCanvasAction::inputEvent(QEvent* event) { switch (event->type()) { case QEvent::NativeGesture: { QNativeGestureEvent *gevent = static_cast(event); KisCanvas2 *canvas = inputManager()->canvas(); KisCanvasController *controller = static_cast(canvas->canvasController()); const float angle = gevent->value(); QPoint widgetPos = canvas->canvasWidget()->mapFromGlobal(gevent->globalPos()); controller->rotateCanvas(angle, widgetPos); return; } case QEvent::TouchUpdate: { QTouchEvent *touchEvent = static_cast(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); KisCanvas2 *canvas = inputManager()->canvas(); KisCanvasController *controller = static_cast(canvas->canvasController()); controller->rotateCanvas(delta); d->previousAngle = newAngle; return; } default: break; } KisAbstractInputAction::inputEvent(event); } KisInputActionGroup KisRotateCanvasAction::inputActionGroup(int shortcut) const { Q_UNUSED(shortcut); return ViewTransformActionGroup; } bool KisRotateCanvasAction::supportsHiResInputEvents() const { return true; } diff --git a/libs/ui/input/kis_rotate_canvas_action.h b/libs/ui/input/kis_rotate_canvas_action.h index 20935d901a..d3e949b17b 100644 --- a/libs/ui/input/kis_rotate_canvas_action.h +++ b/libs/ui/input/kis_rotate_canvas_action.h @@ -1,63 +1,63 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_ROTATE_CANVAS_ACTION_H #define KIS_ROTATE_CANVAS_ACTION_H #include "kis_abstract_input_action.h" /** * \brief Rotate Canvas implementation of KisAbstractInputAction. * * The Rotate Canvas action rotates the canvas. */ class KisRotateCanvasAction : public KisAbstractInputAction { public: /** * The different behaviours for this action. */ enum Shortcut { RotateModeShortcut, ///< Toggle Rotate mode. DiscreteRotateModeShortcut, ///< Toggle Discrete Rotate mode. RotateLeftShortcut, ///< Rotate left by a fixed amount. RotateRightShortcut, ///< Rotate right by a fixed amount. RotateResetShortcut ///< Reset the rotation to 0. }; explicit KisRotateCanvasAction(); ~KisRotateCanvasAction() override; 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 cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos); void inputEvent(QEvent* event) override; KisInputActionGroup inputActionGroup(int shortcut) const override; bool supportsHiResInputEvents() const; private: class Private; Private * const d; }; #endif // KIS_ROTATE_CANVAS_ACTION_H diff --git a/libs/ui/input/kis_zoom_action.cpp b/libs/ui/input/kis_zoom_action.cpp index 917140f6a8..a35fb1cc02 100644 --- a/libs/ui/input/kis_zoom_action.cpp +++ b/libs/ui/input/kis_zoom_action.cpp @@ -1,315 +1,321 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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 "kis_zoom_action.h" #include #include #include #include #include #include #include #include "kis_cursor.h" #include "KisViewManager.h" #include "kis_input_manager.h" #include "kis_config.h" inline QPoint pointFromEvent(QEvent *event) { if (!event) { return QPoint(); } else if (QMouseEvent *mouseEvent = dynamic_cast(event)) { return mouseEvent->pos(); } else if (QTabletEvent *tabletEvent = dynamic_cast(event)) { return tabletEvent->pos(); } else if (QWheelEvent *wheelEvent = dynamic_cast(event)) { return wheelEvent->pos(); } return QPoint(); } class KisZoomAction::Private { public: - Private(KisZoomAction *qq) : q(qq), distance(0), lastDistance(0.f) {} + Private(KisZoomAction *qq) : q(qq), lastDistance(0.f) {} QPointF centerPoint(QTouchEvent* event); KisZoomAction *q; - int distance; Shortcuts mode; QPointF lastPosition; float lastDistance; - QPoint startPoint; + qreal startZoom = 1.0; + qreal lastDescreteZoomDistance = 0.0; void zoomTo(bool zoomIn, const QPoint &pos); }; QPointF KisZoomAction::Private::centerPoint(QTouchEvent* event) { QPointF result; int count = 0; Q_FOREACH (QTouchEvent::TouchPoint point, event->touchPoints()) { if (point.state() != Qt::TouchPointReleased) { result += point.pos(); count++; } } if (count > 0) { return result / count; } else { return QPointF(); } } void KisZoomAction::Private::zoomTo(bool zoomIn, const QPoint &point) { KoZoomAction *zoomAction = q->inputManager()->canvas()->viewManager()->zoomController()->zoomAction(); if (!point.isNull()) { float oldZoom = zoomAction->effectiveZoom(); float newZoom = zoomIn ? zoomAction->nextZoomLevel() : zoomAction->prevZoomLevel(); KoCanvasControllerWidget *controller = dynamic_cast( q->inputManager()->canvas()->canvasController()); controller->zoomRelativeToPoint(point, newZoom / oldZoom); } else { if (zoomIn) { zoomAction->zoomIn(); } else { zoomAction->zoomOut(); } } } KisZoomAction::KisZoomAction() : KisAbstractInputAction("Zoom Canvas") , d(new Private(this)) { setName(i18n("Zoom Canvas")); setDescription(i18n("The Zoom Canvas action zooms the canvas.")); QHash< QString, int > shortcuts; shortcuts.insert(i18n("Zoom Mode"), ZoomModeShortcut); shortcuts.insert(i18n("Discrete Zoom Mode"), DiscreteZoomModeShortcut); shortcuts.insert(i18n("Relative Zoom Mode"), RelativeZoomModeShortcut); shortcuts.insert(i18n("Relative Discrete Zoom Mode"), RelativeDiscreteZoomModeShortcut); shortcuts.insert(i18n("Zoom In"), ZoomInShortcut); shortcuts.insert(i18n("Zoom Out"), ZoomOutShortcut); shortcuts.insert(i18n("Reset Zoom to 100%"), ZoomResetShortcut); shortcuts.insert(i18n("Fit to Page"), ZoomToPageShortcut); shortcuts.insert(i18n("Fit to Width"), ZoomToWidthShortcut); setShortcutIndexes(shortcuts); } KisZoomAction::~KisZoomAction() { delete d; } int KisZoomAction::priority() const { return 4; } void KisZoomAction::activate(int shortcut) { if (shortcut == DiscreteZoomModeShortcut || shortcut == RelativeDiscreteZoomModeShortcut) { QApplication::setOverrideCursor(KisCursor::zoomDiscreteCursor()); } else /* if (shortcut == SmoothZoomModeShortcut) */ { QApplication::setOverrideCursor(KisCursor::zoomSmoothCursor()); } } void KisZoomAction::deactivate(int shortcut) { Q_UNUSED(shortcut); QApplication::restoreOverrideCursor(); } void KisZoomAction::begin(int shortcut, QEvent *event) { KisAbstractInputAction::begin(shortcut, event); d->lastDistance = 0.f; switch(shortcut) { case ZoomModeShortcut: case RelativeZoomModeShortcut: { - d->startPoint = pointFromEvent(event); + d->startZoom = inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); d->mode = (Shortcuts)shortcut; QTouchEvent *tevent = dynamic_cast(event); if(tevent) d->lastPosition = d->centerPoint(tevent); break; } case DiscreteZoomModeShortcut: case RelativeDiscreteZoomModeShortcut: - d->startPoint = pointFromEvent(event); + d->startZoom = inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); + d->lastDescreteZoomDistance = 0; d->mode = (Shortcuts)shortcut; - d->distance = 0; break; case ZoomInShortcut: d->zoomTo(true, pointFromEvent(event)); break; case ZoomOutShortcut: d->zoomTo(false, pointFromEvent(event)); break; case ZoomResetShortcut: inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0); break; case ZoomToPageShortcut: inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_PAGE, 1.0); break; case ZoomToWidthShortcut: inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_WIDTH, 1.0); break; } } void KisZoomAction::inputEvent( QEvent* event ) { switch (event->type()) { case QEvent::TouchUpdate: { QTouchEvent *tevent = static_cast(event); QPointF center = d->centerPoint(tevent); int count = 0; float dist = 0.0f; Q_FOREACH (const QTouchEvent::TouchPoint &point, tevent->touchPoints()) { if (point.state() != Qt::TouchPointReleased) { count++; dist += (point.pos() - center).manhattanLength(); } } dist /= count; float delta = qFuzzyCompare(1.0f, 1.0f + d->lastDistance) ? 1.f : dist / d->lastDistance; if(qAbs(delta) > 0.1f) { qreal zoom = inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); Q_UNUSED(zoom); static_cast(inputManager()->canvas()->canvasController())->zoomRelativeToPoint(center.toPoint(), delta); d->lastDistance = dist; // Also do panning here, as doing it later requires a further check for validity QPointF moveDelta = center - d->lastPosition; inputManager()->canvas()->canvasController()->pan(-moveDelta.toPoint()); d->lastPosition = center; } return; // Don't try to update the cursor during a pinch-zoom } case QEvent::NativeGesture: { QNativeGestureEvent *gevent = static_cast(event); if (gevent->gestureType() == Qt::ZoomNativeGesture) { KisCanvas2 *canvas = inputManager()->canvas(); KisCanvasController *controller = static_cast(canvas->canvasController()); const float delta = 1.0f + gevent->value(); controller->zoomRelativeToPoint(canvas->canvasWidget()->mapFromGlobal(gevent->globalPos()), delta); } else if (gevent->gestureType() == Qt::SmartZoomNativeGesture) { KisCanvas2 *canvas = inputManager()->canvas(); KoZoomController *controller = canvas->viewManager()->zoomController(); if (controller->zoomMode() != KoZoomMode::ZOOM_WIDTH) { controller->setZoom(KoZoomMode::ZOOM_WIDTH, 1.0); } else { controller->setZoom(KoZoomMode::ZOOM_CONSTANT, 1.0); } } return; } default: break; } KisAbstractInputAction::inputEvent(event); } -void KisZoomAction::cursorMoved(const QPointF &lastPos, const QPointF &pos) +void KisZoomAction::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { - QPointF diff = -(pos - lastPos); + QPointF diff = -(pos - startPos); const int stepCont = 100; - const int stepDisc = 20; + const int stepDisc = 50; if (d->mode == ZoomModeShortcut || d->mode == RelativeZoomModeShortcut) { + + const qreal zoom = inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); + const qreal logDistance = std::pow(2.0, qreal(diff.y()) / qreal(stepCont)); + KisConfig cfg(true); - float coeff; + qreal newZoom = zoom; if (cfg.readEntry("InvertMiddleClickZoom", false)) { - coeff = 1.0 - qreal(diff.y()) / stepCont; - } - else { - coeff = 1.0 + qreal(diff.y()) / stepCont; + newZoom = d->startZoom / logDistance; + } else { + newZoom = d->startZoom * logDistance; } if (d->mode == ZoomModeShortcut) { - float zoom = coeff * inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); - inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, zoom); + inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom); } else { + const qreal coeff = newZoom / zoom; + KoCanvasControllerWidget *controller = dynamic_cast( inputManager()->canvas()->canvasController()); - controller->zoomRelativeToPoint(d->startPoint, coeff); + controller->zoomRelativeToPoint(startPos.toPoint(), coeff); } } else if (d->mode == DiscreteZoomModeShortcut || d->mode == RelativeDiscreteZoomModeShortcut) { - d->distance += diff.y(); QPoint stillPoint = d->mode == RelativeDiscreteZoomModeShortcut ? - d->startPoint : QPoint(); + startPos.toPoint() : QPoint(); + + qreal currentDiff = qreal(diff.y()) / stepDisc - d->lastDescreteZoomDistance; - bool zoomIn = d->distance > 0; - while (qAbs(d->distance) > stepDisc) { + bool zoomIn = currentDiff > 0; + while (qAbs(currentDiff) > 1.0) { d->zoomTo(zoomIn, stillPoint); - d->distance += zoomIn ? -stepDisc : stepDisc; + d->lastDescreteZoomDistance += zoomIn ? 1.0 : -1.0; + currentDiff = qreal(diff.y()) / stepDisc - d->lastDescreteZoomDistance; } } } bool KisZoomAction::isShortcutRequired(int shortcut) const { return shortcut == ZoomModeShortcut; } bool KisZoomAction::supportsHiResInputEvents() const { return true; } KisInputActionGroup KisZoomAction::inputActionGroup(int shortcut) const { Q_UNUSED(shortcut); return ViewTransformActionGroup; } diff --git a/libs/ui/input/kis_zoom_action.h b/libs/ui/input/kis_zoom_action.h index e1a6294dcd..78de9831bb 100644 --- a/libs/ui/input/kis_zoom_action.h +++ b/libs/ui/input/kis_zoom_action.h @@ -1,68 +1,68 @@ /* This file is part of the KDE project * Copyright (C) 2012 Arjen Hiemstra * * 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_ACTION_H #define KIS_ZOOM_ACTION_H #include "kis_abstract_input_action.h" /** * \brief Zoom Canvas implementation of KisAbstractInputAction. * * The Zoom Canvas action zooms the canvas. */ class KisZoomAction : public KisAbstractInputAction { public: /** * The different behaviours for this action. */ enum Shortcuts { ZoomModeShortcut, ///< Toggle zoom mode. DiscreteZoomModeShortcut, ///< Toggle discrete zoom mode ZoomInShortcut, ///< Zoom in by a fixed amount. ZoomOutShortcut, ///< Zoom out by a fixed amount. ZoomResetShortcut, ///< Reset zoom to 100%. ZoomToPageShortcut, ///< Zoom fit to page. ZoomToWidthShortcut, ///< Zoom fit to width. RelativeZoomModeShortcut, ///< Toggle zoom mode relative to cursor RelativeDiscreteZoomModeShortcut ///< Toggle discrete zoom mode relative to cursor }; explicit KisZoomAction(); ~KisZoomAction() override; int priority() const override; void activate(int shortcut) override; void deactivate(int shortcut) override; void begin(int shortcut, QEvent *event = 0) override; void inputEvent(QEvent* event) override; - void cursorMoved(const QPointF &lastPos, const QPointF &pos) override; + void cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) override; bool isShortcutRequired(int shortcut) const override; bool supportsHiResInputEvents() const override; KisInputActionGroup inputActionGroup(int shortcut) const override; private: class Private; Private * const d; }; #endif // KIS_ZOOM_ACTION_H diff --git a/libs/ui/input/kis_zoom_and_rotate_action.cpp b/libs/ui/input/kis_zoom_and_rotate_action.cpp index 2185f5f900..c7f0be315a 100644 --- a/libs/ui/input/kis_zoom_and_rotate_action.cpp +++ b/libs/ui/input/kis_zoom_and_rotate_action.cpp @@ -1,79 +1,79 @@ /* * This file is part of the KDE project * Copyright (C) 2019 Sharaf Zaman * * 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 #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) +void KisZoomAndRotateAction::cursorMovedAbsolute(const QPointF &lastPos, const QPointF &pos) { - d->zoomAction->cursorMoved(lastPos, pos); - d->rotateAction->cursorMoved(lastPos, pos); + d->zoomAction->cursorMovedAbsolute(lastPos, pos); + d->rotateAction->cursorMovedAbsolute(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; } diff --git a/libs/ui/input/kis_zoom_and_rotate_action.h b/libs/ui/input/kis_zoom_and_rotate_action.h index 597834c351..73da68bf9e 100644 --- a/libs/ui/input/kis_zoom_and_rotate_action.h +++ b/libs/ui/input/kis_zoom_and_rotate_action.h @@ -1,48 +1,48 @@ /* * This file is part of the KDE project * Copyright (C) 2019 Sharaf Zaman * * 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 cursorMovedAbsolute(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