summaryrefslogtreecommitdiffstats
path: root/tests/manual/highdpi
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-07-18 14:22:14 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-07-18 16:45:44 +0200
commitec190b0da7e39970957fc2a29f745588f493b876 (patch)
treef2617040b88e87f75cb1a40704eee08c191aa990 /tests/manual/highdpi
parentf547381806f6251c176e587d6d95b66bb8dfa88c (diff)
Fix up existing high DPI manual test.
Compile on Windows, add command line options to activate the various tests. Task-number: QTBUG-38858 Change-Id: I38c6a9a6711831b2bd8b6ea051dd19615cc911a1 Reviewed-by: Alessandro Portale <alessandro.portale@digia.com>
Diffstat (limited to 'tests/manual/highdpi')
-rw-r--r--tests/manual/highdpi/highdpi.pro2
-rw-r--r--tests/manual/highdpi/main.cpp176
2 files changed, 125 insertions, 53 deletions
diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro
index b827456f9b..7a2979c74c 100644
--- a/tests/manual/highdpi/highdpi.pro
+++ b/tests/manual/highdpi/highdpi.pro
@@ -2,7 +2,7 @@ TEMPLATE = app
TARGET = highdpi
INCLUDEPATH += .
QT += widgets
-
+CONFIG+=console
# Input
SOURCES += main.cpp
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index c40cbd7b42..290e550afb 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
- ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+ ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -39,9 +39,27 @@
**
****************************************************************************/
-#include <QtCore>
-#include <QtGui>
-#include <QtWidgets>
+#include <QMainWindow>
+#include <QLabel>
+#include <QHBoxLayout>
+#include <QApplication>
+#include <QAction>
+#include <QStyle>
+#include <QToolBar>
+#include <QPushButton>
+#include <QLineEdit>
+#include <QScrollBar>
+#include <QSlider>
+#include <QSpinBox>
+#include <QTabBar>
+#include <QIcon>
+#include <QPainter>
+#include <QWindow>
+#include <QScreen>
+#include <QFile>
+#include <QTemporaryDir>
+#include <QCommandLineParser>
+#include <QCommandLineOption>
class PixmapPainter : public QWidget
@@ -74,7 +92,7 @@ PixmapPainter::PixmapPainter()
qtIcon.addFile(":/qticon32@2x.png");
}
-void PixmapPainter::paintEvent(QPaintEvent *event)
+void PixmapPainter::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(QRect(QPoint(0, 0), size()), QBrush(Qt::gray));
@@ -187,7 +205,7 @@ MainWindow::MainWindow()
class StandardIcons : public QWidget
{
public:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *)
{
int x = 10;
int y = 10;
@@ -203,13 +221,13 @@ public:
y+=dy;
x = ((x + dx) % maxX);
}
- };
+ }
};
class Caching : public QWidget
{
public:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *)
{
QSize layoutSize(75, 75);
@@ -232,7 +250,7 @@ public:
{
const qreal devicePixelRatio = this->windowHandle()->devicePixelRatio();
- QImage cache = QImage(layoutSize * devicePixelRatio, QImage::QImage::Format_ARGB32_Premultiplied);
+ QImage cache = QImage(layoutSize * devicePixelRatio, QImage::Format_ARGB32_Premultiplied);
cache.setDevicePixelRatio(devicePixelRatio);
QPainter cachedPainter(&cache);
@@ -282,7 +300,7 @@ public:
class Fonts : public QWidget
{
public:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *)
{
QPainter painter(this);
int y = 40;
@@ -333,28 +351,22 @@ void apiTest()
class IconDrawing : public QWidget
{
public:
- QIcon *iconHighDPI;
- QIcon *iconNormalDpi;
-
IconDrawing()
{
- QFile::copy(":/qticon32.png", "/tmp/qticon32-2.png");
+ const QString tempPath = m_temporaryDir.path();
+ const QString path32 = tempPath + "/qticon32.png";
+ const QString path32_2 = tempPath + "/qticon32-2.png";
+ const QString path32_2x = tempPath + "/qticon32@2x.png";
- QFile::copy(":/qticon32.png", "/tmp/qticon32.png");
- QFile::copy(":/qticon32@2x.png", "/tmp/qticon32@2x.png");
+ QFile::copy(":/qticon32.png", path32_2);
+ QFile::copy(":/qticon32.png", path32);
+ QFile::copy(":/qticon32@2x.png", path32_2x);
- 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::
+ iconHighDPI.reset(new QIcon(path32)); // will auto-load @2x version.
+ iconNormalDpi.reset(new QIcon(path32_2)); // does not have a 2x version.
}
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *)
{
int x = 10;
int y = 10;
@@ -366,7 +378,7 @@ public:
int sizeIncrement = 5;
// Disable high-dpi icons
- qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false);
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, false);
// normal icon
for (int size = minSize; size < maxSize; size += sizeIncrement) {
@@ -392,7 +404,7 @@ public:
y+=dy;
// Enable high-dpi icons
- qApp->setAttribute(Qt::AA_UseHighDpiPixmaps, true);
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
// normal icon
for (int size = minSize; size < maxSize; size += sizeIncrement) {
@@ -417,7 +429,12 @@ public:
x = 10;
y+=dy;
- };
+ }
+
+private:
+ QTemporaryDir m_temporaryDir;
+ QScopedPointer<QIcon> iconHighDPI;
+ QScopedPointer<QIcon> iconNormalDpi;
};
// Icons on buttons
@@ -456,38 +473,93 @@ public:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- qApp->setAttribute(Qt::AA_UseHighDpiPixmaps);
-
- PixmapPainter pixmapPainter;
- pixmapPainter.show();
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+ QCoreApplication::setApplicationVersion(QT_VERSION_STR);
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("High DPI tester");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption pixmapPainterOption("pixmap", "Test pixmap painter");
+ parser.addOption(pixmapPainterOption);
+ QCommandLineOption labelOption("label", "Test Labels");
+ parser.addOption(labelOption);
+ QCommandLineOption mainWindowOption("mainwindow", "Test QMainWindow");
+ parser.addOption(mainWindowOption);
+ QCommandLineOption standardIconsOption("standard-icons", "Test standard icons");
+ parser.addOption(standardIconsOption);
+ QCommandLineOption cachingOption("caching", "Test caching");
+ parser.addOption(cachingOption);
+ QCommandLineOption styleOption("styles", "Test style");
+ parser.addOption(styleOption);
+ QCommandLineOption fontsOption("fonts", "Test fonts");
+ parser.addOption(fontsOption);
+ QCommandLineOption iconDrawingOption("icondrawing", "Test icon drawing");
+ parser.addOption(iconDrawingOption);
+ QCommandLineOption buttonsOption("buttons", "Test buttons");
+ parser.addOption(buttonsOption);
+
+ parser.process(app);
+
+ QScopedPointer<PixmapPainter> pixmapPainter;
+ if (parser.isSet(pixmapPainterOption)) {
+ pixmapPainter.reset(new PixmapPainter);
+ pixmapPainter->show();
+ }
- Labels label;
- label.resize(200, 200);
-// label.show();
+ QScopedPointer<Labels> label;
+ if (parser.isSet(labelOption)) {
+ label.reset(new Labels);
+ label->resize(200, 200);
+ label->show();
+ }
- MainWindow mainWindow;
-// mainWindow.show();
+ QScopedPointer<MainWindow> mainWindow;
+ if (parser.isSet(mainWindowOption)) {
+ mainWindow.reset(new MainWindow);
+ mainWindow->show();
+ }
- StandardIcons icons;
- icons.resize(510, 510);
-// icons.show();
+ QScopedPointer<StandardIcons> icons;
+ if (parser.isSet(standardIconsOption)) {
+ icons.reset(new StandardIcons);
+ icons->resize(510, 510);
+ icons->show();
+ }
- Caching caching;
- caching.resize(300, 300);
-// caching.show();
+ QScopedPointer<Caching> caching;
+ if (parser.isSet(cachingOption)) {
+ caching.reset(new Caching);
+ caching->resize(300, 300);
+ caching->show();
+ }
- Style style;
-// style.show();
+ QScopedPointer<Style> style;
+ if (parser.isSet(styleOption)) {
+ style.reset(new Style);
+ style->show();
+ }
- Fonts fonts;
-// fonts.show();
+ QScopedPointer<Fonts> fonts;
+ if (parser.isSet(fontsOption)) {
+ fonts.reset(new Fonts);
+ fonts->show();
+ }
- IconDrawing iconDrawing;
-// iconDrawing.show();
+ QScopedPointer<IconDrawing> iconDrawing;
+ if (parser.isSet(iconDrawingOption)) {
+ iconDrawing.reset(new IconDrawing);
+ iconDrawing->show();
+ }
- Buttons buttons;
-// buttons.show();
+ QScopedPointer<Buttons> buttons;
+ if (parser.isSet(buttonsOption)) {
+ buttons.reset(new Buttons);
+ buttons->show();
+ }
+ if (QApplication::topLevelWidgets().isEmpty())
+ parser.showHelp(0);
return app.exec();
}