summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2015-02-24 11:13:31 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2018-04-26 10:39:25 +0000
commit7160df3a15637acbb6548878d3a0afe294e64a6b (patch)
treee542d6ff36a3ff5fe43d50dd5adc255f7337fca3 /tests/manual
parenta9fc91466c2c143bea422d98af24755f43c2b97b (diff)
High-dpi drawTiledPixmap (raster paint engine)
Implement more consistent behavior for drawTiledPixmap(), which should produce the same visual tiling pattern independent of display devicePixelRatio Consider the following pixmaps and draw calls: QPixmap px32; // 32x32 QPixmap px64; // 64x64 drawTiledPixmap(QRect(0, 0, 128, 128), px32); drawTiledPixmap(QRect(0, 0, 128, 128), px64); On 1x displays this will produce 4x4 and 2x2 tiles, respectively. On 2x displays this would previously produce a different tiling pattern, where the paint engine would tile in the device pixel coordinate system. Change this to tile in the device independent coordinate system, producing the same visual tiling pattern as the 1x case. It is possible to produce a 4x4 tiling pattern with high-resolution output from the 64x64 pixmap by setting the devicePixelRatio: QPixmap px64; px64.setDevicePixelRatio(2); drawTiledPixmap(QRect(0, 0, 128, 128), px64); This change adds an inverse scale to the image filler transform that accounts for the pixmap devicePixelRatio. [ChangeLog][QtGui] QPainter::drawTiledPixmap() now tiles in the device independent coordinate system. Change-Id: I4918d274192967f222f181b374571c7c597dcd76 Reviewed-by: Jonathan Courtois <jonathan.courtois@gmail.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: 石博文 <sbw@sbw.so> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/highdpi/main.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index bd6af75b16..6f854a68d4 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -334,6 +334,59 @@ void PixmapPainter::paintEvent(QPaintEvent *)
x+=dx * 2; p.drawImage(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), imageLarge);
}
+class TiledPixmapPainter : public QWidget
+{
+public:
+ QPixmap pixmap1X;
+ QPixmap pixmap2X;
+ QPixmap pixmapLarge;
+
+ TiledPixmapPainter();
+ void paintEvent(QPaintEvent *event);
+};
+
+TiledPixmapPainter::TiledPixmapPainter()
+{
+ pixmap1X = QPixmap(":/qticon32.png");
+ pixmap2X = QPixmap(":/qticon32@2x.png");
+ pixmapLarge = QPixmap(":/qticon64.png");
+}
+
+void TiledPixmapPainter::paintEvent(QPaintEvent *event)
+{
+ QPainter p(this);
+
+ int xoff = 10;
+ int yoff = 10;
+ int tiles = 4;
+ int pixmapEdge = 32;
+ int tileAreaEdge = pixmapEdge * tiles;
+
+ // Expected behavior for both 1x and 2x dislays:
+ // 1x pixmap : 4 x 4 tiles
+ // large pixmap: 2 x 2 tiles
+ // 2x pixmap : 4 x 4 tiles
+ //
+ // On a 2x display the 2x pimxap tiles
+ // will be drawn in high resolution.
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap1X);
+ yoff += tiles * pixmapEdge + 10;
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmapLarge);
+ yoff += tiles * pixmapEdge + 10;
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap2X);
+
+ // Again, with an offset. The offset is in
+ // device-independent pixels.
+ QPoint offset(40, 40); // larger than the pixmap edge size to exercise that code path
+ yoff = 10;
+ xoff = 20 + tiles * pixmapEdge ;
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap1X, offset);
+ yoff += tiles * pixmapEdge + 10;
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmapLarge, offset);
+ yoff += tiles * pixmapEdge + 10;
+ p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap2X, offset);
+}
+
class Labels : public QWidget
{
public:
@@ -1119,6 +1172,7 @@ int main(int argc, char **argv)
DemoContainerList demoList;
demoList << new DemoContainer<PixmapPainter>("pixmap", "Test pixmap painter");
+ demoList << new DemoContainer<TiledPixmapPainter>("tiledpixmap", "Test tiled pixmap painter");
demoList << new DemoContainer<Labels>("label", "Test Labels");
demoList << new DemoContainer<MainWindow>("mainwindow", "Test QMainWindow");
demoList << new DemoContainer<StandardIcons>("standard-icons", "Test standard icons");