KoSelection.h 3.31 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 21 22 23 24 25 26 27 28 29 30 31
/* This file is part of the KDE project

   Copyright (C) 2006 Boudewijn Rempt <boud@valdyas.org>
   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.
*/

#ifndef KOSELECTION_H
#define KOSELECTION_H

#include <QObject>
#include <QSet>

#include "KoShape.h"
#include "KoViewConverter.h"
#include "KoFlake.h"

Thomas Zander's avatar
Thomas Zander committed
32 33
#include <koffice_export.h>

Thomas Zander's avatar
Thomas Zander committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
typedef QSet<KoShape*> KoSelectionSet;

/**
 * A selection is a flake object that contains a number of references
 * to flake objects. That means that a selection can be manipulated in
 * the same way as a single flake object.
 *
 * Note that a single object can be selected in one view, and not in
 * another, and that in a single view, more than one selection can be
 * present. So selections should not be seen as singletons, or as
 * something completely transient.
 *
 * A selection, however, should not be selectable. We need to think
 * a little about the interaction here.
 */
Thomas Zander's avatar
Thomas Zander committed
49
class FLAKE_EXPORT KoSelection : public QObject, public KoShape {
Thomas Zander's avatar
Thomas Zander committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    Q_OBJECT

public:

    KoSelection();
    virtual ~KoSelection();

    virtual void paint( QPainter &painter, KoViewConverter &converter );

    /// add a selected object
    virtual void select(KoShape * object);
    /// remove a selected object
    virtual void deselect(KoShape * object);
    /// clear the selections list
    virtual void deselectAll();
    /**
     * Return the list of selected objects
     * @return the list of selected objects
     * @param strip if StrippedSelection, the returned list will not include any children
     *    of a grouped object if the group-parent is itself also in the set.
     */
    virtual const KoSelectionSet selectedObjects(KoFlake::SelectionType strip = KoFlake::FullSelection) const;
72 73 74 75 76 77
    /**
     * Return the first selected object, or 0 if there is nothing selected.
     * @param strip if StrippedSelection, the returned list will not include any children
     *    of a grouped object if the group-parent is itself also in the set.
     */
    KoShape *firstSelectedObject(KoFlake::SelectionType strip = KoFlake::FullSelection) const;
Thomas Zander's avatar
Thomas Zander committed
78 79 80 81 82 83 84
    /// return if the object is selected
    virtual bool isSelected(const KoShape *object) const;
    /// return the selection count
    virtual int count() const;

    virtual bool hitTest( const QPointF &position ) const;

85
    virtual QRectF boundingRect() const;
Thomas Zander's avatar
Thomas Zander committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

signals:
    /// emitted when the selection is changed
    void selectionChanged();

private slots:
    void selectionChangedEvent();

private:
    void requestSelectionChangedEvent();

    KoSelectionSet m_selectedObjects;
    bool m_eventTriggered;
};

#endif