File indexing completed on 2024-06-23 04:28:11

0001 /* This file is part of the KDE project
0002 
0003    SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org>
0004    SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
0005 
0006    SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef SHAPEMOVESTRATEGY_H
0010 #define SHAPEMOVESTRATEGY_H
0011 
0012 #include <KoInteractionStrategy.h>
0013 
0014 #include <QPointer>
0015 #include <QPointF>
0016 #include <QList>
0017 
0018 #include <KoCanvasBase.h>
0019 
0020 class KoToolBase;
0021 class KoShape;
0022 class KoSelection;
0023 
0024 /**
0025  * Implements the Move action on an object or selected objects.
0026  */
0027 class ShapeMoveStrategy : public KoInteractionStrategy
0028 {
0029 public:
0030     /**
0031      * Constructor that starts to move the objects.
0032      * @param tool the parent tool which controls this strategy
0033      * @param canvas the canvas interface which will supply things like a selection object
0034      * @param clicked the initial point that the user depressed (in pt).
0035      */
0036     ShapeMoveStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked);
0037     ~ShapeMoveStrategy() override {}
0038 
0039     void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override;
0040     KUndo2Command *createCommand() override;
0041     void finishInteraction(Qt::KeyboardModifiers modifiers) override;
0042     void paint(QPainter &painter, const KoViewConverter &converter) override;
0043 private:
0044     void moveSelection(const QPointF &diff);
0045     QList<QPointF> m_previousPositions;
0046     QList<QPointF> m_newPositions;
0047     QPointF m_start, m_finalMove, m_initialOffset;
0048     QList<KoShape *> m_selectedShapes;
0049     QPointer<KoCanvasBase> m_canvas;
0050 };
0051 
0052 #endif