1 /* 2 * DQt - D bindings for the Qt Toolkit 3 * 4 * GNU Lesser General Public License Usage 5 * This file may be used under the terms of the GNU Lesser 6 * General Public License version 3 as published by the Free Software 7 * Foundation and appearing in the file LICENSE.LGPL3 included in the 8 * packaging of this file. Please review the following information to 9 * ensure the GNU Lesser General Public License version 3 requirements 10 * will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 11 */ 12 module qt.gui.pixmap; 13 extern(C++): 14 15 import qt.config; 16 import qt.core.bytearray; 17 import qt.core.global; 18 import qt.core.iodevice; 19 import qt.core.namespace; 20 import qt.core.rect; 21 import qt.core.shareddata; 22 import qt.core.size; 23 import qt.core.string; 24 import qt.core.typeinfo; 25 import qt.core.variant; 26 import qt.gui.bitmap; 27 import qt.gui.color; 28 import qt.gui.image; 29 import qt.gui.imagereader; 30 import qt.gui.imagewriter; 31 import qt.gui.paintdevice; 32 import qt.gui.paintengine; 33 import qt.gui.region; 34 import qt.gui.transform; 35 import qt.helpers; 36 37 extern(C++, class) struct QPlatformPixmap; 38 /+ QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlatformPixmap, Q_GUI_EXPORT) +/ 39 /// Binding for C++ class [QPixmap](https://doc.qt.io/qt-6/qpixmap.html). 40 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_GUI_EXPORT +/ QPixmap 41 { 42 private: 43 immutable void *vtbl; 44 QPaintDeviceFakeInheritance baseQPaintDeviceInterface; 45 46 public QPaintDevice paintDevice() return 47 { 48 return cast(QPaintDevice)&this; 49 } 50 51 alias PaintDeviceMetric = QPaintDevice.PaintDeviceMetric; 52 53 public: 54 import qt.core.namespace; 55 @disable this(); 56 /+this();+/ 57 58 /+ explicit +/this(QPlatformPixmap* data); 59 this(int w, int h); 60 /+ explicit +/this(ref const(QSize) ); 61 this(ref const(QString) fileName, const(char)* format = null, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 62 version(QT_NO_IMAGEFORMAT_XPM){}else 63 { 64 /+ explicit +/this(const(char**) xpm); 65 } 66 @disable this(this); 67 this(ref const(QPixmap) ); 68 /+ QPixmap(QPixmap &&other) noexcept : QPaintDevice(), data(std::move(other.data)) {} +/ 69 mixin(changeWindowsMangling(q{mangleChangeFunctionType("virtual")}, q{ 70 ~this(); 71 })); 72 73 /+ref QPixmap operator =(ref const(QPixmap) );+/ 74 /+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPixmap) +/ 75 /+ inline void swap(QPixmap &other) noexcept 76 { qSwap(data, other.data); } +/ 77 /+bool operator ==(ref const(QPixmap) ) const /+ = delete +/;+/ 78 /+bool operator !=(ref const(QPixmap) ) const /+ = delete +/;+/ 79 80 /+auto opCast(T : QVariant)() const;+/ 81 82 bool isNull() const; 83 mixin(changeWindowsMangling(q{mangleChangeFunctionType("virtual")}, q{ 84 int devType() const; 85 })); 86 87 int width() const; 88 int height() const; 89 QSize size() const; 90 QRect rect() const; 91 int depth() const; 92 93 static int defaultDepth(); 94 95 void fill(ref const(QColor) fillColor /+ = Qt::white +/); 96 97 QBitmap mask() const; 98 void setMask(ref const(QBitmap) ); 99 100 qreal devicePixelRatio() const; 101 void setDevicePixelRatio(qreal scaleFactor); 102 QSizeF deviceIndependentSize() const; 103 104 bool hasAlpha() const; 105 bool hasAlphaChannel() const; 106 107 version(QT_NO_IMAGE_HEURISTIC_MASK){}else 108 { 109 QBitmap createHeuristicMask(bool clipTight = true) const; 110 } 111 QBitmap createMaskFromColor(ref const(QColor) maskColor, /+ Qt:: +/qt.core.namespace.MaskMode mode = /+ Qt:: +/qt.core.namespace.MaskMode.MaskInColor) const; 112 113 pragma(inline, true) QPixmap scaled(int w, int h, /+ Qt:: +/qt.core.namespace.AspectRatioMode aspectMode = /+ Qt:: +/qt.core.namespace.AspectRatioMode.IgnoreAspectRatio, 114 /+ Qt:: +/qt.core.namespace.TransformationMode mode = /+ Qt:: +/qt.core.namespace.TransformationMode.FastTransformation) const 115 { auto tmp = QSize(w, h); return scaled(tmp, aspectMode, mode); } 116 QPixmap scaled(ref const(QSize) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode aspectMode = /+ Qt:: +/qt.core.namespace.AspectRatioMode.IgnoreAspectRatio, 117 /+ Qt:: +/qt.core.namespace.TransformationMode mode = /+ Qt:: +/qt.core.namespace.TransformationMode.FastTransformation) const; 118 QPixmap scaledToWidth(int w, /+ Qt:: +/qt.core.namespace.TransformationMode mode = /+ Qt:: +/qt.core.namespace.TransformationMode.FastTransformation) const; 119 QPixmap scaledToHeight(int h, /+ Qt:: +/qt.core.namespace.TransformationMode mode = /+ Qt:: +/qt.core.namespace.TransformationMode.FastTransformation) const; 120 QPixmap transformed(ref const(QTransform) , /+ Qt:: +/qt.core.namespace.TransformationMode mode = /+ Qt:: +/qt.core.namespace.TransformationMode.FastTransformation) const; 121 static QTransform trueMatrix(ref const(QTransform) m, int w, int h); 122 123 QImage toImage() const; 124 static QPixmap fromImage(ref const(QImage) image, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 125 static QPixmap fromImageReader(QImageReader* imageReader, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 126 /+ static QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags = Qt::AutoColor) 127 { 128 return fromImageInPlace(image, flags); 129 } +/ 130 131 bool load(ref const(QString) fileName, const(char)* format = null, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 132 bool loadFromData(const(uchar)* buf, uint len, const(char)* format = null, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 133 /+ pragma(inline, true) bool loadFromData(ref const(QByteArray) buf, const(char)* format = null, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor) 134 { 135 return loadFromData(reinterpret_cast!(const(uchar)*)(buf.constData()), buf.size(), format, flags); 136 }+/ 137 bool save(ref const(QString) fileName, const(char)* format = null, int quality = -1) const; 138 bool save(QIODevice device, const(char)* format = null, int quality = -1) const; 139 140 bool convertFromImage(ref const(QImage) img, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 141 142 /+ inline QPixmap copy(int x, int y, int width, int height) const; +/ 143 /+ QPixmap copy(const QRect &rect = QRect()) const; +/ 144 145 pragma(inline, true) void scroll(int dx, int dy, int ax, int ay, int awidth, int aheight, QRegion* exposed = null) 146 { 147 auto tmp = QRect(ax, ay, awidth, aheight); scroll(dx, dy, tmp, exposed); 148 } 149 void scroll(int dx, int dy, ref const(QRect) rect, QRegion* exposed = null); 150 151 qint64 cacheKey() const; 152 153 bool isDetached() const; 154 void detach(); 155 156 bool isQBitmap() const; 157 158 mixin(changeWindowsMangling(q{mangleChangeFunctionType("virtual")}, q{ 159 QPaintEngine paintEngine() const; 160 })); 161 162 /+pragma(inline, true) bool operator !() const { return isNull(); }+/ 163 164 protected: 165 mixin(changeWindowsMangling(q{mangleChangeFunctionType("virtual")}, q{ 166 int metric(PaintDeviceMetric) const; 167 })); 168 static QPixmap fromImageInPlace(ref QImage image, /+ Qt:: +/qt.core.namespace.ImageConversionFlags flags = /+ Qt:: +/qt.core.namespace.ImageConversionFlag.AutoColor); 169 170 private: 171 QExplicitlySharedDataPointer!(QPlatformPixmap) data; 172 173 bool doImageIO(QImageWriter* io, int quality) const; 174 175 this(ref const(QSize) s, int type); 176 void doInit(int, int, int); 177 /+ Q_DUMMY_COMPARISON_OPERATOR(QPixmap) +/ 178 /+ friend class QPlatformPixmap; +/ 179 /+ friend class QBitmap; +/ 180 /+ friend class QPaintDevice; +/ 181 /+ friend class QPainter; +/ 182 /+ friend class QOpenGLWidget; +/ 183 /+ friend class QWidgetPrivate; +/ 184 /+ friend class QRasterBuffer; +/ 185 version(QT_NO_DATASTREAM){}else 186 { 187 /+ friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); +/ 188 } 189 190 public: 191 QPlatformPixmap* handle() const; 192 193 public: 194 alias DataPtr = QExplicitlySharedDataPointer!(QPlatformPixmap); 195 pragma(inline, true) ref DataPtr data_ptr() return { return data; } 196 mixin(CREATE_CONVENIENCE_WRAPPERS); 197 } 198 199 /+ Q_DECLARE_SHARED(QPixmap) 200 201 inline QPixmap QPixmap::copy(int ax, int ay, int awidth, int aheight) const 202 { 203 return copy(QRect(ax, ay, awidth, aheight)); 204 } 205 206 207 /***************************************************************************** 208 QPixmap stream functions 209 *****************************************************************************/ 210 211 #if !defined(QT_NO_DATASTREAM) 212 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPixmap &); 213 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPixmap &); 214 #endif 215 216 #ifndef QT_NO_DEBUG_STREAM 217 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPixmap &); 218 #endif +/ 219