Subversion Repositories Scribus

Rev

Rev 9937 | Rev 10390 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3903 cbradney 7
/***************************************************************************
8
        copyright            : (C) 2005 by Craig Bradney
9
        email                : cbradney@zip.com.au
10
***************************************************************************/
11
 
12
/***************************************************************************
13
*                                                                         *
14
*   This program is free software; you can redistribute it and/or modify  *
15
*   it under the terms of the GNU General Public License as published by  *
16
*   the Free Software Foundation; either version 2 of the License, or     *
17
*   (at your option) any later version.                                   *
18
*                                                                         *
19
***************************************************************************/
20
#ifndef SELECTION_H
21
#define SELECTION_H
22
 
9803 fschmid 23
#include <QList>
10223 cbradney 24
#include <QMap>
25
#include <QObject>
26
#include <QPointer>
3903 cbradney 27
 
28
#include "pageitem.h"
3938 cbradney 29
#include "scribusapi.h"
3903 cbradney 30
 
9803 fschmid 31
typedef QList< QPointer<PageItem> > SelectionList;
3903 cbradney 32
 
3937 cbradney 33
class SCRIBUS_API Selection : public QObject
3903 cbradney 34
{
35
        Q_OBJECT
36
        public:
4135 cbradney 37
                /**
4650 subik 38
                 * \brief Create an empty selection that is not a GUI selection
39
                 * @param  parent QObject
4135 cbradney 40
                 */
8266 avox 41
                explicit Selection(QObject* parent);   // otherwise implicit conversion Selection* -> Selection& is possible
4135 cbradney 42
                /**
4650 subik 43
                 * \brief Create an empty selection that may be a GUI selection
44
                 * @param  parent QObject
45
                 * @param  guiSelection If the selection is to be a GUI selection
4135 cbradney 46
                 */
4650 subik 47
                Selection(QObject* parent, bool guiSelection);
4135 cbradney 48
                /**
4650 subik 49
                 * \brief Copy a selection
50
                 * \note We are leaving the connections of the items in place
4135 cbradney 51
                 * and the isGUISelection set in the copy. We cannot disconnect them
52
                 * as they may be connected via the main GUI selection.
4650 subik 53
                 * @param  other selection
4135 cbradney 54
                 */
4650 subik 55
                Selection(const Selection& other);
4147 cbradney 56
                Selection& operator=( const Selection & );
3903 cbradney 57
                ~Selection();
8735 cbradney 58
 
59
                /**
60
                 * \brief Copy the selection of items from one selection to another
61
                 */
62
                void copy(Selection& other, bool copyGUISelectionn, bool emptyOther);
3903 cbradney 63
 
4133 cbradney 64
                bool connectItemToGUI();
3903 cbradney 65
                /**
4650 subik 66
                 * \brief Disconnect all items from the GUI slots.
3903 cbradney 67
                 * This should not really be necessary if all things are going ok
68
                 * except for within the clearAll function.
4650 subik 69
                 * @return bool true on success
3903 cbradney 70
                 */
71
                bool disconnectAllItemsFromGUI();
3936 cbradney 72
                /**
73
                 * @brief Add an item to the selection.
4135 cbradney 74
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 75
                 * @param item Item to add
4280 cbradney 76
                 * @param ignoreGUI Dont connect Item To GUI even if this is a GUI selection
3936 cbradney 77
                 * @return If the item was added
78
                 */
4280 cbradney 79
                bool addItem(PageItem *item, bool ignoreGUI=false);
3936 cbradney 80
                /**
81
                 * @brief Prepend an item to the selection.
4135 cbradney 82
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 83
                 * @param item Item to add
4650 subik 84
                 * @param doEmit call emitAllToGUI()
3936 cbradney 85
                 * @return If the item was added
86
                 */
4632 cbradney 87
                bool prependItem(PageItem *item, bool doEmit=true);
3936 cbradney 88
                /**
4650 subik 89
                 * \brief Unused
3936 cbradney 90
                 */
3903 cbradney 91
                bool addGroup();
3936 cbradney 92
                /**
4650 subik 93
                 * \brief Remove an item from list
94
                 * @param item page item
3936 cbradney 95
                 */
4133 cbradney 96
                bool removeItem(PageItem *item);
3936 cbradney 97
                /**
4650 subik 98
                 * \brief Remove the first item from the list
3936 cbradney 99
                 * @return If the remove was successful
100
                 */
4133 cbradney 101
                bool removeFirst();
3936 cbradney 102
                /**
4650 subik 103
                 * \brief Unused
3936 cbradney 104
                 */
3903 cbradney 105
                bool removeGroup();
3936 cbradney 106
                /**
4650 subik 107
                 * \brief Remove an item from list listNumber and return a pointer to it
3936 cbradney 108
                 * @param itemIndex Index of the item in the list
109
                 * @return Item
110
                 */
8613 cbradney 111
                PageItem* takeItem(int itemIndex);
3936 cbradney 112
                /**
4650 subik 113
                 * \brief Find an item from the selection and return an index to it
3936 cbradney 114
                 * @param item Item pointer to find in the list
115
                 * @return Item
116
                 */
4134 cbradney 117
                int findItem(PageItem *item) const { return m_SelList.findIndex(item); }
3936 cbradney 118
                /**
4650 subik 119
                 * \brief Return the count of the selection
3936 cbradney 120
                 */
4134 cbradney 121
                uint count() const { return m_SelList.count(); }
3936 cbradney 122
                /**
4650 subik 123
                 * \brief Check if the selection is empty.
3936 cbradney 124
                 */
4135 cbradney 125
                bool isEmpty() const { return m_SelList.count()==0; }
3936 cbradney 126
                /**
4650 subik 127
                 * \brief Clear a list
3936 cbradney 128
                 */
4133 cbradney 129
                bool clear();
3903 cbradney 130
                /**
4650 subik 131
                 * \brief See if the first selected item is "me", usually called from an item object with "this".
132
                 * @param item PageItem reference
3903 cbradney 133
                 */
4134 cbradney 134
                bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
8266 avox 135
                PageItem *itemAt(int index=0) { return itemAt_(index); }
136
                const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
137
                QStringList getSelectedItemsByName() const;
4133 cbradney 138
                bool isMultipleSelection() const { return m_hasGroupSelection; }
139
                bool isGUISelection() const { return m_isGUISelection; }
140
                void setIsGUISelection(bool guiSelection) { m_isGUISelection=guiSelection; }
8266 avox 141
                double width() const;
142
                double height() const;
7575 cbradney 143
                //set the group rectangle properties
144
                void setGroupRect();
145
                void getGroupRect(double *x, double *y, double *w, double *h);
7686 cbradney 146
                //!\brief Test to see if all items in the selection are the same typedef
8266 avox 147
                bool itemsAreSameType() const;
3903 cbradney 148
 
149
        protected:
8266 avox 150
                PageItem *itemAt_(int index=0);
4133 cbradney 151
                SelectionList m_SelList;
152
                bool m_hasGroupSelection;
153
                bool m_isGUISelection;
7575 cbradney 154
                double groupX;
155
                double groupY;
156
                double groupW;
157
                double groupH;
158
 
4049 cbradney 159
 
160
        signals:
4130 cbradney 161
                void selectionIsMultiple(bool);
4738 cbradney 162
                void empty();
5859 tsoots 163
                void selectionChanged();
3903 cbradney 164
};
165
 
166
#endif