File indexing completed on 2025-01-18 10:08:15
0001
0002
0003
0004 #ifndef QPIXMAP_H
0005 #define QPIXMAP_H
0006
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtGui/qpaintdevice.h>
0009 #include <QtGui/qcolor.h>
0010 #include <QtCore/qnamespace.h>
0011 #include <QtCore/qshareddata.h>
0012 #include <QtCore/qstring.h> // char*->QString conversion
0013 #include <QtGui/qimage.h>
0014 #include <QtGui/qtransform.h>
0015
0016 QT_BEGIN_NAMESPACE
0017
0018
0019 class QImageWriter;
0020 class QImageReader;
0021 class QColor;
0022 class QVariant;
0023 class QPlatformPixmap;
0024 QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlatformPixmap, Q_GUI_EXPORT)
0025
0026 class Q_GUI_EXPORT QPixmap : public QPaintDevice
0027 {
0028 public:
0029 QPixmap();
0030 explicit QPixmap(QPlatformPixmap *data);
0031 QPixmap(int w, int h);
0032 explicit QPixmap(const QSize &);
0033 QPixmap(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
0034 #ifndef QT_NO_IMAGEFORMAT_XPM
0035 explicit QPixmap(const char * const xpm[]);
0036 #endif
0037 QPixmap(const QPixmap &);
0038 QPixmap(QPixmap &&other) noexcept : QPaintDevice(), data(std::move(other.data)) {}
0039 ~QPixmap();
0040
0041 QPixmap &operator=(const QPixmap &);
0042 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPixmap)
0043 inline void swap(QPixmap &other) noexcept
0044 { data.swap(other.data); }
0045 bool operator==(const QPixmap &) const = delete;
0046 bool operator!=(const QPixmap &) const = delete;
0047
0048 operator QVariant() const;
0049
0050 bool isNull() const;
0051 int devType() const override;
0052
0053 int width() const;
0054 int height() const;
0055 QSize size() const;
0056 QRect rect() const;
0057 int depth() const;
0058
0059 static int defaultDepth();
0060
0061 void fill(const QColor &fillColor = Qt::white);
0062
0063 QBitmap mask() const;
0064 void setMask(const QBitmap &);
0065
0066 qreal devicePixelRatio() const;
0067 void setDevicePixelRatio(qreal scaleFactor);
0068 QSizeF deviceIndependentSize() const;
0069
0070 bool hasAlpha() const;
0071 bool hasAlphaChannel() const;
0072
0073 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
0074 QBitmap createHeuristicMask(bool clipTight = true) const;
0075 #endif
0076 QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode = Qt::MaskInColor) const;
0077
0078 inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
0079 Qt::TransformationMode mode = Qt::FastTransformation) const
0080 { return scaled(QSize(w, h), aspectMode, mode); }
0081 QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
0082 Qt::TransformationMode mode = Qt::FastTransformation) const;
0083 QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
0084 QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
0085 QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
0086 static QTransform trueMatrix(const QTransform &m, int w, int h);
0087
0088 QImage toImage() const;
0089 static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
0090 static QPixmap fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags = Qt::AutoColor);
0091 static QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor)
0092 {
0093 return fromImageInPlace(image, flags);
0094 }
0095
0096 bool load(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
0097 bool loadFromData(const uchar *buf, uint len, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
0098 inline bool loadFromData(const QByteArray &data, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
0099 bool save(const QString& fileName, const char* format = nullptr, int quality = -1) const;
0100 bool save(QIODevice* device, const char* format = nullptr, int quality = -1) const;
0101
0102 bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
0103
0104 inline QPixmap copy(int x, int y, int width, int height) const;
0105 QPixmap copy(const QRect &rect = QRect()) const;
0106
0107 inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = nullptr);
0108 void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = nullptr);
0109
0110 qint64 cacheKey() const;
0111
0112 bool isDetached() const;
0113 void detach();
0114
0115 bool isQBitmap() const;
0116
0117 QPaintEngine *paintEngine() const override;
0118
0119 inline bool operator!() const { return isNull(); }
0120
0121 protected:
0122 int metric(PaintDeviceMetric) const override;
0123 static QPixmap fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
0124
0125 private:
0126 QExplicitlySharedDataPointer<QPlatformPixmap> data;
0127
0128 bool doImageIO(QImageWriter *io, int quality) const;
0129
0130 QPixmap(const QSize &s, int type);
0131 void doInit(int, int, int);
0132 friend class QPlatformPixmap;
0133 friend class QBitmap;
0134 friend class QPaintDevice;
0135 friend class QPainter;
0136 friend class QOpenGLWidget;
0137 friend class QWidgetPrivate;
0138 friend class QRasterBuffer;
0139 #if !defined(QT_NO_DATASTREAM)
0140 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
0141 #endif
0142
0143 public:
0144 QPlatformPixmap* handle() const;
0145
0146 public:
0147 typedef QExplicitlySharedDataPointer<QPlatformPixmap> DataPtr;
0148 inline DataPtr &data_ptr() { return data; }
0149 };
0150
0151 Q_DECLARE_SHARED(QPixmap)
0152
0153 inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
0154 {
0155 return copy(QRect(ax, ay, awidth, aheight));
0156 }
0157
0158 inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
0159 {
0160 scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
0161 }
0162
0163 inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
0164 Qt::ImageConversionFlags flags)
0165 {
0166 return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), uint(buf.size()), format, flags);
0167 }
0168
0169
0170
0171
0172
0173
0174 #if !defined(QT_NO_DATASTREAM)
0175 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
0176 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
0177 #endif
0178
0179 #ifndef QT_NO_DEBUG_STREAM
0180 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &);
0181 #endif
0182
0183 QT_END_NAMESPACE
0184
0185 #endif