krita

kis_image.h

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *                2006 Boudewijn Rempt <boud@valdyas.org>
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_IMAGE_H_
00020 #define KIS_IMAGE_H_
00021 
00022 #include <qobject.h>
00023 #include <qstring.h>
00024 #include <qvaluevector.h>
00025 #include <qmutex.h>
00026 
00027 #include <config.h>
00028 
00029 #include <ksharedptr.h>
00030 #include <kurl.h>
00031 
00032 #include "KoUnit.h"
00033 
00034 #include "kis_composite_op.h"
00035 #include "kis_global.h"
00036 #include "kis_types.h"
00037 #include "kis_annotation.h"
00038 #include "kis_paint_device.h"
00039 
00040 #include <koffice_export.h>
00041 
00042 
00043 class DCOPObject;
00044 class KCommand;
00045 
00046 class KoCommandHistory;
00047 
00048 class KisColorSpace;
00049 class KisNameServer;
00050 class KisUndoAdapter;
00051 class KisPainter;
00052 class KCommand;
00053 class KisColor;
00054 class KisFilterStrategy;
00055 class KisImageIface;
00056 class KisProfile;
00057 class KisProgressDisplayInterface;
00058 class KisPaintLayer;
00059 class KisPerspectiveGrid;
00060 
00061 class KRITACORE_EXPORT KisImage : public QObject, public KShared {
00062     Q_OBJECT
00063 
00064 public:
00065     KisImage(KisUndoAdapter * adapter, Q_INT32 width, Q_INT32 height, KisColorSpace * colorSpace, const QString& name);
00066     KisImage(const KisImage& rhs);
00067     virtual ~KisImage();
00068     virtual DCOPObject *dcopObject();
00069 
00070 public:
00071     typedef enum enumPaintFlags {
00072         PAINT_IMAGE_ONLY = 0,
00073         PAINT_BACKGROUND = 1,
00074         PAINT_SELECTION = 2,
00075         PAINT_MASKINACTIVELAYERS = 4,
00076         PAINT_EMBEDDED_RECT = 8 // If the current layer is an embedded part draw a rect around it
00077     } PaintFlags;
00078 
00081     virtual void renderToPainter(Q_INT32 x1,
00082                     Q_INT32 y1,
00083                     Q_INT32 x2,
00084                     Q_INT32 y2,
00085                     QPainter &painter,
00086                     KisProfile *profile,
00087                     PaintFlags paintFlags,
00088                     float exposure = 0.0f);
00093     virtual QImage convertToQImage(Q_INT32 x1,
00094                                     Q_INT32 y1,
00095                                     Q_INT32 x2,
00096                                     Q_INT32 y2,
00097                                     KisProfile * profile,
00098                                     float exposure = 0.0f);
00099 
00100     virtual QImage convertToQImage(const QRect& r, const QSize& fullImageSize, KisProfile *profile, PaintFlags paintFlags, float exposure = 0.0f);
00101 
00102     KisBackgroundSP background() const;
00103     KisSubstrateSP substrate() const;
00104     
00105 
00106 public:
00107 
00112     void lock();
00113 
00119     void unlock();
00120 
00124     bool locked() const;
00125 
00126     KisColor backgroundColor() const;
00127     void setBackgroundColor(const KisColor & color);
00128 
00129     QString name() const;
00130     void setName(const QString& name);
00131 
00132     QString description() const;
00133     void setDescription(const QString& description);
00134 
00135     QString nextLayerName() const;
00136     void rollBackLayerName();
00137     
00138     KisPerspectiveGrid* perspectiveGrid();
00139     void createPerspectiveGrid(QPoint topLeft, QPoint topRight, QPoint bottomRight, QPoint bottomLeft);
00150     void resize(Q_INT32 w, Q_INT32 h, Q_INT32 x = 0, Q_INT32 y = 0,  bool cropLayers = false);
00151 
00159     void resize(const QRect& rc, bool cropLayers = false);
00160 
00161     void scale(double sx, double sy, KisProgressDisplayInterface *m_progress, KisFilterStrategy *filterStrategy);
00162     void rotate(double radians, KisProgressDisplayInterface *m_progress);
00163     void shear(double angleX, double angleY, KisProgressDisplayInterface *m_progress);
00164 
00168     void convertTo(KisColorSpace * dstColorSpace, Q_INT32 renderingIntent = INTENT_PERCEPTUAL);
00169 
00170     // Get the profile associated with this image
00171     KisProfile *  getProfile() const;
00172 
00182     void setProfile(const KisProfile * profile);
00183 
00188     void setUndoAdapter(KisUndoAdapter * undoAdapter);
00189 
00194     KisUndoAdapter *undoAdapter() const;
00195 
00199     bool undo() const;
00204     void setModified();
00205 
00206     KisColorSpace * colorSpace() const;
00207 
00208     // Resolution of the image == XXX: per inch?
00209     double xRes();
00210     double yRes();
00211     void setResolution(double xres, double yres);
00212 
00213     Q_INT32 width() const;
00214     Q_INT32 height() const;
00215 
00216     bool empty() const;
00217 
00222     KisPaintDeviceSP mergedImage();
00223 
00224     /*
00225     * Returns the colour of the merged image at pixel (x, y).
00226     */
00227     KisColor mergedPixel(Q_INT32 x, Q_INT32 y);
00228 
00230     KisLayerSP newLayer(const QString& name, Q_UINT8 opacity,
00231                             const KisCompositeOp& compositeOp = KisCompositeOp(), KisColorSpace * colorstrategy = 0);
00232 
00234     KisPaintDeviceSP activeDevice();
00235 
00236     void setLayerProperties(KisLayerSP layer, Q_UINT8 opacity, const KisCompositeOp& compositeOp, const QString& name);
00237 
00238     KisGroupLayerSP rootLayer() const;
00239     KisLayerSP activeLayer() const;
00240 
00243     KisPaintDeviceSP projection();
00244     
00245     KisLayerSP activate(KisLayerSP layer);
00246     KisLayerSP findLayer(const QString& name) const;
00247     KisLayerSP findLayer(int id) const;
00248 
00250     bool moveLayer(KisLayerSP layer, KisGroupLayerSP parent, KisLayerSP aboveThis);
00251 
00258     bool addLayer(KisLayerSP layer, KisGroupLayerSP parent);
00259     
00274     bool addLayer(KisLayerSP layer, KisGroupLayerSP parent, KisLayerSP aboveThis);
00275 
00277     bool removeLayer(KisLayerSP layer);
00278 
00280     bool raiseLayer(KisLayerSP layer);
00281 
00283     bool lowerLayer(KisLayerSP layer);
00284 
00286     bool toTop(KisLayerSP layer);
00287 
00289     bool toBottom(KisLayerSP layer);
00290 
00291     Q_INT32 nlayers() const;
00292     Q_INT32 nHiddenLayers() const;
00293 
00294     KCommand *raiseLayerCommand(KisLayerSP layer);
00295     KCommand *lowerLayerCommand(KisLayerSP layer);
00296     KCommand *topLayerCommand(KisLayerSP layer);
00297     KCommand *bottomLayerCommand(KisLayerSP layer);
00298 
00303     void flatten();
00304 
00309     void mergeLayer(KisLayerSP l);
00310 
00311     QRect bounds() const;
00312 
00314     void notifyLayersChanged();
00315 
00316     void notifyPropertyChanged(KisLayerSP layer);
00317 
00318     void notifyImageLoaded();
00319 
00320     void notifyLayerUpdated(KisLayerSP layer, QRect rc);
00321 
00322     void setColorSpace(KisColorSpace * colorSpace);
00323     void setRootLayer(KisGroupLayerSP rootLayer);
00324 
00325     //KisGuideMgr *guides() const;
00326 
00332     void addAnnotation(KisAnnotationSP annotation);
00333 
00335     KisAnnotationSP annotation(QString type);
00336 
00338     void removeAnnotation(QString type);
00339 
00343     vKisAnnotationSP_it beginAnnotations();
00344 
00346     vKisAnnotationSP_it endAnnotations();
00347 
00348 signals:
00349 
00350     void sigActiveSelectionChanged(KisImageSP image);
00351     void sigSelectionChanged(KisImageSP image);
00352     void sigSelectionChanged(KisImageSP image, const QRect& rect);
00353 
00355     void sigLayerActivated(KisLayerSP layer);
00356 
00358     void sigLayerAdded(KisLayerSP layer);
00359 
00367     void sigLayerRemoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP wasAboveThis);
00368 
00374     void sigLayerMoved(KisLayerSP layer, KisGroupLayerSP previousParent, KisLayerSP wasAboveThis);
00375 
00377     void sigLayerPropertiesChanged(KisLayerSP layer);
00378 
00383     void sigLayersChanged(KisGroupLayerSP rootLayer);
00384 
00391     void sigImageUpdated(QRect rc);
00392 
00399     void sigLayerUpdated(KisLayerSP layer, QRect rc);
00400 
00404     void sigImageModified();
00405 
00406     void sigSizeChanged(Q_INT32 w, Q_INT32 h);
00407     void sigProfileChanged(KisProfile *  profile);
00408     void sigColorSpaceChanged(KisColorSpace*  cs);
00409 
00410 
00412     void sigMaskInfoChanged();
00413 public slots:
00414     void slotSelectionChanged();
00415     void slotSelectionChanged(const QRect& r);
00416 
00417 
00418 private:
00419     KisImage& operator=(const KisImage& rhs);
00420     void init(KisUndoAdapter * adapter, Q_INT32 width, Q_INT32 height,  KisColorSpace * colorSpace, const QString& name);
00421     void emitSizeChanged();
00422 
00423 private:
00424 
00425     KURL m_uri;
00426     QString m_name;
00427     QString m_description;
00428 
00429     Q_INT32 m_width;
00430     Q_INT32 m_height;
00431 
00432     double m_xres;
00433     double m_yres;
00434 
00435     KoUnit::Unit m_unit;
00436 
00437     KisColorSpace * m_colorSpace;
00438 
00439     bool m_dirty;
00440     QRect m_dirtyRect;
00441 
00442     KisBackgroundSP m_bkg;
00443 
00444     KisGroupLayerSP m_rootLayer; // The layers are contained in here
00445     KisLayerSP m_activeLayer;
00446 
00447     KisNameServer *m_nserver;
00448     KisUndoAdapter *m_adapter;
00449     //KisGuideMgr m_guides;
00450 
00451     DCOPObject *m_dcop;
00452 
00453     vKisAnnotationSP m_annotations;
00454 
00455     class KisImagePrivate;
00456     KisImagePrivate * m_private;
00457     
00458 };
00459 
00460 #endif // KIS_IMAGE_H_
KDE Home | KDE Accessibility Home | Description of Access Keys