Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpicture.cpp
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
4#include "qpicture.h"
5#include <private/qpicture_p.h>
6
7#ifndef QT_NO_PICTURE
8
9#include <private/qfactoryloader_p.h>
10#include <private/qpaintengine_pic_p.h>
11#include <private/qfont_p.h>
12#include <qguiapplication.h>
13
14#include "qdatastream.h"
15#include "qfile.h"
16#include "qimage.h"
17#include "qmutex.h"
18#include "qpainter.h"
19#include "qpainterpath.h"
20#include "qpixmap.h"
21#include "qregion.h"
22#include "qdebug.h"
23#include <QtCore/private/qlocking_p.h>
24
25#include <algorithm>
26
28
29void qt_format_text(const QFont &fnt, const QRectF &_r,
30 int tf, const QTextOption *opt, const QString& str, QRectF *brect,
31 int tabstops, int *, int tabarraylen,
33
83const char *qt_mfhdr_tag = "QPIC"; // header tag
84static const quint16 mfhdr_maj = QDataStream::Qt_DefaultCompiledVersion; // major version #
85static const quint16 mfhdr_min = 0; // minor version #
86
102QPicture::QPicture(int formatVersion)
103 : QPaintDevice(),
104 d_ptr(new QPicturePrivate)
105{
106 Q_D(QPicture);
107
108 if (formatVersion == 0)
109 qWarning("QPicture: invalid format version 0");
110
111 // still accept the 0 default from before Qt 3.0.
112 if (formatVersion > 0 && formatVersion != (int)mfhdr_maj) {
113 d->formatMajor = formatVersion;
114 d->formatMinor = 0;
115 d->formatOk = false;
116 } else {
117 d->resetFormat();
118 }
119}
120
128 : QPaintDevice(), d_ptr(pic.d_ptr)
129{
130}
131
134 : QPaintDevice(),
135 d_ptr(&dptr)
136{
137}
138
145
150{
151 return QInternal::Picture;
152}
153
181{
182 return d_func()->pictb.buffer().isNull();
183}
184
186{
187 return d_func()->pictb.buffer().size();
188}
189
190const char* QPicture::data() const
191{
192 return d_func()->pictb.buffer();
193}
194
196{
197 d_ptr.detach();
198}
199
201{
202 return d_func()->ref.loadRelaxed() == 1;
203}
204
212void QPicture::setData(const char* data, uint size)
213{
214 detach();
215 d_func()->pictb.setData(data, size);
216 d_func()->resetFormat(); // we'll have to check
217}
218
219
228{
230 if (!f.open(QIODevice::ReadOnly)) {
232 return false;
233 }
234 return load(&f);
235}
236
244{
245 detach();
246 QByteArray a = dev->readAll();
247
248 d_func()->pictb.setData(a); // set byte array in buffer
249 return d_func()->checkFormat();
250}
251
260{
261 if (paintingActive()) {
262 qWarning("QPicture::save: still being painted on. "
263 "Call QPainter::end() first");
264 return false;
265 }
266
268 if (!f.open(QIODevice::WriteOnly))
269 return false;
270 return save(&f);
271}
272
280{
281 if (paintingActive()) {
282 qWarning("QPicture::save: still being painted on. "
283 "Call QPainter::end() first");
284 return false;
285 }
286
287 dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size());
288 return true;
289}
290
297{
298 Q_D(const QPicture);
299 // Use override rect where possible.
300 if (!d->override_rect.isEmpty())
301 return d->override_rect;
302
303 if (!d->formatOk)
304 d_ptr->checkFormat();
305
306 return d->brect;
307}
308
315{
316 d_func()->override_rect = r;
317}
318
330{
331 Q_D(QPicture);
332
333 if (d->pictb.size() == 0) // nothing recorded
334 return true;
335
336 if (!d->formatOk && !d->checkFormat())
337 return false;
338
339 d->pictb.open(QIODevice::ReadOnly); // open buffer device
341 s.setDevice(&d->pictb); // attach data stream to buffer
342 s.device()->seek(10); // go directly to the data
343 s.setVersion(d->formatMajor == 4 ? 3 : d->formatMajor);
344
345 quint8 c, clen;
346 quint32 nrecords;
347 s >> c >> clen;
349 // bounding rect was introduced in ver 4. Read in checkFormat().
350 if (d->formatMajor >= 4) {
351 qint32 dummy;
352 s >> dummy >> dummy >> dummy >> dummy;
353 }
354 s >> nrecords;
355 if (!exec(painter, s, nrecords)) {
356 qWarning("QPicture::play: Format error");
357 d->pictb.close();
358 return false;
359 }
360 d->pictb.close();
361 return true; // no end-command
362}
363
364
365//
366// QFakeDevice is used to create fonts with a custom DPI
367//
369{
370public:
371 QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); }
372 void setDpiX(int dpi) { dpi_x = dpi; }
373 void setDpiY(int dpi) { dpi_y = dpi; }
374 QPaintEngine *paintEngine() const override { return nullptr; }
375 int metric(PaintDeviceMetric m) const override
376 {
377 switch(m) {
378 case PdmPhysicalDpiX:
379 case PdmDpiX:
380 return dpi_x;
381 case PdmPhysicalDpiY:
382 case PdmDpiY:
383 return dpi_y;
384 default:
385 return QPaintDevice::metric(m);
386 }
387 }
388
389private:
390 int dpi_x;
391 int dpi_y;
392};
393
400bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords)
401{
402 Q_D(QPicture);
403#if defined(QT_DEBUG)
404 int strm_pos;
405#endif
406 quint8 c; // command id
407 quint8 tiny_len; // 8-bit length descriptor
408 qint32 len; // 32-bit length descriptor
409 qint16 i_16, i1_16, i2_16; // parameters...
410 qint8 i_8;
411 quint32 ul;
412 double dbl;
413 bool bl;
414 QByteArray str1;
415 QString str;
416 QPointF p, p1, p2;
417 QPoint ip, ip1, ip2;
418 QRect ir;
419 QRectF r;
420 QPolygonF a;
421 QPolygon ia;
423 QFont font;
424 QPen pen;
426 QRegion rgn;
427 qreal wmatrix[6];
429
430 QTransform worldMatrix = painter->transform();
431 worldMatrix.scale(qreal(painter->device()->logicalDpiX()) / qreal(qt_defaultDpiX()),
433 painter->setTransform(worldMatrix);
434
435 while (nrecords-- && !s.atEnd()) {
436 s >> c; // read cmd
437 s >> tiny_len; // read param length
438 if (tiny_len == 255) // longer than 254 bytes
439 s >> len;
440 else
441 len = tiny_len;
442#if defined(QT_DEBUG)
443 strm_pos = s.device()->pos();
444#endif
445 switch (c) { // exec cmd
447 break;
449 if (d->formatMajor <= 5) {
450 s >> ip;
451 painter->drawPoint(ip);
452 } else {
453 s >> p;
455 }
456 break;
458// ## implement me in the picture paint engine
459// s >> a >> i1_32 >> i2_32;
460// painter->drawPoints(a.mid(i1_32, i2_32));
461 break;
464 s >> path;
466 break;
467 }
469 if (d->formatMajor <= 5) {
470 s >> ip1 >> ip2;
471 painter->drawLine(ip1, ip2);
472 } else {
473 s >> p1 >> p2;
475 }
476 break;
478 if (d->formatMajor <= 5) {
479 s >> ir;
480 painter->drawRect(ir);
481 } else {
482 s >> r;
484 }
485 break;
487 if (d->formatMajor <= 5) {
488 s >> ir >> i1_16 >> i2_16;
489 painter->drawRoundedRect(ir, i1_16, i2_16, Qt::RelativeSize);
490 } else {
491 s >> r >> i1_16 >> i2_16;
492 painter->drawRoundedRect(r, i1_16, i2_16, Qt::RelativeSize);
493 }
494 break;
496 if (d->formatMajor <= 5) {
497 s >> ir;
498 painter->drawEllipse(ir);
499 } else {
500 s >> r;
502 }
503 break;
505 if (d->formatMajor <= 5) {
506 s >> ir;
507 r = ir;
508 } else {
509 s >> r;
510 }
511 s >> i1_16 >> i2_16;
512 painter->drawArc(r, i1_16, i2_16);
513 break;
515 if (d->formatMajor <= 5) {
516 s >> ir;
517 r = ir;
518 } else {
519 s >> r;
520 }
521 s >> i1_16 >> i2_16;
522 painter->drawPie(r, i1_16, i2_16);
523 break;
525 if (d->formatMajor <= 5) {
526 s >> ir;
527 r = ir;
528 } else {
529 s >> r;
530 }
531 s >> i1_16 >> i2_16;
532 painter->drawChord(r, i1_16, i2_16);
533 break;
535 s >> ia;
536 painter->drawLines(ia);
537 ia.clear();
538 break;
540 if (d->formatMajor <= 5) {
541 s >> ia;
543 ia.clear();
544 } else {
545 s >> a;
547 a.clear();
548 }
549 break;
551 if (d->formatMajor <= 5) {
552 s >> ia >> i_8;
554 ia.clear();
555 } else {
556 s >> a >> i_8;
558 a.clear();
559 }
560 break;
562 s >> ia;
564 Q_ASSERT(ia.size() == 4);
565 path.moveTo(ia.value(0));
566 path.cubicTo(ia.value(1), ia.value(2), ia.value(3));
568 ia.clear();
569 }
570 break;
572 s >> ip >> str1;
574 break;
576 s >> ir >> i_16 >> str1;
577 painter->drawText(ir, i_16, QString::fromLatin1(str1));
578 break;
580 if (d->formatMajor <= 5) {
581 s >> ip >> str;
582 painter->drawText(ip, str);
583 } else {
584 s >> p >> str;
586 }
587 break;
589 s >> ir;
590 s >> i_16;
591 s >> str;
592 painter->drawText(ir, i_16, str);
593 break;
595 s >> p >> str >> font >> ul;
596
597 // the text layout direction is not used here because it's already
598 // aligned when QPicturePaintEngine::drawTextItem() serializes the
599 // drawText() call, therefore ul is unsed in this context
600
601 if (d->formatMajor >= 9) {
602 s >> dbl;
603 QFont fnt(font);
604 if (dbl != 1.0) {
605 QFakeDevice fake;
606 fake.setDpiX(qRound(dbl*qt_defaultDpiX()));
607 fake.setDpiY(qRound(dbl*qt_defaultDpiY()));
608 fnt = QFont(font, &fake);
609 }
610
611 qreal justificationWidth;
612 s >> justificationWidth;
613
615
616 QSizeF size(1, 1);
617 if (justificationWidth > 0) {
618 size.setWidth(justificationWidth);
621 }
622
623 QFontMetrics fm(fnt);
624 QPointF pt(p.x(), p.y() - fm.ascent());
625 qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/nullptr,
626 str, /*brect=*/nullptr, /*tabstops=*/0, /*...*/nullptr, /*tabarraylen=*/0, painter);
627 } else {
629 str, /*brect=*/nullptr, /*tabstops=*/0, /*...*/nullptr, /*tabarraylen=*/0, painter);
630 }
631
632 break;
633 }
636 if (d->formatMajor < 4) {
637 s >> ip >> pixmap;
639 } else if (d->formatMajor <= 5) {
640 s >> ir >> pixmap;
642 } else {
643 QRectF sr;
644 if (d->in_memory_only) {
645 int index;
646 s >> r >> index >> sr;
647 Q_ASSERT(index < d->pixmap_list.size());
648 pixmap = d->pixmap_list.value(index);
649 } else {
650 s >> r >> pixmap >> sr;
651 }
652 painter->drawPixmap(r, pixmap, sr);
653 }
654 }
655 break;
658 if (d->in_memory_only) {
659 int index;
660 s >> r >> index >> p;
661 Q_ASSERT(index < d->pixmap_list.size());
662 pixmap = d->pixmap_list.value(index);
663 } else {
664 s >> r >> pixmap >> p;
665 }
667 }
668 break;
671 if (d->formatMajor < 4) {
672 s >> p >> image;
674 } else if (d->formatMajor <= 5){
675 s >> ir >> image;
676 painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height()));
677 } else {
678 QRectF sr;
679 if (d->in_memory_only) {
680 int index;
681 s >> r >> index >> sr >> ul;
682 Q_ASSERT(index < d->image_list.size());
683 image = d->image_list.value(index);
684 } else {
685 s >> r >> image >> sr >> ul;
686 }
687 painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul));
688 }
689 }
690 break;
692 s >> ul; // number of records
693 if (!exec(painter, s, ul))
694 return false;
695 break;
697 if (nrecords == 0)
698 return true;
699 break;
701 painter->save();
702 break;
704 painter->restore();
705 break;
707 s >> color;
709 break;
711 s >> i_8;
713 break;
714 case QPicturePrivate::PdcSetROP: // NOP
715 s >> i_8;
716 break;
718 if (d->formatMajor <= 5) {
719 s >> ip;
721 } else {
722 s >> p;
724 }
725 break;
727 s >> font;
729 break;
731 if (d->in_memory_only) {
732 int index;
733 s >> index;
734 Q_ASSERT(index < d->pen_list.size());
735 pen = d->pen_list.value(index);
736 } else {
737 s >> pen;
738 }
739 painter->setPen(pen);
740 break;
742 if (d->in_memory_only) {
743 int index;
744 s >> index;
745 Q_ASSERT(index < d->brush_list.size());
746 brush = d->brush_list.value(index);
747 } else {
748 s >> brush;
749 }
751 break;
753 s >> i_8;
755 break;
757 if (d->formatMajor <= 5) {
758 s >> ir;
759 painter->setWindow(ir);
760 } else {
761 s >> r;
762 painter->setWindow(r.toRect());
763 }
764 break;
766 if (d->formatMajor <= 5) {
767 s >> ir;
768 painter->setViewport(ir);
769 } else {
770 s >> r;
771 painter->setViewport(r.toRect());
772 }
773 break;
775 s >> i_8;
777 break;
779 if (d->formatMajor >= 8) {
780 s >> matrix >> i_8;
781 } else {
782 s >> wmatrix[0] >> wmatrix[1]
783 >> wmatrix[2] >> wmatrix[3]
784 >> wmatrix[4] >> wmatrix[5] >> i_8;
785 matrix = QTransform(wmatrix[0], wmatrix[1],
786 wmatrix[2], wmatrix[3],
787 wmatrix[4], wmatrix[5]);
788 }
789 // i_8 is always false due to updateXForm() in qpaintengine_pic.cpp
790 painter->setTransform(matrix * worldMatrix, i_8);
791 break;
793 s >> i_8;
794 painter->setClipping(i_8);
795 break;
797 s >> rgn >> i_8;
798 if (d->formatMajor >= 9) {
800 } else {
802 }
803 break;
805 {
807 s >> path >> i_8;
809 break;
810 }
812 s >> ul;
814 bool(ul & QPainter::Antialiasing));
819 break;
821 s >> ul;
823 break;
825 s >> bl;
826 painter->setClipping(bl);
827 break;
829 s >> dbl;
830 painter->setOpacity(qreal(dbl));
831 break;
832 default:
833 qWarning("QPicture::play: Invalid command %d", c);
834 if (len > 0) // skip unknown command
835 s.device()->seek(s.device()->pos()+len);
836 }
837#if defined(QT_DEBUG)
838 //qDebug("device->at(): %i, strm_pos: %i len: %i", (int)s.device()->pos(), strm_pos, len);
839 Q_ASSERT(qint32(s.device()->pos() - strm_pos) == len);
840#endif
841 }
842 return false;
843}
844
858{
859 int val;
860 QRect brect = boundingRect();
861 switch (m) {
862 case PdmWidth:
863 val = brect.width();
864 break;
865 case PdmHeight:
866 val = brect.height();
867 break;
868 case PdmWidthMM:
869 val = int(25.4/qt_defaultDpiX()*brect.width());
870 break;
871 case PdmHeightMM:
872 val = int(25.4/qt_defaultDpiY()*brect.height());
873 break;
874 case PdmDpiX:
875 case PdmPhysicalDpiX:
877 break;
878 case PdmDpiY:
879 case PdmPhysicalDpiY:
881 break;
882 case PdmNumColors:
883 val = 16777216;
884 break;
885 case PdmDepth:
886 val = 24;
887 break;
889 val = 1;
890 break;
893 break;
894 default:
895 val = 0;
896 qWarning("QPicture::metric: Invalid metric command");
897 }
898 return val;
899}
900
921{
922 d_ptr = p.d_ptr;
923 return *this;
924}
925
940 : in_memory_only(false)
941{
942}
943
950 : trecs(other.trecs),
951 formatOk(other.formatOk),
952 formatMinor(other.formatMinor),
953 brect(other.brect),
954 override_rect(other.override_rect),
955 in_memory_only(false)
956{
957 pictb.setData(other.pictb.data(), other.pictb.size());
958 if (other.pictb.isOpen()) {
959 pictb.open(other.pictb.openMode());
960 pictb.seek(other.pictb.pos());
961 }
962}
963
976
977
986{
987 resetFormat();
988
989 // can't check anything in an empty buffer
990 if (pictb.size() == 0 || pictb.isOpen())
991 return false;
992
993 pictb.open(QIODevice::ReadOnly); // open buffer device
995 s.setDevice(&pictb); // attach data stream to buffer
996
997 char mf_id[4]; // picture header tag
998 s.readRawData(mf_id, 4); // read actual tag
999 int bufSize = pictb.buffer().size();
1000 if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0 || bufSize < 12) { // wrong header id or size
1001 qWarning("QPicturePaintEngine::checkFormat: Incorrect header");
1002 pictb.close();
1003 return false;
1004 }
1005
1006 int cs_start = sizeof(quint32); // pos of checksum word
1007 int data_start = cs_start + sizeof(quint16);
1008 quint16 cs,ccs;
1009 const QByteArray buf = pictb.buffer(); // pointer to data
1010
1011 s >> cs; // read checksum
1012 ccs = (quint16) qChecksum(QByteArrayView(buf.constData() + data_start, buf.size() - data_start));
1013 if (ccs != cs) {
1014 qWarning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected",
1015 ccs, cs);
1016 pictb.close();
1017 return false;
1018 }
1019
1020 quint16 major, minor;
1021 s >> major >> minor; // read version number
1022 if (major > mfhdr_maj) { // new, incompatible version
1023 qWarning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d",
1024 major, minor);
1025 pictb.close();
1026 return false;
1027 }
1028 s.setVersion(major != 4 ? major : 3);
1029
1030 quint8 c, clen;
1031 s >> c >> clen;
1033 if (!(major >= 1 && major <= 3)) {
1034 qint32 l, t, w, h;
1035 s >> l >> t >> w >> h;
1036 brect = QRect(l, t, w, h);
1037 }
1038 } else {
1039 qWarning("QPicturePaintEngine::checkFormat: Format error");
1040 pictb.close();
1041 return false;
1042 }
1043 pictb.close();
1044
1045 formatOk = true; // picture seems to be ok
1046 formatMajor = major;
1047 formatMinor = minor;
1048 return true;
1049}
1050
1053{
1054 if (!d_func()->paintEngine)
1055 const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine);
1056 return d_func()->paintEngine.data();
1057}
1058
1059/*****************************************************************************
1060 QPicture stream functions
1061 *****************************************************************************/
1062
1063#ifndef QT_NO_DATASTREAM
1072{
1073 quint32 size = r.d_func()->pictb.buffer().size();
1074 s << size;
1075 // null picture ?
1076 if (size == 0)
1077 return s;
1078 // just write the whole buffer to the stream
1079 s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size());
1080 return s;
1081}
1082
1091{
1092 QDataStream sr;
1093
1094 // "init"; this code is similar to the beginning of QPicture::cmd()
1095 sr.setDevice(&r.d_func()->pictb);
1096 sr.setVersion(r.d_func()->formatMajor);
1097 quint32 len;
1098 s >> len;
1100 if (len > 0) {
1101 data.resize(len);
1102 s.readRawData(data.data(), len);
1103 }
1104
1105 r.d_func()->pictb.setData(data);
1106 r.d_func()->resetFormat();
1107 return s;
1108}
1109#endif // QT_NO_DATASTREAM
1110
1112
1113#endif // QT_NO_PICTURE
1114
\inmodule QtGui
Definition qbrush.h:30
bool open(OpenMode openMode) override
\reimp
Definition qbuffer.cpp:295
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition qbuffer.cpp:259
void close() override
\reimp
Definition qbuffer.cpp:315
qint64 size() const override
\reimp
Definition qbuffer.cpp:331
bool seek(qint64 off) override
\reimp
Definition qbuffer.cpp:340
QByteArray & buffer()
Returns a reference to the QBuffer's internal buffer.
Definition qbuffer.cpp:218
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore\reentrant
Definition qdatastream.h:46
void setDevice(QIODevice *)
void QDataStream::setDevice(QIODevice *d)
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
QPaintEngine * paintEngine() const override
Definition qpicture.cpp:374
void setDpiY(int dpi)
Definition qpicture.cpp:373
int metric(PaintDeviceMetric m) const override
Definition qpicture.cpp:375
void setDpiX(int dpi)
Definition qpicture.cpp:372
\inmodule QtCore
Definition qfile.h:93
\reentrant \inmodule QtGui
\reentrant
Definition qfont.h:22
\inmodule QtCore \reentrant
Definition qiodevice.h:34
bool isOpen() const
Returns true if the device is open; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
\inmodule QtGui
Definition qimage.h:37
int logicalDpiX() const
bool paintingActive() const
@ PdmDevicePixelRatioScaled
int logicalDpiY() const
virtual int metric(PaintDeviceMetric metric) const
static qreal devicePixelRatioFScale()
\inmodule QtGui
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawPoint(const QPointF &pt)
Draws a single point at the given position using the current pen's color.
Definition qpainter.h:545
const QPen & pen() const
Returns the painter's current pen.
void setBackground(const QBrush &bg)
Sets the background brush of the painter to the given brush.
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition qpainter.h:519
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or \nullptr if the painter is n...
void setWorldMatrixEnabled(bool enabled)
void drawPie(const QRectF &rect, int a, int alen)
Draws a pie defined by the given rectangle, startAngle and spanAngle.
void strokePath(const QPainterPath &path, const QPen &pen)
Draws the outline (strokes) the path path with the pen specified by pen.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition qpainter.h:442
void setViewport(const QRect &viewport)
Sets the painter's viewport rectangle to the given rectangle, and enables view transformations.
void drawChord(const QRectF &rect, int a, int alen)
Draws the chord defined by the given rectangle, startAngle and spanAngle.
void setBrushOrigin(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpainter.h:698
void setClipPath(const QPainterPath &path, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip path for the painter to the given path, with the clip operation.
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
void restore()
Restores the current painter state (pops a saved state off the stack).
void setOpacity(qreal opacity)
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void save()
Saves the current painter state (pushes the state onto a stack).
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
void setFont(const QFont &f)
Sets the painter's font to the given font.
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position.
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
void drawArc(const QRectF &rect, int a, int alen)
Draws the arc defined by the given rectangle, startAngle and spanAngle.
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
@ NonCosmeticBrushPatterns
Definition qpainter.h:57
@ SmoothPixmapTransform
Definition qpainter.h:54
@ Antialiasing
Definition qpainter.h:52
const QTransform & transform() const
Alias for worldTransform().
CompositionMode
Defines the modes supported for digital image compositing.
Definition qpainter.h:97
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
void setViewTransformEnabled(bool enable)
Enables view transformations if enable is true, or disables view transformations if enable is false.
void setWindow(const QRect &window)
Sets the painter's window to the given rectangle, and enables view transformations.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
void setTransform(const QTransform &transform, bool combine=false)
\inmodule QtGui
Definition qpen.h:28
The QPicture class is a paint device that records and replays QPainter commands.
Definition qpicture.h:19
bool isDetached() const
Definition qpicture.cpp:200
virtual void setData(const char *data, uint size)
Sets the picture data directly from data and size.
Definition qpicture.cpp:212
bool load(QIODevice *dev)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpicture.cpp:243
const char * data() const
Returns a pointer to the picture data.
Definition qpicture.cpp:190
void setBoundingRect(const QRect &r)
Sets the picture's bounding rectangle to r.
Definition qpicture.cpp:314
void detach()
Definition qpicture.cpp:195
QRect boundingRect() const
Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.
Definition qpicture.cpp:296
QPicture(int formatVersion=-1)
Constructs an empty picture.
Definition qpicture.cpp:102
uint size() const
Returns the size of the picture data.
Definition qpicture.cpp:185
QPaintEngine * paintEngine() const override
QPicture & operator=(const QPicture &p)
Move-assigns other to this QPicture instance.
Definition qpicture.cpp:920
int metric(PaintDeviceMetric m) const override
Definition qpicture.cpp:857
int devType() const override
Definition qpicture.cpp:149
bool save(QIODevice *dev)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qpicture.cpp:279
bool isNull() const
Returns true if the picture contains no data; otherwise returns false.
Definition qpicture.cpp:180
bool play(QPainter *p)
Replays the picture using painter, and returns true if successful; otherwise returns false.
Definition qpicture.cpp:329
~QPicture()
Destroys the picture.
Definition qpicture.cpp:142
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:208
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
\reentrant
Definition qtextoption.h:18
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
QString str
[2]
QPixmap p2
QPixmap p1
[0]
QStyleOptionButton opt
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ AlignJustify
Definition qnamespace.h:149
@ RelativeSize
ClipOperation
@ TextJustificationForced
Definition qnamespace.h:179
@ TextSingleLine
Definition qnamespace.h:170
@ TextDontClip
Definition qnamespace.h:171
@ TextForceLeftToRight
Definition qnamespace.h:180
@ WindingFill
@ OddEvenFill
Definition brush.cpp:5
Definition image.cpp:4
Q_CORE_EXPORT quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard=Qt::ChecksumIso3309)
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
Q_GUI_EXPORT int qt_defaultDpiX()
Definition qfont.cpp:110
Q_GUI_EXPORT int qt_defaultDpiY()
Definition qfont.cpp:125
#define qWarning
Definition qlogging.h:166
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLboolean r
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLuint color
[2]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLbitfield flags
GLsizei bufSize
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint GLfloat * val
GLuint GLenum matrix
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
GLenum GLsizei len
const char * qt_mfhdr_tag
Definition qpicture.cpp:83
static const quint16 mfhdr_maj
Definition qpicture.cpp:84
static const quint16 mfhdr_min
Definition qpicture.cpp:85
QT_BEGIN_NAMESPACE void qt_format_text(const QFont &fnt, const QRectF &_r, int tf, const QTextOption *opt, const QString &str, QRectF *brect, int tabstops, int *, int tabarraylen, QPainter *painter)
const char * qt_mfhdr_tag
Definition qpicture.cpp:83
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
unsigned int quint32
Definition qtypes.h:50
short qint16
Definition qtypes.h:47
unsigned short quint16
Definition qtypes.h:48
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition qtypes.h:45
double qreal
Definition qtypes.h:187
unsigned char quint8
Definition qtypes.h:46
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QDataStream & operator>>(QDataStream &in, MyClass &myObj)
QSharedPointer< T > other(t)
[5]
dialog exec()
widget render & pixmap
QPainter painter(this)
[7]