source: trunk/src/gui/image/qpixmap.h@ 260

Last change on this file since 260 was 260, checked in by Dmitry A. Kuminov, 16 years ago

gui: QPixmap: Created OS/2 specific methods for converting pixmaps to HBITMAPs and HPOINTERs.

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