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