krita

kis_paint_device.h

00001 /*
00002  *  copyright (c) 2002 patrick julien <freak@codepimps.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_PAINT_DEVICE_IMPL_H_
00019 #define KIS_PAINT_DEVICE_IMPL_H_
00020 
00021 #include <qcolor.h>
00022 #include <qobject.h>
00023 #include <qpixmap.h>
00024 #include <qptrlist.h>
00025 #include <qrect.h>
00026 #include <qvaluelist.h>
00027 #include <qstring.h>
00028 
00029 #include "kis_types.h"
00030 #include "kdebug.h"
00031 #include "kis_global.h"
00032 #include "kis_image.h"
00033 #include "kis_colorspace.h"
00034 #include "kis_canvas_controller.h"
00035 #include "kis_color.h"
00036 #include <koffice_export.h>
00037 
00038 class DCOPObject;
00039 
00040 class QImage;
00041 class QSize;
00042 class QPoint;
00043 class QWMatrix;
00044 class QTimer;
00045 
00046 class KNamedCommand;
00047 
00048 class KoStore;
00049 
00050 class KisExifInfo;
00051 class KisHLineIteratorPixel;
00052 class KisImage;
00053 class KisRectIteratorPixel;
00054 class KisVLineIteratorPixel;
00055 class KisRandomAccessorPixel;
00056 class KisRandomSubAccessorPixel;
00057 class KisUndoAdapter;
00058 class KisFilter;
00059 class KisDataManager;
00060 typedef KSharedPtr<KisDataManager> KisDataManagerSP;
00061 
00062 class KisMemento;
00063 typedef KSharedPtr<KisMemento> KisMementoSP;
00064 
00065 
00073 class KRITACORE_EXPORT KisPaintDevice
00074     : public QObject
00075     , public KShared
00076 {
00077 
00078         Q_OBJECT
00079 
00080 public:
00081 
00088     KisPaintDevice(KisColorSpace * colorSpace, const char * name = 0);
00089 
00098     KisPaintDevice(KisLayer *parentLayer, KisColorSpace * colorSpace, const char * name = 0);
00099 
00100     KisPaintDevice(const KisPaintDevice& rhs);
00101     virtual ~KisPaintDevice();
00102     virtual DCOPObject *dcopObject();
00103 
00104     void lock(bool lock) { m_lock = lock; }
00105 
00106 public:
00107 
00111     virtual bool write(KoStore *store);
00112 
00116     virtual bool read(KoStore *store);
00117 
00118 public:
00119 
00123     virtual void move(Q_INT32 x, Q_INT32 y);
00124 
00128     virtual void move(const QPoint& pt);
00129 
00134     virtual KNamedCommand * moveCommand(Q_INT32 x, Q_INT32 y);
00135 
00139     bool contains(Q_INT32 x, Q_INT32 y) const;
00140 
00144     bool contains(const QPoint& pt) const;
00145 
00152     virtual void extent(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const;
00153     virtual QRect extent() const;
00154 
00162     bool extentIsValid() const;
00163 
00165     void setExtentIsValid(bool isValid);
00166 
00171     virtual void exactBounds(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const;
00172     virtual QRect exactBounds() const;
00173     virtual QRect exactBoundsOldMethod() const;
00174     virtual QRect exactBoundsImprovedOldMethod() const;
00175 
00179     void crop(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00180 
00182     void crop(QRect r);
00183 
00187     virtual void clear();
00188 
00192     void fill(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, const Q_UINT8 *fillPixel);
00193 
00204     virtual void readBytes(Q_UINT8 * data, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00205 
00214     virtual void writeBytes(const Q_UINT8 * data, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00215 
00220     Q_INT32 numContiguousColumns(Q_INT32 x, Q_INT32 minY, Q_INT32 maxY);
00221 
00226     Q_INT32 numContiguousRows(Q_INT32 y, Q_INT32 minX, Q_INT32 maxX);
00227 
00232     Q_INT32 rowStride(Q_INT32 x, Q_INT32 y);
00233 
00237     KDE_DEPRECATED const Q_UINT8* pixel(Q_INT32 x, Q_INT32 y);
00238 
00242     KDE_DEPRECATED Q_UINT8* writablePixel(Q_INT32 x, Q_INT32 y);
00243 
00247     virtual void convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
00248 
00253     virtual void setProfile(KisProfile * profile);
00254     
00259     virtual void convertFromQImage(const QImage& img, const QString &srcProfileName, Q_INT32 offsetX = 0, Q_INT32 offsetY = 0);
00260 
00273     virtual QImage convertToQImage(KisProfile *  dstProfile, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, float exposure = 0.0f);
00274 
00283     virtual QImage convertToQImage(KisProfile *  dstProfile, float exposure = 0.0f);
00284 
00290     KisPaintDeviceSP createThumbnailDevice(Q_INT32 w, Q_INT32 h);
00291             
00297     virtual QImage createThumbnail(Q_INT32 maxw, Q_INT32 maxh);
00298 
00299 
00308     bool pixel(Q_INT32 x, Q_INT32 y, QColor *c, Q_UINT8 *opacity);
00309 
00310 
00320     bool pixel(Q_INT32 x, Q_INT32 y, KisColor * kc);
00321 
00325     KisColor colorAt(Q_INT32 x, Q_INT32 y);
00326 
00342     bool setPixel(Q_INT32 x, Q_INT32 y, const QColor& c, Q_UINT8 opacity);
00343 
00344     bool setPixel(Q_INT32 x, Q_INT32 y, const KisColor& kc);
00345 
00346     KisColorSpace * colorSpace() const;
00347 
00348     KisDataManagerSP dataManager() const;
00349 
00353     void setData(KisDataManagerSP data, KisColorSpace * colorSpace);
00354 
00358     Q_INT32 getX() const;
00359 
00363     Q_INT32 getY() const;
00364 
00368     void setX(Q_INT32 x);
00369 
00373     void setY(Q_INT32 y);
00374 
00375 
00379     virtual Q_INT32 pixelSize() const;
00380 
00384     virtual Q_INT32 nChannels() const;
00385 
00390     KisImage *image() const;
00391 
00396     KisLayer *parentLayer() const;
00397 
00402     void setParentLayer(KisLayer *parentLayer);
00403 
00407     virtual void setDirty(const QRect & rc);
00408 
00412     virtual void setDirty();
00413     
00414     
00418     void mirrorX();
00422     void mirrorY();
00423 
00424     KisMementoSP getMemento();
00425     void rollback(KisMementoSP memento);
00426     void rollforward(KisMementoSP memento);
00427 
00431     KisRectIteratorPixel createRectIterator(Q_INT32 left, Q_INT32 top, Q_INT32 w, Q_INT32 h, bool writable);
00432 
00436     KisHLineIteratorPixel createHLineIterator(Q_INT32 x, Q_INT32 y, Q_INT32 w, bool writable);
00437 
00441     KisVLineIteratorPixel createVLineIterator(Q_INT32 x, Q_INT32 y, Q_INT32 h, bool writable);
00442 
00449     KisRandomAccessorPixel createRandomAccessor(Q_INT32 x, Q_INT32 y, bool writable);
00450     
00454     KisRandomSubAccessorPixel createRandomSubAccessor();
00455     
00457     KisSelectionSP selection();
00458 
00460     void addSelection(KisSelectionSP selection);
00461 
00463     void subtractSelection(KisSelectionSP selection);
00464 
00466     bool hasSelection();
00467 
00469     bool selectionDeselected();
00470 
00472     void deselect();
00473 
00475     void reselect();
00476         
00478     void clearSelection();
00479 
00484     void applySelectionMask(KisSelectionSP mask);
00485 
00491     KisSelectionSP setSelection(KisSelectionSP selection);
00492 
00496     void emitSelectionChanged();
00497 
00503     void emitSelectionChanged(const QRect& r);
00504 
00505     
00506     KisUndoAdapter *undoAdapter() const;
00507 
00512     KisExifInfo* exifInfo();
00516     bool hasExifInfo() { return m_exifInfo != 0; }
00517 signals:
00518     void positionChanged(KisPaintDeviceSP device);
00519     void ioProgress(Q_INT8 percentage);
00520     void profileChanged(KisProfile *  profile);
00521 
00522 private slots:
00523 
00524     void runBackgroundFilters();
00525     
00526 private:
00527     KisPaintDevice& operator=(const KisPaintDevice&);
00528 
00529 protected:
00530     KisDataManagerSP m_datamanager;
00531     
00532 private:
00533     /* The KisLayer that contains this paint device, or 0 if this is not 
00534      * part of a layer.
00535      */
00536     KisLayer *m_parentLayer;
00537 
00538     bool m_extentIsValid;
00539 
00540     Q_INT32 m_x;
00541     Q_INT32 m_y;
00542     KisColorSpace * m_colorSpace;
00543     // Cached for quick access
00544     Q_INT32 m_pixelSize;
00545     Q_INT32 m_nChannels;
00546 
00547     // Whether the selection is active
00548     bool m_hasSelection;
00549     bool m_selectionDeselected;
00550     
00551     // Contains the actual selection. For now, there can be only
00552     // one selection per layer. XXX: is this a limitation?
00553     KisSelectionSP m_selection;
00554     
00555     DCOPObject * m_dcop;
00556 
00557     KisExifInfo* m_exifInfo;
00558 
00559     QValueList<KisFilter*> m_longRunningFilters;
00560     QTimer * m_longRunningFilterTimer;
00561 
00562     bool m_lock;
00563 };
00564 
00565 inline Q_INT32 KisPaintDevice::pixelSize() const
00566 {
00567     Q_ASSERT(m_pixelSize > 0);
00568     return m_pixelSize;
00569 }
00570 
00571 inline Q_INT32 KisPaintDevice::nChannels() const
00572 {
00573     Q_ASSERT(m_nChannels > 0);
00574     return m_nChannels;
00575 ;
00576 }
00577 
00578 inline KisColorSpace * KisPaintDevice::colorSpace() const
00579 {
00580     Q_ASSERT(m_colorSpace != 0);
00581         return m_colorSpace;
00582 }
00583 
00584 
00585 inline Q_INT32 KisPaintDevice::getX() const
00586 {
00587     return m_x;
00588 }
00589 
00590 inline Q_INT32 KisPaintDevice::getY() const
00591 {
00592     return m_y;
00593 }
00594 
00595 #endif // KIS_PAINT_DEVICE_IMPL_H_
00596 
KDE Home | KDE Accessibility Home | Description of Access Keys