diff --git a/libs/ui/input/kis_pan_action.cpp b/libs/ui/input/kis_pan_action.cpp index c748dfcc91..18eec430ff 100644 --- a/libs/ui/input/kis_pan_action.cpp +++ b/libs/ui/input/kis_pan_action.cpp @@ -1,200 +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::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { 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 ee034719c6..20d251167b 100644 --- a/libs/ui/input/kis_pan_action.h +++ b/libs/ui/input/kis_pan_action.h @@ -1,66 +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 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 7279faad54..0f4c29fc8a 100644 --- a/libs/ui/input/kis_rotate_canvas_action.cpp +++ b/libs/ui/input/kis_rotate_canvas_action.cpp @@ -1,187 +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() : previousAngle(0) {} Shortcut mode; 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: case DiscreteRotateModeShortcut: d->mode = (Shortcut)shortcut; 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::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { const KisCoordinatesConverter *converter = inputManager()->canvas()->coordinatesConverter(); const QPointF centerPoint = converter->flakeToWidget(converter->flakeCenterPoint()); const QPointF startPoint = startPos - centerPoint; const QPointF newPoint = pos - centerPoint; const qreal oldAngle = atan2(startPoint.y(), startPoint.x()); const qreal newAngle = atan2(newPoint.y(), newPoint.x()); qreal newRotation = (180 / M_PI) * (newAngle - oldAngle); if (d->mode == DiscreteRotateModeShortcut) { const qreal angleStep = 15; newRotation = qRound(newRotation / angleStep) * angleStep; } KisCanvasController *canvasController = dynamic_cast(inputManager()->canvas()->canvasController()); 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 e603c7bd7f..d3e949b17b 100644 --- a/libs/ui/input/kis_rotate_canvas_action.h +++ b/libs/ui/input/kis_rotate_canvas_action.h @@ -1,62 +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 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 54b61ddb4b..3f86d20c7b 100644 --- a/libs/ui/input/kis_zoom_action.cpp +++ b/libs/ui/input/kis_zoom_action.cpp @@ -1,318 +1,323 @@ /* 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), lastDistance(0.f) {} QPointF centerPoint(QTouchEvent* event); KisZoomAction *q; Shortcuts mode; QPointF lastPosition; float lastDistance; 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->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->startZoom = inputManager()->canvas()->viewManager()->zoomController()->zoomAction()->effectiveZoom(); d->lastDescreteZoomDistance = 0; d->mode = (Shortcuts)shortcut; 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(); } } if (count == 0) { count = 1; } 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::cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos) { QPointF diff = -(pos - startPos); const int stepCont = 100; 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); qreal newZoom = zoom; if (cfg.readEntry("InvertMiddleClickZoom", false)) { newZoom = d->startZoom / logDistance; } else { newZoom = d->startZoom * logDistance; } if (d->mode == ZoomModeShortcut) { inputManager()->canvas()->viewManager()->zoomController()->setZoom(KoZoomMode::ZOOM_CONSTANT, newZoom); } else { const qreal coeff = newZoom / zoom; KoCanvasControllerWidget *controller = dynamic_cast( inputManager()->canvas()->canvasController()); controller->zoomRelativeToPoint(startPos.toPoint(), coeff); } } else if (d->mode == DiscreteZoomModeShortcut || d->mode == RelativeDiscreteZoomModeShortcut) { QPoint stillPoint = d->mode == RelativeDiscreteZoomModeShortcut ? startPos.toPoint() : QPoint(); qreal currentDiff = qreal(diff.y()) / stepDisc - d->lastDescreteZoomDistance; bool zoomIn = currentDiff > 0; while (qAbs(currentDiff) > 1.0) { d->zoomTo(zoomIn, stillPoint); 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 477e6ebcf9..78de9831bb 100644 --- a/libs/ui/input/kis_zoom_action.h +++ b/libs/ui/input/kis_zoom_action.h @@ -1,67 +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 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