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 KisUndoAdapter;
00056 class KisFilter;
00057 class KisDataManager;
00058 typedef KSharedPtr<KisDataManager> KisDataManagerSP;
00059 
00060 class KisMemento;
00061 typedef KSharedPtr<KisMemento> KisMementoSP;
00062 
00063 
00071 class KRITACORE_EXPORT KisPaintDevice
00072     : public QObject
00073     , public KShared
00074 {
00075 
00076         Q_OBJECT
00077 
00078 public:
00079 
00086     KisPaintDevice(KisColorSpace * colorSpace, const char * name = 0);
00087 
00096     KisPaintDevice(KisLayer *parentLayer, KisColorSpace * colorSpace, const char * name = 0);
00097 
00098     KisPaintDevice(const KisPaintDevice& rhs);
00099     virtual ~KisPaintDevice();
00100     virtual DCOPObject *dcopObject();
00101 
00102 
00103 public:
00104 
00108     virtual bool write(KoStore *store);
00109 
00113     virtual bool read(KoStore *store);
00114 
00115 public:
00116 
00120     virtual void move(Q_INT32 x, Q_INT32 y);
00121 
00125     virtual void move(const QPoint& pt);
00126 
00131     virtual KNamedCommand * moveCommand(Q_INT32 x, Q_INT32 y);
00132 
00136     bool contains(Q_INT32 x, Q_INT32 y) const;
00137 
00141     bool contains(const QPoint& pt) const;
00142 
00149     void extent(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const;
00150     virtual QRect extent() const;
00151 
00159     bool extentIsValid() const;
00160 
00162     void setExtentIsValid(bool isValid);
00163 
00168     void exactBounds(Q_INT32 &x, Q_INT32 &y, Q_INT32 &w, Q_INT32 &h) const;
00169     virtual QRect exactBounds() const;
00170 
00174     void crop(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00175 
00177     void crop(QRect r);
00178 
00182     virtual void clear();
00183 
00187     void fill(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, const Q_UINT8 *fillPixel);
00188 
00199     virtual void readBytes(Q_UINT8 * data, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00200 
00209     virtual void writeBytes(const Q_UINT8 * data, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00210 
00215     Q_INT32 numContiguousColumns(Q_INT32 x, Q_INT32 minY, Q_INT32 maxY);
00216 
00221     Q_INT32 numContiguousRows(Q_INT32 y, Q_INT32 minX, Q_INT32 maxX);
00222 
00227     Q_INT32 rowStride(Q_INT32 x, Q_INT32 y);
00228 
00232     const Q_UINT8* pixel(Q_INT32 x, Q_INT32 y);
00233 
00237     Q_UINT8* writablePixel(Q_INT32 x, Q_INT32 y);
00238 
00242     virtual void convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
00243 
00248     virtual void setProfile(KisProfile * profile);
00249     
00254     virtual void convertFromQImage(const QImage& img, const QString &srcProfileName, Q_INT32 offsetX = 0, Q_INT32 offsetY = 0);
00255 
00268     virtual QImage convertToQImage(KisProfile *  dstProfile, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h, float exposure = 0.0f);
00269 
00278     virtual QImage convertToQImage(KisProfile *  dstProfile, float exposure = 0.0f);
00279 
00285     KisPaintDeviceSP createThumbnailDevice(Q_INT32 w, Q_INT32 h);
00286             
00292     virtual QImage createThumbnail(Q_INT32 maxw, Q_INT32 maxh);
00293 
00294 
00303     bool pixel(Q_INT32 x, Q_INT32 y, QColor *c, Q_UINT8 *opacity);
00304 
00305 
00315     bool pixel(Q_INT32 x, Q_INT32 y, KisColor * kc);
00316 
00320     KisColor colorAt(Q_INT32 x, Q_INT32 y);
00321 
00337     bool setPixel(Q_INT32 x, Q_INT32 y, const QColor& c, Q_UINT8 opacity);
00338 
00339     bool setPixel(Q_INT32 x, Q_INT32 y, const KisColor& kc);
00340 
00341     KisColorSpace * colorSpace() const;
00342 
00343     KisDataManagerSP dataManager() const;
00344 
00348     void setData(KisDataManagerSP data, KisColorSpace * colorSpace);
00349 
00353     Q_INT32 getX() const;
00354 
00358     Q_INT32 getY() const;
00359 
00363     void setX(Q_INT32 x);
00364 
00368     void setY(Q_INT32 y);
00369 
00370 
00374     virtual Q_INT32 pixelSize() const;
00375 
00379     virtual Q_INT32 nChannels() const;
00380 
00385     KisImage *image() const;
00386 
00391     KisLayer *parentLayer() const;
00392 
00397     void setParentLayer(KisLayer *parentLayer);
00398 
00402     void setDirty(const QRect & rc);
00403 
00407     void setDirty();
00408     
00409     
00413     void mirrorX();
00417     void mirrorY();
00418 
00419     KisMementoSP getMemento();
00420     void rollback(KisMementoSP memento);
00421     void rollforward(KisMementoSP memento);
00422 
00426     KisRectIteratorPixel createRectIterator(Q_INT32 left, Q_INT32 top, Q_INT32 w, Q_INT32 h, bool writable);
00427 
00431     KisHLineIteratorPixel createHLineIterator(Q_INT32 x, Q_INT32 y, Q_INT32 w, bool writable);
00432 
00436     KisVLineIteratorPixel createVLineIterator(Q_INT32 x, Q_INT32 y, Q_INT32 h, bool writable);
00437 
00438 
00440     KisSelectionSP selection();
00441 
00443     void addSelection(KisSelectionSP selection);
00444 
00446     void subtractSelection(KisSelectionSP selection);
00447 
00449     bool hasSelection();
00450 
00452     bool selectionDeselected();
00453 
00455     void deselect();
00456 
00458     void reselect();
00459         
00461     void clearSelection();
00462 
00467     void applySelectionMask(KisSelectionSP mask);
00468 
00474     KisSelectionSP setSelection(KisSelectionSP selection);
00475 
00479     void emitSelectionChanged();
00480 
00486     void emitSelectionChanged(const QRect& r);
00487 
00488     
00489     KisUndoAdapter *undoAdapter() const;
00490 
00495     KisExifInfo* exifInfo();
00499     bool hasExifInfo() { return m_exifInfo != 0; }
00500 signals:
00501     void positionChanged(KisPaintDeviceSP device);
00502     void ioProgress(Q_INT8 percentage);
00503     void profileChanged(KisProfile *  profile);
00504 
00505 private slots:
00506 
00507     void runBackgroundFilters();
00508     
00509 private:
00510     KisPaintDevice& operator=(const KisPaintDevice&);
00511 
00512 protected:
00513     KisDataManagerSP m_datamanager;
00514     
00515 private:
00516     /* The KisLayer that contains this paint device, or 0 if this is not 
00517      * part of a layer.
00518      */
00519     KisLayer *m_parentLayer;
00520 
00521     bool m_extentIsValid;
00522 
00523     Q_INT32 m_x;
00524     Q_INT32 m_y;
00525     KisColorSpace * m_colorSpace;
00526     // Cached for quick access
00527     Q_INT32 m_pixelSize;
00528     Q_INT32 m_nChannels;
00529 
00530     // Whether the selection is active
00531     bool m_hasSelection;
00532     bool m_selectionDeselected;
00533     
00534     // Contains the actual selection. For now, there can be only
00535     // one selection per layer. XXX: is this a limitation?
00536     KisSelectionSP m_selection;
00537     
00538     DCOPObject * m_dcop;
00539 
00540     KisExifInfo* m_exifInfo;
00541 
00542     QValueList<KisFilter*> m_longRunningFilters;
00543     QTimer * m_longRunningFilterTimer;
00544 };
00545 
00546 inline Q_INT32 KisPaintDevice::pixelSize() const
00547 {
00548     Q_ASSERT(m_pixelSize > 0);
00549     return m_pixelSize;
00550 }
00551 
00552 inline Q_INT32 KisPaintDevice::nChannels() const
00553 {
00554     Q_ASSERT(m_nChannels > 0);
00555     return m_nChannels;
00556 ;
00557 }
00558 
00559 inline KisColorSpace * KisPaintDevice::colorSpace() const
00560 {
00561     Q_ASSERT(m_colorSpace != 0);
00562         return m_colorSpace;
00563 }
00564 
00565 
00566 inline Q_INT32 KisPaintDevice::getX() const
00567 {
00568     return m_x;
00569 }
00570 
00571 inline Q_INT32 KisPaintDevice::getY() const
00572 {
00573     return m_y;
00574 }
00575 
00576 #endif // KIS_PAINT_DEVICE_IMPL_H_
00577 
KDE Home | KDE Accessibility Home | Description of Access Keys