diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2012-11-20 11:34:52 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-01 08:33:20 +0100 |
commit | 5e61bbe586519c3d9bc636153d32e810da4e59a3 (patch) | |
tree | 67d67ef644be72ee5b3d685c9a22538d7ec1e01d /tests/manual/lance | |
parent | c8dc41bacdc30026cb79d0d6c72255312084bfe3 (diff) |
Basic high-dpi "retina" support for Qt 5.
Bring Qt 5 on par with Qt 4, prepare for more comprehensive
support later on.
Introduce device independent pixels (dips), device pixels,
and devicePixelRatio. Add high-dpi support to QPainter,
QGLWidget, the cocoa platform plugin, mac and fusion styles.
Dips are similar to CSS pixels, Apple points and
Android density-independent pixels. Device pixels
are pixels in the backing store/physical pixels on screen.
devicePixelRatio is the ratio between them, which is
1.0 on standard displays and 2.0 on "retina" displays.
New API:
QImage::devicePixelRatio() and setDevicePixelRatio()
QPixmap::devicePixelRatio() and setDevicePixelRatio()
QWindow::devicePixelRatio()
QScreen::devicePixelRatio()
QGuiApplicaiton::devicePixelRatio()
Change-Id: If98c3ca9bfdf0e1bdbcf7574cd5b912c9ff63856
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'tests/manual/lance')
-rw-r--r-- | tests/manual/lance/main.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/manual/lance/main.cpp b/tests/manual/lance/main.cpp index 97197f0509..c9458f5657 100644 --- a/tests/manual/lance/main.cpp +++ b/tests/manual/lance/main.cpp @@ -121,6 +121,7 @@ static void printHelp() " -commands Displays all available commands\n" " -w Width of the paintdevice\n" " -h Height of the paintdevice\n" + " -scalefactor Scale factor (device pixel ratio) of the paintdevice\n" " -cmp Show the reference picture\n" " -bg-white No checkers background\n"); } @@ -238,6 +239,8 @@ int main(int argc, char **argv) bool highres = false; bool show_cmp = false; int width = 800, height = 800; + int scaledWidth = width, scaledHeight = height; + qreal scalefactor = 1.0; bool verboseMode = false; #ifndef QT_NO_OPENGL @@ -328,6 +331,9 @@ int main(int argc, char **argv) } else if (option == "h") { Q_ASSERT_X(i + 1 < argc, "main", "-h must be followed by a value"); height = atoi(argv[++i]); + } else if (option == "scalefactor") { + Q_ASSERT_X(i + 1 < argc, "main", "-scalefactor must be followed by a value"); + scalefactor = atof(argv[++i]); } else if (option == "cmp") { show_cmp = true; } else if (option == "bg-white") { @@ -350,6 +356,8 @@ int main(int argc, char **argv) #endif } } + scaledWidth = width * scalefactor; + scaledHeight = height * scalefactor; PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); @@ -514,7 +522,8 @@ int main(int argc, char **argv) #endif case PixmapType: { - QPixmap pixmap(width, height); + QPixmap pixmap(scaledWidth, scaledHeight); + pixmap.setDevicePixelRatio(scalefactor); pixmap.fill(Qt::white); QPainter pt(&pixmap); pcmd.setPainter(&pt); @@ -527,7 +536,8 @@ int main(int argc, char **argv) case BitmapType: { - QBitmap bitmap(width, height); + QBitmap bitmap(scaledWidth, scaledHeight); + bitmap.setDevicePixelRatio(scalefactor); QPainter pt(&bitmap); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); @@ -547,9 +557,10 @@ int main(int argc, char **argv) case ImageType: { qDebug() << "Creating image"; - QImage image(width, height, type == ImageMonoType + QImage image(scaledWidth, scaledHeight, type == ImageMonoType ? QImage::Format_MonoLSB : imageFormat); + image.setDevicePixelRatio(scalefactor); image.fill(0); QPainter pt(&image); pcmd.setPainter(&pt); @@ -557,6 +568,7 @@ int main(int argc, char **argv) pcmd.runCommands(); pt.end(); image.convertToFormat(QImage::Format_ARGB32).save("output_image.png", "PNG"); + image.setDevicePixelRatio(1.0); // reset scale factor: display "large" image. #ifndef CONSOLE_APPLICATION QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(image)); |