Subversion Repositories Scribus

Rev

Rev 7575 | Rev 8266 | 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
                /**
4650 subik 38
                 * \brief Create an empty selection that is not a GUI selection
39
                 * @param  parent QObject
4135 cbradney 40
                 */
4650 subik 41
                Selection(QObject* parent);
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();
58
 
4133 cbradney 59
                bool connectItemToGUI();
3903 cbradney 60
                /**
4650 subik 61
                 * \brief Disconnect all items from the GUI slots.
3903 cbradney 62
                 * This should not really be necessary if all things are going ok
63
                 * except for within the clearAll function.
4650 subik 64
                 * @return bool true on success
3903 cbradney 65
                 */
66
                bool disconnectAllItemsFromGUI();
3936 cbradney 67
                /**
68
                 * @brief Add an item to the selection.
4135 cbradney 69
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 70
                 * @param item Item to add
4280 cbradney 71
                 * @param ignoreGUI Dont connect Item To GUI even if this is a GUI selection
3936 cbradney 72
                 * @return If the item was added
73
                 */
4280 cbradney 74
                bool addItem(PageItem *item, bool ignoreGUI=false);
3936 cbradney 75
                /**
76
                 * @brief Prepend an item to the selection.
4135 cbradney 77
                 * If its added to a GUI selection selection and its item 0, its connected to the GUI too
3936 cbradney 78
                 * @param item Item to add
4650 subik 79
                 * @param doEmit call emitAllToGUI()
3936 cbradney 80
                 * @return If the item was added
81
                 */
4632 cbradney 82
                bool prependItem(PageItem *item, bool doEmit=true);
3936 cbradney 83
                /**
4650 subik 84
                 * \brief Unused
3936 cbradney 85
                 */
3903 cbradney 86
                bool addGroup();
3936 cbradney 87
                /**
4650 subik 88
                 * \brief Remove an item from list
89
                 * @param item page item
3936 cbradney 90
                 */
4133 cbradney 91
                bool removeItem(PageItem *item);
3936 cbradney 92
                /**
4650 subik 93
                 * \brief Remove the first item from the list
3936 cbradney 94
                 * @return If the remove was successful
95
                 */
4133 cbradney 96
                bool removeFirst();
3936 cbradney 97
                /**
4650 subik 98
                 * \brief Unused
3936 cbradney 99
                 */
3903 cbradney 100
                bool removeGroup();
3936 cbradney 101
                /**
4650 subik 102
                 * \brief Remove an item from list listNumber and return a pointer to it
3936 cbradney 103
                 * @param itemIndex Index of the item in the list
104
                 * @return Item
105
                 */
4133 cbradney 106
                PageItem* takeItem(uint itemIndex);
3936 cbradney 107
                /**
4650 subik 108
                 * \brief Find an item from the selection and return an index to it
3936 cbradney 109
                 * @param item Item pointer to find in the list
110
                 * @return Item
111
                 */
4134 cbradney 112
                int findItem(PageItem *item) const { return m_SelList.findIndex(item); }
3936 cbradney 113
                /**
4650 subik 114
                 * \brief Return the count of the selection
3936 cbradney 115
                 */
4134 cbradney 116
                uint count() const { return m_SelList.count(); }
3936 cbradney 117
                /**
4650 subik 118
                 * \brief Check if the selection is empty.
3936 cbradney 119
                 */
4135 cbradney 120
                bool isEmpty() const { return m_SelList.count()==0; }
3936 cbradney 121
                /**
4650 subik 122
                 * \brief Clear a list
3936 cbradney 123
                 */
4133 cbradney 124
                bool clear();
3903 cbradney 125
                /**
4650 subik 126
                 * \brief See if the first selected item is "me", usually called from an item object with "this".
127
                 * @param item PageItem reference
3903 cbradney 128
                 */
4134 cbradney 129
                bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
4133 cbradney 130
                PageItem *itemAt(int index=0);
131
                QStringList getSelectedItemsByName();
132
                bool isMultipleSelection() const { return m_hasGroupSelection; }
133
                bool isGUISelection() const { return m_isGUISelection; }
134
                void setIsGUISelection(bool guiSelection) { m_isGUISelection=guiSelection; }
6442 cbradney 135
                double width();
136
                double height();
7575 cbradney 137
                //set the group rectangle properties
138
                void setGroupRect();
139
                void getGroupRect(double *x, double *y, double *w, double *h);
7686 cbradney 140
                //!\brief Test to see if all items in the selection are the same typedef
141
                bool itemsAreSameType();
3903 cbradney 142
 
143
        protected:
4133 cbradney 144
                SelectionList m_SelList;
145
                bool m_hasGroupSelection;
146
                bool m_isGUISelection;
7575 cbradney 147
                double groupX;
148
                double groupY;
149
                double groupW;
150
                double groupH;
151
 
4049 cbradney 152
 
153
        signals:
4130 cbradney 154
                void selectionIsMultiple(bool);
4738 cbradney 155
                void empty();
5859 tsoots 156
                void selectionChanged();
3903 cbradney 157
};
158
 
159
#endif