Qt 4.8
qpicture.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpicture.h"
43 #include <private/qpicture_p.h>
44 
45 #ifndef QT_NO_PICTURE
46 
47 #include <private/qfactoryloader_p.h>
48 #include <private/qpaintengine_pic_p.h>
49 #include <private/qfont_p.h>
50 
51 #include "qdatastream.h"
52 #include "qfile.h"
53 #include "qimage.h"
54 #include "qmutex.h"
55 #include "qpainter.h"
56 #include "qpainterpath.h"
57 #include "qpixmap.h"
58 #include "qregion.h"
59 #include "qdebug.h"
60 
62 
63 void qt_format_text(const QFont &fnt, const QRectF &_r,
64  int tf, const QTextOption *opt, const QString& str, QRectF *brect,
65  int tabstops, int *, int tabarraylen,
66  QPainter *painter);
67 
112 const char *qt_mfhdr_tag = "QPIC"; // header tag
113 static const quint16 mfhdr_maj = 11; // major version #
114 static const quint16 mfhdr_min = 0; // minor version #
115 
131 QPicture::QPicture(int formatVersion)
132  : QPaintDevice(),
133  d_ptr(new QPicturePrivate)
134 {
135  Q_D(QPicture);
136 
137  if (formatVersion == 0)
138  qWarning("QPicture: invalid format version 0");
139 
140  // still accept the 0 default from before Qt 3.0.
141  if (formatVersion > 0 && formatVersion != (int)mfhdr_maj) {
142  d->formatMajor = formatVersion;
143  d->formatMinor = 0;
144  d->formatOk = false;
145  } else {
146  d->resetFormat();
147  }
148 }
149 
157  : QPaintDevice(), d_ptr(pic.d_ptr)
158 {
159 }
160 
163  : QPaintDevice(),
164  d_ptr(&dptr)
165 {
166 }
167 
172 {
173 }
174 
178 int QPicture::devType() const
179 {
180  return QInternal::Picture;
181 }
182 
215 bool QPicture::isNull() const
216 {
217  return d_func()->pictb.buffer().isNull();
218 }
219 
221 {
222  return d_func()->pictb.buffer().size();
223 }
224 
225 const char* QPicture::data() const
226 {
227  return d_func()->pictb.buffer();
228 }
229 
231 {
232  d_ptr.detach();
233 }
234 
236 {
237  return d_func()->ref == 1;
238 }
239 
247 void QPicture::setData(const char* data, uint size)
248 {
249  detach();
250  d_func()->pictb.setData(data, size);
251  d_func()->resetFormat(); // we'll have to check
252 }
253 
254 
265 bool QPicture::load(const QString &fileName, const char *format)
266 {
267  QFile f(fileName);
268  if (!f.open(QIODevice::ReadOnly))
269  return false;
270  return load(&f, format);
271 }
272 
279 bool QPicture::load(QIODevice *dev, const char *format)
280 {
281  if(format) {
282 #ifndef QT_NO_PICTUREIO
283  QPictureIO io(dev, format);
284  bool result = io.read();
285  if (result) {
286  operator=(io.picture());
287 
288  } else if (format)
289 #else
290  bool result = false;
291 #endif
292  {
293  qWarning("QPicture::load: No such picture format: %s", format);
294  }
295  return result;
296  }
297 
298  detach();
299  QByteArray a = dev->readAll();
300 
301  d_func()->pictb.setData(a); // set byte array in buffer
302  return d_func()->checkFormat();
303 }
304 
315 bool QPicture::save(const QString &fileName, const char *format)
316 {
317  if (paintingActive()) {
318  qWarning("QPicture::save: still being painted on. "
319  "Call QPainter::end() first");
320  return false;
321  }
322 
323 
324  if(format) {
325 #ifndef QT_NO_PICTUREIO
326  QPictureIO io(fileName, format);
327  bool result = io.write();
328  if (result) {
329  operator=(io.picture());
330  } else if (format)
331 #else
332  bool result = false;
333 #endif
334  {
335  qWarning("QPicture::save: No such picture format: %s", format);
336  }
337  return result;
338  }
339 
340  QFile f(fileName);
341  if (!f.open(QIODevice::WriteOnly))
342  return false;
343  return save(&f, format);
344 }
345 
352 bool QPicture::save(QIODevice *dev, const char *format)
353 {
354  if (paintingActive()) {
355  qWarning("QPicture::save: still being painted on. "
356  "Call QPainter::end() first");
357  return false;
358  }
359 
360  if(format) {
361 #ifndef QT_NO_PICTUREIO
362  QPictureIO io(dev, format);
363  bool result = io.write();
364  if (result) {
365  operator=(io.picture());
366  } else if (format)
367 #else
368  bool result = false;
369 #endif
370  {
371  qWarning("QPicture::save: No such picture format: %s", format);
372  }
373  return result;
374  }
375 
376  dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size());
377  return true;
378 }
379 
386 {
387  Q_D(const QPicture);
388  // Use override rect where possible.
389  if (!d->override_rect.isEmpty())
390  return d->override_rect;
391 
392  if (!d->formatOk)
393  d_ptr->checkFormat();
394 
395  return d->brect;
396 }
397 
404 {
405  d_func()->override_rect = r;
406 }
407 
416 bool QPicture::play(QPainter *painter)
417 {
418  Q_D(QPicture);
419 
420  if (d->pictb.size() == 0) // nothing recorded
421  return true;
422 
423  if (!d->formatOk && !d->checkFormat())
424  return false;
425 
426  d->pictb.open(QIODevice::ReadOnly); // open buffer device
427  QDataStream s;
428  s.setDevice(&d->pictb); // attach data stream to buffer
429  s.device()->seek(10); // go directly to the data
430  s.setVersion(d->formatMajor == 4 ? 3 : d->formatMajor);
431 
432  quint8 c, clen;
433  quint32 nrecords;
434  s >> c >> clen;
436  // bounding rect was introduced in ver 4. Read in checkFormat().
437  if (d->formatMajor >= 4) {
438  qint32 dummy;
439  s >> dummy >> dummy >> dummy >> dummy;
440  }
441  s >> nrecords;
442  if (!exec(painter, s, nrecords)) {
443  qWarning("QPicture::play: Format error");
444  d->pictb.close();
445  return false;
446  }
447  d->pictb.close();
448  return true; // no end-command
449 }
450 
451 
452 //
453 // QFakeDevice is used to create fonts with a custom DPI
454 //
455 class QFakeDevice : public QPaintDevice
456 {
457 public:
458  QFakeDevice() { dpi_x = qt_defaultDpiX(); dpi_y = qt_defaultDpiY(); }
459  void setDpiX(int dpi) { dpi_x = dpi; }
460  void setDpiY(int dpi) { dpi_y = dpi; }
461  QPaintEngine *paintEngine() const { return 0; }
463  {
464  switch(m) {
465  case PdmPhysicalDpiX:
466  case PdmDpiX:
467  return dpi_x;
468  case PdmPhysicalDpiY:
469  case PdmDpiY:
470  return dpi_y;
471  default:
472  return QPaintDevice::metric(m);
473  }
474  }
475 
476 private:
477  int dpi_x;
478  int dpi_y;
479 };
480 
490 bool QPicture::exec(QPainter *painter, QDataStream &s, int nrecords)
491 {
492  Q_D(QPicture);
493 #if defined(QT_DEBUG)
494  int strm_pos;
495 #endif
496  quint8 c; // command id
497  quint8 tiny_len; // 8-bit length descriptor
498  qint32 len; // 32-bit length descriptor
499  qint16 i_16, i1_16, i2_16; // parameters...
500  qint8 i_8;
501  quint32 ul;
502  double dbl;
503  bool bl;
504  QByteArray str1;
505  QString str;
506  QPointF p, p1, p2;
507  QPoint ip, ip1, ip2;
508  QRect ir;
509  QRectF r;
510  QPolygonF a;
511  QPolygon ia;
512  QColor color;
513  QFont font;
514  QPen pen;
515  QBrush brush;
516  QRegion rgn;
517  QMatrix wmatrix;
518  QTransform matrix;
519 
520  QTransform worldMatrix = painter->transform();
521  worldMatrix.scale(qreal(painter->device()->logicalDpiX()) / qreal(qt_defaultDpiX()),
522  qreal(painter->device()->logicalDpiY()) / qreal(qt_defaultDpiY()));
523  painter->setTransform(worldMatrix);
524 
525  while (nrecords-- && !s.atEnd()) {
526  s >> c; // read cmd
527  s >> tiny_len; // read param length
528  if (tiny_len == 255) // longer than 254 bytes
529  s >> len;
530  else
531  len = tiny_len;
532 #if defined(QT_DEBUG)
533  strm_pos = s.device()->pos();
534 #endif
535  switch (c) { // exec cmd
537  break;
539  if (d->formatMajor <= 5) {
540  s >> ip;
541  painter->drawPoint(ip);
542  } else {
543  s >> p;
544  painter->drawPoint(p);
545  }
546  break;
548 // ## implement me in the picture paint engine
549 // s >> a >> i1_32 >> i2_32;
550 // painter->drawPoints(a.mid(i1_32, i2_32));
551  break;
553  QPainterPath path;
554  s >> path;
555  painter->drawPath(path);
556  break;
557  }
559  if (d->formatMajor <= 5) {
560  s >> ip1 >> ip2;
561  painter->drawLine(ip1, ip2);
562  } else {
563  s >> p1 >> p2;
564  painter->drawLine(p1, p2);
565  }
566  break;
568  if (d->formatMajor <= 5) {
569  s >> ir;
570  painter->drawRect(ir);
571  } else {
572  s >> r;
573  painter->drawRect(r);
574  }
575  break;
577  if (d->formatMajor <= 5) {
578  s >> ir >> i1_16 >> i2_16;
579  painter->drawRoundedRect(ir, i1_16, i2_16, Qt::RelativeSize);
580  } else {
581  s >> r >> i1_16 >> i2_16;
582  painter->drawRoundedRect(r, i1_16, i2_16, Qt::RelativeSize);
583  }
584  break;
586  if (d->formatMajor <= 5) {
587  s >> ir;
588  painter->drawEllipse(ir);
589  } else {
590  s >> r;
591  painter->drawEllipse(r);
592  }
593  break;
595  if (d->formatMajor <= 5) {
596  s >> ir;
597  r = ir;
598  } else {
599  s >> r;
600  }
601  s >> i1_16 >> i2_16;
602  painter->drawArc(r, i1_16, i2_16);
603  break;
605  if (d->formatMajor <= 5) {
606  s >> ir;
607  r = ir;
608  } else {
609  s >> r;
610  }
611  s >> i1_16 >> i2_16;
612  painter->drawPie(r, i1_16, i2_16);
613  break;
615  if (d->formatMajor <= 5) {
616  s >> ir;
617  r = ir;
618  } else {
619  s >> r;
620  }
621  s >> i1_16 >> i2_16;
622  painter->drawChord(r, i1_16, i2_16);
623  break;
625  s >> ia;
626  painter->drawLines(ia);
627  ia.clear();
628  break;
630  if (d->formatMajor <= 5) {
631  s >> ia;
632  painter->drawPolyline(ia);
633  ia.clear();
634  } else {
635  s >> a;
636  painter->drawPolyline(a);
637  a.clear();
638  }
639  break;
641  if (d->formatMajor <= 5) {
642  s >> ia >> i_8;
643  painter->drawPolygon(ia, i_8 ? Qt::WindingFill : Qt::OddEvenFill);
644  a.clear();
645  } else {
646  s >> a >> i_8;
647  painter->drawPolygon(a, i_8 ? Qt::WindingFill : Qt::OddEvenFill);
648  a.clear();
649  }
650  break;
652  s >> ia;
653  QPainterPath path;
654  Q_ASSERT(ia.size() == 4);
655  path.moveTo(ia.at(0));
656  path.cubicTo(ia.at(1), ia.at(2), ia.at(3));
657  painter->strokePath(path, painter->pen());
658  a.clear();
659  }
660  break;
662  s >> ip >> str1;
663  painter->drawText(ip, QString::fromLatin1(str1));
664  break;
666  s >> ir >> i_16 >> str1;
667  painter->drawText(ir, i_16, QString::fromLatin1(str1));
668  break;
670  if (d->formatMajor <= 5) {
671  s >> ip >> str;
672  painter->drawText(ip, str);
673  } else {
674  s >> p >> str;
675  painter->drawText(p, str);
676  }
677  break;
679  s >> ir;
680  s >> i_16;
681  s >> str;
682  painter->drawText(ir, i_16, str);
683  break;
685  s >> p >> str >> font >> ul;
686 
687  // the text layout direction is not used here because it's already
688  // aligned when QPicturePaintEngine::drawTextItem() serializes the
689  // drawText() call, therefore ul is unsed in this context
690 
691  if (d->formatMajor >= 9) {
692  s >> dbl;
693  QFont fnt(font);
694  if (dbl != 1.0) {
695  QFakeDevice fake;
696  fake.setDpiX(qRound(dbl*qt_defaultDpiX()));
697  fake.setDpiY(qRound(dbl*qt_defaultDpiY()));
698  fnt = QFont(font, &fake);
699  }
700 
701  qreal justificationWidth;
702  s >> justificationWidth;
703 
705 
706  QSizeF size(1, 1);
707  if (justificationWidth > 0) {
708  size.setWidth(justificationWidth);
710  flags |= Qt::AlignJustify;
711  }
712 
713  QFontMetrics fm(fnt);
714  QPointF pt(p.x(), p.y() - fm.ascent());
715  qt_format_text(fnt, QRectF(pt, size), flags, /*opt*/0,
716  str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter);
717  } else {
718  qt_format_text(font, QRectF(p, QSizeF(1, 1)), Qt::TextSingleLine | Qt::TextDontClip, /*opt*/0,
719  str, /*brect=*/0, /*tabstops=*/0, /*...*/0, /*tabarraylen=*/0, painter);
720  }
721 
722  break;
723  }
725  QPixmap pixmap;
726  if (d->formatMajor < 4) {
727  s >> ip >> pixmap;
728  painter->drawPixmap(ip, pixmap);
729  } else if (d->formatMajor <= 5) {
730  s >> ir >> pixmap;
731  painter->drawPixmap(ir, pixmap);
732  } else {
733  QRectF sr;
734  if (d->in_memory_only) {
735  int index;
736  s >> r >> index >> sr;
737  Q_ASSERT(index < d->pixmap_list.size());
738  pixmap = d->pixmap_list.at(index);
739  } else {
740  s >> r >> pixmap >> sr;
741  }
742  painter->drawPixmap(r, pixmap, sr);
743  }
744  }
745  break;
747  QPixmap pixmap;
748  if (d->in_memory_only) {
749  int index;
750  s >> r >> index >> p;
751  Q_ASSERT(index < d->pixmap_list.size());
752  pixmap = d->pixmap_list.at(index);
753  } else {
754  s >> r >> pixmap >> p;
755  }
756  painter->drawTiledPixmap(r, pixmap, p);
757  }
758  break;
760  QImage image;
761  if (d->formatMajor < 4) {
762  s >> p >> image;
763  painter->drawImage(p, image);
764  } else if (d->formatMajor <= 5){
765  s >> ir >> image;
766  painter->drawImage(ir, image, QRect(0, 0, ir.width(), ir.height()));
767  } else {
768  QRectF sr;
769  if (d->in_memory_only) {
770  int index;
771  s >> r >> index >> sr >> ul;
772  Q_ASSERT(index < d->image_list.size());
773  image = d->image_list.at(index);
774  } else {
775  s >> r >> image >> sr >> ul;
776  }
777  painter->drawImage(r, image, sr, Qt::ImageConversionFlags(ul));
778  }
779  }
780  break;
782  s >> ul; // number of records
783  if (!exec(painter, s, ul))
784  return false;
785  break;
787  if (nrecords == 0)
788  return true;
789  break;
791  painter->save();
792  break;
794  painter->restore();
795  break;
797  s >> color;
798  painter->setBackground(color);
799  break;
801  s >> i_8;
802  painter->setBackgroundMode((Qt::BGMode)i_8);
803  break;
804  case QPicturePrivate::PdcSetROP: // NOP
805  s >> i_8;
806  break;
808  if (d->formatMajor <= 5) {
809  s >> ip;
810  painter->setBrushOrigin(ip);
811  } else {
812  s >> p;
813  painter->setBrushOrigin(p);
814  }
815  break;
817  s >> font;
818  painter->setFont(font);
819  break;
821  if (d->in_memory_only) {
822  int index;
823  s >> index;
824  Q_ASSERT(index < d->pen_list.size());
825  pen = d->pen_list.at(index);
826  } else {
827  s >> pen;
828  }
829  painter->setPen(pen);
830  break;
832  if (d->in_memory_only) {
833  int index;
834  s >> index;
835  Q_ASSERT(index < d->brush_list.size());
836  brush = d->brush_list.at(index);
837  } else {
838  s >> brush;
839  }
840  painter->setBrush(brush);
841  break;
842 // #ifdef Q_Q3PAINTER
843 // case QPicturePrivate::PdcSetTabStops:
844 // s >> i_16;
845 // painter->setTabStops(i_16);
846 // break;
847 // case QPicturePrivate::PdcSetTabArray:
848 // s >> i_16;
849 // if (i_16 == 0) {
850 // painter->setTabArray(0);
851 // } else {
852 // int *ta = new int[i_16];
853 // for (int i=0; i<i_16; i++) {
854 // s >> i1_16;
855 // ta[i] = i1_16;
856 // }
857 // painter->setTabArray(ta);
858 // delete [] ta;
859 // }
860 // break;
861 // #endif
863  s >> i_8;
864  painter->setViewTransformEnabled(i_8);
865  break;
867  if (d->formatMajor <= 5) {
868  s >> ir;
869  painter->setWindow(ir);
870  } else {
871  s >> r;
872  painter->setWindow(r.toRect());
873  }
874  break;
876  if (d->formatMajor <= 5) {
877  s >> ir;
878  painter->setViewport(ir);
879  } else {
880  s >> r;
881  painter->setViewport(r.toRect());
882  }
883  break;
885  s >> i_8;
886  painter->setMatrixEnabled(i_8);
887  break;
889  if (d->formatMajor >= 8) {
890  s >> matrix >> i_8;
891  } else {
892  s >> wmatrix >> i_8;
893  matrix = QTransform(wmatrix);
894  }
895  // i_8 is always false due to updateXForm() in qpaintengine_pic.cpp
896  painter->setTransform(matrix * worldMatrix, i_8);
897  break;
898 // #ifdef Q_Q3PAINTER
899 // case QPicturePrivate::PdcSaveWMatrix:
900 // painter->saveWorldMatrix();
901 // break;
902 // case QPicturePrivate::PdcRestoreWMatrix:
903 // painter->restoreWorldMatrix();
904 // break;
905 // #endif
907  s >> i_8;
908  painter->setClipping(i_8);
909  break;
911  s >> rgn >> i_8;
912  if (d->formatMajor >= 9) {
913  painter->setClipRegion(rgn, Qt::ClipOperation(i_8));
914  } else {
915  painter->setClipRegion(rgn);
916  }
917  break;
919  {
920  QPainterPath path;
921  s >> path >> i_8;
922  painter->setClipPath(path, Qt::ClipOperation(i_8));
923  break;
924  }
926  s >> ul;
928  bool(ul & QPainter::Antialiasing));
931  break;
933  s >> ul;
935  break;
937  s >> bl;
938  painter->setClipping(bl);
939  break;
941  s >> dbl;
942  painter->setOpacity(qreal(dbl));
943  break;
944  default:
945  qWarning("QPicture::play: Invalid command %d", c);
946  if (len) // skip unknown command
947  s.device()->seek(s.device()->pos()+len);
948  }
949 #if defined(QT_DEBUG)
950  //qDebug("device->at(): %i, strm_pos: %i len: %i", (int)s.device()->pos(), strm_pos, len);
951  Q_ASSERT(qint32(s.device()->pos() - strm_pos) == len);
952 #endif
953  }
954  return false;
955 }
956 
973 {
974  int val;
975  QRect brect = boundingRect();
976  switch (m) {
977  case PdmWidth:
978  val = brect.width();
979  break;
980  case PdmHeight:
981  val = brect.height();
982  break;
983  case PdmWidthMM:
984  val = int(25.4/qt_defaultDpiX()*brect.width());
985  break;
986  case PdmHeightMM:
987  val = int(25.4/qt_defaultDpiY()*brect.height());
988  break;
989  case PdmDpiX:
990  case PdmPhysicalDpiX:
991  val = qt_defaultDpiX();
992  break;
993  case PdmDpiY:
994  case PdmPhysicalDpiY:
995  val = qt_defaultDpiY();
996  break;
997  case PdmNumColors:
998  val = 16777216;
999  break;
1000  case PdmDepth:
1001  val = 24;
1002  break;
1003  default:
1004  val = 0;
1005  qWarning("QPicture::metric: Invalid metric command");
1006  }
1007  return val;
1008 }
1009 
1032 {
1033  // QExplicitelySharedDataPointer takes care of cloning using
1034  // QPicturePrivate's copy constructor. Do not call detach_helper() anymore
1035  // and remove in Qt 5, please.
1036  Q_ASSERT_X(false, "QPicture::detach_helper()", "Do not call this function");
1037 }
1038 
1044 {
1045  d_ptr = p.d_ptr;
1046  return *this;
1047 }
1048 
1066  : in_memory_only(false)
1067 {
1068 }
1069 
1079  : trecs(other.trecs),
1080  formatOk(other.formatOk),
1081  formatMinor(other.formatMinor),
1082  brect(other.brect),
1084  in_memory_only(false)
1085 {
1086  pictb.setData(other.pictb.data(), other.pictb.size());
1087  if (other.pictb.isOpen()) {
1088  pictb.open(other.pictb.openMode());
1089  pictb.seek(other.pictb.pos());
1090  }
1091 }
1092 
1100 {
1101  formatOk = false;
1104 }
1105 
1106 
1118 {
1119  resetFormat();
1120 
1121  // can't check anything in an empty buffer
1122  if (pictb.size() == 0 || pictb.isOpen())
1123  return false;
1124 
1125  pictb.open(QIODevice::ReadOnly); // open buffer device
1126  QDataStream s;
1127  s.setDevice(&pictb); // attach data stream to buffer
1128 
1129  char mf_id[4]; // picture header tag
1130  s.readRawData(mf_id, 4); // read actual tag
1131  if (memcmp(mf_id, qt_mfhdr_tag, 4) != 0) { // wrong header id
1132  qWarning("QPicturePaintEngine::checkFormat: Incorrect header");
1133  pictb.close();
1134  return false;
1135  }
1136 
1137  int cs_start = sizeof(quint32); // pos of checksum word
1138  int data_start = cs_start + sizeof(quint16);
1139  quint16 cs,ccs;
1140  QByteArray buf = pictb.buffer(); // pointer to data
1141 
1142  s >> cs; // read checksum
1143  ccs = (quint16) qChecksum(buf.constData() + data_start, buf.size() - data_start);
1144  if (ccs != cs) {
1145  qWarning("QPicturePaintEngine::checkFormat: Invalid checksum %x, %x expected",
1146  ccs, cs);
1147  pictb.close();
1148  return false;
1149  }
1150 
1151  quint16 major, minor;
1152  s >> major >> minor; // read version number
1153  if (major > mfhdr_maj) { // new, incompatible version
1154  qWarning("QPicturePaintEngine::checkFormat: Incompatible version %d.%d",
1155  major, minor);
1156  pictb.close();
1157  return false;
1158  }
1159  s.setVersion(major != 4 ? major : 3);
1160 
1161  quint8 c, clen;
1162  s >> c >> clen;
1163  if (c == QPicturePrivate::PdcBegin) {
1164  if (!(major >= 1 && major <= 3)) {
1165  qint32 l, t, w, h;
1166  s >> l >> t >> w >> h;
1167  brect = QRect(l, t, w, h);
1168  }
1169  } else {
1170  qWarning("QPicturePaintEngine::checkFormat: Format error");
1171  pictb.close();
1172  return false;
1173  }
1174  pictb.close();
1175 
1176  formatOk = true; // picture seems to be ok
1177  formatMajor = major;
1178  formatMinor = minor;
1179  return true;
1180 }
1181 
1184 {
1185  if (!d_func()->paintEngine)
1186  const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine);
1187  return d_func()->paintEngine.data();
1188 }
1189 
1190 /*****************************************************************************
1191  QPicture stream functions
1192  *****************************************************************************/
1193 
1194 #ifndef QT_NO_DATASTREAM
1195 
1206 {
1207  quint32 size = r.d_func()->pictb.buffer().size();
1208  s << size;
1209  // null picture ?
1210  if (size == 0)
1211  return s;
1212  // just write the whole buffer to the stream
1213  s.writeRawData (r.d_func()->pictb.buffer(), r.d_func()->pictb.buffer().size());
1214  return s;
1215 }
1216 
1228 {
1229  QDataStream sr;
1230 
1231  // "init"; this code is similar to the beginning of QPicture::cmd()
1232  sr.setDevice(&r.d_func()->pictb);
1233  sr.setVersion(r.d_func()->formatMajor);
1234  quint32 len;
1235  s >> len;
1236  QByteArray data;
1237  if (len > 0) {
1238  data.resize(len);
1239  s.readRawData(data.data(), len);
1240  }
1241 
1242  r.d_func()->pictb.setData(data);
1243  r.d_func()->resetFormat();
1244  return s;
1245 }
1246 #endif // QT_NO_DATASTREAM
1247 
1248 
1249 #ifndef QT_NO_PICTUREIO
1250 
1252 #include "qregexp.h"
1253 #include "qapplication.h"
1254 #include "qpictureformatplugin.h"
1256 
1271 {
1272  return QPictureIO::pictureFormat(fileName);
1273 }
1274 
1287 {
1288  return QPictureIO::inputFormats();
1289 }
1290 
1292 {
1293  QStringList list;
1294  for (int i = 0; i < arr.count(); ++i)
1295  list.append(QString::fromLatin1(arr.at(i)));
1296  return list;
1297 }
1298 
1315 {
1317 }
1318 
1319 
1336 {
1338 }
1339 
1352 {
1353  return QPictureIO::outputFormats();
1354 }
1355 
1356 /*****************************************************************************
1357  QPictureIO member functions
1358  *****************************************************************************/
1359 
1385 {
1386  QPicture pi; // picture
1387  int iostat; // IO status
1388  QByteArray frmt; // picture format
1389  QIODevice *iodev; // IO device
1390  QString fname; // file name
1391  QString descr; // picture description
1392  const char *parameters;
1393  int quality;
1394  float gamma;
1395 };
1396 
1402 {
1403  init();
1404 }
1405 
1411 QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format)
1412 {
1413  init();
1414  d->iodev = ioDevice;
1415  d->frmt = format;
1416 }
1417 
1424 {
1425  init();
1426  d->frmt = format;
1427  d->fname = fileName;
1428 }
1429 
1435 {
1436  d = new QPictureIOData();
1437  d->parameters = 0;
1438  d->quality = -1; // default quality of the current format
1439  d->gamma=0.0f;
1440  d->iostat = 0;
1441  d->iodev = 0;
1442 }
1443 
1449 {
1450  if (d->parameters)
1451  delete [] (char*)d->parameters;
1452  delete d;
1453 }
1454 
1455 
1456 /*****************************************************************************
1457  QPictureIO picture handler functions
1458  *****************************************************************************/
1459 
1461 {
1462 public:
1463  QPictureHandler(const char *f, const char *h, const QByteArray& fl,
1465  QByteArray format; // picture format
1466  QRegExp header; // picture header pattern
1467  enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode;
1468  picture_io_handler read_picture; // picture read function
1469  picture_io_handler write_picture; // picture write function
1470  bool obsolete; // support not "published"
1471 };
1472 
1473 QPictureHandler::QPictureHandler(const char *f, const char *h, const QByteArray& fl,
1475  : format(f), header(QString::fromLatin1(h))
1476 {
1478  if (fl.contains('t'))
1480  else if (fl.contains('T'))
1482  obsolete = fl.contains('O');
1483  read_picture = r;
1484  write_picture = w;
1485 }
1486 
1488 Q_GLOBAL_STATIC(QPHList, pictureHandlers)
1489 
1490 #ifndef QT_NO_LIBRARY
1491 Q_GLOBAL_STATIC(QMutex, mutex)
1494  QLatin1String("/pictureformats")))
1495 #endif
1496 void qt_init_picture_plugins()
1497 {
1498 #ifndef QT_NO_LIBRARY
1499  QMutexLocker locker(mutex());
1500  QFactoryLoader *loader = factoryLoader();
1501  QStringList keys = loader->keys();
1502  for (int i = 0; i < keys.count(); ++i)
1503  if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader->instance(keys.at(i))))
1504  format->installIOHandler(keys.at(i));
1505 #endif
1506 }
1507 
1508 static void cleanup()
1509 {
1510  // make sure that picture handlers are delete before plugin manager
1511  if (QPHList *list = pictureHandlers()) {
1512  qDeleteAll(*list);
1513  list->clear();
1514  }
1515 }
1516 
1517 void qt_init_picture_handlers() // initialize picture handlers
1518 {
1520  if (done.testAndSetRelaxed(0, 1)) {
1522  }
1523 }
1524 
1526 { // get pointer to handler
1528  qt_init_picture_plugins();
1529  if (QPHList *list = pictureHandlers()) {
1530  for (int i = 0; i < list->size(); ++i) {
1531  if (list->at(i)->format == format)
1532  return list->at(i);
1533  }
1534  }
1535  return 0; // no such handler
1536 }
1537 
1538 
1579  const char *header,
1580  const char *flags,
1581  picture_io_handler readPicture,
1582  picture_io_handler writePicture)
1583 {
1585  if (QPHList *list = pictureHandlers()) {
1586  QPictureHandler *p;
1587  p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture);
1588  list->prepend(p);
1589  }
1590 }
1591 
1592 
1593 /*****************************************************************************
1594  QPictureIO normal member functions
1595  *****************************************************************************/
1596 
1602 const QPicture &QPictureIO::picture() const { return d->pi; }
1603 
1610 int QPictureIO::status() const { return d->iostat; }
1611 
1616 const char *QPictureIO::format() const { return d->frmt; }
1617 
1623 QIODevice *QPictureIO::ioDevice() const { return d->iodev; }
1624 
1630 QString QPictureIO::fileName() const { return d->fname; }
1631 
1632 
1638 QString QPictureIO::description() const { return d->descr; }
1639 
1645 void QPictureIO::setPicture(const QPicture &picture)
1646 {
1647  d->pi = picture;
1648 }
1649 
1657 {
1658  d->iostat = status;
1659 }
1660 
1675 {
1676  d->frmt = format;
1677 }
1678 
1691 {
1692  d->iodev = ioDevice;
1693 }
1694 
1702 {
1703  d->fname = fileName;
1704 }
1705 
1713 {
1714  return d->quality;
1715 }
1716 
1729 {
1730  d->quality = q;
1731 }
1732 
1739 const char *QPictureIO::parameters() const
1740 {
1741  return d->parameters;
1742 }
1743 
1755 void QPictureIO::setParameters(const char *parameters)
1756 {
1757  if (d->parameters)
1758  delete [] (char*)d->parameters;
1759  d->parameters = qstrdup(parameters);
1760 }
1761 
1773 void QPictureIO::setGamma(float gamma)
1774 {
1775  d->gamma=gamma;
1776 }
1777 
1783 float QPictureIO::gamma() const
1784 {
1785  return d->gamma;
1786 }
1787 
1796 void QPictureIO::setDescription(const QString &description)
1797 {
1798  d->descr = description;
1799 }
1800 
1801 
1809 {
1810  QFile file(fileName);
1812  if (!file.open(QIODevice::ReadOnly))
1813  return format;
1814  format = pictureFormat(&file);
1815  file.close();
1816  return format;
1817 }
1818 
1836 {
1837  // if you change this change the documentation for defineIOHandler()
1838  const int buflen = 14;
1839 
1840  char buf[buflen];
1841  char buf2[buflen];
1843  qt_init_picture_plugins();
1844  int pos = d->pos(); // save position
1845  int rdlen = d->read(buf, buflen); // read a few bytes
1846 
1848  if (rdlen != buflen)
1849  return format;
1850 
1851  memcpy(buf2, buf, buflen);
1852 
1853  for (int n = 0; n < rdlen; n++)
1854  if (buf[n] == '\0')
1855  buf[n] = '\001';
1856  if (rdlen > 0) {
1857  buf[rdlen - 1] = '\0';
1858  QString bufStr = QString::fromLatin1(buf);
1859  if (QPHList *list = pictureHandlers()) {
1860  for (int i = 0; i < list->size(); ++i) {
1861  if (list->at(i)->header.indexIn(bufStr) != -1) { // try match with headers
1862  format = list->at(i)->format;
1863  break;
1864  }
1865  }
1866  }
1867  }
1868  d->seek(pos); // restore position
1869  return format;
1870 }
1871 
1877 {
1878  QList<QByteArray> result;
1879 
1881  qt_init_picture_plugins();
1882 
1883  if (QPHList *list = pictureHandlers()) {
1884  for (int i = 0; i < list->size(); ++i) {
1885  QPictureHandler *p = list->at(i);
1886  if (p->read_picture && !p->obsolete && !result.contains(p->format))
1887  result.append(p->format);
1888  }
1889  }
1890  qSort(result);
1891 
1892  return result;
1893 }
1894 
1900 {
1902  qt_init_picture_plugins();
1903 
1904  QList<QByteArray> result;
1905  if (QPHList *list = pictureHandlers()) {
1906  for (int i = 0; i < list->size(); ++i) {
1907  QPictureHandler *p = list->at(i);
1908  if (p->write_picture && !p->obsolete && !result.contains(p->format))
1909  result.append(p->format);
1910  }
1911  }
1912  return result;
1913 }
1914 
1915 
1916 
1938 {
1939  QFile file;
1940  const char *picture_format;
1941  QPictureHandler *h;
1942 
1943  if (d->iodev) { // read from io device
1944  // ok, already open
1945  } else if (!d->fname.isEmpty()) { // read from file
1946  file.setFileName(d->fname);
1947  if (!file.open(QIODevice::ReadOnly))
1948  return false; // cannot open file
1949  d->iodev = &file;
1950  } else { // no file name or io device
1951  return false;
1952  }
1953  if (d->frmt.isEmpty()) {
1954  // Try to guess format
1955  picture_format = pictureFormat(d->iodev); // get picture format
1956  if (!picture_format) {
1957  if (file.isOpen()) { // unknown format
1958  file.close();
1959  d->iodev = 0;
1960  }
1961  return false;
1962  }
1963  } else {
1964  picture_format = d->frmt;
1965  }
1966 
1967  h = get_picture_handler(picture_format);
1968  if (file.isOpen()) {
1969 #if !defined(Q_OS_UNIX)
1970  if (h && h->text_mode) { // reopen in translated mode
1971  file.close();
1973  }
1974  else
1975 #endif
1976  file.seek(0); // position to start
1977  }
1978  d->iostat = 1; // assume error
1979 
1980  if (h && h->read_picture)
1981  (*h->read_picture)(this);
1982 
1983  if (file.isOpen()) { // picture was read using file
1984  file.close();
1985  d->iodev = 0;
1986  }
1987  return d->iostat == 0; // picture successfully read?
1988 }
1989 
1990 
2007 {
2008  if (d->frmt.isEmpty())
2009  return false;
2011  if (!h || !h->write_picture) {
2012  qWarning("QPictureIO::write: No such picture format handler: %s",
2013  format());
2014  return false;
2015  }
2016  QFile file;
2017  if (!d->iodev && !d->fname.isEmpty()) {
2018  file.setFileName(d->fname);
2019  bool translate = h->text_mode==QPictureHandler::TranslateInOut;
2020  QIODevice::OpenMode fmode = translate ? QIODevice::WriteOnly | QIODevice::Text : QIODevice::OpenMode(QIODevice::WriteOnly);
2021  if (!file.open(fmode)) // couldn't create file
2022  return false;
2023  d->iodev = &file;
2024  }
2025  d->iostat = 1;
2026  (*h->write_picture)(this);
2027  if (file.isOpen()) { // picture was written using file
2028  file.close();
2029  d->iodev = 0;
2030  }
2031  return d->iostat == 0; // picture successfully written?
2032 }
2033 #endif //QT_NO_PICTUREIO
2034 
2045 
2046 #endif // QT_NO_PICTURE
2047 
QScopedPointer< QPaintEngine > paintEngine
Definition: qpicture_p.h:159
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
void setBackgroundMode(Qt::BGMode mode)
Sets the background mode of the painter to the given mode.
Definition: qpainter.cpp:3998
void drawChord(const QRectF &rect, int a, int alen)
Draws the chord defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4744
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
static QList< QByteArray > outputFormats()
Returns a list of picture formats that are supported for picture output.
Definition: qpicture.cpp:1351
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void qt_init_picture_handlers()
Definition: qpicture.cpp:1517
bool read()
Reads an picture into memory and returns true if the picture was successfully read; otherwise returns...
Definition: qpicture.cpp:1937
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
void drawPie(const QRectF &rect, int a, int alen)
Draws a pie defined by the given rectangle, startAngle and and spanAngle.
Definition: qpainter.cpp:4670
double qreal
Definition: qglobal.h:1193
void drawArc(const QRectF &rect, int a, int alen)
Draws the arc defined by the given rectangle, startAngle and spanAngle.
Definition: qpainter.cpp:4602
unsigned char c[8]
Definition: qnumeric_p.h:62
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
bool play(QPainter *p)
Replays the picture using painter, and returns true if successful; otherwise returns false...
Definition: qpicture.cpp:416
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
QPaintEngine * paintEngine() const
Definition: qpicture.cpp:1183
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool save(QIODevice *dev, const char *format=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qpicture.cpp:352
int qint32
Definition: qglobal.h:937
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
const QByteArray & data() const
Returns the data contained in the buffer.
Definition: qbuffer.cpp:301
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
const char * parameters
Definition: qpicture.cpp:1392
void(* picture_io_handler)(QPictureIO *)
Definition: qpicture.h:132
void setViewport(const QRect &viewport)
Sets the painter&#39;s viewport rectangle to the given rectangle, and enables view transformations.
Definition: qpainter.cpp:7815
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
void setFormat(const char *)
Sets the picture format to format for the picture to be read or written.
Definition: qpicture.cpp:1674
int logicalDpiY() const
Definition: qpaintdevice.h:96
void qAddPostRoutine(QtCleanUpFunction p)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
Definition: qbuffer.cpp:315
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
static QList< QByteArray > outputFormats()
Returns a sorted list of picture formats that are supported for picture output.
Definition: qpicture.cpp:1899
void setDpiY(int dpi)
Definition: qpicture.cpp:460
bool open(OpenMode openMode)
Reimplemented Function
Definition: qbuffer.cpp:338
picture_io_handler write_picture
Definition: qpicture.cpp:1469
friend Q_GUI_EXPORT QDataStream & operator>>(QDataStream &s, QPicture &r)
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void close()
Reimplemented Function
Definition: qbuffer.cpp:359
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, factoryLoader,(QPictureFormatInterface_iid, QLatin1String("/pictureformats"))) void qt_init_picture_plugins()
Definition: qpicture.cpp:1492
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void setDescription(const QString &)
Sets the picture description string for picture handlers that support picture descriptions to descrip...
Definition: qpicture.cpp:1796
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
Definition: qiodevice.cpp:624
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
void setMatrixEnabled(bool enabled)
Use setWorldMatrixEnabled() instead.
Definition: qpainter.cpp:3209
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
qint64 pos() const
Reimplemented Function
Definition: qbuffer.cpp:367
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
qint64 size() const
Reimplemented Function
Definition: qbuffer.cpp:375
static const quint16 mfhdr_maj
Definition: qpicture.cpp:113
long ASN1_INTEGER_get ASN1_INTEGER * a
bool isNull() const
Returns true if the picture contains no data; otherwise returns false.
Definition: qpicture.cpp:215
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
unsigned char quint8
Definition: qglobal.h:934
QExplicitlySharedDataPointer< QPicturePrivate > d_ptr
Definition: qpicture.h:115
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QString class provides a Unicode character string.
Definition: qstring.h:83
const QPicture & picture() const
Returns the picture currently set.
Definition: qpicture.cpp:1602
void setWidth(qreal w)
Sets the width to the given width.
Definition: qsize.h:290
void init()
Contains initialization common to all QPictureIO constructors.
Definition: qpicture.cpp:1434
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
void detach_helper()
Definition: qpicture.cpp:1031
#define Q_D(Class)
Definition: qglobal.h:2482
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setStatus(int)
Sets the picture IO status to status.
Definition: qpicture.cpp:1656
void drawPoint(const QPointF &pt)
Draws a single point at the given position using the current pen&#39;s color.
Definition: qpainter.h:676
QStringList keys
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
bool seek(qint64 off)
Reimplemented Function
Definition: qbuffer.cpp:384
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
QPictureIO()
Constructs a QPictureIO object with all parameters set to zero.
Definition: qpicture.cpp:1401
bool paintingActive() const
Definition: qpaintdevice.h:170
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void setVersion(int)
Sets the version number of the data serialization format to v.
Definition: qdatastream.h:215
bool write()
Writes an picture to an IO device and returns true if the picture was successfully written; otherwise...
Definition: qpicture.cpp:2006
uint size() const
Returns the size of the picture data.
Definition: qpicture.cpp:220
void setIODevice(QIODevice *)
Sets the IO device to be used for reading or writing an picture.
Definition: qpicture.cpp:1690
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
int ascent() const
Returns the ascent of the font.
int logicalDpiX() const
Definition: qpaintdevice.h:95
signed char qint8
Definition: qglobal.h:933
Q_CORE_EXPORT quint16 qChecksum(const char *s, uint len)
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
bool testAndSetRelaxed(int expectedValue, int newValue)
QStringList keys() const
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QIODevice * iodev
Definition: qpicture.cpp:1389
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
int devType() const
Definition: qpicture.cpp:178
int readRawData(char *, int len)
Reads at most len bytes from the stream into s and returns the number of bytes read.
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
QIODevice * ioDevice() const
Returns the IO device currently set.
Definition: qpicture.cpp:1623
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
enum QPictureHandler::TMode text_mode
QByteArray & buffer()
Returns a reference to the QBuffer&#39;s internal buffer.
Definition: qbuffer.cpp:271
static bool init
QRect boundingRect() const
Returns the picture&#39;s bounding rectangle or an invalid rectangle if the picture contains no data...
Definition: qpicture.cpp:385
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
short qint16
Definition: qglobal.h:935
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
picture_io_handler read_picture
Definition: qpicture.cpp:1468
QPicture(int formatVersion=-1)
Constructs an empty picture.
Definition: qpicture.cpp:131
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray format
Definition: qpicture.cpp:1465
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
friend Q_GUI_EXPORT QDataStream & operator<<(QDataStream &s, const QPicture &r)
QString fileName() const
Returns the file name currently set.
Definition: qpicture.cpp:1630
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...
Definition: qpainter.cpp:5205
QByteArray frmt
Definition: qpicture.cpp:1388
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QPaintEngine * paintEngine() const
Definition: qpicture.cpp:461
QString description() const
Returns the picture description string.
Definition: qpicture.cpp:1638
bool load(QIODevice *dev, const char *format=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qpicture.cpp:279
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
void strokePath(const QPainterPath &path, const QPen &pen)
Draws the outline (strokes) the path path with the pen specified by pen.
Definition: qpainter.cpp:3413
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
~QPicture()
Destroys the picture.
Definition: qpicture.cpp:171
void setWindow(const QRect &window)
Sets the painter&#39;s window to the given rectangle, and enables view transformations.
Definition: qpainter.cpp:7745
QRect override_rect
Definition: qpicture_p.h:158
static QStringList outputFormatList()
Returns a list of picture formats that are supported for picture output.
Definition: qpicture.cpp:1335
int metric(PaintDeviceMetric m) const
Definition: qpicture.cpp:462
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.
Definition: qpainter.cpp:7146
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setQuality(int)
Sets the quality of the written picture to q, related to the compression ratio.
Definition: qpicture.cpp:1728
const char * parameters() const
Returns the picture&#39;s parameters string.
Definition: qpicture.cpp:1739
void setGamma(float)
Sets the gamma value at which the picture will be viewed to gamma.
Definition: qpicture.cpp:1773
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QList< QPictureHandler * > QPHList
Definition: qpicture.cpp:1487
void setFileName(const QString &)
Sets the name of the file to read or write an picture from to fileName.
Definition: qpicture.cpp:1701
void setViewTransformEnabled(bool enable)
Enables view transformations if enable is true, or disables view transformations if enable is false...
Definition: qpainter.cpp:7906
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
QIODevice * device() const
Returns the I/O device currently set, or 0 if no device is currently set.
Definition: qdatastream.h:206
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
Definition: qpainter.cpp:2422
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Definition: qpainter.cpp:2517
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static QList< QByteArray > inputFormats()
Returns a sorted list of picture formats that are supported for picture input.
Definition: qpicture.cpp:1876
Q_CORE_EXPORT char * qstrdup(const char *)
int metric(PaintDeviceMetric m) const
Internal implementation of the virtual QPaintDevice::metric() function.
Definition: qpicture.cpp:972
OpenMode openMode() const
Returns the mode in which the device has been opened; i.e.
Definition: qiodevice.cpp:465
bool checkFormat()
Checks data integrity and format version number.
Definition: qpicture.cpp:1117
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int quality() const
Returns the quality of the written picture, related to the compression ratio.
Definition: qpicture.cpp:1712
bool isDetached() const
Definition: qpicture.cpp:235
QObject * instance(const QString &key) const
QPictureHandler(const char *f, const char *h, const QByteArray &fl, picture_io_handler r, picture_io_handler w)
Definition: qpicture.cpp:1473
#define QPictureFormatInterface_iid
const char * format() const
Returns the picture format string or 0 if no format has been explicitly set.
Definition: qpicture.cpp:1616
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
bool exec(QPainter *p, QDataStream &ds, int i)
Iterates over the internal picture data and draws the picture using painter.
Definition: qpicture.cpp:490
void resize(int size)
Sets the size of the byte array to size bytes.
unsigned int quint32
Definition: qglobal.h:938
static const quint16 mfhdr_min
Definition: qpicture.cpp:114
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void detach()
If the shared data object&#39;s reference count is greater than 1, this function creates a deep copy of t...
Definition: qshareddata.h:148
static void cleanup()
Definition: qpicture.cpp:1508
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
void setParameters(const char *)
Sets the picture&#39;s parameter string to parameters.
Definition: qpicture.cpp:1755
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
const char * qt_mfhdr_tag
Definition: qpicture.cpp:112
const char * data() const
Returns a pointer to the picture data.
Definition: qpicture.cpp:225
float gamma() const
Returns the gamma value at which the picture will be viewed.
Definition: qpicture.cpp:1783
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
virtual int metric(PaintDeviceMetric metric) const
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
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...
Definition: qpainter.cpp:5619
~QPictureIO()
Destroys the object and all related data.
Definition: qpicture.cpp:1448
The QPictureIO class contains parameters for loading and saving pictures.
Definition: qpicture.h:136
void setDevice(QIODevice *)
void QDataStream::setDevice(QIODevice *d)
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
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...
Definition: qpainter.cpp:3365
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
void setBoundingRect(const QRect &r)
Sets the picture&#39;s bounding rectangle to r.
Definition: qpicture.cpp:403
static const char * pictureFormat(const QString &fileName)
Returns a string that specifies the picture format of the file fileName, or 0 if the file cannot be r...
Definition: qpicture.cpp:1270
void resetFormat()
Definition: qpicture.cpp:1099
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QPicture & operator=(const QPicture &p)
Assigns picture p to this picture and returns a reference to this picture.
Definition: qpicture.cpp:1043
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)
Definition: qpainter.cpp:8458
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
Draws the given rectangle rect with rounded corners.
Definition: qpainter.cpp:4348
void setPicture(const QPicture &)
Sets the picture to picture.
Definition: qpicture.cpp:1645
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
virtual void setData(const char *data, uint size)
Sets the picture data directly from data and size.
Definition: qpicture.cpp:247
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
static QByteArray pictureFormat(const QString &fileName)
Returns a string that specifies the picture format of the file fileName, or null if the file cannot b...
Definition: qpicture.cpp:1808
void detach()
Detaches from shared picture data and makes sure that this picture is the only one referring to the d...
Definition: qpicture.cpp:230
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:58
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055
bool seek(qint64 offset)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qfile.cpp:1784
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
Definition: qiodevice.cpp:659
int status() const
Returns the picture&#39;s IO status.
Definition: qpicture.cpp:1610
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
BGMode
Definition: qnamespace.h:588
static QStringList inputFormatList()
Returns a list of picture formats that are supported for picture input.
Definition: qpicture.cpp:1314
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void setBackground(const QBrush &bg)
Sets the background brush of the painter to the given brush.
Definition: qpainter.cpp:4258
void setDpiX(int dpi)
Definition: qpicture.cpp:459
void setFileName(const QString &name)
Sets the name of the file.
Definition: qfile.cpp:494
static QPictureHandler * get_picture_handler(const char *format)
Definition: qpicture.cpp:1525
static QStringList qToStringList(const QList< QByteArray > arr)
Definition: qpicture.cpp:1291
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
static void defineIOHandler(const char *format, const char *header, const char *flags, picture_io_handler read_picture, picture_io_handler write_picture)
Defines a picture I/O handler for the picture format called format, which is recognized using the reg...
Definition: qpicture.cpp:1578
static QList< QByteArray > inputFormats()
Returns a list of picture formats that are supported for picture input.
Definition: qpicture.cpp:1286
ClipOperation
Definition: qnamespace.h:1495