kspread

selection.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
00003    Copyright (C) 2005-2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef KSPREAD_SELECTION
00022 #define KSPREAD_SELECTION
00023 
00024 #include <qobject.h>
00025 
00026 #include <kdebug.h>
00027 
00028 #include "region.h"
00029 
00030 namespace KSpread
00031 {
00032 class View;
00033 
00034 class Selection : public QObject, public Region
00035 {
00036   Q_OBJECT
00037 public:
00038   Selection(View*);
00039   Selection(const Selection&);
00040   ~Selection();
00041 
00045   void initialize(const QPoint&, Sheet* sheet = 0);
00049   void initialize(const QRect&, Sheet* sheet = 0);
00053   void initialize(const Region&, Sheet* sheet = 0);
00054 
00058   void update();
00062   void update(const QPoint&);
00063 
00067   void extend(const QPoint&, Sheet* sheet = 0);
00071   void extend(const QRect&, Sheet* sheet = 0);
00075   void extend(const Region&);
00076 
00081   virtual Element* eor(const QPoint& point, Sheet* sheet = 0);
00082 
00086   const QPoint& anchor() const;
00090   const QPoint& cursor() const;
00094   const QPoint& marker() const;
00095 
00099   bool isSingular() const;
00103   QRect selectionHandleArea() const;
00104 
00108   QString name(Sheet* originSheet = 0) const;
00109 
00114   void setSheet(Sheet* sheet);
00118   Sheet* sheet() const;
00119 
00123   void setActiveElement(const QPoint& point);
00127   void setActiveElement(uint number);
00131   Element* activeElement() const;
00136   void setActiveSubRegion(uint start, uint length);
00140   QString activeSubRegionName() const;
00144   void clearSubRegion();
00148   void fixSubRegionDimension();
00152   virtual void clear();
00153 
00154 
00158   void setMultipleSelection(bool state);
00159 
00160   QRect lastRange(bool extend = true) const;
00161   QRect extendToMergedAreas(QRect area) const;
00162 
00163   const QValueList<QColor>& colors() const;
00164 
00165   // TODO Stefan #2: replace this
00166   QRect selection(bool extend = true) const;
00167 
00168 signals:
00169   void changed(const Region&);
00170 
00171 protected:
00172   class Point;
00173   class Range;
00174 
00175   virtual Region::Point* createPoint(const QPoint&) const;
00176   virtual Region::Point* createPoint(const QString&) const;
00177   virtual Region::Point* createPoint(const Point&) const;
00178   virtual Region::Range* createRange(const QRect&) const;
00179   virtual Region::Range* createRange(const QString&) const;
00180   virtual Region::Range* createRange(const Range&) const;
00181 
00182 private:
00183   class Private;
00184   Private *d;
00185 };
00186 
00187 /***************************************************************************
00188   class Selection::Point
00189 ****************************************************************************/
00190 
00191 class Selection::Point : public Region::Point
00192 {
00193 public:
00194   Point(const QPoint& point);
00195   Point(const QString& string);
00196 
00197   void setColor(const QColor& color) { m_color = color; }
00198   virtual const QColor& color() const { return m_color; }
00199 
00200   bool columnFixed() const { return m_columnFixed; }
00201   bool rowFixed() const { return m_rowFixed; }
00202 
00203 protected:
00204 
00205 private:
00206   QColor m_color;
00207   bool m_columnFixed : 1;
00208   bool m_rowFixed    : 1;
00209 };
00210 
00211 /***************************************************************************
00212   class Selection::Range
00213 ****************************************************************************/
00214 
00215 class Selection::Range : public Region::Range
00216 {
00217 public:
00218   Range(const QRect& rect);
00219   Range(const QString& string);
00220 
00221   virtual bool isColorizable() const { return true; }
00222 
00223   void setColor(const QColor& color) { m_color = color; }
00224   const QColor& color() const { return m_color; }
00225 
00226 protected:
00227 
00228 private:
00229   QColor m_color;
00230   bool m_leftFixed   : 1;
00231   bool m_rightFixed  : 1;
00232   bool m_topFixed    : 1;
00233   bool m_bottomFixed : 1;
00234 };
00235 
00236 } // namespace KSpread
00237 
00238 
00239 /***************************************************************************
00240   kdDebug support
00241 ****************************************************************************/
00242 
00243 inline kdbgstream operator<<( kdbgstream str, const KSpread::Selection& s )
00244 {
00245   str << "Selection = " << s.name();
00246   return str;
00247 }
00248 
00249 inline kndbgstream operator<<( kndbgstream str, const KSpread::Selection& )
00250 {
00251   return str;
00252 }
00253 
00254 #endif // KSPREAD_SELECTION
KDE Home | KDE Accessibility Home | Description of Access Keys