| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 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 | ** 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 qt-info@nokia.com.
|
|---|
| 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 |
|
|---|
| 69 | #if defined(Q_WS_PM)
|
|---|
| 70 | class QIcon;
|
|---|
| 71 | #endif
|
|---|
| 72 |
|
|---|
| 73 | class QPixmapData;
|
|---|
| 74 |
|
|---|
| 75 | class Q_GUI_EXPORT QPixmap : public QPaintDevice
|
|---|
| 76 | {
|
|---|
| 77 | public:
|
|---|
| 78 | QPixmap();
|
|---|
| 79 | explicit QPixmap(QPixmapData *data);
|
|---|
| 80 | QPixmap(int w, int h);
|
|---|
| 81 | QPixmap(const QSize &);
|
|---|
| 82 | QPixmap(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 83 | #ifndef QT_NO_IMAGEFORMAT_XPM
|
|---|
| 84 | QPixmap(const char * const xpm[]);
|
|---|
| 85 | #endif
|
|---|
| 86 | QPixmap(const QPixmap &);
|
|---|
| 87 | ~QPixmap();
|
|---|
| 88 |
|
|---|
| 89 | QPixmap &operator=(const QPixmap &);
|
|---|
| 90 | operator QVariant() const;
|
|---|
| 91 |
|
|---|
| 92 | bool isNull() const; // ### Qt 5: make inline
|
|---|
| 93 | int devType() const;
|
|---|
| 94 |
|
|---|
| 95 | int width() const; // ### Qt 5: make inline
|
|---|
| 96 | int height() const; // ### Qt 5: make inline
|
|---|
| 97 | QSize size() const;
|
|---|
| 98 | QRect rect() const;
|
|---|
| 99 | int depth() const;
|
|---|
| 100 |
|
|---|
| 101 | static int defaultDepth();
|
|---|
| 102 |
|
|---|
| 103 | void fill(const QColor &fillColor = Qt::white);
|
|---|
| 104 | void fill(const QWidget *widget, const QPoint &ofs);
|
|---|
| 105 | inline void fill(const QWidget *widget, int xofs, int yofs) { fill(widget, QPoint(xofs, yofs)); }
|
|---|
| 106 |
|
|---|
| 107 | QBitmap mask() const;
|
|---|
| 108 | void setMask(const QBitmap &);
|
|---|
| 109 |
|
|---|
| 110 | QPixmap alphaChannel() const;
|
|---|
| 111 | void setAlphaChannel(const QPixmap &);
|
|---|
| 112 |
|
|---|
| 113 | bool hasAlpha() const;
|
|---|
| 114 | bool hasAlphaChannel() const;
|
|---|
| 115 |
|
|---|
| 116 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
|---|
| 117 | QBitmap createHeuristicMask(bool clipTight = true) const;
|
|---|
| 118 | #endif
|
|---|
| 119 | QBitmap createMaskFromColor(const QColor &maskColor) const; // ### Qt 5: remove
|
|---|
| 120 | QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const;
|
|---|
| 121 |
|
|---|
| 122 | static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
|
|---|
| 123 | static QPixmap grabWidget(QWidget *widget, const QRect &rect);
|
|---|
| 124 | static inline QPixmap grabWidget(QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
|
|---|
| 125 | { return grabWidget(widget, QRect(x, y, w, h)); }
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 129 | Qt::TransformationMode mode = Qt::FastTransformation) const
|
|---|
| 130 | { return scaled(QSize(w, h), aspectMode, mode); }
|
|---|
| 131 | QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 132 | Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 133 | QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 134 | QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 135 | QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 136 | static QMatrix trueMatrix(const QMatrix &m, int w, int h);
|
|---|
| 137 | QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 138 | static QTransform trueMatrix(const QTransform &m, int w, int h);
|
|---|
| 139 |
|
|---|
| 140 | QImage toImage() const;
|
|---|
| 141 | static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 142 |
|
|---|
| 143 | bool load(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 144 | bool loadFromData(const uchar *buf, uint len, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 145 | inline bool loadFromData(const QByteArray &data, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 146 | bool save(const QString& fileName, const char* format = 0, int quality = -1) const;
|
|---|
| 147 | bool save(QIODevice* device, const char* format = 0, int quality = -1) const;
|
|---|
| 148 |
|
|---|
| 149 | #if defined(Q_WS_WIN)
|
|---|
| 150 | enum HBitmapFormat {
|
|---|
| 151 | NoAlpha,
|
|---|
| 152 | PremultipliedAlpha,
|
|---|
| 153 | Alpha
|
|---|
| 154 | };
|
|---|
| 155 |
|
|---|
| 156 | HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
|
|---|
| 157 | HICON toWinHICON() const;
|
|---|
| 158 |
|
|---|
| 159 | static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
|
|---|
| 160 | static QPixmap fromWinHICON(HICON hicon);
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | #if defined(Q_WS_PM)
|
|---|
| 164 | HBITMAP toPmHBITMAP(HBITMAP *mask = 0, bool embedRealAlpha = false) const;
|
|---|
| 165 | static QPixmap fromPmHBITMAP(HBITMAP hbm, HBITMAP hbmMask = NULLHANDLE);
|
|---|
| 166 | static HPOINTER toPmHPOINTER(const QIcon &icon, bool isPointer = false,
|
|---|
| 167 | int hotX = 0, int hotY = 0,
|
|---|
| 168 | bool embedRealAlpha = false, bool isMini = true);
|
|---|
| 169 | static QIcon fromPmHPOINTER(HPOINTER hpointer, QPixmap *pixmap = 0,
|
|---|
| 170 | QPixmap *pixmapMini = 0);
|
|---|
| 171 | #endif
|
|---|
| 172 |
|
|---|
| 173 | #if defined(Q_WS_MAC)
|
|---|
| 174 | CGImageRef toMacCGImageRef() const;
|
|---|
| 175 | static QPixmap fromMacCGImageRef(CGImageRef image);
|
|---|
| 176 | #endif
|
|---|
| 177 |
|
|---|
| 178 | #if defined(Q_OS_SYMBIAN)
|
|---|
| 179 | CFbsBitmap *toSymbianCFbsBitmap() const;
|
|---|
| 180 | static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
|
|---|
| 181 | RSgImage* toSymbianRSgImage() const;
|
|---|
| 182 | static QPixmap fromSymbianRSgImage(RSgImage *sgImage);
|
|---|
| 183 | #endif
|
|---|
| 184 |
|
|---|
| 185 | inline QPixmap copy(int x, int y, int width, int height) const;
|
|---|
| 186 | QPixmap copy(const QRect &rect = QRect()) const;
|
|---|
| 187 |
|
|---|
| 188 | inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
|
|---|
| 189 | void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
|
|---|
| 190 |
|
|---|
| 191 | int serialNumber() const;
|
|---|
| 192 | qint64 cacheKey() const;
|
|---|
| 193 |
|
|---|
| 194 | bool isDetached() const;
|
|---|
| 195 | void detach();
|
|---|
| 196 |
|
|---|
| 197 | bool isQBitmap() const;
|
|---|
| 198 |
|
|---|
| 199 | #if defined(Q_WS_QWS)
|
|---|
| 200 | const uchar *qwsBits() const;
|
|---|
| 201 | int qwsBytesPerLine() const;
|
|---|
| 202 | QRgb *clut() const;
|
|---|
| 203 | #ifdef QT_DEPRECATED
|
|---|
| 204 | QT_DEPRECATED int numCols() const;
|
|---|
| 205 | #endif
|
|---|
| 206 | int colorCount() const;
|
|---|
| 207 | #elif defined(Q_WS_MAC)
|
|---|
| 208 | Qt::HANDLE macQDHandle() const;
|
|---|
| 209 | Qt::HANDLE macQDAlphaHandle() const;
|
|---|
| 210 | Qt::HANDLE macCGHandle() const;
|
|---|
| 211 | #elif defined(Q_WS_X11)
|
|---|
| 212 | enum ShareMode { ImplicitlyShared, ExplicitlyShared };
|
|---|
| 213 |
|
|---|
| 214 | static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared);
|
|---|
| 215 | static int x11SetDefaultScreen(int screen);
|
|---|
| 216 | void x11SetScreen(int screen);
|
|---|
| 217 | const QX11Info &x11Info() const;
|
|---|
| 218 | Qt::HANDLE x11PictureHandle() const;
|
|---|
| 219 | #endif
|
|---|
| 220 |
|
|---|
| 221 | #if defined(Q_WS_X11) || defined(Q_WS_QWS)
|
|---|
| 222 | Qt::HANDLE handle() const;
|
|---|
| 223 | #endif
|
|---|
| 224 |
|
|---|
| 225 | QPaintEngine *paintEngine() const;
|
|---|
| 226 |
|
|---|
| 227 | inline bool operator!() const { return isNull(); }
|
|---|
| 228 |
|
|---|
| 229 | protected:
|
|---|
| 230 | int metric(PaintDeviceMetric) const;
|
|---|
| 231 |
|
|---|
| 232 | #ifdef QT3_SUPPORT
|
|---|
| 233 | public:
|
|---|
| 234 | enum ColorMode { Auto, Color, Mono };
|
|---|
| 235 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode);
|
|---|
| 236 | QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode);
|
|---|
| 237 | QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode);
|
|---|
| 238 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image);
|
|---|
| 239 | QT3_SUPPORT QPixmap &operator=(const QImage &);
|
|---|
| 240 | inline QT3_SUPPORT QImage convertToImage() const { return toImage(); }
|
|---|
| 241 | QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode);
|
|---|
| 242 | QT3_SUPPORT bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor)
|
|---|
| 243 | { (*this) = fromImage(img, flags); return !isNull(); }
|
|---|
| 244 | inline QT3_SUPPORT operator QImage() const { return toImage(); }
|
|---|
| 245 | inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
|
|---|
| 246 | inline QT3_SUPPORT bool selfMask() const { return false; }
|
|---|
| 247 | private:
|
|---|
| 248 | void resize_helper(const QSize &s);
|
|---|
| 249 | public:
|
|---|
| 250 | inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); }
|
|---|
| 251 | inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); }
|
|---|
| 252 | #endif
|
|---|
| 253 |
|
|---|
| 254 | private:
|
|---|
| 255 | QExplicitlySharedDataPointer<QPixmapData> data;
|
|---|
| 256 |
|
|---|
| 257 | bool doImageIO(QImageWriter *io, int quality) const;
|
|---|
| 258 |
|
|---|
| 259 | // ### Qt5: remove the following three lines
|
|---|
| 260 | enum Type { PixmapType, BitmapType }; // must match QPixmapData::PixelType
|
|---|
| 261 | QPixmap(const QSize &s, Type);
|
|---|
| 262 | void init(int, int, Type = PixmapType);
|
|---|
| 263 |
|
|---|
| 264 | QPixmap(const QSize &s, int type);
|
|---|
| 265 | void init(int, int, int);
|
|---|
| 266 | void deref();
|
|---|
| 267 | #if defined(Q_WS_WIN)
|
|---|
| 268 | void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi);
|
|---|
| 269 | #endif
|
|---|
| 270 | Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
|
|---|
| 271 | #ifdef Q_WS_MAC
|
|---|
| 272 | friend CGContextRef qt_mac_cg_context(const QPaintDevice*);
|
|---|
| 273 | friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&);
|
|---|
| 274 | friend IconRef qt_mac_create_iconref(const QPixmap&);
|
|---|
| 275 | friend quint32 *qt_mac_pixmap_get_base(const QPixmap*);
|
|---|
| 276 | friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*);
|
|---|
| 277 | #endif
|
|---|
| 278 | friend class QPixmapData;
|
|---|
| 279 | friend class QX11PixmapData;
|
|---|
| 280 | friend class QMacPixmapData;
|
|---|
| 281 | friend class QS60PixmapData;
|
|---|
| 282 | friend class QBitmap;
|
|---|
| 283 | friend class QPaintDevice;
|
|---|
| 284 | friend class QPainter;
|
|---|
| 285 | friend class QGLWidget;
|
|---|
| 286 | friend class QX11PaintEngine;
|
|---|
| 287 | friend class QCoreGraphicsPaintEngine;
|
|---|
| 288 | friend class QWidgetPrivate;
|
|---|
| 289 | friend class QRasterPaintEngine;
|
|---|
| 290 | friend class QRasterBuffer;
|
|---|
| 291 | friend class QPixmapCacheEntry;
|
|---|
| 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
|
|---|