1// qpainter.sip generated by MetaSIP 2// 3// This file is part of the QtGui Python extension module. 4// 5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com> 6// 7// This file is part of PyQt5. 8// 9// This file may be used under the terms of the GNU General Public License 10// version 3.0 as published by the Free Software Foundation and appearing in 11// the file LICENSE included in the packaging of this file. Please review the 12// following information to ensure the GNU General Public License version 3.0 13// requirements will be met: http://www.gnu.org/copyleft/gpl.html. 14// 15// If you do not wish to use this file under the terms of the GPL version 3.0 16// then you may purchase a commercial license. For more information contact 17// info@riverbankcomputing.com. 18// 19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 22 23class QPainter 24{ 25%TypeHeaderCode 26#include <qpainter.h> 27%End 28 29%TypeCode 30// Return an array on the heap of class instances extracted from a set of 31// Python arguments. 32template<class TYPE> 33static TYPE *qtgui_inst_array(const TYPE *first, PyObject *t, sipTypeDef *td) 34{ 35 TYPE *arr = new TYPE[1 + PyTuple_Size(t)]; 36 37 arr[0] = *first; 38 39 for (Py_ssize_t i = 0; i < PyTuple_Size(t); ++i) 40 { 41 int iserr = 0, state; 42 TYPE *itm; 43 44 itm = reinterpret_cast<TYPE *>(sipForceConvertToType(PyTuple_GetItem(t, i), td, 0, SIP_NOT_NONE, &state, &iserr)); 45 46 if (iserr) 47 { 48 sipReleaseType(itm, td, state); 49 50 PyErr_Format(PyExc_TypeError, "each argument must be an instance of %s", sipPyTypeName(sipTypeAsPyTypeObject(td))); 51 52 delete[] arr; 53 return 0; 54 } 55 56 arr[1 + i] = *itm; 57 58 sipReleaseType(itm, td, state); 59 } 60 61 return arr; 62} 63%End 64 65public: 66 enum RenderHint 67 { 68 Antialiasing, 69 TextAntialiasing, 70 SmoothPixmapTransform, 71 HighQualityAntialiasing, 72 NonCosmeticDefaultPen, 73 Qt4CompatiblePainting, 74%If (Qt_5_13_0 -) 75 LosslessImageRendering, 76%End 77 }; 78 79 typedef QFlags<QPainter::RenderHint> RenderHints; 80 QPainter(); 81 explicit QPainter(QPaintDevice *); 82 ~QPainter(); 83 SIP_PYOBJECT __enter__(); 84%MethodCode 85 // Check a device was passed. 86 if (sipCpp->isActive()) 87 { 88 // Just return a reference to self. 89 sipRes = sipSelf; 90 Py_INCREF(sipRes); 91 } 92 else 93 { 94 PyErr_SetString(PyExc_ValueError, "QPainter must be created with a device"); 95 sipRes = 0; 96 } 97%End 98 99 void __exit__(SIP_PYOBJECT type, SIP_PYOBJECT value, SIP_PYOBJECT traceback); 100%MethodCode 101 sipCpp->end(); 102%End 103 104 QPaintDevice *device() const; 105 bool begin(QPaintDevice *); 106 bool end(); 107 bool isActive() const; 108 109 enum CompositionMode 110 { 111 CompositionMode_SourceOver, 112 CompositionMode_DestinationOver, 113 CompositionMode_Clear, 114 CompositionMode_Source, 115 CompositionMode_Destination, 116 CompositionMode_SourceIn, 117 CompositionMode_DestinationIn, 118 CompositionMode_SourceOut, 119 CompositionMode_DestinationOut, 120 CompositionMode_SourceAtop, 121 CompositionMode_DestinationAtop, 122 CompositionMode_Xor, 123 CompositionMode_Plus, 124 CompositionMode_Multiply, 125 CompositionMode_Screen, 126 CompositionMode_Overlay, 127 CompositionMode_Darken, 128 CompositionMode_Lighten, 129 CompositionMode_ColorDodge, 130 CompositionMode_ColorBurn, 131 CompositionMode_HardLight, 132 CompositionMode_SoftLight, 133 CompositionMode_Difference, 134 CompositionMode_Exclusion, 135 RasterOp_SourceOrDestination, 136 RasterOp_SourceAndDestination, 137 RasterOp_SourceXorDestination, 138 RasterOp_NotSourceAndNotDestination, 139 RasterOp_NotSourceOrNotDestination, 140 RasterOp_NotSourceXorDestination, 141 RasterOp_NotSource, 142 RasterOp_NotSourceAndDestination, 143 RasterOp_SourceAndNotDestination, 144 RasterOp_NotSourceOrDestination, 145 RasterOp_SourceOrNotDestination, 146 RasterOp_ClearDestination, 147 RasterOp_SetDestination, 148 RasterOp_NotDestination, 149 }; 150 151 void setCompositionMode(QPainter::CompositionMode mode); 152 QPainter::CompositionMode compositionMode() const; 153 const QFont &font() const; 154 void setFont(const QFont &f); 155 QFontMetrics fontMetrics() const; 156 QFontInfo fontInfo() const; 157 void setPen(const QColor &color); 158 void setPen(const QPen &pen); 159 void setPen(Qt::PenStyle style); 160 const QPen &pen() const; 161 void setBrush(const QBrush &brush); 162 void setBrush(Qt::BrushStyle style); 163 const QBrush &brush() const; 164 void setBackgroundMode(Qt::BGMode mode); 165 Qt::BGMode backgroundMode() const; 166 QPoint brushOrigin() const; 167 void setBrushOrigin(const QPointF &); 168 void setBackground(const QBrush &bg); 169 const QBrush &background() const; 170 QRegion clipRegion() const; 171 QPainterPath clipPath() const; 172 void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation = Qt::ReplaceClip); 173 void setClipRegion(const QRegion ®ion, Qt::ClipOperation operation = Qt::ReplaceClip); 174 void setClipPath(const QPainterPath &path, Qt::ClipOperation operation = Qt::ReplaceClip); 175 void setClipping(bool enable); 176 bool hasClipping() const; 177 void save(); 178 void restore(); 179 void scale(qreal sx, qreal sy); 180 void shear(qreal sh, qreal sv); 181 void rotate(qreal a); 182 void translate(const QPointF &offset); 183 QRect window() const; 184 void setWindow(const QRect &window); 185 QRect viewport() const; 186 void setViewport(const QRect &viewport); 187 void setViewTransformEnabled(bool enable); 188 bool viewTransformEnabled() const; 189 void strokePath(const QPainterPath &path, const QPen &pen); 190 void fillPath(const QPainterPath &path, const QBrush &brush); 191 void drawPath(const QPainterPath &path); 192 void drawPoints(const QPointF *point, ...); 193%MethodCode 194 QPointF *points = qtgui_inst_array<QPointF>(a0, a1, sipType_QPointF); 195 196 if (points) 197 { 198 sipCpp->drawPoints(points, 1 + PyTuple_Size(a1)); 199 delete[] points; 200 } 201 else 202 sipIsErr = 1; 203%End 204 205 void drawPoints(const QPolygonF &points); 206 void drawPoints(const QPoint *point, ...); 207%MethodCode 208 QPoint *points = qtgui_inst_array<QPoint>(a0, a1, sipType_QPoint); 209 210 if (points) 211 { 212 sipCpp->drawPoints(points, 1 + PyTuple_Size(a1)); 213 delete[] points; 214 } 215 else 216 sipIsErr = 1; 217%End 218 219 void drawPoints(const QPolygon &points); 220 void drawLines(const QLineF *line, ...); 221%MethodCode 222 QLineF *lines = qtgui_inst_array<QLineF>(a0, a1, sipType_QLineF); 223 224 if (lines) 225 { 226 sipCpp->drawLines(lines, 1 + PyTuple_Size(a1)); 227 delete[] lines; 228 } 229 else 230 sipIsErr = 1; 231%End 232 233 void drawLines(const QVector<QLineF> &lines); 234 void drawLines(const QPointF *pointPair, ...); 235%MethodCode 236 QPointF *pairs = qtgui_inst_array<QPointF>(a0, a1, sipType_QPointF); 237 238 if (pairs) 239 { 240 sipCpp->drawLines(pairs, (1 + PyTuple_Size(a1)) / 2); 241 delete[] pairs; 242 } 243 else 244 sipIsErr = 1; 245%End 246 247 void drawLines(const QVector<QPointF> &pointPairs); 248 void drawLines(const QLine *line, ...); 249%MethodCode 250 QLine *lines = qtgui_inst_array<QLine>(a0, a1, sipType_QLine); 251 252 if (lines) 253 { 254 sipCpp->drawLines(lines, 1 + PyTuple_Size(a1)); 255 delete[] lines; 256 } 257 else 258 sipIsErr = 1; 259%End 260 261 void drawLines(const QVector<QLine> &lines); 262 void drawLines(const QPoint *pointPair, ...); 263%MethodCode 264 QPoint *pairs = qtgui_inst_array<QPoint>(a0, a1, sipType_QPoint); 265 266 if (pairs) 267 { 268 sipCpp->drawLines(pairs, (1 + PyTuple_Size(a1)) / 2); 269 delete[] pairs; 270 } 271 else 272 sipIsErr = 1; 273%End 274 275 void drawLines(const QVector<QPoint> &pointPairs); 276 void drawRects(const QRectF *rect, ...); 277%MethodCode 278 QRectF *rects = qtgui_inst_array<QRectF>(a0, a1, sipType_QRectF); 279 280 if (rects) 281 { 282 sipCpp->drawRects(rects, 1 + PyTuple_Size(a1)); 283 delete[] rects; 284 } 285 else 286 sipIsErr = 1; 287%End 288 289 void drawRects(const QVector<QRectF> &rects); 290 void drawRects(const QRect *rect, ...); 291%MethodCode 292 QRect *rects = qtgui_inst_array<QRect>(a0, a1, sipType_QRect); 293 294 if (rects) 295 { 296 sipCpp->drawRects(rects, 1 + PyTuple_Size(a1)); 297 delete[] rects; 298 } 299 else 300 sipIsErr = 1; 301%End 302 303 void drawRects(const QVector<QRect> &rects); 304 void drawEllipse(const QRectF &r); 305 void drawEllipse(const QRect &r); 306 void drawPolyline(const QPointF *point, ...); 307%MethodCode 308 QPointF *points = qtgui_inst_array<QPointF>(a0, a1, sipType_QPointF); 309 310 if (points) 311 { 312 sipCpp->drawPolyline(points, 1 + PyTuple_Size(a1)); 313 delete[] points; 314 } 315 else 316 sipIsErr = 1; 317%End 318 319 void drawPolyline(const QPolygonF &polyline); 320 void drawPolyline(const QPoint *point, ...); 321%MethodCode 322 QPoint *points = qtgui_inst_array<QPoint>(a0, a1, sipType_QPoint); 323 324 if (points) 325 { 326 sipCpp->drawPolyline(points, 1 + PyTuple_Size(a1)); 327 delete[] points; 328 } 329 else 330 sipIsErr = 1; 331%End 332 333 void drawPolyline(const QPolygon &polyline); 334 void drawPolygon(const QPointF *point, ...); 335%MethodCode 336 QPointF *points = qtgui_inst_array<QPointF>(a0, a1, sipType_QPointF); 337 338 if (points) 339 { 340 sipCpp->drawPolygon(points, 1 + PyTuple_Size(a1)); 341 delete[] points; 342 } 343 else 344 sipIsErr = 1; 345%End 346 347 void drawPolygon(const QPolygonF &points, Qt::FillRule fillRule = Qt::OddEvenFill); 348 void drawPolygon(const QPoint *point, ...); 349%MethodCode 350 QPoint *points = qtgui_inst_array<QPoint>(a0, a1, sipType_QPoint); 351 352 if (points) 353 { 354 sipCpp->drawPolygon(points, 1 + PyTuple_Size(a1)); 355 delete[] points; 356 } 357 else 358 sipIsErr = 1; 359%End 360 361 void drawPolygon(const QPolygon &points, Qt::FillRule fillRule = Qt::OddEvenFill); 362 void drawConvexPolygon(const QPointF *point, ...); 363%MethodCode 364 QPointF *points = qtgui_inst_array<QPointF>(a0, a1, sipType_QPointF); 365 366 if (points) 367 { 368 sipCpp->drawConvexPolygon(points, 1 + PyTuple_Size(a1)); 369 delete[] points; 370 } 371 else 372 sipIsErr = 1; 373%End 374 375 void drawConvexPolygon(const QPolygonF &poly); 376 void drawConvexPolygon(const QPoint *point, ...); 377%MethodCode 378 QPoint *points = qtgui_inst_array<QPoint>(a0, a1, sipType_QPoint); 379 380 if (points) 381 { 382 sipCpp->drawConvexPolygon(points, 1 + PyTuple_Size(a1)); 383 delete[] points; 384 } 385 else 386 sipIsErr = 1; 387%End 388 389 void drawConvexPolygon(const QPolygon &poly); 390 void drawArc(const QRectF &rect, int a, int alen); 391 void drawPie(const QRectF &rect, int a, int alen); 392 void drawChord(const QRectF &rect, int a, int alen); 393 void drawTiledPixmap(const QRectF &rectangle, const QPixmap &pixmap, const QPointF &pos = QPointF()); 394 void drawPicture(const QPointF &p, const QPicture &picture); 395 void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect); 396 void setLayoutDirection(Qt::LayoutDirection direction); 397 Qt::LayoutDirection layoutDirection() const; 398 void drawText(const QPointF &p, const QString &s); 399 void drawText(const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect /Out/ = 0); 400 void drawText(const QRect &rectangle, int flags, const QString &text, QRect *boundingRect /Out/ = 0); 401 void drawText(const QRectF &rectangle, const QString &text, const QTextOption &option = QTextOption()); 402 QRectF boundingRect(const QRectF &rect, int flags, const QString &text); 403 QRect boundingRect(const QRect &rect, int flags, const QString &text); 404 QRectF boundingRect(const QRectF &rectangle, const QString &text, const QTextOption &option = QTextOption()); 405 void fillRect(const QRectF &, const QBrush &); 406 void fillRect(const QRect &, const QBrush &); 407 void eraseRect(const QRectF &); 408 void setRenderHint(QPainter::RenderHint hint, bool on = true); 409 QPainter::RenderHints renderHints() const; 410 void setRenderHints(QPainter::RenderHints hints, bool on = true); 411 QPaintEngine *paintEngine() const; 412 void drawLine(const QLineF &l); 413 void drawLine(const QLine &line); 414 void drawLine(int x1, int y1, int x2, int y2); 415 void drawLine(const QPoint &p1, const QPoint &p2); 416 void drawLine(const QPointF &p1, const QPointF &p2); 417 void drawRect(const QRectF &rect); 418 void drawRect(int x, int y, int w, int h); 419 void drawRect(const QRect &r); 420 void drawPoint(const QPointF &p); 421 void drawPoint(int x, int y); 422 void drawPoint(const QPoint &p); 423 void drawEllipse(int x, int y, int w, int h); 424 void drawArc(const QRect &r, int a, int alen); 425 void drawArc(int x, int y, int w, int h, int a, int alen); 426 void drawPie(const QRect &rect, int a, int alen); 427 void drawPie(int x, int y, int w, int h, int a, int alen); 428 void drawChord(const QRect &rect, int a, int alen); 429 void drawChord(int x, int y, int w, int h, int a, int alen); 430 void setClipRect(int x, int y, int width, int height, Qt::ClipOperation operation = Qt::ReplaceClip); 431 void setClipRect(const QRect &rectangle, Qt::ClipOperation operation = Qt::ReplaceClip); 432 void eraseRect(const QRect &rect); 433 void eraseRect(int x, int y, int w, int h); 434 void fillRect(int x, int y, int w, int h, const QBrush &b); 435 void setBrushOrigin(int x, int y); 436 void setBrushOrigin(const QPoint &p); 437 void drawTiledPixmap(const QRect &rectangle, const QPixmap &pixmap, const QPoint &pos = QPoint()); 438 void drawTiledPixmap(int x, int y, int width, int height, const QPixmap &pixmap, int sx = 0, int sy = 0); 439 void drawPixmap(const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect); 440 void drawPixmap(const QPointF &p, const QPixmap &pm); 441 void drawPixmap(const QPoint &p, const QPixmap &pm); 442 void drawPixmap(const QRect &r, const QPixmap &pm); 443 void drawPixmap(int x, int y, const QPixmap &pm); 444 void drawPixmap(int x, int y, int w, int h, const QPixmap &pm); 445 void drawPixmap(int x, int y, int w, int h, const QPixmap &pm, int sx, int sy, int sw, int sh); 446 void drawPixmap(int x, int y, const QPixmap &pm, int sx, int sy, int sw, int sh); 447 void drawPixmap(const QPointF &p, const QPixmap &pm, const QRectF &sr); 448 void drawPixmap(const QPoint &p, const QPixmap &pm, const QRect &sr); 449 void drawImage(const QRectF &r, const QImage &image); 450 void drawImage(const QRect &r, const QImage &image); 451 void drawImage(const QPointF &p, const QImage &image); 452 void drawImage(const QPoint &p, const QImage &image); 453 void drawImage(int x, int y, const QImage &image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 454 void drawText(const QPoint &p, const QString &s); 455 void drawText(int x, int y, int width, int height, int flags, const QString &text, QRect *boundingRect /Out/ = 0); 456 void drawText(int x, int y, const QString &s); 457 QRect boundingRect(int x, int y, int w, int h, int flags, const QString &text); 458 qreal opacity() const; 459 void setOpacity(qreal opacity); 460 void translate(qreal dx, qreal dy); 461 void translate(const QPoint &offset); 462 void setViewport(int x, int y, int w, int h); 463 void setWindow(int x, int y, int w, int h); 464 bool worldMatrixEnabled() const; 465 void setWorldMatrixEnabled(bool enabled); 466 void drawPicture(int x, int y, const QPicture &p); 467 void drawPicture(const QPoint &pt, const QPicture &p); 468 void setTransform(const QTransform &transform, bool combine = false); 469 const QTransform &transform() const; 470 const QTransform &deviceTransform() const; 471 void resetTransform(); 472 void setWorldTransform(const QTransform &matrix, bool combine = false); 473 const QTransform &worldTransform() const; 474 QTransform combinedTransform() const; 475 bool testRenderHint(QPainter::RenderHint hint) const; 476 void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize); 477 void drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize); 478 void drawRoundedRect(const QRect &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize); 479 void drawEllipse(const QPointF ¢er, qreal rx, qreal ry); 480 void drawEllipse(const QPoint ¢er, int rx, int ry); 481 void fillRect(const QRectF &, const QColor &color); 482 void fillRect(const QRect &, const QColor &color); 483 void fillRect(int x, int y, int w, int h, const QColor &b); 484 void fillRect(int x, int y, int w, int h, Qt::GlobalColor c); 485 void fillRect(const QRect &r, Qt::GlobalColor c); 486 void fillRect(const QRectF &r, Qt::GlobalColor c); 487 void fillRect(int x, int y, int w, int h, Qt::BrushStyle style); 488 void fillRect(const QRect &r, Qt::BrushStyle style); 489 void fillRect(const QRectF &r, Qt::BrushStyle style); 490 void beginNativePainting(); 491 void endNativePainting(); 492 493 class PixmapFragment 494 { 495%TypeHeaderCode 496#include <qpainter.h> 497%End 498 499 public: 500 qreal x; 501 qreal y; 502 qreal sourceLeft; 503 qreal sourceTop; 504 qreal width; 505 qreal height; 506 qreal scaleX; 507 qreal scaleY; 508 qreal rotation; 509 qreal opacity; 510 static QPainter::PixmapFragment create(const QPointF &pos, const QRectF &sourceRect, qreal scaleX = 1, qreal scaleY = 1, qreal rotation = 0, qreal opacity = 1) /Factory/; 511 }; 512 513 enum PixmapFragmentHint 514 { 515 OpaqueHint, 516 }; 517 518 typedef QFlags<QPainter::PixmapFragmentHint> PixmapFragmentHints; 519 void drawPixmapFragments(SIP_PYLIST fragments /TypeHint="List[QPainter.PixmapFragment]"/, const QPixmap &pixmap, QFlags<QPainter::PixmapFragmentHint> hints = 0); 520%MethodCode 521 // Allocate temporary storage for the C++ conversions. 522 Py_ssize_t numFragments = PyList_Size(a0); 523 QPainter::PixmapFragment *fragments = new QPainter::PixmapFragment[numFragments]; 524 525 // Convert the fragments. 526 for (Py_ssize_t i = 0; i < numFragments; ++i) 527 { 528 void *cpp = sipForceConvertToType(PyList_GetItem(a0, i), sipType_QPainter_PixmapFragment, NULL, SIP_NO_CONVERTORS, NULL, &sipIsErr); 529 530 fragments[i] = *reinterpret_cast<QPainter::PixmapFragment *>(cpp); 531 } 532 533 if (!sipIsErr) 534 { 535 Py_BEGIN_ALLOW_THREADS 536 sipCpp->drawPixmapFragments(fragments, numFragments, *a1, *a2); 537 Py_END_ALLOW_THREADS 538 } 539 540 delete[] fragments; 541%End 542 543 void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText); 544 void drawStaticText(const QPoint &p, const QStaticText &staticText); 545 void drawStaticText(int x, int y, const QStaticText &staticText); 546 QRectF clipBoundingRect() const; 547%If (PyQt_RawFont) 548 void drawGlyphRun(const QPointF &position, const QGlyphRun &glyphRun); 549%End 550%If (Qt_5_12_0 -) 551 void fillRect(int x, int y, int w, int h, QGradient::Preset preset); 552%End 553%If (Qt_5_12_0 -) 554 void fillRect(const QRect &r, QGradient::Preset preset); 555%End 556%If (Qt_5_12_0 -) 557 void fillRect(const QRectF &r, QGradient::Preset preset); 558%End 559 void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 560 void drawImage(const QRect &targetRect, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 561 void drawImage(const QPointF &p, const QImage &image, const QRectF &sr, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 562 void drawImage(const QPoint &p, const QImage &image, const QRect &sr, Qt::ImageConversionFlags flags = Qt::ImageConversionFlag::AutoColor); 563 564private: 565 QPainter(const QPainter &); 566}; 567 568QFlags<QPainter::RenderHint> operator|(QPainter::RenderHint f1, QFlags<QPainter::RenderHint> f2); 569