Warning, file /office/calligra/libs/flake/KoSelection.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2006 Boudewijn Rempt <boud@valdyas.org> 0004 Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org> 0005 Copyright (C) 2007,2009 Thomas Zander <zander@kde.org> 0006 Copyright (C) 2006,2007 Jan Hambrecht <jaham@gmx.net> 0007 0008 This library is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU Library General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Library General Public License for more details. 0017 0018 You should have received a copy of the GNU Library General Public License 0019 along with this library; see the file COPYING.LIB. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 * Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #ifndef KOSELECTION_H 0025 #define KOSELECTION_H 0026 0027 #include <QObject> 0028 0029 #include "KoShape.h" 0030 #include "KoFlake.h" 0031 0032 #include "flake_export.h" 0033 0034 class KoViewConverter; 0035 class KoShapeLayer; 0036 class KoSelectionPrivate; 0037 0038 /** 0039 * A selection is a shape that contains a number of references 0040 * to shapes. That means that a selection can be manipulated in 0041 * the same way as a single shape. 0042 * 0043 * Note that a single shape can be selected in one view, and not in 0044 * another, and that in a single view, more than one selection can be 0045 * present. So selections should not be seen as singletons, or as 0046 * something completely transient. 0047 * 0048 * A selection, however, should not be selectable. We need to think 0049 * a little about the interaction here. 0050 */ 0051 class FLAKE_EXPORT KoSelection : public QObject, public KoShape 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 0057 KoSelection(); 0058 ~KoSelection() override; 0059 0060 void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override; 0061 0062 /** 0063 * Adds a shape to the selection. 0064 * 0065 * If the shape is a KoShapeGroup all of its child shapes are automatically added 0066 * to the selection. 0067 * If the shape has no parent or is not a KoShapeGroup, only the given shape is 0068 * added to the selection. 0069 * If the given shape is a child of a KoShapeGroup and recursive selection is enabled 0070 * the all parents and their child shapes up to the toplevel KoShapeGroup are added to 0071 * the selection. 0072 * 0073 * @param shape the shape to add to the selection 0074 * @param recursive enables recursively selecting shapes of parent groups 0075 */ 0076 void select(KoShape *shape, bool recursive = true); 0077 0078 /** 0079 * Removes a selected shape. 0080 * 0081 * If the shape is a KoShapeGroup all of its child shapes are automatically removed 0082 * from the selection. 0083 * If the shape has no parent or is not a KoShapeGroup, only the given shape is 0084 * removed from the selection. 0085 * If the given shape is a child of a KoShapeGroup and recursive selection is enabled 0086 * the all parents and their child shape up to the toplevel KoShapeGroup are removed 0087 * from the selection. 0088 * 0089 * @param shape the shape to remove from the selection 0090 * @param recursive enables recursively deselecting shapes of parent groups 0091 */ 0092 void deselect(KoShape *shape, bool recursive = true); 0093 0094 /// clear the selections list 0095 void deselectAll(); 0096 0097 /** 0098 * Return the list of selected shapes 0099 * @return the list of selected shapes 0100 * @param strip if StrippedSelection, the returned list will not include any children 0101 * of a container shape if the container-parent is itself also in the set. 0102 */ 0103 const QList<KoShape*> selectedShapes(KoFlake::SelectionType strip = KoFlake::FullSelection) const; 0104 0105 /** 0106 * Return the first selected shape, or 0 if there is nothing selected. 0107 * @param strip if StrippedSelection, the returned list will not include any children 0108 * of a grouped shape if the group-parent is itself also in the set. 0109 */ 0110 KoShape *firstSelectedShape(KoFlake::SelectionType strip = KoFlake::FullSelection) const; 0111 0112 /// return true if the shape is selected 0113 bool isSelected(const KoShape *shape) const; 0114 0115 /// return the selection count, i.e. the number of all selected shapes 0116 int count() const; 0117 0118 bool hitTest(const QPointF &position) const override; 0119 0120 QRectF boundingRect() 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 /// Updates the size and position of the selection 0136 void updateSizeAndPosition(); 0137 0138 Q_SIGNALS: 0139 /// emitted when the selection is changed 0140 void selectionChanged(); 0141 0142 /// emitted when the current layer is changed 0143 void currentLayerChanged(const KoShapeLayer *layer); 0144 0145 private: 0146 void saveOdf(KoShapeSavingContext &) const override; 0147 bool loadOdf(const KoXmlElement &, KoShapeLoadingContext &) override; 0148 0149 Q_PRIVATE_SLOT(d_func(), void selectionChangedEvent()) 0150 Q_DECLARE_PRIVATE_D(KoShape::d_ptr, KoSelection) 0151 }; 0152 0153 #endif