1 | /****************************************************************************
|
---|
2 | ** $Id: qpixmap.h 56 2006-01-19 21:09:05Z dmik $
|
---|
3 | **
|
---|
4 | ** Definition of QPixmap class
|
---|
5 | **
|
---|
6 | ** Created : 940501
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #ifndef QPIXMAP_H
|
---|
39 | #define QPIXMAP_H
|
---|
40 |
|
---|
41 | #ifndef QT_H
|
---|
42 | #include "qpaintdevice.h"
|
---|
43 | #include "qcolor.h" // char*->QColor conversion
|
---|
44 | #include "qstring.h" // char*->QString conversion
|
---|
45 | #include "qnamespace.h"
|
---|
46 | #endif // QT_H
|
---|
47 |
|
---|
48 | class QGfx;
|
---|
49 | class QPixmapPrivate;
|
---|
50 |
|
---|
51 | #if defined(Q_WS_WIN)
|
---|
52 | // Internal pixmap memory optimization class for Windows 9x
|
---|
53 | class QMultiCellPixmap;
|
---|
54 | #endif
|
---|
55 |
|
---|
56 |
|
---|
57 | class Q_EXPORT QPixmap : public QPaintDevice, public Qt
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | enum ColorMode { Auto, Color, Mono };
|
---|
61 | enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim,
|
---|
62 | NormalOptim, BestOptim };
|
---|
63 |
|
---|
64 | QPixmap();
|
---|
65 | QPixmap( const QImage& image );
|
---|
66 | QPixmap( int w, int h, int depth = -1, Optimization = DefaultOptim );
|
---|
67 | QPixmap( const QSize &, int depth = -1, Optimization = DefaultOptim );
|
---|
68 | #ifndef QT_NO_IMAGEIO
|
---|
69 | QPixmap( const QString& fileName, const char *format=0,
|
---|
70 | ColorMode mode=Auto );
|
---|
71 | QPixmap( const QString& fileName, const char *format,
|
---|
72 | int conversion_flags );
|
---|
73 | QPixmap( const char *xpm[] ); // ### in 4.0, 'const char * const xpm[]'?
|
---|
74 | QPixmap( const QByteArray &data );
|
---|
75 | #endif
|
---|
76 | QPixmap( const QPixmap & );
|
---|
77 | ~QPixmap();
|
---|
78 |
|
---|
79 | QPixmap &operator=( const QPixmap & );
|
---|
80 | QPixmap &operator=( const QImage & );
|
---|
81 |
|
---|
82 | bool isNull() const;
|
---|
83 |
|
---|
84 | int width() const { return data->w; }
|
---|
85 | int height() const { return data->h; }
|
---|
86 | QSize size() const { return QSize(data->w,data->h); }
|
---|
87 | QRect rect() const { return QRect(0,0,data->w,data->h); }
|
---|
88 | int depth() const { return data->d; }
|
---|
89 | static int defaultDepth();
|
---|
90 |
|
---|
91 | void fill( const QColor &fillColor = Qt::white );
|
---|
92 | void fill( const QWidget *, int xofs, int yofs );
|
---|
93 | void fill( const QWidget *, const QPoint &ofs );
|
---|
94 | void resize( int width, int height );
|
---|
95 | void resize( const QSize & );
|
---|
96 |
|
---|
97 | const QBitmap *mask() const;
|
---|
98 | void setMask( const QBitmap & );
|
---|
99 | bool selfMask() const;
|
---|
100 | bool hasAlpha() const;
|
---|
101 | bool hasAlphaChannel() const;
|
---|
102 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
---|
103 | QBitmap createHeuristicMask( bool clipTight = TRUE ) const;
|
---|
104 | #endif
|
---|
105 | #ifndef QT_NO_MIME
|
---|
106 | static QPixmap fromMimeSource( const QString& abs_name );
|
---|
107 | #endif
|
---|
108 | static QPixmap grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
|
---|
109 | static QPixmap grabWidget( QWidget * widget,
|
---|
110 | int x=0, int y=0, int w=-1, int h=-1 );
|
---|
111 |
|
---|
112 | #ifndef QT_NO_PIXMAP_TRANSFORMATION
|
---|
113 | QPixmap xForm( const QWMatrix & ) const;
|
---|
114 | static QWMatrix trueMatrix( const QWMatrix &, int w, int h );
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | QImage convertToImage() const;
|
---|
118 | bool convertFromImage( const QImage &, ColorMode mode=Auto );
|
---|
119 | bool convertFromImage( const QImage &, int conversion_flags );
|
---|
120 | #ifndef QT_NO_IMAGEIO
|
---|
121 | static const char* imageFormat( const QString &fileName );
|
---|
122 | bool load( const QString& fileName, const char *format=0,
|
---|
123 | ColorMode mode=Auto );
|
---|
124 | bool load( const QString& fileName, const char *format,
|
---|
125 | int conversion_flags );
|
---|
126 | bool loadFromData( const uchar *buf, uint len,
|
---|
127 | const char* format=0,
|
---|
128 | ColorMode mode=Auto );
|
---|
129 | bool loadFromData( const uchar *buf, uint len,
|
---|
130 | const char* format,
|
---|
131 | int conversion_flags );
|
---|
132 | bool loadFromData( const QByteArray &data,
|
---|
133 | const char* format=0,
|
---|
134 | int conversion_flags=0 );
|
---|
135 | bool save( const QString& fileName, const char* format, int quality = -1 ) const;
|
---|
136 | bool save( QIODevice* device, const char* format, int quality = -1 ) const;
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | #if defined(Q_WS_WIN)
|
---|
140 | HBITMAP hbm() const;
|
---|
141 | #elif defined(Q_WS_PM)
|
---|
142 | HBITMAP hbm() const;
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | int serialNumber() const;
|
---|
146 |
|
---|
147 | Optimization optimization() const;
|
---|
148 | void setOptimization( Optimization );
|
---|
149 | static Optimization defaultOptimization();
|
---|
150 | static void setDefaultOptimization( Optimization );
|
---|
151 |
|
---|
152 | virtual void detach();
|
---|
153 |
|
---|
154 | bool isQBitmap() const;
|
---|
155 |
|
---|
156 | #if defined(Q_WS_WIN)
|
---|
157 | // These functions are internal and used by Windows 9x only
|
---|
158 | bool isMultiCellPixmap() const;
|
---|
159 | HDC multiCellHandle() const;
|
---|
160 | HBITMAP multiCellBitmap() const;
|
---|
161 | int multiCellOffset() const;
|
---|
162 | int allocCell();
|
---|
163 | void freeCell( bool = FALSE );
|
---|
164 | #elif defined(Q_WS_PM)
|
---|
165 | static HPOINTER createIcon( bool pointer, int hotX, int hotY,
|
---|
166 | const QPixmap *normal, const QPixmap *mini );
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | #if defined(Q_WS_QWS)
|
---|
170 | virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
|
---|
171 | virtual unsigned char * scanLine(int) const;
|
---|
172 | virtual int bytesPerLine() const;
|
---|
173 | QRgb * clut() const;
|
---|
174 | int numCols() const;
|
---|
175 | #elif defined(Q_WS_X11)
|
---|
176 | static int x11SetDefaultScreen( int screen );
|
---|
177 | void x11SetScreen( int screen );
|
---|
178 | #endif
|
---|
179 |
|
---|
180 | #ifndef Q_QDOC
|
---|
181 | Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | protected:
|
---|
185 | QPixmap( int w, int h, const uchar *data, bool isXbitmap );
|
---|
186 | int metric( int ) const;
|
---|
187 |
|
---|
188 | #if defined(Q_WS_WIN)
|
---|
189 | struct QMCPI { // mem optim for win9x
|
---|
190 | QMultiCellPixmap *mcp;
|
---|
191 | int offset;
|
---|
192 | };
|
---|
193 | #endif
|
---|
194 |
|
---|
195 | struct QPixmapData : public QShared { // internal pixmap data
|
---|
196 | QCOORD w, h;
|
---|
197 | short d;
|
---|
198 | uint uninit : 1;
|
---|
199 | uint bitmap : 1;
|
---|
200 | uint selfmask : 1;
|
---|
201 | #if defined(Q_WS_WIN)
|
---|
202 | uint mcp : 1;
|
---|
203 | #endif
|
---|
204 | int ser_no;
|
---|
205 | QBitmap *mask;
|
---|
206 | #if defined(Q_WS_WIN)
|
---|
207 | QPixmap *maskpm;
|
---|
208 | union {
|
---|
209 | HBITMAP hbm; // if mcp == FALSE
|
---|
210 | QMCPI *mcpi; // if mcp == TRUE
|
---|
211 | } hbm_or_mcpi;
|
---|
212 | uchar *realAlphaBits;
|
---|
213 | #ifdef Q_OS_TEMP
|
---|
214 | uchar* ppvBits; // Pointer to DIBSection bits
|
---|
215 | #endif
|
---|
216 | #elif defined(Q_WS_PM)
|
---|
217 | HBITMAP hbm;
|
---|
218 | HBITMAP maskedHbm; // pixmap precomposed for masking
|
---|
219 | //@@TODO (dmik): need this?
|
---|
220 | uchar *realAlphaBits;
|
---|
221 | #elif defined(Q_WS_X11)
|
---|
222 | void *ximage;
|
---|
223 | void *maskgc;
|
---|
224 | QPixmap *alphapm;
|
---|
225 | #elif defined(Q_WS_MAC)
|
---|
226 | ColorTable *clut;
|
---|
227 | QPixmap *alphapm;
|
---|
228 | #elif defined(Q_WS_QWS)
|
---|
229 | int id; // ### should use QPaintDevice::hd, since it is there
|
---|
230 | QRgb * clut;
|
---|
231 | int numcols;
|
---|
232 | int rw;
|
---|
233 | int rh;
|
---|
234 | bool hasAlpha;
|
---|
235 | #endif
|
---|
236 | Optimization optim;
|
---|
237 | #if defined(Q_WS_WIN)
|
---|
238 | HBITMAP old_hbm;
|
---|
239 | #endif
|
---|
240 | } *data;
|
---|
241 | private:
|
---|
242 | #ifndef QT_NO_IMAGEIO
|
---|
243 | bool doImageIO( QImageIO* io, int quality ) const;
|
---|
244 | #endif
|
---|
245 | QPixmap( int w, int h, int depth, bool, Optimization );
|
---|
246 | void init( int, int, int, bool, Optimization );
|
---|
247 | void deref();
|
---|
248 | QPixmap copy( bool ignoreMask = FALSE ) const;
|
---|
249 | #if defined(Q_WS_WIN)
|
---|
250 | void initAlphaPixmap( uchar *bytes, int length, struct tagBITMAPINFO *bmi );
|
---|
251 | void convertToAlphaPixmap( bool initAlpha=TRUE );
|
---|
252 | static void bitBltAlphaPixmap( QPixmap *dst, int dx, int dy,
|
---|
253 | const QPixmap *src, int sx, int sy,
|
---|
254 | int sw, int sh, bool useDstAlpha );
|
---|
255 | #elif defined(Q_WS_PM)
|
---|
256 | void prepareForMasking( bool prepare );
|
---|
257 | HPOINTER createIcon( bool pointer, int hotX, int hotY, bool mini );
|
---|
258 | void attachHandle( HBITMAP hbm );
|
---|
259 | HBITMAP detachHandle();
|
---|
260 | friend class QPMMimeImage;
|
---|
261 | #endif
|
---|
262 | static Optimization defOptim;
|
---|
263 | friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
|
---|
264 | const QPaintDevice *,
|
---|
265 | int, int, int, int, RasterOp, bool );
|
---|
266 | friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
|
---|
267 | const QImage* src,
|
---|
268 | int, int, int, int, int conversion_flags );
|
---|
269 | friend Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
|
---|
270 | const QPixmap *src, int sx, int sy,
|
---|
271 | int sw, int sh );
|
---|
272 |
|
---|
273 | #if defined(Q_WS_MAC)
|
---|
274 | friend void unclippedScaledBitBlt(QPaintDevice *, int, int, int, int,
|
---|
275 | const QPaintDevice *, int, int, int, int,
|
---|
276 | Qt::RasterOp, bool, bool);
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | friend class QBitmap;
|
---|
280 | friend class QPaintDevice;
|
---|
281 | friend class QPainter;
|
---|
282 | friend class QGLWidget;
|
---|
283 | };
|
---|
284 |
|
---|
285 |
|
---|
286 | inline bool QPixmap::isNull() const
|
---|
287 | {
|
---|
288 | return data->w == 0;
|
---|
289 | }
|
---|
290 |
|
---|
291 | inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
|
---|
292 | {
|
---|
293 | fill( w, ofs.x(), ofs.y() );
|
---|
294 | }
|
---|
295 |
|
---|
296 | inline void QPixmap::resize( const QSize &s )
|
---|
297 | {
|
---|
298 | resize( s.width(), s.height() );
|
---|
299 | }
|
---|
300 |
|
---|
301 | inline const QBitmap *QPixmap::mask() const
|
---|
302 | {
|
---|
303 | return data->mask;
|
---|
304 | }
|
---|
305 |
|
---|
306 | inline bool QPixmap::selfMask() const
|
---|
307 | {
|
---|
308 | return data->selfmask;
|
---|
309 | }
|
---|
310 |
|
---|
311 | #if defined(Q_WS_WIN)
|
---|
312 | inline HBITMAP QPixmap::hbm() const
|
---|
313 | {
|
---|
314 | return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
|
---|
315 | }
|
---|
316 | #elif defined(Q_WS_PM)
|
---|
317 | inline HBITMAP QPixmap::hbm() const
|
---|
318 | {
|
---|
319 | return data->hbm;
|
---|
320 | }
|
---|
321 | #endif
|
---|
322 |
|
---|
323 | inline int QPixmap::serialNumber() const
|
---|
324 | {
|
---|
325 | return data->ser_no;
|
---|
326 | }
|
---|
327 |
|
---|
328 | inline QPixmap::Optimization QPixmap::optimization() const
|
---|
329 | {
|
---|
330 | return data->optim;
|
---|
331 | }
|
---|
332 |
|
---|
333 | inline bool QPixmap::isQBitmap() const
|
---|
334 | {
|
---|
335 | return data->bitmap;
|
---|
336 | }
|
---|
337 |
|
---|
338 | #if defined(Q_WS_WIN)
|
---|
339 | inline bool QPixmap::isMultiCellPixmap() const
|
---|
340 | {
|
---|
341 | return data->mcp;
|
---|
342 | }
|
---|
343 | #endif
|
---|
344 |
|
---|
345 |
|
---|
346 | /*****************************************************************************
|
---|
347 | QPixmap stream functions
|
---|
348 | *****************************************************************************/
|
---|
349 |
|
---|
350 | #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
|
---|
351 | Q_EXPORT QDataStream &operator<<( QDataStream &, const QPixmap & );
|
---|
352 | Q_EXPORT QDataStream &operator>>( QDataStream &, QPixmap & );
|
---|
353 | #endif
|
---|
354 |
|
---|
355 | /*****************************************************************************
|
---|
356 | QPixmap (and QImage) helper functions
|
---|
357 | *****************************************************************************/
|
---|
358 |
|
---|
359 | #ifndef QT_NO_PIXMAP_TRANSFORMATION
|
---|
360 | # define QT_XFORM_TYPE_MSBFIRST 0
|
---|
361 | # define QT_XFORM_TYPE_LSBFIRST 1
|
---|
362 | # if defined(Q_WS_WIN)
|
---|
363 | # define QT_XFORM_TYPE_WINDOWSPIXMAP 2
|
---|
364 | # endif
|
---|
365 | bool qt_xForm_helper( const QWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
|
---|
369 | const QPixmap *src, int sx = 0, int sy = 0,
|
---|
370 | int sw = -1, int sh = -1 );
|
---|
371 |
|
---|
372 | #endif // QPIXMAP_H
|
---|