Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpixmap.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QPIXMAP_H
6#define QPIXMAP_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtGui/qpaintdevice.h>
10#include <QtGui/qcolor.h>
11#include <QtCore/qnamespace.h>
12#include <QtCore/qshareddata.h>
13#include <QtCore/qstring.h> // char*->QString conversion
14#include <QtGui/qimage.h>
15#include <QtGui/qtransform.h>
16
18
19
20class QImageWriter;
21class QImageReader;
22class QColor;
23class QVariant;
24class QPlatformPixmap;
25QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlatformPixmap, Q_GUI_EXPORT)
26
27class Q_GUI_EXPORT QPixmap : public QPaintDevice
28{
29public:
30 QPixmap();
31 explicit QPixmap(QPlatformPixmap *data);
32 QPixmap(int w, int h);
33 explicit QPixmap(const QSize &);
34 QPixmap(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
35#ifndef QT_NO_IMAGEFORMAT_XPM
36 explicit QPixmap(const char * const xpm[]);
37#endif
38 QPixmap(const QPixmap &);
39 QPixmap(QPixmap &&other) noexcept : QPaintDevice(), data(std::move(other.data)) {}
40 ~QPixmap();
41
42 QPixmap &operator=(const QPixmap &);
43 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPixmap)
44 inline void swap(QPixmap &other) noexcept
45 { data.swap(other.data); }
46 bool operator==(const QPixmap &) const = delete;
47 bool operator!=(const QPixmap &) const = delete;
48
49 operator QVariant() const;
50
51 bool isNull() const;
52 int devType() const override;
53
54 int width() const;
55 int height() const;
56 QSize size() const;
57 QRect rect() const;
58 int depth() const;
59
60 static int defaultDepth();
61
62 void fill(const QColor &fillColor = Qt::white);
63
64 QBitmap mask() const;
65 void setMask(const QBitmap &);
66
67 qreal devicePixelRatio() const;
68 void setDevicePixelRatio(qreal scaleFactor);
69 QSizeF deviceIndependentSize() const;
70
71 bool hasAlpha() const;
72 bool hasAlphaChannel() const;
73
74#ifndef QT_NO_IMAGE_HEURISTIC_MASK
75 QBitmap createHeuristicMask(bool clipTight = true) const;
76#endif
77 QBitmap createMaskFromColor(const QColor &maskColor, Qt::MaskMode mode = Qt::MaskInColor) const;
78
79 inline QPixmap scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
80 Qt::TransformationMode mode = Qt::FastTransformation) const
81 { return scaled(QSize(w, h), aspectMode, mode); }
82 QPixmap scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
83 Qt::TransformationMode mode = Qt::FastTransformation) const;
84 QPixmap scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
85 QPixmap scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
86 QPixmap transformed(const QTransform &, Qt::TransformationMode mode = Qt::FastTransformation) const;
87 static QTransform trueMatrix(const QTransform &m, int w, int h);
88
89 QImage toImage() const;
90 static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
91 static QPixmap fromImageReader(QImageReader *imageReader, Qt::ImageConversionFlags flags = Qt::AutoColor);
92 static QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor)
93 {
94 return fromImageInPlace(image, flags);
95 }
96
97 bool load(const QString& fileName, const char *format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
98 bool loadFromData(const uchar *buf, uint len, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
99 inline bool loadFromData(const QByteArray &data, const char* format = nullptr, Qt::ImageConversionFlags flags = Qt::AutoColor);
100 bool save(const QString& fileName, const char* format = nullptr, int quality = -1) const;
101 bool save(QIODevice* device, const char* format = nullptr, int quality = -1) const;
102
103 bool convertFromImage(const QImage &img, Qt::ImageConversionFlags flags = Qt::AutoColor);
104
105 inline QPixmap copy(int x, int y, int width, int height) const;
106 QPixmap copy(const QRect &rect = QRect()) const;
107
108 inline void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed = nullptr);
109 void scroll(int dx, int dy, const QRect &rect, QRegion *exposed = nullptr);
110
111 qint64 cacheKey() const;
112
113 bool isDetached() const;
114 void detach();
115
116 bool isQBitmap() const;
117
118 QPaintEngine *paintEngine() const override;
119
120 inline bool operator!() const { return isNull(); }
121
122protected:
123 int metric(PaintDeviceMetric) const override;
124 static QPixmap fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor);
125
126private:
127 QExplicitlySharedDataPointer<QPlatformPixmap> data;
128
129 bool doImageIO(QImageWriter *io, int quality) const;
130
131 QPixmap(const QSize &s, int type);
132 void doInit(int, int, int);
133 friend class QPlatformPixmap;
134 friend class QBitmap;
135 friend class QPaintDevice;
136 friend class QPainter;
137 friend class QOpenGLWidget;
138 friend class QWidgetPrivate;
139 friend class QRasterBuffer;
140#if !defined(QT_NO_DATASTREAM)
141 friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
142#endif
143
144public:
145 QPlatformPixmap* handle() const;
146
147public:
148 typedef QExplicitlySharedDataPointer<QPlatformPixmap> DataPtr;
149 inline DataPtr &data_ptr() { return data; }
150};
151
153
154inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const
155{
156 return copy(QRect(ax, ay, awidth, aheight));
157}
158
159inline void QPixmap::scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion *exposed)
160{
161 scroll(dx, dy, QRect(ax, ay, awidth, aheight), exposed);
162}
163
164inline bool QPixmap::loadFromData(const QByteArray &buf, const char *format,
165 Qt::ImageConversionFlags flags)
166{
167 return loadFromData(reinterpret_cast<const uchar *>(buf.constData()), uint(buf.size()), format, flags);
168}
169
170
171/*****************************************************************************
172 QPixmap stream functions
173*****************************************************************************/
174
175#if !defined(QT_NO_DATASTREAM)
176Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &);
177Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &);
178#endif
179
180#ifndef QT_NO_DEBUG_STREAM
181Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &);
182#endif
183
184QT_END_NAMESPACE
185
186#endif // QPIXMAP_H
The QCommandLineParser class provides a means for handling the command line options.
\inmodule QtCore\reentrant
Definition qdatastream.h:50
void contextMenuEvent(QContextMenuEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
void mousePressEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void resizeEvent(QResizeEvent *event) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
void decreaseGridSize()
Definition qpixeltool.h:37
void mouseReleaseEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void keyPressEvent(QKeyEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
void setZoomVisible(bool visible)
void aboutPixelTool()
QSize sizeHint() const override
void mouseMoveEvent(QMouseEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
void toggleGrid()
void saveToFile()
void decreaseZoom()
void setGridSize(int gridSize)
void keyReleaseEvent(QKeyEvent *event) override
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
void paintEvent(QPaintEvent *event) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
void increaseGridSize()
Definition qpixeltool.h:36
void toggleFreeze()
void setPreviewImage(const QImage &image)
void increaseZoom()
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:28
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
int main(int argc, char *argv[])
[ctor_close]