summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/highdpi/highdpi.pro12
-rw-r--r--tests/manual/highdpi/highdpi.qrc7
-rw-r--r--tests/manual/highdpi/main.cpp366
-rw-r--r--tests/manual/highdpi/qticon.pngbin0 -> 6474 bytes
-rw-r--r--tests/manual/highdpi/qticon@2x.pngbin0 -> 17168 bytes
-rw-r--r--tests/manual/highdpi/qticon_large.pngbin0 -> 17168 bytes
-rw-r--r--tests/manual/lance/main.cpp18
7 files changed, 400 insertions, 3 deletions
diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro
new file mode 100644
index 0000000000..635ba37a38
--- /dev/null
+++ b/tests/manual/highdpi/highdpi.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+TARGET = highdpi
+DEPENDPATH += .
+INCLUDEPATH += .
+QT += widgets
+
+# Input
+SOURCES += main.cpp
+
+RESOURCES += \
+ highdpi.qrc
+
diff --git a/tests/manual/highdpi/highdpi.qrc b/tests/manual/highdpi/highdpi.qrc
new file mode 100644
index 0000000000..b43c2c07ad
--- /dev/null
+++ b/tests/manual/highdpi/highdpi.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>qticon.png</file>
+ <file>qticon@2x.png</file>
+ <file>qticon_large.png</file>
+ </qresource>
+</RCC>
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
new file mode 100644
index 0000000000..ee2d8ed29e
--- /dev/null
+++ b/tests/manual/highdpi/main.cpp
@@ -0,0 +1,366 @@
+/****************************************************************************
+ **
+ ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+ ** Contact: http://www.qt-project.org/legal
+ **
+ ** This file is part of the QtGui module of the Qt Toolkit.
+ **
+ ** $QT_BEGIN_LICENSE:LGPL$
+ ** Commercial License Usage
+ ** Licensees holding valid commercial Qt licenses may use this file in
+ ** accordance with the commercial license agreement provided with the
+ ** Software or, alternatively, in accordance with the terms contained in
+ ** a written agreement between you and Digia. For licensing terms and
+ ** conditions see http://qt.digia.com/licensing. For further information
+ ** use the contact form at http://qt.digia.com/contact-us.
+ **
+ ** GNU Lesser General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU Lesser
+ ** General Public License version 2.1 as published by the Free Software
+ ** Foundation and appearing in the file LICENSE.LGPL included in the
+ ** packaging of this file. Please review the following information to
+ ** ensure the GNU Lesser General Public License version 2.1 requirements
+ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ **
+ ** In addition, as a special exception, Digia gives you certain additional
+ ** rights. These rights are described in the Digia Qt LGPL Exception
+ ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ **
+ ** GNU General Public License Usage
+ ** Alternatively, this file may be used under the terms of the GNU
+ ** General Public License version 3.0 as published by the Free Software
+ ** Foundation and appearing in the file LICENSE.GPL included in the
+ ** packaging of this file. Please review the following information to
+ ** ensure the GNU General Public License version 3.0 requirements will be
+ ** met: http://www.gnu.org/copyleft/gpl.html.
+ **
+ **
+ ** $QT_END_LICENSE$
+ **
+ ****************************************************************************/
+
+#include <QtCore>
+#include <QtGui>
+#include <QtWidgets>
+
+
+class PixmapPainter : public QWidget
+{
+public:
+ PixmapPainter();
+ void paintEvent(QPaintEvent *event);
+
+ QPixmap pixmap1X;
+ QPixmap pixmap2X;
+ QPixmap pixmapLarge;
+ QImage image1X;
+ QImage image2X;
+ QImage imageLarge;
+ QIcon qtIcon;
+};
+
+
+PixmapPainter::PixmapPainter()
+{
+ pixmap1X = QPixmap(":/qticon.png");
+ pixmap2X = QPixmap(":/qticon@2x.png");
+ pixmapLarge = QPixmap(":/qticon_large.png");
+
+ image1X = QImage(":/qticon.png");
+ image2X = QImage(":/qticon@2x.png");
+ imageLarge = QImage(":/qticon_large.png");
+
+ qtIcon.addFile(":/qticon.png");
+ qtIcon.addFile(":/qticon@2x.png");
+}
+
+void PixmapPainter::paintEvent(QPaintEvent *event)
+{
+ QPainter p(this);
+ p.fillRect(QRect(QPoint(0, 0), size()), QBrush(Qt::gray));
+
+ int pixmapPointSize = 64;
+ int y = 30;
+ int dy = 150;
+
+ int x = 10;
+ int dx = 80;
+ // draw at point
+// qDebug() << "paint pixmap" << pixmap1X.devicePixelRatio();
+ p.drawPixmap(x, y, pixmap1X);
+ x+=dx;p.drawPixmap(x, y, pixmap2X);
+ x+=dx;p.drawPixmap(x, y, pixmapLarge);
+ x+=dx*2;p.drawPixmap(x, y, qtIcon.pixmap(QSize(pixmapPointSize, pixmapPointSize)));
+ x+=dx;p.drawImage(x, y, image1X);
+ x+=dx;p.drawImage(x, y, image2X);
+ x+=dx;p.drawImage(x, y, imageLarge);
+
+ // draw at 64x64 rect
+ y+=dy;
+ x = 10;
+ p.drawPixmap(QRect(x, y, pixmapPointSize, pixmapPointSize), pixmap1X);
+ x+=dx;p.drawPixmap(QRect(x, y, pixmapPointSize, pixmapPointSize), pixmap2X);
+ x+=dx;p.drawPixmap(QRect(x, y, pixmapPointSize, pixmapPointSize), pixmapLarge);
+ x+=dx;p.drawPixmap(QRect(x, y, pixmapPointSize, pixmapPointSize), qtIcon.pixmap(QSize(pixmapPointSize, pixmapPointSize)));
+ x+=dx;p.drawImage(QRect(x, y, pixmapPointSize, pixmapPointSize), image1X);
+ x+=dx;p.drawImage(QRect(x, y, pixmapPointSize, pixmapPointSize), image2X);
+ x+=dx;p.drawImage(QRect(x, y, pixmapPointSize, pixmapPointSize), imageLarge);
+
+
+ // draw at 128x128 rect
+ y+=dy - 50;
+ x = 10;
+ p.drawPixmap(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), pixmap1X);
+ x+=dx * 2; p.drawPixmap(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), pixmap2X);
+ x+=dx * 2; p.drawPixmap(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), pixmapLarge);
+ x+=dx * 2; p.drawPixmap(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), qtIcon.pixmap(QSize(pixmapPointSize, pixmapPointSize)));
+ x+=dx * 2; p.drawImage(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), image1X);
+ x+=dx * 2; p.drawImage(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), image2X);
+ x+=dx * 2; p.drawImage(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), imageLarge);
+ }
+
+class Labels : public QWidget
+{
+public:
+ Labels();
+
+ QPixmap pixmap1X;
+ QPixmap pixmap2X;
+ QPixmap pixmapLarge;
+ QIcon qtIcon;
+};
+
+Labels::Labels()
+{
+ pixmap1X = QPixmap(":/qticon.png");
+ pixmap2X = QPixmap(":/qticon@2x.png");
+ pixmapLarge = QPixmap(":/qticon_large.png");
+
+ qtIcon.addFile(":/qticon.png");
+ qtIcon.addFile(":/qticon@2x.png");
+ setWindowIcon(qtIcon);
+ setWindowTitle("Labels");
+
+ QLabel *label1x = new QLabel();
+ label1x->setPixmap(pixmap1X);
+ QLabel *label2x = new QLabel();
+ label2x->setPixmap(pixmap2X);
+ QLabel *labelIcon = new QLabel();
+ labelIcon->setPixmap(qtIcon.pixmap(QSize(64,64)));
+ QLabel *labelLarge = new QLabel();
+ labelLarge->setPixmap(pixmapLarge);
+
+ QHBoxLayout *layout = new QHBoxLayout(this);
+// layout->addWidget(label1x); //expected low-res on high-dpi displays
+ layout->addWidget(label2x);
+// layout->addWidget(labelIcon);
+// layout->addWidget(labelLarge); // expected large size and low-res
+ setLayout(layout);
+}
+
+class MainWindow : public QMainWindow
+{
+public:
+ MainWindow();
+
+ QIcon qtIcon;
+ QIcon qtIcon1x;
+ QIcon qtIcon2x;
+
+ QToolBar *fileToolBar;
+};
+
+MainWindow::MainWindow()
+{
+ qtIcon.addFile(":/qticon.png");
+ qtIcon.addFile(":/qticon@2x.png");
+ qtIcon1x.addFile(":/qticon.png");
+ qtIcon2x.addFile(":/qticon@2x.png");
+ setWindowIcon(qtIcon);
+ setWindowTitle("MainWindow");
+
+ fileToolBar = addToolBar(tr("File"));
+// fileToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ fileToolBar->addAction(new QAction(qtIcon, QString("1x and 2x"), this));
+ fileToolBar->addAction(new QAction(qtIcon1x, QString("1x"), this));
+ fileToolBar->addAction(new QAction(qtIcon2x, QString("2x"), this));
+}
+
+class StandardIcons : public QWidget
+{
+public:
+ void paintEvent(QPaintEvent *event)
+ {
+ int x = 10;
+ int y = 10;
+ int dx = 50;
+ int dy = 50;
+ int maxX = 500;
+
+ for (int iconIndex = QStyle::SP_TitleBarMenuButton; iconIndex < QStyle::SP_MediaVolumeMuted; ++iconIndex) {
+ QIcon icon = qApp->style()->standardIcon(QStyle::StandardPixmap(iconIndex));
+ QPainter p(this);
+ p.drawPixmap(x, y, icon.pixmap(dx - 5, dy - 5));
+ if (x + dx > maxX)
+ y+=dy;
+ x = ((x + dx) % maxX);
+ }
+ };
+};
+
+class Caching : public QWidget
+{
+public:
+ void paintEvent(QPaintEvent *event)
+ {
+ QSize layoutSize(75, 75);
+
+ QPainter widgetPainter(this);
+ widgetPainter.fillRect(QRect(QPoint(0, 0), this->size()), Qt::gray);
+
+ {
+ const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio();
+ QPixmap cache(layoutSize * devicePixelRatio);
+ cache.setDevicePixelRatio(devicePixelRatio);
+
+ QPainter cachedPainter(&cache);
+ cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue);
+ cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red);
+ cachedPainter.drawEllipse(QRect(10,10, 55, 55));
+
+ QPainter widgetPainter(this);
+ widgetPainter.drawPixmap(QPoint(10, 10), cache);
+ }
+
+ {
+ const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio();
+ QImage cache = QImage(layoutSize * devicePixelRatio, QImage::QImage::Format_ARGB32_Premultiplied);
+ cache.setDevicePixelRatio(devicePixelRatio);
+
+ QPainter cachedPainter(&cache);
+ cachedPainter.fillRect(QRect(0,0, 75, 75), Qt::blue);
+ cachedPainter.fillRect(QRect(10,10, 55, 55), Qt::red);
+ cachedPainter.drawEllipse(QRect(10,10, 55, 55));
+
+ QPainter widgetPainter(this);
+ widgetPainter.drawImage(QPoint(95, 10), cache);
+ }
+
+ }
+};
+
+class Style : public QWidget {
+public:
+ QPushButton *button;
+ QLineEdit *lineEdit;
+ QSlider *slider;
+ QHBoxLayout *row1;
+
+ Style() {
+ row1 = new QHBoxLayout();
+ setLayout(row1);
+
+ button = new QPushButton();
+ button->setText("Test Button");
+ row1->addWidget(button);
+
+ lineEdit = new QLineEdit();
+ lineEdit->setText("Test Lineedit");
+ row1->addWidget(lineEdit);
+
+ slider = new QSlider();
+ row1->addWidget(slider);
+
+ row1->addWidget(new QSpinBox);
+ row1->addWidget(new QScrollBar);
+
+ QTabBar *tab = new QTabBar();
+ tab->addTab("Foo");
+ tab->addTab("Bar");
+ row1->addWidget(tab);
+ }
+};
+
+class Fonts : public QWidget
+{
+public:
+ void paintEvent(QPaintEvent *event)
+ {
+ QPainter painter(this);
+ int y = 40;
+ for (int fontSize = 2; fontSize < 18; fontSize += 2) {
+ QFont font;
+ font.setPointSize(fontSize);
+ QString string = QString(QStringLiteral("%1 The quick brown fox jumped over the lazy Doug.")).arg(fontSize);
+ painter.setFont(font);
+ painter.drawText(10, y, string);
+ y += (fontSize * 2.5);
+ }
+ }
+};
+
+
+template <typename T>
+void apiTestdevicePixelRatioGetter()
+{
+ if (0) {
+ T *t = 0;
+ t->devicePixelRatio();
+ }
+}
+
+template <typename T>
+void apiTestdevicePixelRatioSetter()
+{
+ if (0) {
+ T *t = 0;
+ t->setDevicePixelRatio(2.0);
+ }
+}
+
+void apiTest()
+{
+ // compile call to devicePixelRatio getter and setter (verify spelling)
+ apiTestdevicePixelRatioGetter<QWindow>();
+ apiTestdevicePixelRatioGetter<QScreen>();
+ apiTestdevicePixelRatioGetter<QGuiApplication>();
+
+ apiTestdevicePixelRatioGetter<QImage>();
+ apiTestdevicePixelRatioSetter<QImage>();
+ apiTestdevicePixelRatioGetter<QPixmap>();
+ apiTestdevicePixelRatioSetter<QPixmap>();
+}
+
+int main(int argc, char **argv)
+{
+ qputenv("QT_HIGHDPI_AWARE", "1");
+ QApplication app(argc, argv);
+
+ PixmapPainter pixmapPainter;
+
+// Enable for lots of pixmap drawing
+ pixmapPainter.show();
+
+ Labels label;
+ label.resize(200, 200);
+ label.show();
+
+ MainWindow mainWindow;
+ mainWindow.show();
+
+ StandardIcons icons;
+ icons.resize(510, 510);
+ icons.show();
+
+ Caching caching;
+ caching.resize(300, 300);
+ caching.show();
+
+ Style style;
+ style.show();
+
+ Fonts fonts;
+ fonts.show();
+
+ return app.exec();
+}
diff --git a/tests/manual/highdpi/qticon.png b/tests/manual/highdpi/qticon.png
new file mode 100644
index 0000000000..76f02c6c96
--- /dev/null
+++ b/tests/manual/highdpi/qticon.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon@2x.png b/tests/manual/highdpi/qticon@2x.png
new file mode 100644
index 0000000000..0b00c00c96
--- /dev/null
+++ b/tests/manual/highdpi/qticon@2x.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon_large.png b/tests/manual/highdpi/qticon_large.png
new file mode 100644
index 0000000000..0b00c00c96
--- /dev/null
+++ b/tests/manual/highdpi/qticon_large.png
Binary files differ
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));