00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QPIXMAP_H
00043 #define QPIXMAP_H
00044
00045 #include <QtGui/qpaintdevice.h>
00046 #include <QtGui/qcolor.h>
00047 #include <QtCore/qnamespace.h>
00048 #include <QtCore/qstring.h>
00049 #include <QtCore/qsharedpointer.h>
00050 #include <QtGui/qimage.h>
00051 #include <QtGui/qtransform.h>
00052
00053 QT_BEGIN_HEADER
00054
00055 #if defined(Q_OS_SYMBIAN)
00056 class CFbsBitmap;
00057 class RSgImage;
00058 #endif
00059
00060 QT_BEGIN_NAMESPACE
00061
00062 QT_MODULE(Gui)
00063
00064 class QImageWriter;
00065 class QImageReader;
00066 class QColor;
00067 class QVariant;
00068 class QX11Info;
00069 class QPixmapData;
00070
00071 class Q_GUI_EXPORT QPixmap : public QPaintDevice
00072 {
00073 public:
00074 QPixmap();
00075 explicit QPixmap(QPixmapData *data);
00076 QPixmap(int w, int h);
00077 QPixmap(const QSize &);
00078 QPixmap(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
00079 #ifndef QT_NO_IMAGEFORMAT_XPM
00080 QPixmap(const char * const xpm[]);
00081 #endif
00082 QPixmap(const QPixmap &);
00083 ~QPixmap();
00084
00085 QPixmap &operator=(const QPixmap &);
00086 operator QVariant() const;
00087
00088 bool isNull() const;
00089 int devType() const;
00090
00091 int width() const;
00092 int height() const;
00093 QSize size() const;
00094 QRect rect() const;
00095 int depth() const;
00096
00097 static int defaultDepth();
00098
00099 void fill(const QColor &fillColor = Qt::white);
00100 void fill(const QWidget *widget, const QPoint &ofs);
00101 inline void fill(const QWidget *widget, int xofs, int yofs) { fill(widget, QPoint(xofs, yofs)); }
00102
00103 QBitmap mask() const;
00104 void setMask(const QBitmap &);
00105
00106 QPixmap alphaChannel() const;
00107 void setAlphaChannel(const QPixmap &);
00108
00109 bool hasAlpha() const;
00110 bool hasAlphaChannel() const;
00111
00112 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
00113 QBitmap createHeuristicMask(bool clipTight = true) const;
00114 #endif
00115 QBitmap createMaskFromColor(const QColor &maskColor) const;
00116 QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode) const;
00117
00118 static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
00119 static QPixmap grabWidget(QWidget *widget, const QRect &rect);
00120 static inline QPixmap grabWidget(QWidget *widget, int x=0, int y=0, int w=-1, int h=-1)
00121 { return grabWidget(widget, QRect(x, y, w, h)); }
00122
00123
00124 inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
00125 Qt::TransformationMode mode = Qt::FastTransformation) const
00126 { return scaled(QSize(w, h), aspectMode, mode); }
00127 QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
00128 Qt::TransformationMode mode = Qt::FastTransformation) const;
00129 QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
00130 QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
00131 QPixmap transformed(const QMatrix &, Qt::TransformationMode mode = Qt::FastTransformation) const;
00132 static QMatrix trueMatrix(const QMatrix &m, int w, int h);
00133 QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
00134 static QTransform trueMatrix(const QTransform &m, int w, int h);
00135
00136 QImage toImage() const;
00137 static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
00138 static QPixmap fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags = Qt::AutoColor);
00139
00140 bool load(const QString& fileName, const char *format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
00141 bool loadFromData(const uchar *buf, uint len, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
00142 inline bool loadFromData(const QByteArray &data, const char* format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor);
00143 bool save(const QString& fileName, const char* format = 0, int quality = -1) const;
00144 bool save(QIODevice* device, const char* format = 0, int quality = -1) const;
00145
00146 bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
00147
00148 #if defined(Q_WS_WIN)
00149 enum HBitmapFormat {
00150 NoAlpha,
00151 PremultipliedAlpha,
00152 Alpha
00153 };
00154
00155 HBITMAP toWinHBITMAP(HBitmapFormat format = NoAlpha) const;
00156 HICON toWinHICON() const;
00157
00158 static QPixmap fromWinHBITMAP(HBITMAP hbitmap, HBitmapFormat format = NoAlpha);
00159 static QPixmap fromWinHICON(HICON hicon);
00160 #endif
00161
00162 #if defined(Q_WS_MAC)
00163 CGImageRef toMacCGImageRef() const;
00164 static QPixmap fromMacCGImageRef(CGImageRef image);
00165 #endif
00166
00167 #if defined(Q_OS_SYMBIAN)
00168 CFbsBitmap *toSymbianCFbsBitmap() const;
00169 static QPixmap fromSymbianCFbsBitmap(CFbsBitmap *bitmap);
00170 RSgImage* toSymbianRSgImage() const;
00171 static QPixmap fromSymbianRSgImage(RSgImage *sgImage);
00172 #endif
00173
00174 inline QPixmap copy(int x, int y, int width, int height) const;
00175 QPixmap copy(const QRect &rect = QRect()) const;
00176
00177 inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = 0);
00178 void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = 0);
00179
00180 int serialNumber() const;
00181 qint64 cacheKey() const;
00182
00183 bool isDetached() const;
00184 void detach();
00185
00186 bool isQBitmap() const;
00187
00188 #if defined(Q_WS_QWS)
00189 const uchar *qwsBits() const;
00190 int qwsBytesPerLine() const;
00191 QRgb *clut() const;
00192 #ifdef QT_DEPRECATED
00193 QT_DEPRECATED int numCols() const;
00194 #endif
00195 int colorCount() const;
00196 #elif defined(Q_WS_MAC)
00197 Qt::HANDLE macQDHandle() const;
00198 Qt::HANDLE macQDAlphaHandle() const;
00199 Qt::HANDLE macCGHandle() const;
00200 #elif defined(Q_WS_X11)
00201 enum ShareMode { ImplicitlyShared, ExplicitlyShared };
00202
00203 static QPixmap fromX11Pixmap(Qt::HANDLE pixmap, ShareMode mode = ImplicitlyShared);
00204 static int x11SetDefaultScreen(int screen);
00205 void x11SetScreen(int screen);
00206 const QX11Info &x11Info() const;
00207 Qt::HANDLE x11PictureHandle() const;
00208 #endif
00209
00210 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
00211 Qt::HANDLE handle() const;
00212 #endif
00213
00214 QPaintEngine *paintEngine() const;
00215
00216 inline bool operator!() const { return isNull(); }
00217
00218 protected:
00219 int metric(PaintDeviceMetric) const;
00220
00221 #ifdef QT3_SUPPORT
00222 public:
00223 enum ColorMode { Auto, Color, Mono };
00224 QT3_SUPPORT_CONSTRUCTOR QPixmap(const QString& fileName, const char *format, ColorMode mode);
00225 QT3_SUPPORT bool load(const QString& fileName, const char *format, ColorMode mode);
00226 QT3_SUPPORT bool loadFromData(const uchar *buf, uint len, const char* format, ColorMode mode);
00227 QT3_SUPPORT_CONSTRUCTOR QPixmap(const QImage& image);
00228 QT3_SUPPORT QPixmap &operator=(const QImage &);
00229 inline QT3_SUPPORT QImage convertToImage() const { return toImage(); }
00230 QT3_SUPPORT bool convertFromImage(const QImage &, ColorMode mode);
00231 inline QT3_SUPPORT operator QImage() const { return toImage(); }
00232 inline QT3_SUPPORT QPixmap xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
00233 inline QT3_SUPPORT bool selfMask() const { return false; }
00234 private:
00235 void resize_helper(const QSize &s);
00236 public:
00237 inline QT3_SUPPORT void resize(const QSize &s) { resize_helper(s); }
00238 inline QT3_SUPPORT void resize(int width, int height) { resize_helper(QSize(width, height)); }
00239 #endif
00240
00241 private:
00242 QExplicitlySharedDataPointer<QPixmapData> data;
00243
00244 bool doImageIO(QImageWriter *io, int quality) const;
00245
00246
00247 enum Type { PixmapType, BitmapType };
00248 QPixmap(const QSize &s, Type);
00249 void init(int, int, Type = PixmapType);
00250
00251 QPixmap(const QSize &s, int type);
00252 void init(int, int, int);
00253 void deref();
00254 #if defined(Q_WS_WIN)
00255 void initAlphaPixmap(uchar *bytes, int length, struct tagBITMAPINFO *bmi);
00256 #endif
00257 Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
00258 #ifdef Q_WS_MAC
00259 friend CGContextRef qt_mac_cg_context(const QPaintDevice*);
00260 friend CGImageRef qt_mac_create_imagemask(const QPixmap&, const QRectF&);
00261 friend IconRef qt_mac_create_iconref(const QPixmap&);
00262 friend quint32 *qt_mac_pixmap_get_base(const QPixmap*);
00263 friend int qt_mac_pixmap_get_bytes_per_line(const QPixmap*);
00264 #endif
00265 friend class QPixmapData;
00266 friend class QX11PixmapData;
00267 friend class QMacPixmapData;
00268 friend class QS60PixmapData;
00269 friend class QBitmap;
00270 friend class QPaintDevice;
00271 friend class QPainter;
00272 friend class QGLWidget;
00273 friend class QX11PaintEngine;
00274 friend class QCoreGraphicsPaintEngine;
00275 friend class QWidgetPrivate;
00276 friend class QRasterBuffer;
00277 #if !defined(QT_NO_DATASTREAM)
00278 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
00279 #endif
00280 friend Q_GUI_EXPORT qint64 qt_pixmap_id(const QPixmap &pixmap);
00281
00282 public:
00283 QPixmapData* pixmapData() const;
00284
00285 public:
00286 typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
00287 inline DataPtr &data_ptr() { return data; }
00288 };
00289
00290 Q_DECLARE_SHARED(QPixmap)
00291
00292 inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
00293 {
00294 return copy(QRect(ax, ay, awidth, aheight));
00295 }
00296
00297 inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
00298 {
00299 scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
00300 }
00301
00302 inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
00303 Qt::ImageConversionFlags flags)
00304 {
00305 return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), buf.size(), format, flags);
00306 }
00307
00308
00309
00310
00311
00312 #if !defined(QT_NO_DATASTREAM)
00313 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
00314 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
00315 #endif
00316
00317
00318
00319
00320 #ifdef QT3_SUPPORT
00321 QT3_SUPPORT Q_GUI_EXPORT void copyBlt(QPixmap *dst, int dx, int dy, const QPixmap *src,
00322 int sx=0, int sy=0, int sw=-1, int sh=-1);
00323 #endif // QT3_SUPPORT
00324
00325 QT_END_NAMESPACE
00326
00327 QT_END_HEADER
00328
00329 #endif // QPIXMAP_H