File indexing completed on 2024-05-12 15:56:47

0001 /* This file is part of the KDE project
0002  *
0003  * SPDX-FileCopyrightText: 2006-2007, 2010 Thomas Zander <zander@kde.org>
0004  * SPDX-FileCopyrightText: 2006-2008 Thorsten Zachmann <zachmann@kde.org>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.0-or-later
0007  */
0008 
0009 #ifndef KOSHAPECONTROLLER_H
0010 #define KOSHAPECONTROLLER_H
0011 
0012 #include "kritaflake_export.h"
0013 
0014 #include <QObject>
0015 #include <QList>
0016 #include <QMetaType>
0017 
0018 class KoCanvasBase;
0019 class KoShape;
0020 class KoShapeContainer;
0021 class KoShapeControllerBase;
0022 class KUndo2Command;
0023 class KoDocumentResourceManager;
0024 
0025 /**
0026  * Class used by tools to maintain the list of shapes.
0027  * All applications have some sort of list of all shapes that belong to the document.
0028  * The applications implement the KoShapeControllerBase interface (all pure virtuals)
0029  * to add and remove shapes from the document. To ensure that an application can expect
0030  * a certain protocol to be adhered to when adding/removing shapes, all tools use the API
0031  * from this class for maintaining the list of shapes in the document. So no tool gets
0032  * to access the application directly.
0033  */
0034 class KRITAFLAKE_EXPORT KoShapeController : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     /**
0040      * Create a new Controller; typically not called by applications, only
0041      * by the KonCanvasBase constructor.
0042      * @param canvas the canvas this controller works for. The canvas can be 0
0043      * @param shapeController the application provided shapeController that we can call.
0044      */
0045     KoShapeController(KoCanvasBase *canvas, KoShapeControllerBase *shapeController);
0046     /// destructor
0047     ~KoShapeController() override;
0048 
0049     /**
0050      * @brief reset sets the canvas and shapebased document to 0.
0051      */
0052     void reset();
0053 
0054     /**
0055      * @brief Add a shape to the document.
0056      * If the shape has no parent, the active layer will become its parent.
0057      *
0058      * @param shape to add to the document
0059      * @param parentShape the parent shape
0060      * @param parent the parent command if the resulting command is a compound undo command.
0061      *
0062      * @return command which will insert the shape into the document or 0 if the
0063      *         insertion was cancelled. The command is not yet executed.
0064      */
0065     KUndo2Command* addShape(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent = 0);
0066 
0067     /**
0068      * @brief Add a shape to the document, skipping any dialogs or other user interaction.
0069      *
0070      * @param shape to add to the document
0071      * @param parentShape the parent shape
0072      * @param parent the parent command if the resulting command is a compound undo command.
0073      *
0074      * @return command which will insert the shape into the document. The command is not yet executed.
0075      */
0076     KUndo2Command* addShapeDirect(KoShape *shape, KoShapeContainer *parentShape, KUndo2Command *parent = 0);
0077 
0078     /**
0079      * @brief Add shapes to the document, skipping any dialogs or other user interaction.
0080      *
0081      * @param shape  the shape to add to the document
0082      * @param parentShape the parent shape
0083      * @param parent the parent command if the resulting command is a compound undo command.
0084      *
0085      * @return command which will insert the shapes into the document. The command is not yet executed.
0086      */
0087     KUndo2Command* addShapesDirect(const QList<KoShape*> shape, KoShapeContainer *parentShape, KUndo2Command *parent = 0);
0088 
0089     /**
0090      * @brief Remove a shape from the document.
0091      *
0092      * @param shape to remove from the document
0093      * @param parent the parent command if the resulting command is a compound undo command.
0094      *
0095      * @return command which will remove the shape from the document.
0096      *         The command is not yet executed.
0097      */
0098     KUndo2Command* removeShape(KoShape *shape, KUndo2Command *parent = 0);
0099 
0100     /**
0101      * Remove a shape from the document.
0102      *
0103      * @param shapes the set of shapes to remove from the document
0104      * @param parent the parent command if the resulting command is a compound undo command.
0105      *
0106      * @return command which will remove the shape from the document.
0107      *         The command is not yet executed.
0108      */
0109     KUndo2Command* removeShapes(const QList<KoShape*> &shapes, KUndo2Command *parent = 0);
0110 
0111     /**
0112      * @brief Set the KoShapeControllerBase used to add/remove shapes.
0113      *
0114      * NOTE: only Sheets uses this method. Do not use it in your application. Sheets
0115      * has to also call:
0116      * <code>KoToolManager::instance()->updateShapeControllerBase(shapeController, canvas->canvasController());</code>
0117      *
0118      * @param shapeController the new shapeController.
0119      */
0120     void setShapeControllerBase(KoShapeControllerBase *shapeController);
0121 
0122     /**
0123      * The size of the document measured in rasterized pixels. This information is needed for loading
0124      * SVG documents that use 'px' as the default unit.
0125      */
0126     QRectF documentRectInPixels() const;
0127 
0128     /**
0129      * Resolution of the rasterized representation of the document. Used to load SVG documents correctly.
0130      */
0131     qreal pixelsPerInch() const;
0132 
0133     /**
0134      * Document rect measured in 'pt'
0135      */
0136     QRectF documentRect() const;
0137 
0138     /**
0139      * Return a pointer to the resource manager associated with the
0140      * shape-set (typically a document). The resource manager contains
0141      * document wide resources * such as variable managers, the image
0142      * collection and others.
0143      */
0144     KoDocumentResourceManager *resourceManager() const;
0145 
0146     /**
0147      * @brief Returns the KoShapeControllerBase used to add/remove shapes.
0148      *
0149      * @return the KoShapeControllerBase
0150      */
0151     KoShapeControllerBase *documentBase() const;
0152 
0153 private:
0154     class Private;
0155     Private * const d;
0156 };
0157 
0158 Q_DECLARE_METATYPE(KoShapeController *)
0159 
0160 #endif