Eneboo - Documentación para desarrolladores
src/qt/include/qpixmap.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qpixmap.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QPixmap class
00005 **
00006 ** Created : 940501
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the kernel module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QPIXMAP_H
00039 #define QPIXMAP_H
00040 
00041 #ifndef QT_H
00042 #include "qpaintdevice.h"
00043 #include "qcolor.h" // char*->QColor conversion
00044 #include "qstring.h" // char*->QString conversion
00045 #include "qnamespace.h"
00046 #endif // QT_H
00047 
00048 class QGfx;
00049 class QPixmapPrivate;
00050 
00051 #if defined(Q_WS_WIN)
00052 // Internal pixmap memory optimization class for Windows 9x
00053 class QMultiCellPixmap;
00054 #endif
00055 
00056 
00057 class Q_EXPORT QPixmap : public QPaintDevice, public Qt
00058 {
00059 public:
00060     enum ColorMode { Auto, Color, Mono };
00061     enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim,
00062                         NormalOptim, BestOptim };
00063 
00064     QPixmap();
00065     QPixmap( const QImage& image );
00066     QPixmap( int w, int h,  int depth = -1, Optimization = DefaultOptim );
00067     QPixmap( const QSize &, int depth = -1, Optimization = DefaultOptim );
00068 #ifndef QT_NO_IMAGEIO
00069     QPixmap( const QString& fileName, const char *format=0,
00070              ColorMode mode=Auto );
00071     QPixmap( const QString& fileName, const char *format,
00072              int conversion_flags );
00073     QPixmap( const char *xpm[] ); // ### in 4.0, 'const char * const xpm[]'?
00074     QPixmap( const QByteArray &data );
00075 #endif
00076     QPixmap( const QPixmap & );
00077    ~QPixmap();
00078 
00079     QPixmap    &operator=( const QPixmap & );
00080     QPixmap    &operator=( const QImage  & );
00081 
00082     bool        isNull()        const;
00083 
00084     int         width()         const { return data->w; }
00085     int         height()        const { return data->h; }
00086     QSize       size()          const { return QSize(data->w,data->h); }
00087     QRect       rect()          const { return QRect(0,0,data->w,data->h); }
00088     int         depth()         const { return data->d; }
00089     static int  defaultDepth();
00090 
00091     void        fill( const QColor &fillColor = Qt::white );
00092     void        fill( const QWidget *, int xofs, int yofs );
00093     void        fill( const QWidget *, const QPoint &ofs );
00094     void        resize( int width, int height );
00095     void        resize( const QSize & );
00096 
00097     const QBitmap *mask() const;
00098     void        setMask( const QBitmap & );
00099     bool        selfMask() const;
00100     bool        hasAlpha() const;
00101     bool        hasAlphaChannel() const;
00102 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
00103     QBitmap     createHeuristicMask( bool clipTight = TRUE ) const;
00104 #endif
00105 #ifndef QT_NO_MIME
00106     static QPixmap fromMimeSource( const QString& abs_name );
00107 #endif
00108     static  QPixmap grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
00109     static  QPixmap grabWidget( QWidget * widget,
00110                                 int x=0, int y=0, int w=-1, int h=-1 );
00111 
00112 #ifndef QT_NO_PIXMAP_TRANSFORMATION
00113     QPixmap         xForm( const QWMatrix & ) const;
00114     static QWMatrix trueMatrix( const QWMatrix &, int w, int h );
00115 #endif
00116 
00117     QImage      convertToImage() const;
00118     bool        convertFromImage( const QImage &, ColorMode mode=Auto );
00119     bool        convertFromImage( const QImage &, int conversion_flags );
00120 #ifndef QT_NO_IMAGEIO
00121     static const char* imageFormat( const QString &fileName );
00122     bool        load( const QString& fileName, const char *format=0,
00123                       ColorMode mode=Auto );
00124     bool        load( const QString& fileName, const char *format,
00125                       int conversion_flags );
00126     bool        loadFromData( const uchar *buf, uint len,
00127                               const char* format=0,
00128                               ColorMode mode=Auto );
00129     bool        loadFromData( const uchar *buf, uint len,
00130                               const char* format,
00131                               int conversion_flags );
00132     bool        loadFromData( const QByteArray &data,
00133                               const char* format=0,
00134                               int conversion_flags=0 );
00135     bool        save( const QString& fileName, const char* format, int quality = -1 ) const;
00136     bool        save( QIODevice* device, const char* format, int quality = -1 ) const;
00137 #endif
00138 
00139 #if defined(Q_WS_WIN)
00140     HBITMAP     hbm()           const;
00141 #endif
00142 
00143     int         serialNumber()  const;
00144 
00145     Optimization        optimization() const;
00146     void                setOptimization( Optimization );
00147     static Optimization defaultOptimization();
00148     static void         setDefaultOptimization( Optimization );
00149 
00150     virtual void detach();
00151 
00152     bool        isQBitmap() const;
00153 
00154 #if defined(Q_WS_WIN)
00155     // These functions are internal and used by Windows 9x only
00156     bool        isMultiCellPixmap() const;
00157     HDC         multiCellHandle() const;
00158     HBITMAP     multiCellBitmap() const;
00159     int         multiCellOffset() const;
00160     int         allocCell();
00161     void        freeCell( bool = FALSE );
00162 #endif
00163 
00164 #if defined(Q_WS_QWS)
00165     virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
00166     virtual unsigned char * scanLine(int) const;
00167     virtual int bytesPerLine() const;
00168     QRgb * clut() const;
00169     int numCols() const;
00170 #elif defined(Q_WS_X11)
00171     static int x11SetDefaultScreen( int screen );
00172     void x11SetScreen( int screen );
00173 #endif
00174 
00175 #ifndef Q_QDOC
00176     Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
00177 #endif
00178 
00179 protected:
00180     QPixmap( int w, int h, const uchar *data, bool isXbitmap );
00181     int metric( int ) const;
00182 
00183 #if defined(Q_WS_WIN)
00184     struct QMCPI {                              // mem optim for win9x
00185         QMultiCellPixmap *mcp;
00186         int     offset;
00187     };
00188 #endif
00189 
00190     struct QPixmapData : public QShared {       // internal pixmap data
00191         QCOORD  w, h;
00192         short   d;
00193         uint    uninit   : 1;
00194         uint    bitmap   : 1;
00195         uint    selfmask : 1;
00196 #if defined(Q_WS_WIN)
00197         uint    mcp      : 1;
00198 #endif
00199         int     ser_no;
00200         QBitmap *mask;
00201 #if defined(Q_WS_WIN)
00202         QPixmap *maskpm;
00203         union {
00204             HBITMAP hbm;    // if mcp == FALSE
00205             QMCPI  *mcpi;   // if mcp == TRUE
00206         } hbm_or_mcpi;
00207         uchar *realAlphaBits;
00208 #ifdef Q_OS_TEMP
00209         uchar* ppvBits; // Pointer to DIBSection bits
00210 #endif
00211 #elif defined(Q_WS_X11)
00212         void   *ximage;
00213         void   *maskgc;
00214         QPixmap *alphapm;
00215 #elif defined(Q_WS_MAC)
00216         ColorTable *clut;
00217         QPixmap *alphapm;
00218 #elif defined(Q_WS_QWS)
00219         int id; // ### should use QPaintDevice::hd, since it is there
00220         QRgb * clut;
00221         int numcols;
00222         int rw;
00223         int rh;
00224         bool hasAlpha;
00225 #endif
00226         Optimization optim;
00227 #if defined(Q_WS_WIN)
00228         HBITMAP old_hbm;
00229 #endif
00230     } *data;
00231 private:
00232 #ifndef QT_NO_IMAGEIO
00233     bool doImageIO( QImageIO* io, int quality ) const;
00234 #endif
00235     QPixmap( int w, int h, int depth, bool, Optimization );
00236     void        init( int, int, int, bool, Optimization );
00237     void        deref();
00238     QPixmap     copy( bool ignoreMask = FALSE ) const;
00239 #if defined(Q_WS_WIN)
00240     void initAlphaPixmap( uchar *bytes, int length, struct tagBITMAPINFO *bmi );
00241     void convertToAlphaPixmap( bool initAlpha=TRUE );
00242     static void bitBltAlphaPixmap( QPixmap *dst, int dx, int dy,
00243                                    const QPixmap *src, int sx, int sy,
00244                                    int sw, int sh, bool useDstAlpha );
00245 #endif
00246     static Optimization defOptim;
00247     friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
00248                                  const QPaintDevice *,
00249                                  int, int, int, int, RasterOp, bool );
00250     friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
00251                                  const QImage* src,
00252                                  int, int, int, int, int conversion_flags );
00253     friend Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
00254                                   const QPixmap *src, int sx, int sy,
00255                                   int sw, int sh );
00256 
00257 #if defined(Q_WS_MAC)
00258     friend void unclippedScaledBitBlt(QPaintDevice *, int, int, int, int,
00259                                       const QPaintDevice *, int, int, int, int,
00260                                       Qt::RasterOp, bool, bool);
00261 #endif
00262 
00263     friend class QBitmap;
00264     friend class QPaintDevice;
00265     friend class QPainter;
00266     friend class QGLWidget;
00267 };
00268 
00269 
00270 inline bool QPixmap::isNull() const
00271 {
00272     return data->w == 0;
00273 }
00274 
00275 inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
00276 {
00277     fill( w, ofs.x(), ofs.y() );
00278 }
00279 
00280 inline void QPixmap::resize( const QSize &s )
00281 {
00282     resize( s.width(), s.height() );
00283 }
00284 
00285 inline const QBitmap *QPixmap::mask() const
00286 {
00287     return data->mask;
00288 }
00289 
00290 inline bool QPixmap::selfMask() const
00291 {
00292     return data->selfmask;
00293 }
00294 
00295 #if defined(Q_WS_WIN)
00296 inline HBITMAP QPixmap::hbm() const
00297 {
00298     return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
00299 }
00300 #endif
00301 
00302 inline int QPixmap::serialNumber() const
00303 {
00304     return data->ser_no;
00305 }
00306 
00307 inline QPixmap::Optimization QPixmap::optimization() const
00308 {
00309     return data->optim;
00310 }
00311 
00312 inline bool QPixmap::isQBitmap() const
00313 {
00314     return data->bitmap;
00315 }
00316 
00317 #if defined(Q_WS_WIN)
00318 inline bool QPixmap::isMultiCellPixmap() const
00319 {
00320     return data->mcp;
00321 }
00322 #endif
00323 
00324 
00325 /*****************************************************************************
00326   QPixmap stream functions
00327  *****************************************************************************/
00328 
00329 #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
00330 Q_EXPORT QDataStream &operator<<( QDataStream &, const QPixmap & );
00331 Q_EXPORT QDataStream &operator>>( QDataStream &, QPixmap & );
00332 #endif
00333 
00334 /*****************************************************************************
00335   QPixmap (and QImage) helper functions
00336  *****************************************************************************/
00337 
00338 #ifndef QT_NO_PIXMAP_TRANSFORMATION
00339 #  define QT_XFORM_TYPE_MSBFIRST 0
00340 #  define QT_XFORM_TYPE_LSBFIRST 1
00341 #  if defined(Q_WS_WIN)
00342 #    define QT_XFORM_TYPE_WINDOWSPIXMAP 2
00343 #  endif
00344 bool qt_xForm_helper( const QWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
00345 #endif
00346 
00347 Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
00348                        const QPixmap *src, int sx = 0, int sy = 0,
00349                        int sw = -1, int sh = -1 );
00350 
00351 #endif // QPIXMAP_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'