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

0001 /* This file is part of the KDE project
0002 
0003    SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
0004    SPDX-FileCopyrightText: 2006 Thorsten Zachmann <zachmann@kde.org>
0005    SPDX-FileCopyrightText: 2007, 2009 Thomas Zander <zander@kde.org>
0006    SPDX-FileCopyrightText: 2006, 2007 Jan Hambrecht <jaham@gmx.net>
0007 
0008    SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 
0011 #ifndef KOSELECTION_H
0012 #define KOSELECTION_H
0013 
0014 #include <QObject>
0015 
0016 #include "KoShape.h"
0017 #include "KoFlake.h"
0018 
0019 #include "kritaflake_export.h"
0020 
0021 class KoShapeLayer;
0022 class KoSelectionPrivate;
0023 
0024 /**
0025  * A selection is a shape that contains a number of references
0026  * to shapes. That means that a selection can be manipulated in
0027  * the same way as a single shape.
0028  *
0029  * Note that a single shape can be selected in one view, and not in
0030  * another, and that in a single view, more than one selection can be
0031  * present. So selections should not be seen as singletons, or as
0032  * something completely transient.
0033  *
0034  * A selection, however, should not be selectable. We need to think
0035  * a little about the interaction here.
0036  */
0037 class KRITAFLAKE_EXPORT KoSelection : public QObject, public KoShape, public KoShape::ShapeChangeListener
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042 
0043     KoSelection(QObject *parent = 0);
0044     ~KoSelection() override;
0045 
0046     void paint(QPainter &painter) const override;
0047     void setSize(const QSizeF &size) override;
0048     QSizeF size() const override;
0049     QRectF outlineRect() const override;
0050     QRectF boundingRect() const override;
0051 
0052     /**
0053      * Adds a shape to the selection.
0054      *
0055      * If the shape is a KoShapeGroup all of its child shapes are automatically added
0056      * to the selection.
0057      * If the shape has no parent or is not a KoShapeGroup, only the given shape is
0058      * added to the selection.
0059      * If the given shape is a child of a KoShapeGroup and recursive selection is enabled
0060      * the all parents and their child shapes up to the toplevel KoShapeGroup are added to
0061      * the selection.
0062      *
0063      * @param shape the shape to add to the selection
0064      */
0065     void select(KoShape *shape);
0066 
0067     /**
0068      * Removes a selected shape.
0069      *
0070      * If the shape is a KoShapeGroup all of its child shapes are automatically removed
0071      * from the selection.
0072      * If the shape has no parent or is not a KoShapeGroup, only the given shape is
0073      * removed from the selection.
0074      * If the given shape is a child of a KoShapeGroup and recursive selection is enabled
0075      * the all parents and their child shape up to the toplevel KoShapeGroup are removed
0076      * from the selection.
0077      *
0078      * @param shape the shape to remove from the selection
0079      */
0080     void deselect(KoShape *shape);
0081 
0082     /// clear the selections list
0083     void deselectAll();
0084 
0085     /**
0086      * Return the list of selected shapes
0087      * @return the list of selected shapes
0088      */
0089     const QList<KoShape*> selectedShapes() const;
0090 
0091     /**
0092      * Same as selectedShapes() but only for shapes in visible state. Used by
0093      * the algorithms that draw shapes on the image
0094      */
0095     const QList<KoShape*> selectedVisibleShapes() const;
0096 
0097     /**
0098      * Same as selectedShapes() but only for editable shapes. Used by
0099      * the algorithms that modify the image
0100      */
0101     const QList<KoShape*> selectedEditableShapes() const;
0102 
0103     /**
0104      * Same as selectedEditableShapes() but also includes shapes delegates.
0105      * Used for
0106      */
0107     const QList<KoShape*> selectedEditableShapesAndDelegates() const;
0108 
0109     /**
0110      * Return the first selected shape, or 0 if there is nothing selected.
0111      */
0112     KoShape *firstSelectedShape() const;
0113 
0114     /// return true if the shape is selected
0115     bool isSelected(const KoShape *shape) const;
0116 
0117     /// return the selection count, i.e. the number of all selected shapes
0118     int count() const;
0119 
0120     bool hitTest(const QPointF &position) const override;
0121 
0122     /**
0123      * Sets the currently active layer.
0124      * @param layer the new active layer
0125      */
0126     void setActiveLayer(KoShapeLayer *layer);
0127 
0128     /**
0129      * Returns a currently active layer.
0130      *
0131      * @return the currently active layer, or zero if there is none
0132      */
0133     KoShapeLayer *activeLayer() const;
0134 
0135     void notifyShapeChanged(ChangeType type, KoShape *shape) override;
0136 
0137 Q_SIGNALS:
0138     /// emitted when the selection is changed
0139     void selectionChanged();
0140 
0141     /// emitted when the current layer is changed
0142     void currentLayerChanged(const KoShapeLayer *layer);
0143 
0144 protected:
0145     KoSelection(const KoSelection &rhs);
0146 
0147 private:
0148     class Private;
0149     QSharedDataPointer<Private> d;
0150 };
0151 
0152 #endif