krita

kis_selection.h

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  this program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the gnu general public license as published by
00006  *  the free software foundation; either version 2 of the license, or
00007  *  (at your option) any later version.
00008  *
00009  *  this program is distributed in the hope that it will be useful,
00010  *  but without any warranty; without even the implied warranty of
00011  *  merchantability or fitness for a particular purpose.  see the
00012  *  gnu general public license for more details.
00013  *
00014  *  you should have received a copy of the gnu general public license
00015  *  along with this program; if not, write to the free software
00016  *  foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
00017  */
00018 #ifndef KIS_SELECTION_H_
00019 #define KIS_SELECTION_H_
00020 
00021 #include <qrect.h>
00022 
00023 #include "kis_types.h"
00024 #include "kis_paint_device.h"
00025 
00026 #include <koffice_export.h>
00027 
00028 
00029 enum enumSelectionMode {
00030     SELECTION_ADD,
00031     SELECTION_SUBTRACT
00032 };
00033 
00043 class KRITACORE_EXPORT KisSelection : public KisPaintDevice {
00044 
00045     typedef KisPaintDevice super;
00046 
00047 public:
00053     KisSelection(KisPaintDeviceSP dev);
00054 
00058     KisSelection();
00059     
00063     KisSelection(const KisSelection& rhs);
00064     
00065     virtual ~KisSelection();
00066 
00067     // Returns selectedness, or 0 if invalid coordinates
00068     Q_UINT8 selected(Q_INT32 x, Q_INT32 y);
00069 
00070     void setSelected(Q_INT32 x, Q_INT32 y, Q_UINT8 s);
00071 
00072     QImage maskImage();
00073 
00074     void select(QRect r);
00075 
00076     void invert();
00077 
00078     void clear(QRect r);
00079 
00080     void clear();
00081 
00083     bool isTotallyUnselected(QRect r);
00084 
00091     bool isProbablyTotallyUnselected(QRect r);
00092 
00097     QRect selectedRect() const;
00098 
00103     QRect selectedExactRect() const;
00104 
00105     void paintSelection(QImage img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00106     void paintSelection(QImage img, const QRect& scaledImageRect, const QSize& scaledImageSize, const QSize& imageSize);
00107 
00108     void startCachingExactRect();
00109     void stopCachingExactRect();
00110 
00111     // if the parent layer is interested in keeping up to date with the dirtyness
00112     // of this layer, set to true
00113     void setInterestedInDirtyness(bool b) { m_dirty = b; }
00114     bool interestedInDirtyness() const { return m_dirty; }
00115 
00116     virtual void setDirty(const QRect & rc);
00117     virtual void setDirty();
00118     inline KisPaintDeviceSP parentPaintDevice() { return m_parentPaintDevice; }
00119 private:
00120     void paintUniformSelectionRegion(QImage img, const QRect& imageRect, const QRegion& uniformRegion);
00121 
00122 private:
00123 
00124     // We don't want these methods to be used on selections:
00125     void extent(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const 
00126         { 
00127             KisPaintDevice::extent(x,y,w,h);
00128         }
00129     
00130     QRect extent() const { return KisPaintDevice::extent(); }
00131     
00132     void exactBounds(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const 
00133         {
00134             return KisPaintDevice::exactBounds(x,y,w,h);
00135         }   
00136 
00137     QRect exactBounds() const
00138         {
00139             return KisPaintDevice::exactBounds();
00140         }
00141 
00142     QRect exactBoundsOldMethod() const 
00143         {
00144             return KisPaintDevice::exactBoundsOldMethod();
00145         }
00146 
00147     QRect exactBoundsImprovedOldMethod() const
00148         {
00149             return KisPaintDevice::exactBoundsImprovedOldMethod();
00150         }
00151 
00152 
00153 private:
00154     KisPaintDeviceSP m_parentPaintDevice;
00155     bool m_doCacheExactRect;
00156     QRect m_cachedExactRect;
00157     bool m_dirty;
00158 };
00159 
00160 #endif // KIS_SELECTION_H_
KDE Home | KDE Accessibility Home | Description of Access Keys