krita

kis_iteratorpixeltrait.h

00001 /* This file is part of the KDE project
00002  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>, the original iteratorpixel
00003  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>, made it into a trait
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program 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
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KIS_ITERATORPIXELTRAIT_H_
00021 #define KIS_ITERATORPIXELTRAIT_H_
00022 
00023 #include "kis_iterator.h"
00024 #include <kis_paint_device.h>
00025 
00026 template< typename _iTp>
00027 class KisIteratorPixelTrait
00028 {
00029 public:
00030     KisIteratorPixelTrait(KisPaintDevice * ndevice, _iTp *underlyingIterator)
00031     :    m_device(ndevice),
00032         m_underlyingIterator(underlyingIterator)
00033     {
00034         m_selectionIterator = NULL;
00035     };
00036 
00037     ~KisIteratorPixelTrait()
00038     {
00039         delete m_selectionIterator;
00040     };
00041 
00042     KisIteratorPixelTrait(const KisIteratorPixelTrait& rhs)
00043     {
00044         if (this == &rhs)
00045             return;
00046         m_device = rhs.m_device;
00047         m_underlyingIterator = rhs.m_underlyingIterator;
00048 
00049         if (rhs.m_selectionIterator) {
00050             m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
00051         } else {
00052             m_selectionIterator = 0;
00053         }
00054     }
00055 
00056     KisIteratorPixelTrait& operator=(const KisIteratorPixelTrait& rhs)
00057     {
00058         if (this == &rhs)
00059             return *this;
00060         m_device = rhs.m_device;
00061         m_underlyingIterator = rhs.m_underlyingIterator;
00062 
00063         delete m_selectionIterator;
00064         if (rhs.m_selectionIterator) {
00065             m_selectionIterator = new _iTp(*rhs.m_selectionIterator);
00066         } else {
00067             m_selectionIterator = 0;
00068         }
00069 
00070         return *this;
00071     }
00072 
00073 
00074 public:
00079     inline Q_UINT8 operator[](int index) const
00080             { return m_underlyingIterator->rawData()[index]; };
00081 
00085     inline bool isSelected() const
00086         {
00087             if (m_selectionIterator)
00088                 return *(m_selectionIterator->rawData()) > SELECTION_THRESHOLD;
00089             else
00090                 return true;
00091         };
00092 
00096     inline Q_UINT8 selectedness() const
00097         {
00098             if (m_selectionIterator)
00099                 return *(m_selectionIterator->rawData());
00100             else {
00101                 return MAX_SELECTED;
00102             }
00103         };
00104 
00110     inline Q_UINT8 * selectionMask() const
00111         {
00112             if ( m_selectionIterator )
00113                 return m_selectionIterator->rawData();
00114             else
00115                 return 0;
00116         }
00117 
00118 
00119 protected:
00120     KisPaintDevice *m_device;
00121 
00122     inline void advance(int n){if (m_selectionIterator) for(int i=0; i< n; i++) ++(*m_selectionIterator);};
00123 
00124     void setSelectionIterator(_iTp *si){m_selectionIterator = si;};
00125 
00126     _iTp *m_underlyingIterator;
00127     _iTp *m_selectionIterator;
00128 };
00129 
00130 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys