0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 QColor;
|
|
66 |
class QVariant;
|
|
67 |
class QX11Info;
|
|
68 |
class QPixmapData;
|
|
69 |
|
|
70 |
class Q_GUI_EXPORT QPixmap : public QPaintDevice
|
|
71 |
{
|
|
72 |
public:
|
|
73 |
QPixmap();
|
|
74 |
explicit QPixmap(QPixmapData *data);
|
|
75 |
QPixmap(int w, int h);
|
|
76 |
QPixmap(const QSize &);
|
|
77 |
QPixmap(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|
78 |
#ifndef QT_NO_IMAGEFORMAT_XPM
|
|
79 |
QPixmap(const char * const xpm[]);
|
|
80 |
#endif
|
|
81 |
QPixmap(const QPixmap &);
|
|
82 |
~QPixmap();
|
|
83 |
|
|
84 |
QPixmap &operator=(const QPixmap &);
|
|
85 |
operator QVariant() const;
|
|
86 |
|
|
87 |
bool isNull() const; // ### Qt 5: make inline
|
|
88 |
int devType() const;
|
|
89 |
|
|
90 |
int width() const; // ### Qt 5: make inline
|
|
91 |
int height() const; // ### Qt 5: make inline
|
|
92 |
QSize size() const;
|
|
93 |
QRect rect() const;
|
|
94 |
int depth() const;
|
|
95 |
|
|
96 |
static int defaultDepth();
|
|
97 |
|
|
98 |
void fill(const QColor &fillColor = Qt::white);
|
|
99 |
void fill(const QWidget *widget, const QPoint &ofs);
|
|
100 |
inline void fill(const QWidget *widget, int xofs, int yofs) { fill(widget, QPoint(xofs, yofs)); }
|
|
101 |
|
|
102 |
QBitmap mask() const;
|
|
103 |
void setMask(const QBitmap &);
|
|
104 |
|
|
105 |
QPixmap alphaChannel() const;
|
|
106 |
void setAlphaChannel(const QPixmap &);
|
|
107 |
|
|
108 |
bool hasAlpha() const;
|
|
109 |
bool hasAlphaChannel() const;
|
|
110 |
|
|
111 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
|
112 |
QBitmap createHeuristicMask(bool clipTight = true) const;
|
|
113 |
#endif
|
|
114 |
QBitmap createMaskFromColor(const QColor &maskColor) const; // ### Qt 5: remove
|
|
115 |
QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const;
|
|
116 |
|
|
117 |
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
|
|
118 |
static QPixmap grabWidget(QWidget *widget, const QRect &rect);
|
|
119 |
static inline QPixmap grabWidget(QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
|
|
120 |
{ return grabWidget(widget, QRect(x, y, w, h)); }
|
|
121 |
|
|
122 |
|
|
123 |
inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|
124 |
Qt::TransformationMode mode = Qt::FastTransformation) const
|
|
125 |
{ return scaled(QSize(w, h), aspectMode, mode); }
|
|
126 |
QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|
127 |
Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|
128 |
QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|
129 |
QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|
130 |
QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|
131 |
static QMatrix trueMatrix(const QMatrix &m, int w, int h);
|
|
132 |
QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|
133 |
static QTransform trueMatrix(const QTransform &m, int w, int h);
|
|
134 |
|
|
135 |
QImage toImage() const;
|
|
136 |
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|
137 |
|
|
138 |
bool load(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|
139 |
bool loadFromData(const uchar *buf, uint len, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|
140 |
inline bool loadFromData(const QByteArray &data, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|
141 |
bool save(const QString& fileName, const char* format = 0, int quality = -1) const;
|
|
142 |
bool save(QIODevice* device, const char* format = 0, int quality = -1) const;
|
|
143 |
|
|
144 |
#if defined(Q_WS_WIN)
|
|
145 |
enum HBitmapFormat {
|
|
146 |
NoAlpha,
|
|
147 |
PremultipliedAlpha,
|
|
148 |
Alpha
|
|
149 |
};
|
|
150 |
|
|
151 |
HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
|
|
152 |
HICON toWinHICON() const;
|
|
153 |
|
|
154 |
static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
|
|
155 |
static QPixmap fromWinHICON(HICON hicon);
|
|
156 |
#endif
|
|
157 |
|
|
158 |
#if defined(Q_WS_MAC)
|
|
159 |
CGImageRef toMacCGImageRef() const;
|
|
160 |
static QPixmap fromMacCGImageRef(CGImageRef image);
|
|
161 |
#endif
|
|
162 |
|
|
163 |
#if defined(Q_OS_SYMBIAN)
|
|
164 |
CFbsBitmap *toSymbianCFbsBitmap() const;
|
|
165 |
static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
|
|
166 |
RSgImage* toSymbianRSgImage() const;
|
|
167 |
static QPixmap fromSymbianRSgImage(RSgImage *sgImage);
|
|
168 |
#endif
|
|
169 |
|
|
170 |
inline QPixmap copy(int x, int y, int width, int height) const;
|
|
171 |
QPixmap copy(const QRect &rect = QRect()) const;
|
|
172 |
|
|
173 |
inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
|
|
174 |
void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
|
|
175 |
|
|
176 |
int serialNumber() const;
|
|
177 |
qint64 cacheKey() const;
|
|
178 |
|
|
179 |
bool isDetached() const;
|
|
180 |
void detach();
|
|
181 |
|
|
182 |
bool isQBitmap() const;
|
|
183 |
|
|
184 |
#if defined(Q_WS_QWS)
|
|
185 |
const uchar *qwsBits() const;
|
|
186 |
int qwsBytesPerLine() const;
|
|
187 |
QRgb *clut() const;
|
|
188 |
int numCols() const;
|
|
189 |
#elif defined(Q_WS_MAC)
|
|
190 |
Qt::HANDLE macQDHandle() const;
|
|
191 |
Qt::HANDLE macQDAlphaHandle() const;
|
|
192 |
Qt::HANDLE macCGHandle() const;
|
|
193 |
#elif defined(Q_WS_X11)
|
|
194 |
enum ShareMode { ImplicitlyShared, ExplicitlyShared };
|
|
195 |
|
|
196 |
static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared);
|
|
197 |
static int x11SetDefaultScreen(int screen);
|
|
198 |
void x11SetScreen(int screen);
|
|
199 |
const QX11Info &x11Info() const;
|
|
200 |
Qt::HANDLE x11PictureHandle() const;
|
|
201 |
#endif
|
|
202 |
|
|
203 |
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
|
|
204 |
Qt::HANDLE handle() const;
|
|
205 |
#endif
|
|
206 |
|
|
207 |
QPaintEngine *paintEngine() const;
|
|
208 |
|
|
209 |
inline bool operator!() const { return isNull(); }
|
|
210 |
|
|
211 |
protected:
|
|
212 |
int metric(PaintDeviceMetric) const;
|
|
213 |
|
|
214 |
#ifdef QT3_SUPPORT
|
|
215 |
public:
|
|
216 |
enum ColorMode { Auto, Color, Mono };
|
|
217 |
QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode);
|
|
218 |
QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode);
|
|
219 |
QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode);
|
|
220 |
QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image);
|
|
221 |
QT3_SUPPORT QPixmap &operator=(const QImage &);
|
|
222 |
inline QT3_SUPPORT QImage convertToImage() const { return toImage(); }
|
|
223 |
QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode);
|
|
224 |
QT3_SUPPORT bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor)
|
|
225 |
{ (*this) = fromImage(img, flags); return !isNull(); }
|
|
226 |
inline QT3_SUPPORT operator QImage() const { return toImage(); }
|
|
227 |
inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
|
|
228 |
inline QT3_SUPPORT bool selfMask() const { return false; }
|
|
229 |
private:
|
|
230 |
void resize_helper(const QSize &s);
|
|
231 |
public:
|
|
232 |
inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); }
|
|
233 |
inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); }
|
|
234 |
#endif
|
|
235 |
|
|
236 |
private:
|
|
237 |
QExplicitlySharedDataPointer<QPixmapData> data;
|
|
238 |
|
|
239 |
bool doImageIO(QImageWriter *io, int quality) const;
|
|
240 |
|
|
241 |
// ### Qt5: remove the following three lines
|
|
242 |
enum Type { PixmapType, BitmapType }; // must match QPixmapData::PixelType
|
|
243 |
QPixmap(const QSize &s, Type);
|
|
244 |
void init(int, int, Type = PixmapType);
|
|
245 |
|
|
246 |
QPixmap(const QSize &s, int type);
|
|
247 |
void init(int, int, int);
|
|
248 |
void deref();
|
|
249 |
#if defined(Q_WS_WIN)
|
|
250 |
void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi);
|
|
251 |
#endif
|
|
252 |
Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
|
|
253 |
#ifdef Q_WS_MAC
|
|
254 |
friend CGContextRef qt_mac_cg_context(const QPaintDevice*);
|
|
255 |
friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&);
|
|
256 |
friend IconRef qt_mac_create_iconref(const QPixmap&);
|
|
257 |
friend quint32 *qt_mac_pixmap_get_base(const QPixmap*);
|
|
258 |
friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*);
|
|
259 |
#endif
|
|
260 |
friend class QPixmapData;
|
|
261 |
friend class QX11PixmapData;
|
|
262 |
friend class QMacPixmapData;
|
|
263 |
friend class QS60PixmapData;
|
|
264 |
friend class QBitmap;
|
|
265 |
friend class QPaintDevice;
|
|
266 |
friend class QPainter;
|
|
267 |
friend class QGLWidget;
|
|
268 |
friend class QX11PaintEngine;
|
|
269 |
friend class QCoreGraphicsPaintEngine;
|
|
270 |
friend class QWidgetPrivate;
|
|
271 |
friend class QRasterPaintEngine;
|
|
272 |
friend class QRasterBuffer;
|
|
273 |
friend class QPixmapCacheEntry;
|
|
274 |
#if !defined(QT_NO_DATASTREAM)
|
|
275 |
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
|
276 |
#endif
|
|
277 |
friend Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap);
|
|
278 |
|
|
279 |
public:
|
|
280 |
QPixmapData* pixmapData() const;
|
|
281 |
|
|
282 |
public:
|
|
283 |
typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
|
|
284 |
inline DataPtr &data_ptr() { return data; }
|
|
285 |
};
|
|
286 |
|
|
287 |
Q_DECLARE_SHARED(QPixmap)
|
|
288 |
|
|
289 |
inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
|
|
290 |
{
|
|
291 |
return copy(QRect(ax, ay, awidth, aheight));
|
|
292 |
}
|
|
293 |
|
|
294 |
inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
|
|
295 |
{
|
|
296 |
scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
|
|
297 |
}
|
|
298 |
|
|
299 |
inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
|
|
300 |
Qt::ImageConversionFlags flags)
|
|
301 |
{
|
|
302 |
return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags);
|
|
303 |
}
|
|
304 |
|
|
305 |
/*****************************************************************************
|
|
306 |
QPixmap stream functions
|
|
307 |
*****************************************************************************/
|
|
308 |
|
|
309 |
#if !defined(QT_NO_DATASTREAM)
|
|
310 |
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
|
|
311 |
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
|
312 |
#endif
|
|
313 |
|
|
314 |
/*****************************************************************************
|
|
315 |
QPixmap (and QImage) helper functions
|
|
316 |
*****************************************************************************/
|
|
317 |
#ifdef QT3_SUPPORT
|
|
318 |
QT3_SUPPORT Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src,
|
|
319 |
int sx=0, int sy=0, int sw=-1, int sh=-1);
|
|
320 |
#endif // QT3_SUPPORT
|
|
321 |
|
|
322 |
QT_END_NAMESPACE
|
|
323 |
|
|
324 |
QT_END_HEADER
|
|
325 |
|
|
326 |
#endif // QPIXMAP_H
|