Scribus
Open source desktop publishing at your fingertips
selection.h
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 */
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 <QList>
24 #include <QMap>
25 #include <QObject>
26 #include <QPointer>
27 #include <QRectF>
28 
29 #include "pageitem.h"
30 #include "scribusapi.h"
31 
32 typedef QList< QPointer<PageItem> > SelectionList;
33 
34 class SCRIBUS_API Selection : public QObject
35 {
36  Q_OBJECT
37  public:
42  explicit Selection(QObject* parent); // otherwise implicit conversion Selection* -> Selection& is possible
48  Selection(QObject* parent, bool guiSelection);
56  Selection(const Selection& other);
57  Selection& operator=( const Selection & );
58  ~Selection();
59 
63  void copy(Selection& other, bool emptyOther);
64 
65  bool connectItemToGUI();
72  bool disconnectAllItemsFromGUI();
80  bool addItem(PageItem *item, bool ignoreGUI=false);
88  bool prependItem(PageItem *item, bool doEmit=true);
89 
90  bool containsItem(PageItem *item) const { return m_SelList.contains(item); }
94  bool addGroup();
99  bool removeItem(PageItem *item);
104  bool removeFirst();
108  bool removeGroup();
114  PageItem* takeItem(int itemIndex);
120  int findItem(PageItem *item) const { return m_SelList.indexOf(item); }
124  int count() const { return m_SelList.count(); }
128  bool isEmpty() const { return m_SelList.count()==0; }
132  bool clear();
137  bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
138  const SelectionList& selectionList() const {return m_SelList;}
139  PageItem *itemAt(int index=0) { return itemAt_(index); }
140  const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
141  QList<PageItem*> items() const;
142  QStringList getSelectedItemsByName() const;
143  bool isMultipleSelection() const { return (m_SelList.count() > 1); }
144  bool isGUISelection() const { return m_isGUISelection; }
145  double width() const;
146  double height() const;
147  //set the group rectangle properties
148  void setGroupRect();
149  void getGroupRect(double *x, double *y, double *w, double *h);
150  QRectF getGroupRect();
151  void getVisualGroupRect(double *x, double *y, double *w, double *h);
152  QRectF getVisualGroupRect();
154  bool itemsAreSameType() const;
155 
160  int objectsLayer(void) const;
161 
166  bool objectsHaveSameParent(void) const;
167 
168  bool signalsDelayed(void);
169  void delaySignalsOn(void);
170  void delaySignalsOff(void);
171 
172  protected:
173  PageItem *itemAt_(int index=0);
174  SelectionList m_SelList;
175  bool m_isGUISelection;
176  double groupX;
177  double groupY;
178  double groupW;
179  double groupH;
180 
181  double visualGX;
182  double visualGY;
183  double visualGW;
184  double visualGH;
185 
186  int m_delaySignals;
187  bool m_sigSelectionChanged;
188  bool m_sigSelectionIsMultiple;
189 
190  void sendSignals(bool guiConnect = true);
191 
192  signals:
193  void selectionIsMultiple(bool);
194  void empty();
195  void selectionChanged();
196 };
197 
198 #endif
int count() const
Return the count of the selection.
Definition: selection.h:124
int findItem(PageItem *item) const
Find an item from the selection and return an index to it.
Definition: selection.h:120
bool primarySelectionIs(const PageItem *item) const
See if the first selected item is "me", usually called from an item object with "this".
Definition: selection.h:137
bool isEmpty() const
Check if the selection is empty.
Definition: selection.h:128
Definition: pageitem.h:92
Definition: selection.h:34