KoShapeManager.h 5.5 KB
Newer Older
Thomas Zander's avatar
Thomas Zander committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* This file is part of the KDE project

   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

Thomas Zander's avatar
Thomas Zander committed
21 22
#ifndef KOSHAPEMANAGER_H
#define KOSHAPEMANAGER_H
Thomas Zander's avatar
Thomas Zander committed
23 24 25

#include <QList>
#include <QObject>
26
#include <QSet>
Thomas Zander's avatar
Thomas Zander committed
27

Thomas Zander's avatar
Thomas Zander committed
28
#include "KoFlake.h"
29
#include <koffice_export.h>
30
#include <KoRTree.h>
31

Thomas Zander's avatar
Thomas Zander committed
32 33 34 35 36 37 38
class KoShape;
class KoSelection;
class KoViewConverter;
class KoCanvasBase;

class QPainter;
class QPointF;
39
class QRectF;
Thomas Zander's avatar
Thomas Zander committed
40 41

/**
Thomas Zander's avatar
Thomas Zander committed
42 43
 * The shape manager hold a list of all shape which are in scope.
 * There is one shape manager per view.
Thomas Zander's avatar
Thomas Zander committed
44 45 46
 *
 * The selection in the different views can be different.
 */
47
class FLAKE_EXPORT KoShapeManager : public QObject
Thomas Zander's avatar
Thomas Zander committed
48 49 50 51 52 53 54
{
    Q_OBJECT

public:
    /**
     * Empty constructor.
     */
55
    explicit KoShapeManager(KoCanvasBase *canvas);
Thomas Zander's avatar
Thomas Zander committed
56
    /**
Thomas Zander's avatar
Thomas Zander committed
57 58
     * Constructor that takes a list of shapes, convenience version.
     * @param shapes the shapes to start out with, see also setShapes()
Thomas Zander's avatar
Thomas Zander committed
59 60
     * @param canvas the canvas this shape manager is working on.
     */
Thomas Zander's avatar
Thomas Zander committed
61
    KoShapeManager(KoCanvasBase *canvas, const QList<KoShape *> &shapes);
Thomas Zander's avatar
Thomas Zander committed
62 63 64
    virtual ~KoShapeManager();

    /**
Thomas Zander's avatar
Thomas Zander committed
65
     * Remove all previously owned shapes and make the argument list the new shapes
Thomas Zander's avatar
Thomas Zander committed
66
     * to be managed by this manager.
Thomas Zander's avatar
Thomas Zander committed
67
     * @param shapes the new shapes to manage.
Thomas Zander's avatar
Thomas Zander committed
68
     */
Thomas Zander's avatar
Thomas Zander committed
69
    void setShapes( const QList<KoShape *> &shapes );
70

Thomas Zander's avatar
Thomas Zander committed
71 72
    /// returns the list of maintained shapes
    const QList<KoShape *> & shapes() const { return m_shapes; }
Thomas Zander's avatar
Thomas Zander committed
73 74 75 76 77 78

    /**
     * Add a KoShape to be displayed and managed by this manager.
     * @param shape the shape to add
     */
    void add(KoShape *shape);
79

Thomas Zander's avatar
Thomas Zander committed
80 81 82 83 84 85
    /**
     * Remove a KoShape from this manager
     * @param shape the shape to remove
     */
    void remove(KoShape *shape);

Thomas Zander's avatar
Thomas Zander committed
86
    /// return the selection shapes for this shapeManager
Thomas Zander's avatar
Thomas Zander committed
87 88 89
    KoSelection * selection() const { return m_selection; }

    /**
Thomas Zander's avatar
Thomas Zander committed
90
     * Paint all shapes and their selection handles etc.
Thomas Zander's avatar
Thomas Zander committed
91 92
     * @param painter the painter to paint to.
     * @param forPrint if true, make sure only actual content is drawn and no decorations.
93
     * @param converter to convert between document and view coordinates.
Thomas Zander's avatar
Thomas Zander committed
94
     */
95
    virtual void paint( QPainter &painter, const KoViewConverter &converter, bool forPrint );
Thomas Zander's avatar
Thomas Zander committed
96 97

    /**
Thomas Zander's avatar
Thomas Zander committed
98
     * Returns the shape located at a specific point in the document.
99 100
     * If more than one shape is located at the specific point, the given selection type
     * controls which of them is returned.
101
     * @param position the position in the document coordinate system.
102 103
     * @param selection controls which shape is returned when more than one shape is at the specific point
     * @param omitHiddenShapes if true, only visible shapes are considered
Thomas Zander's avatar
Thomas Zander committed
104
     */
Thomas Zander's avatar
Thomas Zander committed
105
    KoShape * shapeAt( const QPointF &position, KoFlake::ShapeSelection selection = KoFlake::ShapeOnTop, bool omitHiddenShapes = false );
Thomas Zander's avatar
Thomas Zander committed
106

107 108 109
    /**
     * Returns the shapes which intersects the specific rect in the document.
     * @param rect the rectangle in the document coordinate system.
110
     * @param omitHiddenShapes if true, only visible shapes are considered
111
     */
112
    QList<KoShape *> shapesAt( const QRectF &rect, bool omitHiddenShapes = false );
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    /**
     * Request a repaint to be queued.
     * The repaint will be restricted to the parameters rectangle, which is expected to be
     * in points (the document coordinates system of KoShape) and it is expected to be
     * normalized and based in the global coordinates, not any local coordinates.
     * <p>This method will return immediately and only request a repaint. Successive calls
     * will be merged into an appropriate repaint action.
     * @param rect the rectangle (in pt) to queue for repaint.
     * @param shape the shape that is going to be redrawn; only needed when selectionHandles=true
     * @param selectionHandles if true; find out if the shape is selected and repaint its
     *   selection handles at the same time.
     */
    void repaint( QRectF &rect, const KoShape *shape = 0, bool selectionHandles = false );

    /**
     * Update the tree for finding the shapes.
130
     * This will remove the shape from the tree and will reinsert it again.
Thomas Zander's avatar
Thomas Zander committed
131
     * The update to the tree will be posponed until it is needed so that successive calls
132 133 134
     * will be merged into one.
     * @param shape the shape to updated its position in the tree.
     */
Thomas Zander's avatar
Thomas Zander committed
135
    void notifyShapeChanged( KoShape * shape );
136

Thomas Zander's avatar
Thomas Zander committed
137
private:
138
    /**
139 140
     * Update the tree when there are shapes in m_aggregate4update. This is done so not all
     * updates to the tree are done when they are asked for but when they are needed.
141 142 143
     */
    void updateTree();

Thomas Zander's avatar
Thomas Zander committed
144 145 146 147 148
signals:
    /// emitted when the selection is changed
    void selectionChanged();

private:
Thomas Zander's avatar
Thomas Zander committed
149
    QList<KoShape *> m_shapes;
Thomas Zander's avatar
Thomas Zander committed
150
    KoSelection * m_selection;
151
    KoCanvasBase * m_canvas;
152
    KoRTree<KoShape *> m_tree;
153
    QSet<KoShape *> m_aggregate4update;
Thomas Zander's avatar
Thomas Zander committed
154 155
};

Thomas Zander's avatar
Thomas Zander committed
156
#endif
Thomas Zander's avatar
Thomas Zander committed
157