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

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006-2007 Thomas Zander <zander@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef SHAPEROTATESTRATEGY_H
0008 #define SHAPEROTATESTRATEGY_H
0009 
0010 #include <KoInteractionStrategy.h>
0011 
0012 #include <QPointF>
0013 #include <QRectF>
0014 #include <QTransform>
0015 #include <QList>
0016 
0017 class KoToolBase;
0018 class KoShape;
0019 class KoSelection;
0020 
0021 /**
0022  * A strategy for the KoInteractionTool.
0023  * This strategy is invoked when the user starts a rotate of a selection of objects,
0024  * the strategy will then rotate the objects interactively and provide a command afterwards.
0025  */
0026 class ShapeRotateStrategy : public KoInteractionStrategy
0027 {
0028 public:
0029     /**
0030      * Constructor that starts to rotate the objects.
0031      * @param tool the parent tool which controls this strategy
0032      * @param clicked the initial point that the user depressed (in pt).
0033      */
0034     ShapeRotateStrategy(KoToolBase *tool, KoSelection *selection, const QPointF &clicked, Qt::MouseButtons buttons);
0035     ~ShapeRotateStrategy() override {}
0036 
0037     void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override;
0038     KUndo2Command *createCommand() override;
0039     void finishInteraction(Qt::KeyboardModifiers modifiers) override
0040     {
0041         Q_UNUSED(modifiers);
0042     }
0043     void paint(QPainter &painter, const KoViewConverter &converter) override;
0044 
0045 private:
0046     void rotateBy(qreal angle);
0047 
0048     QPointF m_start;
0049     QTransform m_rotationMatrix;
0050     QList<QTransform> m_oldTransforms;
0051     QPointF m_rotationCenter;
0052     QList<KoShape *> m_transformedShapesAndSelection;
0053 };
0054 
0055 #endif
0056