| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2011 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 |
#ifdef QT_DEPRECATED |
| 189 |
QT_DEPRECATED int numCols() const; |
| 190 |
#endif |
| 191 |
int colorCount() const; |
| 192 |
#elif defined(Q_WS_MAC) |
| 193 |
Qt::HANDLE macQDHandle() const; |
| 194 |
Qt::HANDLE macQDAlphaHandle() const; |
| 195 |
Qt::HANDLE macCGHandle() const; |
| 196 |
#elif defined(Q_WS_X11) |
| 197 |
enum ShareMode { ImplicitlyShared, ExplicitlyShared }; |
| 198 |
|
| 199 |
static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared); |
| 200 |
static int x11SetDefaultScreen(int screen); |
| 201 |
void x11SetScreen(int screen); |
| 202 |
const QX11Info &x11Info() const; |
| 203 |
Qt::HANDLE x11PictureHandle() const; |
| 204 |
#endif |
| 205 |
|
| 206 |
#if defined(Q_WS_X11) || defined(Q_WS_QWS) |
| 207 |
Qt::HANDLE handle() const; |
| 208 |
#endif |
| 209 |
|
| 210 |
QPaintEngine *paintEngine() const; |
| 211 |
|
| 212 |
inline bool operator!() const { return isNull(); } |
| 213 |
|
| 214 |
protected: |
| 215 |
int metric(PaintDeviceMetric) const; |
| 216 |
|
| 217 |
#ifdef QT3_SUPPORT |
| 218 |
public: |
| 219 |
enum ColorMode { Auto, Color, Mono }; |
| 220 |
QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode); |
| 221 |
QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode); |
| 222 |
QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode); |
| 223 |
QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image); |
| 224 |
QT3_SUPPORT QPixmap &operator=(const QImage &); |
| 225 |
inline QT3_SUPPORT QImage convertToImage() const { return toImage(); } |
| 226 |
QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode); |
| 227 |
QT3_SUPPORT bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| 228 |
{ (*this) = fromImage(img, flags); return !isNull(); } |
| 229 |
inline QT3_SUPPORT operator QImage() const { return toImage(); } |
| 230 |
inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); } |
| 231 |
inline QT3_SUPPORT bool selfMask() const { return false; } |
| 232 |
private: |
| 233 |
void resize_helper(const QSize &s); |
| 234 |
public: |
| 235 |
inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); } |
| 236 |
inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); } |
| 237 |
#endif |
| 238 |
|
| 239 |
private: |
| 240 |
QExplicitlySharedDataPointer<QPixmapData> data; |
| 241 |
|
| 242 |
bool doImageIO(QImageWriter *io, int quality) const; |
| 243 |
|
| 244 |
// ### Qt5: remove the following three lines |
| 245 |
enum Type { PixmapType, BitmapType }; // must match QPixmapData::PixelType |
| 246 |
QPixmap(const QSize &s, Type); |
| 247 |
void init(int, int, Type = PixmapType); |
| 248 |
|
| 249 |
QPixmap(const QSize &s, int type); |
| 250 |
void init(int, int, int); |
| 251 |
void deref(); |
| 252 |
#if defined(Q_WS_WIN) |
| 253 |
void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi); |
| 254 |
#endif |
| 255 |
Q_DUMMY_COMPARISON_OPERATOR(QPixmap) |
| 256 |
#ifdef Q_WS_MAC |
| 257 |
friend CGContextRef qt_mac_cg_context(const QPaintDevice*); |
| 258 |
friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&); |
| 259 |
friend IconRef qt_mac_create_iconref(const QPixmap&); |
| 260 |
friend quint32 *qt_mac_pixmap_get_base(const QPixmap*); |
| 261 |
friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*); |
| 262 |
#endif |
| 263 |
friend class QPixmapData; |
| 264 |
friend class QX11PixmapData; |
| 265 |
friend class QMacPixmapData; |
| 266 |
friend class QS60PixmapData; |
| 267 |
friend class QBitmap; |
| 268 |
friend class QPaintDevice; |
| 269 |
friend class QPainter; |
| 270 |
friend class QGLWidget; |
| 271 |
friend class QX11PaintEngine; |
| 272 |
friend class QCoreGraphicsPaintEngine; |
| 273 |
friend class QWidgetPrivate; |
| 274 |
friend class QRasterPaintEngine; |
| 275 |
friend class QRasterBuffer; |
| 276 |
friend class QPixmapCacheEntry; |
| 277 |
#if !defined(QT_NO_DATASTREAM) |
| 278 |
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); |
| 279 |
#endif |
| 280 |
friend Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap); |
| 281 |
|
| 282 |
public: |
| 283 |
QPixmapData* pixmapData() const; |
| 284 |
|
| 285 |
public: |
| 286 |
typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr; |
| 287 |
inline DataPtr &data_ptr() { return data; } |
| 288 |
}; |
| 289 |
|
| 290 |
Q_DECLARE_SHARED(QPixmap) |
| 291 |
|
| 292 |
inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const |
| 293 |
{ |
| 294 |
return copy(QRect(ax, ay, awidth, aheight)); |
| 295 |
} |
| 296 |
|
| 297 |
inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed) |
| 298 |
{ |
| 299 |
scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed); |
| 300 |
} |
| 301 |
|
| 302 |
inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format, |
| 303 |
Qt::ImageConversionFlags flags) |
| 304 |
{ |
| 305 |
return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags); |
| 306 |
} |
| 307 |
|
| 308 |
/***************************************************************************** |
| 309 |
QPixmap stream functions |
| 310 |
*****************************************************************************/ |
| 311 |
|
| 312 |
#if !defined(QT_NO_DATASTREAM) |
| 313 |
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &); |
| 314 |
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); |
| 315 |
#endif |
| 316 |
|
| 317 |
/***************************************************************************** |
| 318 |
QPixmap (and QImage) helper functions |
| 319 |
*****************************************************************************/ |
| 320 |
#ifdef QT3_SUPPORT |
| 321 |
QT3_SUPPORT Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src, |
| 322 |
int sx=0, int sy=0, int sw=-1, int sh=-1); |
| 323 |
#endif // QT3_SUPPORT |
| 324 |
|
| 325 |
QT_END_NAMESPACE |
| 326 |
|
| 327 |
QT_END_HEADER |
| 328 |
|
| 329 |
#endif // QPIXMAP_H |