Subversion Repositories Scribus

Rev

Rev 4280 | Rev 4632 | 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
 
23
#include <qguardedptr.h>
24
#include <qobject.h>
25
#include <qmap.h>
26
#include <qvaluevector.h>
27
 
28
#include "pageitem.h"
3938 cbradney 29
#include "scribusapi.h"
3903 cbradney 30
 
31
typedef QValueList< QGuardedPtr<PageItem> > SelectionList;
32
 
3937 cbradney 33
class SCRIBUS_API Selection : public QObject
3903 cbradney 34
{
35
        Q_OBJECT
36
        public:
4135 cbradney 37
                /**
38
                 * Create an empty selection that is not a GUI selection
39
                 * @param  parent
40
                 * @return Selection
41
                 */
4133 cbradney 42
                Selection(QObject*);
4135 cbradney 43
                /**
44
                 * Create an empty selection that may be a GUI selection
45
                 * @param  parent
46
                 * @param  If the selection is to be a GUI selection
47
                 * @return Selection
48
                 */
4133 cbradney 49
                Selection(QObject*, bool);
4135 cbradney 50
                /**
51
                 * Copy a selection
52
                 * NOTE: We are leaving the connections of the items in place
53
                 * and the isGUISelection set in the copy. We cannot disconnect them
54
                 * as they may be connected via the main GUI selection.
55
                 * @param  Other selection
56
                 * @return New selection
57
                 */
4130 cbradney 58
                Selection(const Selection&);
4147 cbradney 59
                Selection& operator=( const Selection & );
3903 cbradney 60
                ~Selection();
61
 
4133 cbradney 62
                bool connectItemToGUI();
3903 cbradney 63
                /**
64
                 * Disconnect all items from the GUI slots.
65
                 * This should not really be necessary if all things are going ok
66
                 * except for within the clearAll function.
67
                 * @return
68
                 */
69
                bool disconnectAllItemsFromGUI();
3936 cbradney 70
                /**
71
                 * @brief Add an item to the selection.
4135 cbradney 72
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 73
                 * @param item Item to add
4280 cbradney 74
                 * @param ignoreGUI Dont connect Item To GUI even if this is a GUI selection
3936 cbradney 75
                 * @return If the item was added
76
                 */
4280 cbradney 77
                bool addItem(PageItem *item, bool ignoreGUI=false);
3936 cbradney 78
                /**
79
                 * @brief Prepend an item to the selection.
4135 cbradney 80
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 81
                 * @param item Item to add
82
                 * @return If the item was added
83
                 */
4133 cbradney 84
                bool prependItem(PageItem *item);
3936 cbradney 85
                /**
86
                 * Unused
87
                 * @return
88
                 */
3903 cbradney 89
                bool addGroup();
3936 cbradney 90
                /**
4135 cbradney 91
                 * Remove an item from list
3936 cbradney 92
                 * @param item
93
                 * @return
94
                 */
4133 cbradney 95
                bool removeItem(PageItem *item);
3936 cbradney 96
                /**
97
                 * Remove the first item from the list
98
                 * @return If the remove was successful
99
                 */
4133 cbradney 100
                bool removeFirst();
3936 cbradney 101
                /**
102
                 * Unused
103
                 * @return
104
                 */
3903 cbradney 105
                bool removeGroup();
3936 cbradney 106
                /**
107
                 * Remove an item from list listNumber and return a pointer to it
108
                 * @param itemIndex Index of the item in the list
109
                 * @return Item
110
                 */
4133 cbradney 111
                PageItem* takeItem(uint itemIndex);
3936 cbradney 112
                /**
4135 cbradney 113
                 * 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
                /**
4135 cbradney 119
                 * Return the count of the selection
3936 cbradney 120
                 * @return
121
                 */
4134 cbradney 122
                uint count() const { return m_SelList.count(); }
3936 cbradney 123
                /**
4135 cbradney 124
                 * Check if the selection is empty.
3939 cbradney 125
                 * @return
3936 cbradney 126
                 */
4135 cbradney 127
                bool isEmpty() const { return m_SelList.count()==0; }
3936 cbradney 128
                /**
129
                 * Clear a list
130
                 * @return
131
                 */
4133 cbradney 132
                bool clear();
3903 cbradney 133
                /**
3936 cbradney 134
                 * See if the first selected item is "me", usually called from an item object with "this".
3903 cbradney 135
                 * @param item
136
                 * @return
137
                 */
4134 cbradney 138
                bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
4133 cbradney 139
                PageItem *itemAt(int index=0);
140
                QStringList getSelectedItemsByName();
141
                bool isMultipleSelection() const { return m_hasGroupSelection; }
142
                bool isGUISelection() const { return m_isGUISelection; }
143
                void setIsGUISelection(bool guiSelection) { m_isGUISelection=guiSelection; }
3903 cbradney 144
 
145
        protected:
4133 cbradney 146
                SelectionList m_SelList;
147
                bool m_hasGroupSelection;
148
                bool m_isGUISelection;
4049 cbradney 149
 
150
        signals:
4130 cbradney 151
                void selectionIsMultiple(bool);
3903 cbradney 152
};
153
 
154
#endif