Subversion Repositories Scribus

Rev

Rev 11729 | Rev 12463 | 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
                 */
11729 jghali 62
                void copy(Selection& other, 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);
10978 avox 88
 
89
                bool containsItem(PageItem *item) const { return m_SelList.contains(item); }
3936 cbradney 90
                /**
4650 subik 91
                 * \brief Unused
3936 cbradney 92
                 */
3903 cbradney 93
                bool addGroup();
3936 cbradney 94
                /**
4650 subik 95
                 * \brief Remove an item from list
96
                 * @param item page item
3936 cbradney 97
                 */
4133 cbradney 98
                bool removeItem(PageItem *item);
3936 cbradney 99
                /**
4650 subik 100
                 * \brief Remove the first item from the list
3936 cbradney 101
                 * @return If the remove was successful
102
                 */
4133 cbradney 103
                bool removeFirst();
3936 cbradney 104
                /**
4650 subik 105
                 * \brief Unused
3936 cbradney 106
                 */
3903 cbradney 107
                bool removeGroup();
3936 cbradney 108
                /**
4650 subik 109
                 * \brief Remove an item from list listNumber and return a pointer to it
3936 cbradney 110
                 * @param itemIndex Index of the item in the list
111
                 * @return Item
112
                 */
8613 cbradney 113
                PageItem* takeItem(int itemIndex);
3936 cbradney 114
                /**
4650 subik 115
                 * \brief Find an item from the selection and return an index to it
3936 cbradney 116
                 * @param item Item pointer to find in the list
117
                 * @return Item
118
                 */
10394 cbradney 119
                int findItem(PageItem *item) const { return m_SelList.indexOf(item); }
3936 cbradney 120
                /**
4650 subik 121
                 * \brief Return the count of the selection
3936 cbradney 122
                 */
10390 cbradney 123
                int count() const { return m_SelList.count(); }
3936 cbradney 124
                /**
4650 subik 125
                 * \brief Check if the selection is empty.
3936 cbradney 126
                 */
4135 cbradney 127
                bool isEmpty() const { return m_SelList.count()==0; }
3936 cbradney 128
                /**
4650 subik 129
                 * \brief Clear a list
3936 cbradney 130
                 */
4133 cbradney 131
                bool clear();
3903 cbradney 132
                /**
4650 subik 133
                 * \brief See if the first selected item is "me", usually called from an item object with "this".
134
                 * @param item PageItem reference
3903 cbradney 135
                 */
4134 cbradney 136
                bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
8266 avox 137
                PageItem *itemAt(int index=0) { return itemAt_(index); }
138
                const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
139
                QStringList getSelectedItemsByName() const;
4133 cbradney 140
                bool isMultipleSelection() const { return m_hasGroupSelection; }
141
                bool isGUISelection() const { return m_isGUISelection; }
8266 avox 142
                double width() const;
143
                double height() const;
7575 cbradney 144
                //set the group rectangle properties
145
                void setGroupRect();
146
                void getGroupRect(double *x, double *y, double *w, double *h);
7686 cbradney 147
                //!\brief Test to see if all items in the selection are the same typedef
8266 avox 148
                bool itemsAreSameType() const;
11729 jghali 149
 
150
                bool signalsDelayed(void);
151
                void delaySignalsOn(void);
152
                void delaySignalsOff(void);
3903 cbradney 153
 
154
        protected:
8266 avox 155
                PageItem *itemAt_(int index=0);
4133 cbradney 156
                SelectionList m_SelList;
157
                bool m_hasGroupSelection;
158
                bool m_isGUISelection;
7575 cbradney 159
                double groupX;
160
                double groupY;
161
                double groupW;
162
                double groupH;
163
 
11729 jghali 164
                int  m_delaySignals;
165
                bool m_sigSelectionChanged;
166
                bool m_sigSelectionIsMultiple;
167
 
12125 jghali 168
                void sendSignals(bool guiConnect = true);
4049 cbradney 169
 
170
        signals:
4130 cbradney 171
                void selectionIsMultiple(bool);
4738 cbradney 172
                void empty();
5859 tsoots 173
                void selectionChanged();
3903 cbradney 174
};
175
 
176
#endif