summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-03-01 12:41:43 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-29 09:47:32 +0100
commiteb5d8d2fc30bb9588320eaada0abf1e69bddf980 (patch)
treea0f7b69efc37aa216748359d06e585b30127167a /tests
parent0d98a67424f727ba446e90daa12b19c3e435b5ca (diff)
Update the high-dpi manual test.
- Organize the test images into different sizes. - Add a button and icon drawing test. - Don't show all tests by default. Change-Id: I95eff846b8c5159085f53b413dea7212c1ea5071 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/highdpi/highdpi.qrc8
-rw-r--r--tests/manual/highdpi/main.cpp201
-rw-r--r--tests/manual/highdpi/qticon16.pngbin0 -> 1884 bytes
-rw-r--r--tests/manual/highdpi/qticon16@2x.pngbin0 -> 3187 bytes
-rw-r--r--tests/manual/highdpi/qticon32.pngbin0 -> 3187 bytes
-rw-r--r--tests/manual/highdpi/qticon32@2x.png (renamed from tests/manual/highdpi/qticon.png)bin6474 -> 6474 bytes
-rw-r--r--tests/manual/highdpi/qticon64.pngbin0 -> 6474 bytes
-rw-r--r--tests/manual/highdpi/qticon@2x.pngbin17168 -> 0 bytes
-rw-r--r--tests/manual/highdpi/qticon_large.pngbin17168 -> 0 bytes
9 files changed, 169 insertions, 40 deletions
diff --git a/tests/manual/highdpi/highdpi.qrc b/tests/manual/highdpi/highdpi.qrc
index b43c2c07ad..10efac44fa 100644
--- a/tests/manual/highdpi/highdpi.qrc
+++ b/tests/manual/highdpi/highdpi.qrc
@@ -1,7 +1,9 @@
<RCC>
<qresource prefix="/">
- <file>qticon.png</file>
- <file>qticon@2x.png</file>
- <file>qticon_large.png</file>
+ <file>qticon16.png</file>
+ <file>qticon16@2x.png</file>
+ <file>qticon32.png</file>
+ <file>qticon32@2x.png</file>
+ <file>qticon64.png</file>
</qresource>
</RCC>
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index fb1e06f0f1..d093569ea8 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -62,16 +62,16 @@ public:
PixmapPainter::PixmapPainter()
{
- pixmap1X = QPixmap(":/qticon.png");
- pixmap2X = QPixmap(":/qticon@2x.png");
- pixmapLarge = QPixmap(":/qticon_large.png");
+ pixmap1X = QPixmap(":/qticon32.png");
+ pixmap2X = QPixmap(":/qticon32@2x.png");
+ pixmapLarge = QPixmap(":/qticon64.png");
- image1X = QImage(":/qticon.png");
- image2X = QImage(":/qticon@2x.png");
- imageLarge = QImage(":/qticon_large.png");
+ image1X = QImage(":/qticon32.png");
+ image2X = QImage(":/qticon32@2x.png");
+ imageLarge = QImage(":/qticon64.png");
- qtIcon.addFile(":/qticon.png");
- qtIcon.addFile(":/qticon@2x.png");
+ qtIcon.addFile(":/qticon32.png");
+ qtIcon.addFile(":/qticon32@2x.png");
}
void PixmapPainter::paintEvent(QPaintEvent *event)
@@ -79,12 +79,12 @@ void PixmapPainter::paintEvent(QPaintEvent *event)
QPainter p(this);
p.fillRect(QRect(QPoint(0, 0), size()), QBrush(Qt::gray));
- int pixmapPointSize = 64;
+ int pixmapPointSize = 32;
int y = 30;
- int dy = 150;
+ int dy = 90;
int x = 10;
- int dx = 80;
+ int dx = 40;
// draw at point
// qDebug() << "paint pixmap" << pixmap1X.devicePixelRatio();
p.drawPixmap(x, y, pixmap1X);
@@ -95,7 +95,7 @@ void PixmapPainter::paintEvent(QPaintEvent *event)
x+=dx;p.drawImage(x, y, image2X);
x+=dx;p.drawImage(x, y, imageLarge);
- // draw at 64x64 rect
+ // draw at 32x32 rect
y+=dy;
x = 10;
p.drawPixmap(QRect(x, y, pixmapPointSize, pixmapPointSize), pixmap1X);
@@ -107,7 +107,7 @@ void PixmapPainter::paintEvent(QPaintEvent *event)
x+=dx;p.drawImage(QRect(x, y, pixmapPointSize, pixmapPointSize), imageLarge);
- // draw at 128x128 rect
+ // draw at 64x64 rect
y+=dy - 50;
x = 10;
p.drawPixmap(QRect(x, y, pixmapPointSize * 2, pixmapPointSize * 2), pixmap1X);
@@ -132,12 +132,12 @@ public:
Labels::Labels()
{
- pixmap1X = QPixmap(":/qticon.png");
- pixmap2X = QPixmap(":/qticon@2x.png");
- pixmapLarge = QPixmap(":/qticon_large.png");
+ pixmap1X = QPixmap(":/qticon32.png");
+ pixmap2X = QPixmap(":/qticon32@2x.png");
+ pixmapLarge = QPixmap(":/qticon64.png");
- qtIcon.addFile(":/qticon.png");
- qtIcon.addFile(":/qticon@2x.png");
+ qtIcon.addFile(":/qticon32.png");
+ qtIcon.addFile(":/qticon32@2x.png");
setWindowIcon(qtIcon);
setWindowTitle("Labels");
@@ -146,15 +146,15 @@ Labels::Labels()
QLabel *label2x = new QLabel();
label2x->setPixmap(pixmap2X);
QLabel *labelIcon = new QLabel();
- labelIcon->setPixmap(qtIcon.pixmap(QSize(64,64)));
+ labelIcon->setPixmap(qtIcon.pixmap(QSize(32,32)));
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
+ layout->addWidget(label1x); //expected low-res on high-dpi displays
+ layout->addWidget(label2x); //expected high-res on high-dpi displays
+ layout->addWidget(labelIcon); //expected high-res on high-dpi displays
+ layout->addWidget(labelLarge); // expected large size and low-res
setLayout(layout);
}
@@ -172,16 +172,14 @@ public:
MainWindow::MainWindow()
{
- qtIcon.addFile(":/qticon.png");
- qtIcon.addFile(":/qticon@2x.png");
- qtIcon1x.addFile(":/qticon.png");
- qtIcon2x.addFile(":/qticon@2x.png");
+ // beware that QIcon auto-loads the @2x versions.
+ qtIcon1x.addFile(":/qticon16.png");
+ qtIcon2x.addFile(":/qticon32.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));
}
@@ -331,36 +329,165 @@ void apiTest()
apiTestdevicePixelRatioSetter<QPixmap>();
}
+// Request and draw an icon at different sizes
+class IconDrawing : public QWidget
+{
+public:
+ QIcon *iconHighDPI;
+ QIcon *iconNormalDpi;
+
+ IconDrawing()
+ {
+ QFile::copy(":/qticon32.png", "/tmp/qticon32-2.png");
+
+ QFile::copy(":/qticon32.png", "/tmp/qticon32.png");
+ QFile::copy(":/qticon32@2x.png", "/tmp/qticon32@2x.png");
+
+ iconHighDPI = new QIcon("/tmp/qticon32.png"); // will auto-load @2x version.
+ iconNormalDpi = new QIcon("/tmp/qticon32-2.png"); // does not have a 2x version.
+ }
+
+ ~IconDrawing()
+ {
+ delete iconHighDPI;
+ delete iconNormalDpi;
+// Qile::
+ }
+
+ void paintEvent(QPaintEvent *event)
+ {
+ int x = 10;
+ int y = 10;
+ int dx = 50;
+ int dy = 50;
+ int maxX = 600;
+ int minSize = 5;
+ int maxSize = 64;
+ int sizeIncrement = 5;
+
+ // Disable high-dpi icons
+ qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false);
+
+ // normal icon
+ for (int size = minSize; size < maxSize; size += sizeIncrement) {
+ QPainter p(this);
+ p.drawPixmap(x, y, iconNormalDpi->pixmap(size, size));
+ if (x + dx > maxX)
+ y+=dy;
+ x = ((x + dx) % maxX);
+ }
+ x = 10;
+ y+=dy;
+
+ // high-dpi icon
+ for (int size = minSize; size < maxSize; size += sizeIncrement) {
+ QPainter p(this);
+ p.drawPixmap(x, y, iconHighDPI->pixmap(size, size));
+ if (x + dx > maxX)
+ y+=dy;
+ x = ((x + dx) % maxX);
+ }
+
+ x = 10;
+ y+=dy;
+
+ // Enable high-dpi icons
+ qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, true);
+
+ // normal icon
+ for (int size = minSize; size < maxSize; size += sizeIncrement) {
+ QPainter p(this);
+ p.drawPixmap(x, y, iconNormalDpi->pixmap(size, size));
+ if (x + dx > maxX)
+ y+=dy;
+ x = ((x + dx) % maxX);
+ }
+ x = 10;
+ y+=dy;
+
+ // high-dpi icon (draw point)
+ for (int size = minSize; size < maxSize; size += sizeIncrement) {
+ QPainter p(this);
+ p.drawPixmap(x, y, iconHighDPI->pixmap(size, size));
+ if (x + dx > maxX)
+ y+=dy;
+ x = ((x + dx) % maxX);
+ }
+
+ x = 10;
+ y+=dy;
+
+ };
+};
+
+// Icons on buttons
+class Buttons : public QWidget
+{
+public:
+ Buttons()
+ {
+ QIcon icon;
+ icon.addFile(":/qticon16@2x.png");
+
+ QPushButton *button = new QPushButton(this);
+ button->setIcon(icon);
+ button->setText("16@2x");
+
+ QTabBar *tab = new QTabBar(this);
+ tab->addTab(QIcon(":/qticon16.png"), "16@1x");
+ tab->addTab(QIcon(":/qticon16@2x.png"), "16@2x");
+ tab->addTab(QIcon(":/qticon16.png"), "");
+ tab->addTab(QIcon(":/qticon16@2x.png"), "");
+ tab->move(10, 100);
+ tab->show();
+
+ QToolBar *toolBar = new QToolBar(this);
+ toolBar->addAction(QIcon(":/qticon16.png"), "16");
+ toolBar->addAction(QIcon(":/qticon16@2x.png"), "16@2x");
+ toolBar->addAction(QIcon(":/qticon32.png"), "32");
+ toolBar->addAction(QIcon(":/qticon32@2x.png"), "32@2x");
+
+ toolBar->move(10, 200);
+ toolBar->show();
+ }
+};
+
+
int main(int argc, char **argv)
{
- qputenv("QT_HIGHDPI_AWARE", "1");
QApplication app(argc, argv);
+ qApp->setAttribute(Qt::AA_UseHighDpiPixmaps);
PixmapPainter pixmapPainter;
-
-// Enable for lots of pixmap drawing
pixmapPainter.show();
Labels label;
label.resize(200, 200);
- label.show();
+// label.show();
MainWindow mainWindow;
- mainWindow.show();
+// mainWindow.show();
StandardIcons icons;
icons.resize(510, 510);
- icons.show();
+// icons.show();
Caching caching;
caching.resize(300, 300);
- caching.show();
+// caching.show();
Style style;
- style.show();
+// style.show();
Fonts fonts;
- fonts.show();
+// fonts.show();
+
+ IconDrawing iconDrawing;
+// iconDrawing.show();
+
+ Buttons buttons;
+// buttons.show();
+
return app.exec();
}
diff --git a/tests/manual/highdpi/qticon16.png b/tests/manual/highdpi/qticon16.png
new file mode 100644
index 0000000000..b6b01a4d64
--- /dev/null
+++ b/tests/manual/highdpi/qticon16.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon16@2x.png b/tests/manual/highdpi/qticon16@2x.png
new file mode 100644
index 0000000000..205461daf0
--- /dev/null
+++ b/tests/manual/highdpi/qticon16@2x.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon32.png b/tests/manual/highdpi/qticon32.png
new file mode 100644
index 0000000000..205461daf0
--- /dev/null
+++ b/tests/manual/highdpi/qticon32.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon.png b/tests/manual/highdpi/qticon32@2x.png
index 76f02c6c96..76f02c6c96 100644
--- a/tests/manual/highdpi/qticon.png
+++ b/tests/manual/highdpi/qticon32@2x.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon64.png b/tests/manual/highdpi/qticon64.png
new file mode 100644
index 0000000000..76f02c6c96
--- /dev/null
+++ b/tests/manual/highdpi/qticon64.png
Binary files differ
diff --git a/tests/manual/highdpi/qticon@2x.png b/tests/manual/highdpi/qticon@2x.png
deleted file mode 100644
index 0b00c00c96..0000000000
--- a/tests/manual/highdpi/qticon@2x.png
+++ /dev/null
Binary files differ
diff --git a/tests/manual/highdpi/qticon_large.png b/tests/manual/highdpi/qticon_large.png
deleted file mode 100644
index 0b00c00c96..0000000000
--- a/tests/manual/highdpi/qticon_large.png
+++ /dev/null
Binary files differ