Subversion Repositories Scribus

Rev

Rev 8501 | Rev 8735 | 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
 
8501 cbradney 23
#include <qpointer.h>
3903 cbradney 24
#include <qobject.h>
25
#include <qmap.h>
8501 cbradney 26
#include <q3valuevector.h>
27
//Added by qt3to4:
28
#include <Q3ValueList>
3903 cbradney 29
 
30
#include "pageitem.h"
3938 cbradney 31
#include "scribusapi.h"
3903 cbradney 32
 
8501 cbradney 33
typedef Q3ValueList< QPointer<PageItem> > SelectionList;
3903 cbradney 34
 
3937 cbradney 35
class SCRIBUS_API Selection : public QObject
3903 cbradney 36
{
37
        Q_OBJECT
38
        public:
4135 cbradney 39
                /**
4650 subik 40
                 * \brief Create an empty selection that is not a GUI selection
41
                 * @param  parent QObject
4135 cbradney 42
                 */
8266 avox 43
                explicit Selection(QObject* parent);   // otherwise implicit conversion Selection* -> Selection& is possible
4135 cbradney 44
                /**
4650 subik 45
                 * \brief Create an empty selection that may be a GUI selection
46
                 * @param  parent QObject
47
                 * @param  guiSelection If the selection is to be a GUI selection
4135 cbradney 48
                 */
4650 subik 49
                Selection(QObject* parent, bool guiSelection);
4135 cbradney 50
                /**
4650 subik 51
                 * \brief Copy a selection
52
                 * \note We are leaving the connections of the items in place
4135 cbradney 53
                 * and the isGUISelection set in the copy. We cannot disconnect them
54
                 * as they may be connected via the main GUI selection.
4650 subik 55
                 * @param  other selection
4135 cbradney 56
                 */
4650 subik 57
                Selection(const Selection& other);
4147 cbradney 58
                Selection& operator=( const Selection & );
3903 cbradney 59
                ~Selection();
60
 
4133 cbradney 61
                bool connectItemToGUI();
3903 cbradney 62
                /**
4650 subik 63
                 * \brief Disconnect all items from the GUI slots.
3903 cbradney 64
                 * This should not really be necessary if all things are going ok
65
                 * except for within the clearAll function.
4650 subik 66
                 * @return bool true on success
3903 cbradney 67
                 */
68
                bool disconnectAllItemsFromGUI();
3936 cbradney 69
                /**
70
                 * @brief Add an item to the selection.
4135 cbradney 71
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 72
                 * @param item Item to add
4280 cbradney 73
                 * @param ignoreGUI Dont connect Item To GUI even if this is a GUI selection
3936 cbradney 74
                 * @return If the item was added
75
                 */
4280 cbradney 76
                bool addItem(PageItem *item, bool ignoreGUI=false);
3936 cbradney 77
                /**
78
                 * @brief Prepend an item to the selection.
4135 cbradney 79
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 80
                 * @param item Item to add
4650 subik 81
                 * @param doEmit call emitAllToGUI()
3936 cbradney 82
                 * @return If the item was added
83
                 */
4632 cbradney 84
                bool prependItem(PageItem *item, bool doEmit=true);
3936 cbradney 85
                /**
4650 subik 86
                 * \brief Unused
3936 cbradney 87
                 */
3903 cbradney 88
                bool addGroup();
3936 cbradney 89
                /**
4650 subik 90
                 * \brief Remove an item from list
91
                 * @param item page item
3936 cbradney 92
                 */
4133 cbradney 93
                bool removeItem(PageItem *item);
3936 cbradney 94
                /**
4650 subik 95
                 * \brief Remove the first item from the list
3936 cbradney 96
                 * @return If the remove was successful
97
                 */
4133 cbradney 98
                bool removeFirst();
3936 cbradney 99
                /**
4650 subik 100
                 * \brief Unused
3936 cbradney 101
                 */
3903 cbradney 102
                bool removeGroup();
3936 cbradney 103
                /**
4650 subik 104
                 * \brief Remove an item from list listNumber and return a pointer to it
3936 cbradney 105
                 * @param itemIndex Index of the item in the list
106
                 * @return Item
107
                 */
8613 cbradney 108
                PageItem* takeItem(int itemIndex);
3936 cbradney 109
                /**
4650 subik 110
                 * \brief Find an item from the selection and return an index to it
3936 cbradney 111
                 * @param item Item pointer to find in the list
112
                 * @return Item
113
                 */
4134 cbradney 114
                int findItem(PageItem *item) const { return m_SelList.findIndex(item); }
3936 cbradney 115
                /**
4650 subik 116
                 * \brief Return the count of the selection
3936 cbradney 117
                 */
4134 cbradney 118
                uint count() const { return m_SelList.count(); }
3936 cbradney 119
                /**
4650 subik 120
                 * \brief Check if the selection is empty.
3936 cbradney 121
                 */
4135 cbradney 122
                bool isEmpty() const { return m_SelList.count()==0; }
3936 cbradney 123
                /**
4650 subik 124
                 * \brief Clear a list
3936 cbradney 125
                 */
4133 cbradney 126
                bool clear();
3903 cbradney 127
                /**
4650 subik 128
                 * \brief See if the first selected item is "me", usually called from an item object with "this".
129
                 * @param item PageItem reference
3903 cbradney 130
                 */
4134 cbradney 131
                bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
8266 avox 132
                PageItem *itemAt(int index=0) { return itemAt_(index); }
133
                const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
134
                QStringList getSelectedItemsByName() const;
4133 cbradney 135
                bool isMultipleSelection() const { return m_hasGroupSelection; }
136
                bool isGUISelection() const { return m_isGUISelection; }
137
                void setIsGUISelection(bool guiSelection) { m_isGUISelection=guiSelection; }
8266 avox 138
                double width() const;
139
                double height() const;
7575 cbradney 140
                //set the group rectangle properties
141
                void setGroupRect();
142
                void getGroupRect(double *x, double *y, double *w, double *h);
7686 cbradney 143
                //!\brief Test to see if all items in the selection are the same typedef
8266 avox 144
                bool itemsAreSameType() const;
3903 cbradney 145
 
146
        protected:
8266 avox 147
                PageItem *itemAt_(int index=0);
4133 cbradney 148
                SelectionList m_SelList;
149
                bool m_hasGroupSelection;
150
                bool m_isGUISelection;
7575 cbradney 151
                double groupX;
152
                double groupY;
153
                double groupW;
154
                double groupH;
155
 
4049 cbradney 156
 
157
        signals:
4130 cbradney 158
                void selectionIsMultiple(bool);
4738 cbradney 159
                void empty();
5859 tsoots 160
                void selectionChanged();
3903 cbradney 161
};
162
 
163
#endif