tests/auto/qpainter/tst_qpainter.cpp
branchGCC_SURGE
changeset 31 5daf16870df6
parent 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
27:93b982ccede2 31:5daf16870df6
   105     void drawPixmap_comp();
   105     void drawPixmap_comp();
   106     void saveAndRestore_data();
   106     void saveAndRestore_data();
   107     void saveAndRestore();
   107     void saveAndRestore();
   108 
   108 
   109     void drawBorderPixmap();
   109     void drawBorderPixmap();
       
   110     void drawPixmapFragments();
   110 
   111 
   111     void drawLine_data();
   112     void drawLine_data();
   112     void drawLine();
   113     void drawLine();
   113     void drawLine_clipped();
   114     void drawLine_clipped();
   114     void drawLine_task121143();
   115     void drawLine_task121143();
   992     p.setTransform(QTransform(-1,0,0,-1,173.5,153.5));
   993     p.setTransform(QTransform(-1,0,0,-1,173.5,153.5));
   993     qDrawBorderPixmap(&p, QRect(0,0,75,105), QMargins(39,39,39,39), src, QRect(0,0,79,79), QMargins(39,39,39,39),
   994     qDrawBorderPixmap(&p, QRect(0,0,75,105), QMargins(39,39,39,39), src, QRect(0,0,79,79), QMargins(39,39,39,39),
   994                        QTileRules(Qt::StretchTile,Qt::StretchTile), 0);
   995                        QTileRules(Qt::StretchTile,Qt::StretchTile), 0);
   995 }
   996 }
   996 
   997 
       
   998 void tst_QPainter::drawPixmapFragments()
       
   999 {
       
  1000     QPixmap origPixmap(20, 20);
       
  1001     QPixmap resPixmap(20, 20);
       
  1002     QPainter::PixmapFragment fragments[4] = { {15, 15,  0,  0, 10, 10, 1, 1, 0, 1},
       
  1003                                               { 5, 15, 10,  0, 10, 10, 1, 1, 0, 1},
       
  1004                                               {15,  5,  0, 10, 10, 10, 1, 1, 0, 1},
       
  1005                                               { 5,  5, 10, 10, 10, 10, 1, 1, 0, 1} };
       
  1006     {
       
  1007         QPainter p(&origPixmap);
       
  1008         p.fillRect(0, 0, 10, 10, Qt::red);
       
  1009         p.fillRect(10, 0, 10, 10, Qt::green);
       
  1010         p.fillRect(0, 10, 10, 10, Qt::blue);
       
  1011         p.fillRect(10, 10, 10, 10, Qt::yellow);
       
  1012     }
       
  1013     {
       
  1014         QPainter p(&resPixmap);
       
  1015         p.drawPixmapFragments(fragments, 4, origPixmap);
       
  1016     }
       
  1017 
       
  1018     QImage origImage = origPixmap.toImage().convertToFormat(QImage::Format_ARGB32);
       
  1019     QImage resImage = resPixmap.toImage().convertToFormat(QImage::Format_ARGB32);
       
  1020 
       
  1021     QVERIFY(resImage.size() == resPixmap.size());
       
  1022     QVERIFY(resImage.pixel(5, 5) == origImage.pixel(15, 15));
       
  1023     QVERIFY(resImage.pixel(5, 15) == origImage.pixel(15, 5));
       
  1024     QVERIFY(resImage.pixel(15, 5) == origImage.pixel(5, 15));
       
  1025     QVERIFY(resImage.pixel(15, 15) == origImage.pixel(5, 5));
       
  1026 
       
  1027 
       
  1028     QPainter::PixmapFragment fragment = QPainter::PixmapFragment::create(QPointF(20, 20), QRectF(30, 30, 2, 2));
       
  1029     QVERIFY(fragment.x == 20);
       
  1030     QVERIFY(fragment.y == 20);
       
  1031     QVERIFY(fragment.sourceLeft == 30);
       
  1032     QVERIFY(fragment.sourceTop == 30);
       
  1033     QVERIFY(fragment.width == 2);
       
  1034     QVERIFY(fragment.height == 2);
       
  1035     QVERIFY(fragment.scaleX == 1);
       
  1036     QVERIFY(fragment.scaleY == 1);
       
  1037     QVERIFY(fragment.rotation == 0);
       
  1038     QVERIFY(fragment.opacity == 1);
       
  1039 }
       
  1040 
   997 void tst_QPainter::drawLine_data()
  1041 void tst_QPainter::drawLine_data()
   998 {
  1042 {
   999     QTest::addColumn<QLine>("line");
  1043     QTest::addColumn<QLine>("line");
  1000 
  1044 
  1001     QTest::newRow("0-45") << QLine(0, 20, 100, 0);
  1045     QTest::newRow("0-45") << QLine(0, 20, 100, 0);
  3441         } else {
  3485         } else {
  3442             FOR_EACH_NEIGHBOR_4 {
  3486             FOR_EACH_NEIGHBOR_4 {
  3443                 if ((dx == 0) == (dy == 0))
  3487                 if ((dx == 0) == (dy == 0))
  3444                     continue;
  3488                     continue;
  3445                 QRgb neighbor = img.pixel(p.x() + dx, p.y() + dy);
  3489                 QRgb neighbor = img.pixel(p.x() + dx, p.y() + dy);
  3446                 if (pixel == inside && neighbor == outside ||
  3490                 if ((pixel == inside && neighbor == outside) ||
  3447                     pixel == outside && neighbor == inside)
  3491                     (pixel == outside && neighbor == inside))
  3448                     return false;
  3492                     return false;
  3449             }
  3493             }
  3450         }
  3494         }
  3451     }
  3495     }
  3452 
  3496