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