| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 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 qt-sales@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 <QtGui/qimage.h>
|
|---|
| 50 | #include <QtGui/qtransform.h>
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_HEADER
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_NAMESPACE
|
|---|
| 55 |
|
|---|
| 56 | QT_MODULE(Gui)
|
|---|
| 57 |
|
|---|
| 58 | class QImageWriter;
|
|---|
| 59 | class QColor;
|
|---|
| 60 | class QVariant;
|
|---|
| 61 | class QX11Info;
|
|---|
| 62 |
|
|---|
| 63 | class QPixmapData;
|
|---|
| 64 |
|
|---|
| 65 | class Q_GUI_EXPORT QPixmap : public QPaintDevice
|
|---|
| 66 | {
|
|---|
| 67 | public:
|
|---|
| 68 | QPixmap();
|
|---|
| 69 | explicit QPixmap(QPixmapData *data);
|
|---|
| 70 | QPixmap(int w, int h);
|
|---|
| 71 | QPixmap(const QSize &);
|
|---|
| 72 | QPixmap(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 73 | #ifndef QT_NO_IMAGEFORMAT_XPM
|
|---|
| 74 | QPixmap(const char * const xpm[]);
|
|---|
| 75 | #endif
|
|---|
| 76 | QPixmap(const QPixmap &);
|
|---|
| 77 | ~QPixmap();
|
|---|
| 78 |
|
|---|
| 79 | QPixmap &operator=(const QPixmap &);
|
|---|
| 80 | operator QVariant() const;
|
|---|
| 81 |
|
|---|
| 82 | bool isNull() const;
|
|---|
| 83 | int devType() const;
|
|---|
| 84 |
|
|---|
| 85 | int width() const;
|
|---|
| 86 | int height() const;
|
|---|
| 87 | QSize size() const;
|
|---|
| 88 | QRect rect() const;
|
|---|
| 89 | int depth() const;
|
|---|
| 90 |
|
|---|
| 91 | static int defaultDepth();
|
|---|
| 92 |
|
|---|
| 93 | void fill(const QColor &fillColor = Qt::white);
|
|---|
| 94 | void fill(const QWidget *widget, const QPoint &ofs);
|
|---|
| 95 | inline void fill(const QWidget *widget, int xofs, int yofs) { fill(widget, QPoint(xofs, yofs)); }
|
|---|
| 96 |
|
|---|
| 97 | QBitmap mask() const;
|
|---|
| 98 | void setMask(const QBitmap &);
|
|---|
| 99 |
|
|---|
| 100 | QPixmap alphaChannel() const;
|
|---|
| 101 | void setAlphaChannel(const QPixmap &);
|
|---|
| 102 |
|
|---|
| 103 | bool hasAlpha() const;
|
|---|
| 104 | bool hasAlphaChannel() const;
|
|---|
| 105 |
|
|---|
| 106 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
|---|
| 107 | QBitmap createHeuristicMask(bool clipTight = true) const;
|
|---|
| 108 | #endif
|
|---|
| 109 | QBitmap createMaskFromColor(const QColor &maskColor) const; // ### Qt 5: remove
|
|---|
| 110 | QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const;
|
|---|
| 111 |
|
|---|
| 112 | static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
|
|---|
| 113 | static QPixmap grabWidget(QWidget *widget, const QRect &rect);
|
|---|
| 114 | static inline QPixmap grabWidget(QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
|
|---|
| 115 | { return grabWidget(widget, QRect(x, y, w, h)); }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 119 | Qt::TransformationMode mode = Qt::FastTransformation) const
|
|---|
| 120 | { return scaled(QSize(w, h), aspectMode, mode); }
|
|---|
| 121 | QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 122 | Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 123 | QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 124 | QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 125 | QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 126 | static QMatrix trueMatrix(const QMatrix &m, int w, int h);
|
|---|
| 127 | QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 128 | static QTransform trueMatrix(const QTransform &m, int w, int h);
|
|---|
| 129 |
|
|---|
| 130 | QImage toImage() const;
|
|---|
| 131 | static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 132 |
|
|---|
| 133 | bool load(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 134 | bool loadFromData(const uchar *buf, uint len, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 135 | inline bool loadFromData(const QByteArray &data, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 136 | bool save(const QString& fileName, const char* format = 0, int quality = -1) const;
|
|---|
| 137 | bool save(QIODevice* device, const char* format = 0, int quality = -1) const;
|
|---|
| 138 |
|
|---|
| 139 | #if defined(Q_WS_WIN)
|
|---|
| 140 | enum HBitmapFormat {
|
|---|
| 141 | NoAlpha,
|
|---|
| 142 | PremultipliedAlpha,
|
|---|
| 143 | Alpha
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 | HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
|
|---|
| 147 | static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
|
|---|
| 148 | #endif
|
|---|
| 149 |
|
|---|
| 150 | #if defined(Q_WS_MAC)
|
|---|
| 151 | CGImageRef toMacCGImageRef() const;
|
|---|
| 152 | static QPixmap fromMacCGImageRef(CGImageRef image);
|
|---|
| 153 | #endif
|
|---|
| 154 |
|
|---|
| 155 | inline QPixmap copy(int x, int y, int width, int height) const;
|
|---|
| 156 | QPixmap copy(const QRect &rect = QRect()) const;
|
|---|
| 157 |
|
|---|
| 158 | int serialNumber() const;
|
|---|
| 159 | qint64 cacheKey() const;
|
|---|
| 160 |
|
|---|
| 161 | bool isDetached() const;
|
|---|
| 162 | void detach();
|
|---|
| 163 |
|
|---|
| 164 | bool isQBitmap() const;
|
|---|
| 165 |
|
|---|
| 166 | #if defined(Q_WS_QWS)
|
|---|
| 167 | const uchar *qwsBits() const;
|
|---|
| 168 | int qwsBytesPerLine() const;
|
|---|
| 169 | QRgb *clut() const;
|
|---|
| 170 | int numCols() const;
|
|---|
| 171 | #elif defined(Q_WS_MAC)
|
|---|
| 172 | Qt::HANDLE macQDHandle() const;
|
|---|
| 173 | Qt::HANDLE macQDAlphaHandle() const;
|
|---|
| 174 | Qt::HANDLE macCGHandle() const;
|
|---|
| 175 | #elif defined(Q_WS_X11)
|
|---|
| 176 | enum ShareMode { ImplicitlyShared, ExplicitlyShared };
|
|---|
| 177 |
|
|---|
| 178 | static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared);
|
|---|
| 179 | static int x11SetDefaultScreen(int screen);
|
|---|
| 180 | void x11SetScreen(int screen);
|
|---|
| 181 | const QX11Info &x11Info() const;
|
|---|
| 182 | Qt::HANDLE x11PictureHandle() const;
|
|---|
| 183 | #endif
|
|---|
| 184 |
|
|---|
| 185 | #if defined(Q_WS_X11) || defined(Q_WS_QWS)
|
|---|
| 186 | Qt::HANDLE handle() const;
|
|---|
| 187 | #endif
|
|---|
| 188 |
|
|---|
| 189 | QPaintEngine *paintEngine() const;
|
|---|
| 190 |
|
|---|
| 191 | inline bool operator!() const { return isNull(); }
|
|---|
| 192 |
|
|---|
| 193 | protected:
|
|---|
| 194 | int metric(PaintDeviceMetric) const;
|
|---|
| 195 |
|
|---|
| 196 | #ifdef QT3_SUPPORT
|
|---|
| 197 | public:
|
|---|
| 198 | enum ColorMode { Auto, Color, Mono };
|
|---|
| 199 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode);
|
|---|
| 200 | QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode);
|
|---|
| 201 | QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode);
|
|---|
| 202 | QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image);
|
|---|
| 203 | QT3_SUPPORT QPixmap &operator=(const QImage &);
|
|---|
| 204 | inline QT3_SUPPORT QImage convertToImage() const { return toImage(); }
|
|---|
| 205 | QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode);
|
|---|
| 206 | QT3_SUPPORT bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor)
|
|---|
| 207 | { (*this) = fromImage(img, flags); return !isNull(); }
|
|---|
| 208 | inline QT3_SUPPORT operator QImage() const { return toImage(); }
|
|---|
| 209 | inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
|
|---|
| 210 | inline QT3_SUPPORT bool selfMask() const { return false; }
|
|---|
| 211 | private:
|
|---|
| 212 | void resize_helper(const QSize &s);
|
|---|
| 213 | public:
|
|---|
| 214 | inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); }
|
|---|
| 215 | inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); }
|
|---|
| 216 | #endif
|
|---|
| 217 |
|
|---|
| 218 | private:
|
|---|
| 219 | QPixmapData *data;
|
|---|
| 220 |
|
|---|
| 221 | bool doImageIO(QImageWriter *io, int quality) const;
|
|---|
| 222 |
|
|---|
| 223 | // ### Qt5: remove the following three lines
|
|---|
| 224 | enum Type { PixmapType, BitmapType }; // must match QPixmapData::PixelType
|
|---|
| 225 | QPixmap(const QSize &s, Type);
|
|---|
| 226 | void init(int, int, Type = PixmapType);
|
|---|
| 227 |
|
|---|
| 228 | QPixmap(const QSize &s, int type);
|
|---|
| 229 | void init(int, int, int);
|
|---|
| 230 | void deref();
|
|---|
| 231 | #if defined(Q_WS_WIN)
|
|---|
| 232 | void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi);
|
|---|
| 233 | #endif
|
|---|
| 234 | Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
|
|---|
| 235 | #ifdef Q_WS_MAC
|
|---|
| 236 | friend CGContextRef qt_mac_cg_context(const QPaintDevice*);
|
|---|
| 237 | friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&);
|
|---|
| 238 | friend IconRef qt_mac_create_iconref(const QPixmap&);
|
|---|
| 239 | friend quint32 *qt_mac_pixmap_get_base(const QPixmap*);
|
|---|
| 240 | friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*);
|
|---|
| 241 | #endif
|
|---|
| 242 | friend class QPixmapData;
|
|---|
| 243 | friend class QX11PixmapData;
|
|---|
| 244 | friend class QMacPixmapData;
|
|---|
| 245 | friend class QBitmap;
|
|---|
| 246 | friend class QPaintDevice;
|
|---|
| 247 | friend class QPainter;
|
|---|
| 248 | friend class QGLWidget;
|
|---|
| 249 | friend class QX11PaintEngine;
|
|---|
| 250 | friend class QCoreGraphicsPaintEngine;
|
|---|
| 251 | friend class QWidgetPrivate;
|
|---|
| 252 | friend class QRasterPaintEngine;
|
|---|
| 253 | friend class QRasterBuffer;
|
|---|
| 254 | friend class QDirect3DPaintEngine;
|
|---|
| 255 | friend class QDirect3DPaintEnginePrivate;
|
|---|
| 256 | friend class QDetachedPixmap;
|
|---|
| 257 | #if !defined(QT_NO_DATASTREAM)
|
|---|
| 258 | friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
|---|
| 259 | #endif
|
|---|
| 260 | friend Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap);
|
|---|
| 261 |
|
|---|
| 262 | public:
|
|---|
| 263 | QPixmapData* pixmapData() const;
|
|---|
| 264 |
|
|---|
| 265 | public:
|
|---|
| 266 | typedef QPixmapData * DataPtr;
|
|---|
| 267 | inline DataPtr &data_ptr() { return data; }
|
|---|
| 268 | };
|
|---|
| 269 |
|
|---|
| 270 | Q_DECLARE_SHARED(QPixmap)
|
|---|
| 271 |
|
|---|
| 272 | inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
|
|---|
| 273 | {
|
|---|
| 274 | return copy(QRect(ax, ay, awidth, aheight));
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
|
|---|
| 278 | Qt::ImageConversionFlags flags)
|
|---|
| 279 | {
|
|---|
| 280 | return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags);
|
|---|
| 281 | }
|
|---|
| 282 |
|
|---|
| 283 | /*****************************************************************************
|
|---|
| 284 | QPixmap stream functions
|
|---|
| 285 | *****************************************************************************/
|
|---|
| 286 |
|
|---|
| 287 | #if !defined(QT_NO_DATASTREAM)
|
|---|
| 288 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
|
|---|
| 289 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
|
|---|
| 290 | #endif
|
|---|
| 291 |
|
|---|
| 292 | /*****************************************************************************
|
|---|
| 293 | QPixmap (and QImage) helper functions
|
|---|
| 294 | *****************************************************************************/
|
|---|
| 295 | #ifdef QT3_SUPPORT
|
|---|
| 296 | QT3_SUPPORT Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src,
|
|---|
| 297 | int sx=0, int sy=0, int sw=-1, int sh=-1);
|
|---|
| 298 | #endif // QT3_SUPPORT
|
|---|
| 299 |
|
|---|
| 300 | QT_END_NAMESPACE
|
|---|
| 301 |
|
|---|
| 302 | QT_END_HEADER
|
|---|
| 303 |
|
|---|
| 304 | #endif // QPIXMAP_H
|
|---|