diff --git a/libs/flake/tools/KoInteractionTool.cpp b/libs/flake/tools/KoInteractionTool.cpp index 38bcbf5d7c..7bceae3fc3 100644 --- a/libs/flake/tools/KoInteractionTool.cpp +++ b/libs/flake/tools/KoInteractionTool.cpp @@ -1,218 +1,217 @@ /* This file is part of the KDE project Copyright (C) 2006-2007, 2010 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KoInteractionTool.h" #include "KoInteractionTool_p.h" #include "KoToolBase_p.h" #include "KoPointerEvent.h" #include "KoCanvasBase.h" #include "kis_global.h" #include "kis_assert.h" - KoInteractionTool::KoInteractionTool(KoCanvasBase *canvas) : KoToolBase(*(new KoInteractionToolPrivate(this, canvas))) { } KoInteractionTool::~KoInteractionTool() { } void KoInteractionTool::paint(QPainter &painter, const KoViewConverter &converter) { Q_D(KoInteractionTool); if (d->currentStrategy) { d->currentStrategy->paint(painter, converter); } else { Q_FOREACH (KoInteractionStrategyFactorySP factory, d->interactionFactories) { // skip the rest of rendering if the factory asks for it if (factory->paintOnHover(painter, converter)) break; } } } void KoInteractionTool::mousePressEvent(KoPointerEvent *event) { Q_D(KoInteractionTool); if (d->currentStrategy) { // possible if the user presses an extra mouse button cancelCurrentStrategy(); return; } d->currentStrategy = createStrategyBase(event); if (d->currentStrategy == 0) event->ignore(); } void KoInteractionTool::mouseMoveEvent(KoPointerEvent *event) { Q_D(KoInteractionTool); d->lastPoint = event->point; if (d->currentStrategy) d->currentStrategy->handleMouseMove(d->lastPoint, event->modifiers()); else { Q_FOREACH (KoInteractionStrategyFactorySP factory, d->interactionFactories) { // skip the rest of rendering if the factory asks for it if (factory->hoverEvent(event)) return; } event->ignore(); } } void KoInteractionTool::mouseReleaseEvent(KoPointerEvent *event) { Q_D(KoInteractionTool); if (d->currentStrategy) { d->currentStrategy->finishInteraction(event->modifiers()); KUndo2Command *command = d->currentStrategy->createCommand(); if (command) d->canvas->addCommand(command); delete d->currentStrategy; d->currentStrategy = 0; repaintDecorations(); } else event->ignore(); } void KoInteractionTool::keyPressEvent(QKeyEvent *event) { Q_D(KoInteractionTool); event->ignore(); if (d->currentStrategy && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift || event->key() == Qt::Key_Meta)) { d->currentStrategy->handleMouseMove(d->lastPoint, event->modifiers()); event->accept(); } } void KoInteractionTool::keyReleaseEvent(QKeyEvent *event) { Q_D(KoInteractionTool); if (!d->currentStrategy) { KoToolBase::keyReleaseEvent(event); return; } if (event->key() == Qt::Key_Escape) { cancelCurrentStrategy(); event->accept(); } else if (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift || event->key() == Qt::Key_Meta) { d->currentStrategy->handleMouseMove(d->lastPoint, event->modifiers()); } } KoInteractionStrategy *KoInteractionTool::currentStrategy() { Q_D(KoInteractionTool); return d->currentStrategy; } void KoInteractionTool::cancelCurrentStrategy() { Q_D(KoInteractionTool); if (d->currentStrategy) { d->currentStrategy->cancelInteraction(); delete d->currentStrategy; d->currentStrategy = 0; } } KoInteractionStrategy *KoInteractionTool::createStrategyBase(KoPointerEvent *event) { Q_D(KoInteractionTool); Q_FOREACH (KoInteractionStrategyFactorySP factory, d->interactionFactories) { KoInteractionStrategy *strategy = factory->createStrategy(event); if (strategy) { return strategy; } } return createStrategy(event); } void KoInteractionTool::addInteractionFactory(KoInteractionStrategyFactory *factory) { Q_D(KoInteractionTool); Q_FOREACH (auto f, d->interactionFactories) { KIS_SAFE_ASSERT_RECOVER_RETURN(f->id() != factory->id()); } d->interactionFactories.append(toQShared(factory)); std::sort(d->interactionFactories.begin(), d->interactionFactories.end(), KoInteractionStrategyFactory::compareLess); } void KoInteractionTool::removeInteractionFactory(const QString &id) { Q_D(KoInteractionTool); QList::iterator it = d->interactionFactories.begin(); while (it != d->interactionFactories.end()) { if ((*it)->id() == id) { it = d->interactionFactories.erase(it); } else { ++it; } } } bool KoInteractionTool::hasInteractioFactory(const QString &id) { Q_D(KoInteractionTool); Q_FOREACH (auto f, d->interactionFactories) { if (f->id() == id) { return true; } } return false; } bool KoInteractionTool::tryUseCustomCursor() { Q_D(KoInteractionTool); Q_FOREACH (auto f, d->interactionFactories) { if (f->tryUseCustomCursor()) { return true; } } return false; } KoInteractionTool::KoInteractionTool(KoInteractionToolPrivate &dd) : KoToolBase(dd) { } diff --git a/libs/ui/tool/KisStrokeBasedInteractionStrategy.cpp b/libs/ui/tool/KisStrokeBasedInteractionStrategy.cpp index a22ffed52a..540275a01b 100644 --- a/libs/ui/tool/KisStrokeBasedInteractionStrategy.cpp +++ b/libs/ui/tool/KisStrokeBasedInteractionStrategy.cpp @@ -1,78 +1,92 @@ /* This file is part of the KDE project Copyright (C) 2019 Tusooa Zhu This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "KisStrokeBasedInteractionStrategy.h" #include #include #include #include struct KisStrokeBasedInteractionStrategy::Private { Private(KoToolBase *tool); ~Private() = default; + // WARNING: stroke strategy is owned by stroke + StrokeStrategy *strokeStrategy; KisStrokesFacade *strokesFacade; KisStrokeId stroke; }; +KisStrokeBasedInteractionStrategy::StrokeStrategy::StrokeStrategy(QString id, KisCanvas2 *canvas, const KUndo2MagicString &name) + : KisNodeReplaceBasedStrokeStrategy(id, canvas, name) +{ +} + +KisStrokeBasedInteractionStrategy::StrokeStrategy::~StrokeStrategy() +{ +} + KisStrokeBasedInteractionStrategy::Private::Private(KoToolBase *tool) { strokesFacade = dynamic_cast(tool->canvas())->image().data(); } -KisStrokeBasedInteractionStrategy::KisStrokeBasedInteractionStrategy(KoToolBase *tool, const QString &id, - const KUndo2MagicString &name) +KisStrokeBasedInteractionStrategy::KisStrokeBasedInteractionStrategy(KoToolBase *tool) : KoInteractionStrategy(tool) - , KisNodeReplaceBasedStrokeStrategy(id, dynamic_cast(tool->canvas()), name) , m_d(new Private(tool)) { - m_d->stroke = m_d->strokesFacade->startStroke(this); } KisStrokeBasedInteractionStrategy::~KisStrokeBasedInteractionStrategy() { } +void KisStrokeBasedInteractionStrategy::startStroke(StrokeStrategy *strategy) +{ + m_d->strokeStrategy = strategy; + m_d->stroke = m_d->strokesFacade->startStroke(strategy); +} + void KisStrokeBasedInteractionStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) { m_d->strokesFacade->addJob(m_d->stroke, new KisRunnableStrokeJobData( - [&]() { mouseMoveCallback(mouseLocation, modifiers); }, + [&]() { m_d->strokeStrategy->mouseMoveCallback(mouseLocation, modifiers); }, KisStrokeJobData::SEQUENTIAL, - KisStrokeJobData::EXCLUSIVE)); + KisStrokeJobData::NORMAL)); } void KisStrokeBasedInteractionStrategy::cancelInteraction() { m_d->strokesFacade->cancelStroke(m_d->stroke); } void KisStrokeBasedInteractionStrategy::finishInteraction(Qt::KeyboardModifiers modifiers) { Q_UNUSED(modifiers); m_d->strokesFacade->endStroke(m_d->stroke); } KUndo2Command *KisStrokeBasedInteractionStrategy::createCommand() { return 0; } diff --git a/libs/ui/tool/KisStrokeBasedInteractionStrategy.h b/libs/ui/tool/KisStrokeBasedInteractionStrategy.h index b6fb582244..2096e3b835 100644 --- a/libs/ui/tool/KisStrokeBasedInteractionStrategy.h +++ b/libs/ui/tool/KisStrokeBasedInteractionStrategy.h @@ -1,74 +1,87 @@ /* This file is part of the KDE project Copyright (C) 2019 Tusooa Zhu This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_STROKE_BASED_INTERACTION_STRATEGY_H_ #define KIS_STROKE_BASED_INTERACTION_STRATEGY_H_ #include #include "strokes/KisNodeReplaceBasedStrokeStrategy.h" #include #include -class KRITAUI_EXPORT KisStrokeBasedInteractionStrategy : public KoInteractionStrategy, public KisNodeReplaceBasedStrokeStrategy +class KRITAUI_EXPORT KisStrokeBasedInteractionStrategy : public KoInteractionStrategy { +public: + class KRITAUI_EXPORT StrokeStrategy : public KisNodeReplaceBasedStrokeStrategy + { + public: + StrokeStrategy(QString id, KisCanvas2 *canvas, const KUndo2MagicString &name); + ~StrokeStrategy() override; + + /** + * Override this function for the actual mouse handling. + * The function will be called via strokesFacade->addJob(), + * so it runs in the image thread. + */ + virtual void mouseMoveCallback(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) = 0; + }; public: /** * The constructor for a stroke-based interaction strategy. - * It will start a stroke in the image. */ - KisStrokeBasedInteractionStrategy(KoToolBase *tool, const QString &id, const KUndo2MagicString &name); + KisStrokeBasedInteractionStrategy(KoToolBase *tool); ~KisStrokeBasedInteractionStrategy() override; + /** + * This function starts the stroke with the given strategy. + * It should be called in the constructor of child classes. + * The stroke takes ownership of strategy. + */ + void startStroke(StrokeStrategy *strategy); + /** * This function adds mouseMoveCallback() as a job to the stroke. */ void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; /** * This function cancels the stroke for the action. */ void cancelInteraction() override; /** * This function ends the stroke for the action. */ void finishInteraction(Qt::KeyboardModifiers modifiers) override; /** * This function returns a null pointer as the undo command is * to be created in the stroke. */ KUndo2Command *createCommand() override; - /** - * Override this function for the actual mouse handling. - * The function will be called via strokesFacade->addJob(), - * so it runs in the image thread. - */ - virtual void mouseMoveCallback(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) = 0; - private: struct Private; QScopedPointer m_d; }; #endif diff --git a/libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp b/libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp index a2ca03dafd..c520de19cf 100644 --- a/libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp +++ b/libs/ui/tool/strokes/KisNodeReplaceBasedStrokeStrategy.cpp @@ -1,120 +1,121 @@ /* * Copyright (c) 2019 Tusooa Zhu * * 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 "KisNodeReplaceBasedStrokeStrategy.h" #include #include #include #include struct KisNodeReplaceBasedStrokeStrategy::Private { Private(KisResourcesSnapshotSP resources); Private(const Private &rhs) = default; ~Private() = default; KisNodeSP affectedNode; KisNodeSP originalState; KisPostExecutionUndoAdapter *postExecUndoAdapter; class NodeReplaceCommand : public KUndo2Command { public: NodeReplaceCommand(KisNodeSP affectedNode, KisNodeSP originalState, const KUndo2MagicString &name); ~NodeReplaceCommand() override = default; void undo() override; void redo() override; KisNodeSP m_affectedNode; KisNodeSP m_originalState; KisNodeSP m_editedState; }; }; KisNodeReplaceBasedStrokeStrategy::Private::Private(KisResourcesSnapshotSP resources) : affectedNode(resources->currentNode()) , originalState(affectedNode->clone()) , postExecUndoAdapter(resources->postExecutionUndoAdapter()) { } KisNodeReplaceBasedStrokeStrategy::Private::NodeReplaceCommand::NodeReplaceCommand(KisNodeSP affectedNode, KisNodeSP originalState, const KUndo2MagicString &name) : KUndo2Command(name) , m_affectedNode(affectedNode) , m_originalState(originalState) , m_editedState(affectedNode->clone()) { KIS_SAFE_ASSERT_RECOVER_NOOP(m_editedState); } void KisNodeReplaceBasedStrokeStrategy::Private::NodeReplaceCommand::undo() { m_affectedNode->copyFromNode(m_originalState.data()); } void KisNodeReplaceBasedStrokeStrategy::Private::NodeReplaceCommand::redo() { m_affectedNode->copyFromNode(m_editedState.data()); } KisNodeReplaceBasedStrokeStrategy::KisNodeReplaceBasedStrokeStrategy(QString id, KisResourcesSnapshotSP resources, const KUndo2MagicString &name) : KisRunnableBasedStrokeStrategy(id, name) , m_d(new Private(resources)) { enableJob(KisSimpleStrokeStrategy::JOB_INIT); - enableJob(KisSimpleStrokeStrategy::JOB_FINISH); + enableJob(KisSimpleStrokeStrategy::JOB_FINISH, /* enable = */ true, + KisStrokeJobData::SEQUENTIAL, KisStrokeJobData::EXCLUSIVE); enableJob(KisSimpleStrokeStrategy::JOB_CANCEL); } KisNodeReplaceBasedStrokeStrategy::KisNodeReplaceBasedStrokeStrategy(QString id, KisCanvas2 *canvas, const KUndo2MagicString &name) : KisNodeReplaceBasedStrokeStrategy(id, new KisResourcesSnapshot(canvas->image().toStrongRef(), canvas->imageView()->currentNode(), canvas->resourceManager()), name) { } KisNodeReplaceBasedStrokeStrategy::KisNodeReplaceBasedStrokeStrategy(const KisNodeReplaceBasedStrokeStrategy &rhs) : KisRunnableBasedStrokeStrategy(rhs) , m_d(new Private(*rhs.m_d)) { } KisNodeReplaceBasedStrokeStrategy::~KisNodeReplaceBasedStrokeStrategy() { } void KisNodeReplaceBasedStrokeStrategy::initStrokeCallback() { } void KisNodeReplaceBasedStrokeStrategy::cancelStrokeCallback() { m_d->affectedNode->copyFromNode(m_d->originalState.data()); } void KisNodeReplaceBasedStrokeStrategy::finishStrokeCallback() { KUndo2CommandSP cmd(new Private::NodeReplaceCommand(m_d->affectedNode, m_d->originalState, name())); m_d->postExecUndoAdapter->addCommand(cmd); } diff --git a/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.cpp b/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.cpp index f7caa4e8be..23f1406c96 100644 --- a/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.cpp +++ b/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.cpp @@ -1,130 +1,134 @@ /* This file is part of the KDE project Copyright (C) 2006 Thorsten Zachmann Copyright (C) 2006-2007 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ShapeMoveStrategy.h" #include "SelectionDecorator.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_debug.h" ShapeMoveStrategy::ShapeMoveStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked) - : KisStrokeBasedInteractionStrategy(tool, "MOVE_SHAPES", kundo2_i18n("Move shapes (new)")) + : KisStrokeBasedInteractionStrategy(tool) +{ + startStroke(new ShapeMoveStrokeStrategy(tool, selection, clicked)); +} + +ShapeMoveStrategy::~ShapeMoveStrategy() +{ +} + +void ShapeMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers) +{ + KisStrokeBasedInteractionStrategy::finishInteraction(modifiers); + tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); +} + +void ShapeMoveStrategy::paint(QPainter &painter, const KoViewConverter &converter) +{ + Q_UNUSED(painter); + Q_UNUSED(converter); +} + +ShapeMoveStrokeStrategy::ShapeMoveStrokeStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked) + : KisStrokeBasedInteractionStrategy::StrokeStrategy("MOVE_SHAPES", dynamic_cast(tool->canvas()), + kundo2_i18n("Move shapes (new)")) , m_start(clicked) , m_canvas(tool->canvas()) { QList selectedShapes = selection->selectedEditableShapes(); QRectF boundingRect; Q_FOREACH (KoShape *shape, selectedShapes) { m_selectedShapes << shape; m_previousPositions << shape->absolutePosition(KoFlake::Center); m_newPositions << shape->absolutePosition(KoFlake::Center); boundingRect = boundingRect.united(shape->boundingRect()); } KoFlake::AnchorPosition anchor = - KoFlake::AnchorPosition( - m_canvas->resourceManager()->resource(KoFlake::HotPosition).toInt()); + KoFlake::AnchorPosition( + m_canvas->resourceManager()->resource(KoFlake::HotPosition).toInt()); m_initialOffset = selection->absolutePosition(anchor) - m_start; m_canvas->snapGuide()->setIgnoredShapes(KoShape::linearizeSubtree(m_selectedShapes)); tool->setStatusText(i18n("Press Shift to hold x- or y-position.")); +}; + +ShapeMoveStrokeStrategy::~ShapeMoveStrokeStrategy() +{ } -void ShapeMoveStrategy::mouseMoveCallback(const QPointF &point, Qt::KeyboardModifiers modifiers) +void ShapeMoveStrokeStrategy::mouseMoveCallback(const QPointF &point, Qt::KeyboardModifiers modifiers) { if (m_selectedShapes.isEmpty()) { return; } QPointF diff = point - m_start; if (modifiers & Qt::ShiftModifier) { // Limit change to one direction only diff = snapToClosestAxis(diff); } else { QPointF positionToSnap = point + m_initialOffset; - tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); - QPointF snappedPosition = tool()->canvas()->snapGuide()->snap(positionToSnap, modifiers); - tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); + m_canvas->updateCanvas(m_canvas->snapGuide()->boundingRect()); + QPointF snappedPosition = m_canvas->snapGuide()->snap(positionToSnap, modifiers); + m_canvas->updateCanvas(m_canvas->snapGuide()->boundingRect()); diff = snappedPosition - m_initialOffset - m_start; } moveSelection(diff); m_finalMove = diff; } -void ShapeMoveStrategy::moveSelection(const QPointF &diff) +void ShapeMoveStrokeStrategy::moveSelection(const QPointF &diff) { Q_ASSERT(m_newPositions.count()); int i = 0; Q_FOREACH (KoShape *shape, m_selectedShapes) { QPointF delta = m_previousPositions.at(i) + diff - shape->absolutePosition(KoFlake::Center); if (shape->parent()) { shape->parent()->model()->proposeMove(shape, delta); } - tool()->canvas()->clipToDocument(shape, delta); + m_canvas->clipToDocument(shape, delta); QPointF newPos(shape->absolutePosition(KoFlake::Center) + delta); m_newPositions[i] = newPos; const QRectF oldDirtyRect = shape->boundingRect(); shape->setAbsolutePosition(newPos, KoFlake::Center); shape->updateAbsolute(oldDirtyRect | oldDirtyRect.translated(delta)); i++; } } - -/* -KUndo2Command *ShapeMoveStrategy::createCommand() -{ - tool()->canvas()->snapGuide()->reset(); - if (m_finalMove.isNull()) { - return 0; - } - return new KoShapeMoveCommand(m_selectedShapes, m_previousPositions, m_newPositions); -} -*/ - -void ShapeMoveStrategy::finishInteraction(Qt::KeyboardModifiers modifiers) -{ - KisStrokeBasedInteractionStrategy::finishInteraction(modifiers); - tool()->canvas()->updateCanvas(tool()->canvas()->snapGuide()->boundingRect()); -} - -void ShapeMoveStrategy::paint(QPainter &painter, const KoViewConverter &converter) -{ - Q_UNUSED(painter); - Q_UNUSED(converter); -} diff --git a/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.h b/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.h index 8f29d8c202..5289cdbf13 100644 --- a/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.h +++ b/plugins/tools/defaulttool/defaulttool/ShapeMoveStrategy.h @@ -1,65 +1,76 @@ /* This file is part of the KDE project Copyright (C) 2006 Thorsten Zachmann Copyright (C) 2006-2007 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef SHAPEMOVESTRATEGY_H #define SHAPEMOVESTRATEGY_H #include #include #include #include #include class KoToolBase; class KoShape; class KoSelection; /** * Implements the Move action on an object or selected objects. */ class ShapeMoveStrategy : public KisStrokeBasedInteractionStrategy { public: /** * Constructor that starts to move the objects. * @param tool the parent tool which controls this strategy * @param canvas the canvas interface which will supply things like a selection object * @param clicked the initial point that the user depressed (in pt). */ ShapeMoveStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked); - ~ShapeMoveStrategy() override {} + ~ShapeMoveStrategy() override; - void mouseMoveCallback(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; void finishInteraction(Qt::KeyboardModifiers modifiers) override; void paint(QPainter &painter, const KoViewConverter &converter) override; +private: + +}; + +class ShapeMoveStrokeStrategy : public KisStrokeBasedInteractionStrategy::StrokeStrategy +{ +public: + ShapeMoveStrokeStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked); + ~ShapeMoveStrokeStrategy() override; + + void mouseMoveCallback(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; + private: void moveSelection(const QPointF &diff); QList m_previousPositions; QList m_newPositions; QPointF m_start, m_finalMove, m_initialOffset; QList m_selectedShapes; QPointer m_canvas; }; #endif