Back to index

scribus-ng  1.3.4.dfsg+svn20071115
selection.h
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008        copyright            : (C) 2005 by Craig Bradney
00009        email                : cbradney@zip.com.au
00010 ***************************************************************************/
00011 
00012 /***************************************************************************
00013 *                                                                         *
00014 *   This program is free software; you can redistribute it and/or modify  *
00015 *   it under the terms of the GNU General Public License as published by  *
00016 *   the Free Software Foundation; either version 2 of the License, or     *
00017 *   (at your option) any later version.                                   *
00018 *                                                                         *
00019 ***************************************************************************/
00020 #ifndef SELECTION_H
00021 #define SELECTION_H
00022 
00023 #include <qguardedptr.h>
00024 #include <qobject.h>
00025 #include <qmap.h>
00026 #include <qvaluevector.h>
00027 
00028 #include "pageitem.h"
00029 #include "scribusapi.h"
00030 
00031 typedef QValueList< QGuardedPtr<PageItem> > SelectionList;
00032 
00033 class SCRIBUS_API Selection : public QObject
00034 {
00035        Q_OBJECT
00036        public:
00041               explicit Selection(QObject* parent);   // otherwise implicit conversion Selection* -> Selection& is possible
00047               Selection(QObject* parent, bool guiSelection);
00055               Selection(const Selection& other);
00056               Selection& operator=( const Selection & );
00057               ~Selection();
00058               
00062               void copy(Selection& other, bool copyGUISelectionn, bool emptyOther);
00063               
00064               bool connectItemToGUI();
00071               bool disconnectAllItemsFromGUI();
00079               bool addItem(PageItem *item, bool ignoreGUI=false);
00087               bool prependItem(PageItem *item, bool doEmit=true);
00091               bool addGroup();
00096               bool removeItem(PageItem *item);
00101               bool removeFirst();
00105               bool removeGroup();
00111               PageItem* takeItem(uint itemIndex);
00117               int findItem(PageItem *item) const { return m_SelList.findIndex(item); }
00121               uint count() const { return m_SelList.count(); }
00125               bool isEmpty() const { return m_SelList.count()==0; }
00129               bool clear();
00134               bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
00135               PageItem *itemAt(int index=0) { return itemAt_(index); }
00136               const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
00137               QStringList getSelectedItemsByName() const;
00138               bool isMultipleSelection() const { return m_hasGroupSelection; }
00139               bool isGUISelection() const { return m_isGUISelection; }
00140               void setIsGUISelection(bool guiSelection) { m_isGUISelection=guiSelection; }
00141               double width() const;
00142               double height() const;
00143               //set the group rectangle properties
00144               void setGroupRect();
00145               void getGroupRect(double *x, double *y, double *w, double *h);
00147               bool itemsAreSameType() const;
00148               
00149        protected:
00150               PageItem *itemAt_(int index=0);
00151               SelectionList m_SelList;
00152               bool m_hasGroupSelection;
00153               bool m_isGUISelection;
00154               double groupX;
00155               double groupY;
00156               double groupW;
00157               double groupH;
00158 
00159               
00160        signals:
00161               void selectionIsMultiple(bool);
00162               void empty();
00163               void selectionChanged();
00164 };
00165 
00166 #endif