Warning, file /office/calligra/libs/flake/KoShapeManager.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-2008 Thorsten Zachmann <zachmann@kde.org> 0004 Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KOSHAPEMANAGER_H 0023 #define KOSHAPEMANAGER_H 0024 0025 #include <QList> 0026 #include <QObject> 0027 #include <QSet> 0028 0029 #include "KoFlake.h" 0030 #include "flake_export.h" 0031 0032 class KoShape; 0033 class KoSelection; 0034 class KoViewConverter; 0035 class KoCanvasBase; 0036 class KoPointerEvent; 0037 class KoShapeManagerPaintingStrategy; 0038 class KoShapePaintingContext; 0039 0040 0041 class QPainter; 0042 class QPointF; 0043 class QRectF; 0044 0045 /** 0046 * The shape manager hold a list of all shape which are in scope. 0047 * There is one shape manager per canvas. This makes the shape manager 0048 * different from QGraphicsScene, which contains the datamodel for all 0049 * graphics items: KoShapeManager only contains the subset of shapes 0050 * that are shown in its canvas. 0051 * 0052 * The selection in the different views can be different. 0053 */ 0054 class FLAKE_EXPORT KoShapeManager : public QObject 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 /// enum for add() 0060 enum Repaint { 0061 PaintShapeOnAdd, ///< Causes each shapes 'update()' to be called after being added to the shapeManager 0062 AddWithoutRepaint ///< Avoids each shapes 'update()' to be called for faster addition when its possible. 0063 }; 0064 0065 /** 0066 * Constructor. 0067 */ 0068 explicit KoShapeManager(KoCanvasBase *canvas); 0069 /** 0070 * Constructor that takes a list of shapes, convenience version. 0071 * @param shapes the shapes to start out with, see also setShapes() 0072 * @param canvas the canvas this shape manager is working on. 0073 */ 0074 KoShapeManager(KoCanvasBase *canvas, const QList<KoShape *> &shapes); 0075 ~KoShapeManager() override; 0076 0077 0078 /** 0079 * Remove all previously owned shapes and make the argument list the new shapes 0080 * to be managed by this manager. 0081 * @param shapes the new shapes to manage. 0082 * @param repaint if true it will trigger a repaint of the shapes 0083 */ 0084 void setShapes(const QList<KoShape *> &shapes, Repaint repaint = PaintShapeOnAdd); 0085 0086 /// returns the list of maintained shapes 0087 QList<KoShape*> shapes() const; 0088 0089 /** 0090 * Get a list of all shapes that don't have a parent. 0091 */ 0092 QList<KoShape*> topLevelShapes() const; 0093 0094 public Q_SLOTS: 0095 /** 0096 * Add a KoShape to be displayed and managed by this manager. 0097 * This will trigger a repaint of the shape. 0098 * @param shape the shape to add 0099 * @param repaint if true it will trigger a repaint of the shape 0100 */ 0101 void addShape(KoShape *shape, KoShapeManager::Repaint repaint = PaintShapeOnAdd); 0102 0103 /** 0104 * Add an additional shape to the manager. 0105 * 0106 * For additional shapes only updates are handled 0107 */ 0108 void addAdditional(KoShape *shape); 0109 0110 /** 0111 * Remove a KoShape from this manager 0112 * @param shape the shape to remove 0113 */ 0114 void remove(KoShape *shape); 0115 0116 /** 0117 * Remove an additional shape 0118 * 0119 * For additional shapes only updates are handled 0120 */ 0121 void removeAdditional(KoShape *shape); 0122 0123 public: 0124 /// return the selection shapes for this shapeManager 0125 KoSelection *selection() const; 0126 0127 /** 0128 * Paint all shapes and their selection handles etc. 0129 * @param painter the painter to paint to. 0130 * @param forPrint if true, make sure only actual content is drawn and no decorations. 0131 * @param converter to convert between document and view coordinates. 0132 */ 0133 void paint(QPainter &painter, const KoViewConverter &converter, bool forPrint); 0134 0135 /** 0136 * Returns the shape located at a specific point in the document. 0137 * If more than one shape is located at the specific point, the given selection type 0138 * controls which of them is returned. 0139 * @param position the position in the document coordinate system. 0140 * @param selection controls which shape is returned when more than one shape is at the specific point 0141 * @param omitHiddenShapes if true, only visible shapes are considered 0142 */ 0143 KoShape *shapeAt(const QPointF &position, KoFlake::ShapeSelection selection = KoFlake::ShapeOnTop, bool omitHiddenShapes = true); 0144 0145 /** 0146 * Returns the shapes which intersects the specific rect in the document. 0147 * @param rect the rectangle in the document coordinate system. 0148 * @param omitHiddenShapes if true, only visible shapes are considered 0149 */ 0150 QList<KoShape *> shapesAt(const QRectF &rect, bool omitHiddenShapes = true); 0151 0152 /** 0153 * Request a repaint to be queued. 0154 * The repaint will be restricted to the parameters rectangle, which is expected to be 0155 * in points (the document coordinates system of KoShape) and it is expected to be 0156 * normalized and based in the global coordinates, not any local coordinates. 0157 * <p>This method will return immediately and only request a repaint. Successive calls 0158 * will be merged into an appropriate repaint action. 0159 * @param rect the rectangle (in pt) to queue for repaint. 0160 * @param shape the shape that is going to be redrawn; only needed when selectionHandles=true 0161 * @param selectionHandles if true; find out if the shape is selected and repaint its 0162 * selection handles at the same time. 0163 */ 0164 void update(QRectF &rect, const KoShape *shape = 0, bool selectionHandles = false); 0165 0166 /** 0167 * Update the tree for finding the shapes. 0168 * This will remove the shape from the tree and will reinsert it again. 0169 * The update to the tree will be postponed until it is needed so that successive calls 0170 * will be merged into one. 0171 * @param shape the shape to updated its position in the tree. 0172 */ 0173 void notifyShapeChanged(KoShape *shape); 0174 0175 /** 0176 * Switch to editing the shape that is at the position of the event. 0177 * This method will check select a shape at the event position and switch to the default tool 0178 * for that shape, or switch to the default tool if there is no shape at the position. 0179 * @param event the event that holds the point where to look for a shape. 0180 */ 0181 void suggestChangeTool(KoPointerEvent *event); 0182 0183 /** 0184 * Paint a shape 0185 * 0186 * @param shape the shape to paint 0187 * @param painter the painter to paint to. 0188 * @param converter to convert between document and view coordinates. 0189 * @param paintContext the painting context. 0190 */ 0191 void paintShape(KoShape *shape, QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintContext); 0192 0193 /** 0194 * Set the strategy of the KoShapeManager 0195 * 0196 * This can be used to change the behaviour of the painting of the shapes. 0197 * @param strategy the new strategy. The ownership of the argument \p 0198 * strategy will be taken by the shape manager. 0199 */ 0200 void setPaintingStrategy(KoShapeManagerPaintingStrategy *strategy); 0201 0202 Q_SIGNALS: 0203 /// emitted when the selection is changed 0204 void selectionChanged(); 0205 /// emitted when an object in the selection is changed (moved/rotated etc) 0206 void selectionContentChanged(); 0207 /// emitted when any object changed (moved/rotated etc) 0208 void contentChanged(); 0209 /// emitted when a shape is removed. 0210 void shapeRemoved(KoShape *); 0211 /// emitted when any shape changed. 0212 void shapeChanged(KoShape *); 0213 0214 private: 0215 0216 friend class KoShapeManagerPaintingStrategy; 0217 KoCanvasBase *canvas(); 0218 0219 0220 class Private; 0221 Private * const d; 0222 Q_PRIVATE_SLOT(d, void updateTree()) 0223 }; 0224 0225 #endif