krita

kis_fill_painter.h

00001 /*
00002  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
00003  *  Copyright (c) 2004 Bart Coppens <kde@bartcoppens.be>
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 #ifndef KIS_FILL_PAINTER_H_
00020 #define KIS_FILL_PAINTER_H_
00021 
00022 #include <qrect.h>
00023 
00024 #include "kis_meta_registry.h"
00025 #include "kis_color.h"
00026 #include "kis_colorspace_factory_registry.h"
00027 #include "kis_painter.h"
00028 #include "kis_types.h"
00029 #include <koffice_export.h>
00030 
00031 class KisPattern;
00032 
00033 // XXX: Filling should set dirty rect.
00038 class KRITACORE_EXPORT KisFillPainter : public KisPainter
00039 {
00040 
00041     typedef KisPainter super;
00042 
00043 public:
00044 
00049     KisFillPainter();
00053     KisFillPainter(KisPaintDeviceSP device);
00054 
00058     void eraseRect(Q_INT32 x1, Q_INT32 y1, Q_INT32 w, Q_INT32 h);
00062     void eraseRect(const QRect& rc);
00063 
00067     void fillRect(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, const KisColor& c);
00071     void fillRect(const QRect& rc, const KisColor& c);
00072 
00076     void fillRect(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, const KisColor& c, Q_UINT8 opacity);
00080     void fillRect(const QRect& rc, const KisColor& c, Q_UINT8 opacity);
00081 
00086     void fillRect(Q_INT32 x1, Q_INT32 y1, Q_INT32 w, Q_INT32 h, KisPattern * pattern);
00090     void fillRect(const QRect& rc, KisPattern * pattern);
00091 
00096     void fillColor(int startX, int startY);
00097 
00102     void fillPattern(int startX, int startY);
00103 
00107     KisSelectionSP createFloodSelection(int startX, int startY);
00108 
00113     void setFillThreshold(int threshold);
00115     int fillThreshold() const { return m_threshold; }
00116 
00118     void setWidth(int w) { m_width = w; }
00119 
00121     void setHeight(int h) { m_height = h; }
00122 
00125     bool sampleMerged() const { return m_sampleMerged; }
00127     void setSampleMerged(bool set) { m_sampleMerged = set; }
00128 
00130     bool careForSelection() const { return m_careForSelection; }
00132     void setCareForSelection(bool set) { m_careForSelection = set; }
00133 
00139     bool fuzzyFill() const { return m_fuzzy; }
00141     void setFuzzyFill(bool set) { m_fuzzy = set; }
00142 
00143 private:
00144     // for floodfill
00145     void genericFillStart(int startX, int startY);
00146     void genericFillEnd(KisPaintDeviceSP filled);
00147 
00148     KisSelectionSP m_selection;
00149 
00150     int m_threshold;
00151     int m_size;
00152     int m_width, m_height;
00153     QRect m_rect;
00154     bool m_sampleMerged;
00155     bool m_careForSelection;
00156     bool m_fuzzy;
00157 };
00158 
00159 
00160 inline
00161 void KisFillPainter::fillRect(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, const KisColor& c)
00162 {
00163     fillRect(x, y, w, h, c, OPACITY_OPAQUE);
00164 }
00165 
00166 inline
00167 void KisFillPainter::fillRect(const QRect& rc, const KisColor& c)
00168 {
00169     fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, OPACITY_OPAQUE);
00170 }
00171 
00172 inline
00173 void KisFillPainter::eraseRect(Q_INT32 x1, Q_INT32 y1, Q_INT32 w, Q_INT32 h)
00174 {
00175     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
00176     KisColor c(Qt::black, cs);
00177     fillRect(x1, y1, w, h, c, OPACITY_TRANSPARENT);
00178 }
00179 
00180 inline
00181 void KisFillPainter::eraseRect(const QRect& rc)
00182 {
00183     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
00184     KisColor c(Qt::black, cs);
00185     fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, OPACITY_TRANSPARENT);
00186 }
00187 
00188 inline
00189 void KisFillPainter::fillRect(const QRect& rc, const KisColor& c, Q_UINT8 opacity)
00190 {
00191     fillRect(rc.x(), rc.y(), rc.width(), rc.height(), c, opacity);
00192 }
00193 
00194 inline
00195 void KisFillPainter::fillRect(const QRect& rc, KisPattern *pattern)
00196 {
00197     fillRect(rc.x(), rc.y(), rc.width(), rc.height(), pattern);
00198 }
00199 
00200 inline
00201 void KisFillPainter::setFillThreshold(int threshold)
00202 {
00203     m_threshold = threshold;
00204 }
00205 
00206 
00207 #endif //KIS_FILL_PAINTER_H_
KDE Home | KDE Accessibility Home | Description of Access Keys