1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QPIXMAP_H
|
---|
43 | #define QPIXMAP_H
|
---|
44 |
|
---|
45 | #include <QtGui/qpaintdevice.h>
|
---|
46 | #include <QtGui/qcolor.h>
|
---|
47 | #include <QtCore/qnamespace.h>
|
---|
48 | #include <QtCore/qstring.h> // char*->QString conversion
|
---|
49 | #include <QtCore/qsharedpointer.h>
|
---|
50 | #include <QtGui/qimage.h>
|
---|
51 | #include <QtGui/qtransform.h>
|
---|
52 |
|
---|
53 | QT_BEGIN_HEADER
|
---|
54 |
|
---|
55 | #if defined(Q_OS_SYMBIAN)
|
---|
56 | class CFbsBitmap;
|
---|
57 | class RSgImage;
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | QT_BEGIN_NAMESPACE
|
---|
61 |
|
---|
62 | QT_MODULE(Gui)
|
---|
63 |
|
---|
64 | class QImageWriter;
|
---|
65 | class QImageReader;
|
---|
66 | class QColor;
|
---|
67 | class QVariant;
|
---|
68 | class QX11Info;
|
---|
69 |
|
---|
70 | #if defined(Q_WS_PM)
|
---|
71 | class QIcon;
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | class QPixmapData;
|
---|
75 |
|
---|
76 | class Q_GUI_EXPORT QPixmap : public QPaintDevice
|
---|
77 | {
|
---|
78 | public:
|
---|
79 | QPixmap();
|
---|
80 | explicit QPixmap(QPixmapData *data);
|
---|
81 | QPixmap(int w, int h);
|
---|
82 | QPixmap(const QSize &);
|
---|
83 | QPixmap(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
84 | #ifndef QT_NO_IMAGEFORMAT_XPM
|
---|
85 | QPixmap(const char * const xpm[]);
|
---|
86 | #endif
|
---|
87 | QPixmap(const QPixmap &);
|
---|
88 | ~QPixmap();
|
---|
89 |
|
---|
90 | QPixmap &operator=(const QPixmap &);
|
---|
91 | operator QVariant() const;
|
---|
92 |
|
---|
93 | bool isNull() const; // ### Qt 5: make inline
|
---|
94 | int devType() const;
|
---|
95 |
|
---|
96 | int width() const; // ### Qt 5: make inline
|
---|
97 | int height() const; // ### Qt 5: make inline
|
---|
98 | QSize size() const;
|
---|
99 | QRect rect() const;
|
---|
100 | int depth() const;
|
---|
101 |
|
---|
102 | static int defaultDepth();
|
---|
103 |
|
---|
104 | void fill(const QColor &fillColor = Qt::white);
|
---|
105 | void fill(const QWidget *widget, const QPoint &ofs);
|
---|
106 | inline void fill(const QWidget *widget, int xofs, int yofs) { fill(widget, QPoint(xofs, yofs)); }
|
---|
107 |
|
---|
108 | QBitmap mask() const;
|
---|
109 | void setMask(const QBitmap &);
|
---|
110 |
|
---|
111 | QPixmap alphaChannel() const;
|
---|
112 | void setAlphaChannel(const QPixmap &);
|
---|
113 |
|
---|
114 | bool hasAlpha() const;
|
---|
115 | bool hasAlphaChannel() const;
|
---|
116 |
|
---|
117 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
---|
118 | QBitmap createHeuristicMask(bool clipTight = true) const;
|
---|
119 | #endif
|
---|
120 | QBitmap createMaskFromColor(const QColor &maskColor) const; // ### Qt 5: remove
|
---|
121 | QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const;
|
---|
122 |
|
---|
123 | static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
|
---|
124 | static QPixmap grabWidget(QWidget *widget, const QRect &rect);
|
---|
125 | static inline QPixmap grabWidget(QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
|
---|
126 | { return grabWidget(widget, QRect(x, y, w, h)); }
|
---|
127 |
|
---|
128 |
|
---|
129 | inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
---|
130 | Qt::TransformationMode mode = Qt::FastTransformation) const
|
---|
131 | { return scaled(QSize(w, h), aspectMode, mode); }
|
---|
132 | QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
---|
133 | Qt::TransformationMode mode = Qt::FastTransformation) const;
|
---|
134 | QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
---|
135 | QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
---|
136 | QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
---|
137 | static QMatrix trueMatrix(const QMatrix &m, int w, int h);
|
---|
138 | QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
---|
139 | static QTransform trueMatrix(const QTransform &m, int w, int h);
|
---|
140 |
|
---|
141 | QImage toImage() const;
|
---|
142 | static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
143 | static QPixmap fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
144 |
|
---|
145 | bool load(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
146 | bool loadFromData(const uchar *buf, uint len, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
147 | inline bool loadFromData(const QByteArray &data, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
148 | bool save(const QString& fileName, const char* format = 0, int quality = -1) const;
|
---|
149 | bool save(QIODevice* device, const char* format = 0, int quality = -1) const;
|
---|
150 |
|
---|
151 | bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
---|
152 |
|
---|
153 | #if defined(Q_WS_WIN)
|
---|
154 | enum HBitmapFormat {
|
---|
155 | NoAlpha,
|
---|
156 | PremultipliedAlpha,
|
---|
157 | Alpha
|
---|
158 | };
|
---|
159 |
|
---|
160 | HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
|
---|
161 | HICON toWinHICON() const;
|
---|
162 |
|
---|
163 | static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
|
---|
164 | static QPixmap fromWinHICON(HICON hicon);
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | #if defined(Q_WS_PM)
|
---|
168 | HBITMAP toPmHBITMAP(HBITMAP *mask = 0, bool embedRealAlpha = false) const;
|
---|
169 | static QPixmap fromPmHBITMAP(HBITMAP hbm, HBITMAP hbmMask = NULLHANDLE);
|
---|
170 | static HPOINTER toPmHPOINTER(const QIcon &icon, bool isPointer = false,
|
---|
171 | int hotX = 0, int hotY = 0,
|
---|
172 | bool embedRealAlpha = false, bool isMini = true);
|
---|
173 | static QIcon fromPmHPOINTER(HPOINTER hpointer, QPixmap *pixmap = 0,
|
---|
174 | QPixmap *pixmapMini = 0);
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | #if defined(Q_WS_MAC)
|
---|
178 | CGImageRef toMacCGImageRef() const;
|
---|
179 | static QPixmap fromMacCGImageRef(CGImageRef image);
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | #if defined(Q_OS_SYMBIAN)
|
---|
183 | CFbsBitmap *toSymbianCFbsBitmap() const;
|
---|
184 | static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
|
---|
185 | RSgImage* toSymbianRSgImage() const;
|
---|
186 | static QPixmap fromSymbianRSgImage(RSgImage *sgImage);
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | inline QPixmap copy(int x, int y, int width, int height) const;
|
---|
190 | QPixmap copy(const QRect &rect = QRect()) const;
|
---|
191 |
|
---|
192 | inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
|
---|
193 | void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
|
---|
194 |
|
---|
195 | int serialNumber() const;
|
---|
196 | qint64 cacheKey() const;
|
---|
197 |
|
---|
198 | bool isDetached() const;
|
---|
199 | void detach();
|
---|
200 |
|
---|
201 | bool isQBitmap() const;
|
---|
202 |
|
---|
203 | #if defined(Q_WS_QWS)
|
---|
204 | const uchar *qwsBits() const;
|
---|
205 | int qwsBytesPerLine() const;
|
---|
206 | QRgb *clut() const;
|
---|
207 | #ifdef QT_DEPRECATED
|
---|
208 | QT_DEPRECATED int numCols() const;
|
---|
209 | #endif
|
---|
210 | int colorCount() const;
|
---|
211 | #elif defined(Q_WS_MAC)
|
---|
212 | Qt::HANDLE macQDHandle() const;
|
---|
213 | Qt::HANDLE macQDAlphaHandle() const;
|
---|
214 | Qt::HANDLE macCGHandle() const;
|
---|
215 | #elif defined(Q_WS_X11)
|
---|
216 | enum ShareMode { ImplicitlyShared, ExplicitlyShared };
|
---|
217 |
|
---|
218 | static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared);
|
---|
219 | static int x11SetDefaultScreen(int screen);
|
---|
220 | void x11SetScreen(int screen);
|
---|
221 | const QX11Info &x11Info() const;
|
---|
222 | Qt::HANDLE x11PictureHandle() const;
|
---|
223 | #endif
|
---|
224 |
|
---|
225 | #if defined(Q_WS_X11) || defined(Q_WS_QWS)
|
---|
226 | Qt::HANDLE handle() const;
|
---|
227 | #endif
|
---|
228 |
|
---|
229 | QPaintEngine *paintEngine() const;
|
---|
230 |
|
---|
231 | inline bool operator!() const { return isNull(); }
|
---|
232 |
|
---|
233 | protected:
|
---|
234 | int metric(PaintDeviceMetric) const;
|
---|
235 |
|
---|
236 | #ifdef QT3_SUPPORT
|
---|
237 | public:
|
---|
238 | enum ColorMode { Auto, Color, Mono };
|
---|
239 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode);
|
---|
240 | QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode);
|
---|
241 | QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode);
|
---|
242 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image);
|
---|
243 | QT3_SUPPORT QPixmap &operator=(const QImage &);
|
---|
244 | inline QT3_SUPPORT QImage convertToImage() const { return toImage(); }
|
---|
245 | QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode);
|
---|
246 | inline QT3_SUPPORT operator QImage() const { return toImage(); }
|
---|
247 | inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
|
---|
248 | inline QT3_SUPPORT bool selfMask() const { return false; }
|
---|
249 | private:
|
---|
250 | void resize_helper(const QSize &s);
|
---|
251 | public:
|
---|
252 | inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); }
|
---|
253 | inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); }
|
---|
254 | #endif
|
---|
255 |
|
---|
256 | private:
|
---|
257 | QExplicitlySharedDataPointer<QPixmapData> data;
|
---|
258 |
|
---|
259 | bool doImageIO(QImageWriter *io, int quality) const;
|
---|
260 |
|
---|
261 | // ### Qt5: remove the following three lines
|
---|
262 | enum Type { PixmapType, BitmapType }; // must match QPixmapData::PixelType
|
---|
263 | QPixmap(const QSize &s, Type);
|
---|
264 | void init(int, int, Type = PixmapType);
|
---|
265 |
|
---|
266 | QPixmap(const QSize &s, int type);
|
---|
267 | void init(int, int, int);
|
---|
268 | void deref();
|
---|
269 | #if defined(Q_WS_WIN)
|
---|
270 | void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi);
|
---|
271 | #endif
|
---|
272 | Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
|
---|
273 | #ifdef Q_WS_MAC
|
---|
274 | friend CGContextRef qt_mac_cg_context(const QPaintDevice*);
|
---|
275 | friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&);
|
---|
276 | friend IconRef qt_mac_create_iconref(const QPixmap&);
|
---|
277 | friend quint32 *qt_mac_pixmap_get_base(const QPixmap*);
|
---|
278 | friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*);
|
---|
279 | #endif
|
---|
280 | friend class QPixmapData;
|
---|
281 | friend class QX11PixmapData;
|
---|
282 | friend class QMacPixmapData;
|
---|
283 | friend class QS60PixmapData;
|
---|
284 | friend class QBitmap;
|
---|
285 | friend class QPaintDevice;
|
---|
286 | friend class QPainter;
|
---|
287 | friend class QGLWidget;
|
---|
288 | friend class QX11PaintEngine;
|
---|
289 | friend class QCoreGraphicsPaintEngine;
|
---|
290 | friend class QWidgetPrivate;
|
---|
291 | friend class QRasterBuffer;
|
---|
292 | #if !defined(QT_NO_DATASTREAM)
|
---|
293 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
---|
294 | #endif
|
---|
295 | friend Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap);
|
---|
296 |
|
---|
297 | public:
|
---|
298 | QPixmapData* pixmapData() const;
|
---|
299 |
|
---|
300 | public:
|
---|
301 | typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
|
---|
302 | inline DataPtr &data_ptr() { return data; }
|
---|
303 | };
|
---|
304 |
|
---|
305 | Q_DECLARE_SHARED(QPixmap)
|
---|
306 |
|
---|
307 | inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
|
---|
308 | {
|
---|
309 | return copy(QRect(ax, ay, awidth, aheight));
|
---|
310 | }
|
---|
311 |
|
---|
312 | inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
|
---|
313 | {
|
---|
314 | scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
|
---|
315 | }
|
---|
316 |
|
---|
317 | inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
|
---|
318 | Qt::ImageConversionFlags flags)
|
---|
319 | {
|
---|
320 | return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags);
|
---|
321 | }
|
---|
322 |
|
---|
323 | /*****************************************************************************
|
---|
324 | QPixmap stream functions
|
---|
325 | *****************************************************************************/
|
---|
326 |
|
---|
327 | #if !defined(QT_NO_DATASTREAM)
|
---|
328 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
|
---|
329 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
---|
330 | #endif
|
---|
331 |
|
---|
332 | /*****************************************************************************
|
---|
333 | QPixmap (and QImage) helper functions
|
---|
334 | *****************************************************************************/
|
---|
335 | #ifdef QT3_SUPPORT
|
---|
336 | QT3_SUPPORT Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src,
|
---|
337 | int sx=0, int sy=0, int sw=-1, int sh=-1);
|
---|
338 | #endif // QT3_SUPPORT
|
---|
339 |
|
---|
340 | QT_END_NAMESPACE
|
---|
341 |
|
---|
342 | QT_END_HEADER
|
---|
343 |
|
---|
344 | #endif // QPIXMAP_H
|
---|