Rev 23268 | 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> |
||
13801 | pierre | 27 | #include <QRectF> |
3903 | cbradney | 28 | |
29 | #include "pageitem.h" |
||
3938 | cbradney | 30 | #include "scribusapi.h" |
3903 | cbradney | 31 | |
9803 | fschmid | 32 | typedef QList< QPointer<PageItem> > SelectionList; |
3903 | cbradney | 33 | |
3937 | cbradney | 34 | class SCRIBUS_API Selection : public QObject |
3903 | cbradney | 35 | { |
36 | Q_OBJECT |
||
37 | public: |
||
4135 | cbradney | 38 | /** |
4650 | subik | 39 | * \brief Create an empty selection that is not a GUI selection |
40 | * @param parent QObject |
||
4135 | cbradney | 41 | */ |
8266 | avox | 42 | explicit Selection(QObject* parent); // otherwise implicit conversion Selection* -> Selection& is possible |
4135 | cbradney | 43 | /** |
4650 | subik | 44 | * \brief Create an empty selection that may be a GUI selection |
45 | * @param parent QObject |
||
46 | * @param guiSelection If the selection is to be a GUI selection |
||
4135 | cbradney | 47 | */ |
4650 | subik | 48 | Selection(QObject* parent, bool guiSelection); |
4135 | cbradney | 49 | /** |
4650 | subik | 50 | * \brief Copy a selection |
51 | * \note We are leaving the connections of the items in place |
||
4135 | cbradney | 52 | * and the isGUISelection set in the copy. We cannot disconnect them |
53 | * as they may be connected via the main GUI selection. |
||
4650 | subik | 54 | * @param other selection |
4135 | cbradney | 55 | */ |
4650 | subik | 56 | Selection(const Selection& other); |
4147 | cbradney | 57 | Selection& operator=( const Selection & ); |
3903 | cbradney | 58 | ~Selection(); |
8735 | cbradney | 59 | |
60 | /** |
||
61 | * \brief Copy the selection of items from one selection to another |
||
62 | */ |
||
11729 | jghali | 63 | void copy(Selection& other, bool emptyOther); |
3903 | cbradney | 64 | |
4133 | cbradney | 65 | bool connectItemToGUI(); |
3903 | cbradney | 66 | /** |
4650 | subik | 67 | * \brief Disconnect all items from the GUI slots. |
3903 | cbradney | 68 | * This should not really be necessary if all things are going ok |
69 | * except for within the clearAll function. |
||
4650 | subik | 70 | * @return bool true on success |
3903 | cbradney | 71 | */ |
72 | bool disconnectAllItemsFromGUI(); |
||
3936 | cbradney | 73 | /** |
74 | * @brief Add an item to the selection. |
||
4135 | cbradney | 75 | * If its added to a GUI selection selection and its item 0, its connected to the GUI too |
3936 | cbradney | 76 | * @param item Item to add |
21017 | craig | 77 | * @param ignoreGUI Don't connect Item To GUI even if this is a GUI selection |
3936 | cbradney | 78 | * @return If the item was added |
79 | */ |
||
4280 | cbradney | 80 | bool addItem(PageItem *item, bool ignoreGUI=false); |
3936 | cbradney | 81 | /** |
23254 | jghali | 82 | * @brief Add items to the selection. |
83 | * If its added to a GUI selection selection and its item 0, its connected to the GUI too |
||
84 | * @param item Item to add |
||
85 | * @return If any item was added |
||
86 | */ |
||
87 | bool addItems(QList<PageItem *> items); |
||
88 | /** |
||
3936 | cbradney | 89 | * @brief Prepend an item to the selection. |
4135 | cbradney | 90 | * If its added to a GUI selection selection and its item 0, its connected to the GUI too |
3936 | cbradney | 91 | * @param item Item to add |
4650 | subik | 92 | * @param doEmit call emitAllToGUI() |
3936 | cbradney | 93 | * @return If the item was added |
94 | */ |
||
23269 | jghali | 95 | bool prependItem(PageItem *item); |
10978 | avox | 96 | |
97 | bool containsItem(PageItem *item) const { return m_SelList.contains(item); } |
||
23252 | jghali | 98 | |
3936 | cbradney | 99 | /** |
4650 | subik | 100 | * \brief Remove an item from list |
101 | * @param item page item |
||
3936 | cbradney | 102 | */ |
4133 | cbradney | 103 | bool removeItem(PageItem *item); |
3936 | cbradney | 104 | /** |
23249 | jghali | 105 | * \brief Remove items from specified layer |
23175 | jghali | 106 | */ |
107 | bool removeItemsOfLayer(int layedID); |
||
108 | /** |
||
4650 | subik | 109 | * \brief Remove the first item from the list |
3936 | cbradney | 110 | * @return If the remove was successful |
111 | */ |
||
4133 | cbradney | 112 | bool removeFirst(); |
3936 | cbradney | 113 | /** |
4650 | subik | 114 | * \brief Unused |
3936 | cbradney | 115 | */ |
3903 | cbradney | 116 | bool removeGroup(); |
23249 | jghali | 117 | |
3936 | cbradney | 118 | /** |
23249 | jghali | 119 | * Replace item in selection by another |
120 | */ |
||
121 | void replaceItem(PageItem* oldItem, PageItem* newItem); |
||
122 | |||
123 | /** |
||
4650 | subik | 124 | * \brief Remove an item from list listNumber and return a pointer to it |
3936 | cbradney | 125 | * @param itemIndex Index of the item in the list |
126 | * @return Item |
||
127 | */ |
||
8613 | cbradney | 128 | PageItem* takeItem(int itemIndex); |
3936 | cbradney | 129 | /** |
4650 | subik | 130 | * \brief Find an item from the selection and return an index to it |
3936 | cbradney | 131 | * @param item Item pointer to find in the list |
132 | * @return Item |
||
133 | */ |
||
10394 | cbradney | 134 | int findItem(PageItem *item) const { return m_SelList.indexOf(item); } |
3936 | cbradney | 135 | /** |
4650 | subik | 136 | * \brief Return the count of the selection |
3936 | cbradney | 137 | */ |
10390 | cbradney | 138 | int count() const { return m_SelList.count(); } |
3936 | cbradney | 139 | /** |
4650 | subik | 140 | * \brief Check if the selection is empty. |
3936 | cbradney | 141 | */ |
23134 | craig | 142 | bool isEmpty() const { return m_SelList.count() == 0; } |
3936 | cbradney | 143 | /** |
4650 | subik | 144 | * \brief Clear a list |
3936 | cbradney | 145 | */ |
4133 | cbradney | 146 | bool clear(); |
3903 | cbradney | 147 | /** |
4650 | subik | 148 | * \brief See if the first selected item is "me", usually called from an item object with "this". |
149 | * @param item PageItem reference |
||
3903 | cbradney | 150 | */ |
4134 | cbradney | 151 | bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); } |
13801 | pierre | 152 | const SelectionList& selectionList() const {return m_SelList;} |
8266 | avox | 153 | PageItem *itemAt(int index=0) { return itemAt_(index); } |
154 | const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); } |
||
18357 | jghali | 155 | QList<PageItem*> items() const; |
8266 | avox | 156 | QStringList getSelectedItemsByName() const; |
16546 | jghali | 157 | bool isMultipleSelection() const { return (m_SelList.count() > 1); } |
4133 | cbradney | 158 | bool isGUISelection() const { return m_isGUISelection; } |
8266 | avox | 159 | double width() const; |
160 | double height() const; |
||
7575 | cbradney | 161 | //set the group rectangle properties |
162 | void setGroupRect(); |
||
163 | void getGroupRect(double *x, double *y, double *w, double *h); |
||
13801 | pierre | 164 | QRectF getGroupRect(); |
12463 | pierre | 165 | void getVisualGroupRect(double *x, double *y, double *w, double *h); |
13801 | pierre | 166 | QRectF getVisualGroupRect(); |
22120 | jghali | 167 | //!\brief Test if selection contains object of specified item type |
168 | bool containsItemType(PageItem::ItemType type) const; |
||
7686 | cbradney | 169 | //!\brief Test to see if all items in the selection are the same typedef |
8266 | avox | 170 | bool itemsAreSameType() const; |
23188 | jghali | 171 | //!\brief Test to see if all items in the selection are on same page |
172 | bool itemsAreOnSamePage() const; |
||
11729 | jghali | 173 | |
14296 | jghali | 174 | /** |
175 | * \brief get the layer ID of items in the selection |
||
176 | * @return the layer ID or -1 if items do not belong to the same layer |
||
177 | */ |
||
22598 | craig | 178 | int objectsLayer() const; |
14296 | jghali | 179 | |
17092 | jghali | 180 | /** |
181 | * \brief detect if selected object have all same parent (doc or group) |
||
182 | * @return true if objects share same parent, false otherwise |
||
183 | */ |
||
22598 | craig | 184 | bool objectsHaveSameParent() const; |
17092 | jghali | 185 | |
22598 | craig | 186 | bool signalsDelayed(); |
187 | void delaySignalsOn(); |
||
188 | void delaySignalsOff(); |
||
3903 | cbradney | 189 | |
190 | protected: |
||
8266 | avox | 191 | PageItem *itemAt_(int index=0); |
4133 | cbradney | 192 | SelectionList m_SelList; |
193 | bool m_isGUISelection; |
||
20691 | craig | 194 | double m_groupX; |
195 | double m_groupY; |
||
196 | double m_groupW; |
||
197 | double m_groupH; |
||
12463 | pierre | 198 | |
20691 | craig | 199 | double m_visualGX; |
200 | double m_visualGY; |
||
201 | double m_visualGW; |
||
202 | double m_visualGH; |
||
7575 | cbradney | 203 | |
11729 | jghali | 204 | int m_delaySignals; |
205 | bool m_sigSelectionChanged; |
||
206 | |||
12125 | jghali | 207 | void sendSignals(bool guiConnect = true); |
4049 | cbradney | 208 | |
209 | signals: |
||
5859 | tsoots | 210 | void selectionChanged(); |
3903 | cbradney | 211 | }; |
212 | |||
213 | #endif |