From 3e5362bfa123cfc0b56c77d5e34ad63ea6e9f89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 27 Apr 2016 01:15:48 +0200 Subject: =?UTF-8?q?HighDPI:=20Add=20=E2=80=9Cmetrics=E2=80=9D=20manual=20t?= =?UTF-8?q?est?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test displays a summary of relevant DPI and scale factor/devicePixelRatio values: - DPI and DPR as seen by the application - Input from QPlatformScreen - Input from environment variables. Task-number: QTBUG-53022 Change-Id: I340391624b202e342f22902ffbd7228fe7fbe94b Reviewed-by: Friedemann Kleint --- tests/manual/highdpi/main.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'tests/manual/highdpi/main.cpp') diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp index 7225587ac0..8884c5feed 100644 --- a/tests/manual/highdpi/main.cpp +++ b/tests/manual/highdpi/main.cpp @@ -37,10 +37,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -55,9 +57,16 @@ #include #include #include +#include #include "dragwidget.h" +static QTextStream &operator<<(QTextStream &str, const QRect &r) +{ + str << r.width() << 'x' << r.height() << forcesign << r.x() << r.y() << noforcesign; + return str; +} + class DemoContainerBase { public: @@ -1176,6 +1185,85 @@ public: } }; +class MetricsTest : public QWidget +{ + QPlainTextEdit *m_textEdit; + +public: + MetricsTest() + { + qDebug() << R"( +MetricsTest +Relevant environment variables are: +QT_FONT_DPI=N +QT_SCALE_FACTOR=n +QT_ENABLE_HIGHDPI_SCALING=0|1 +QT_USE_PHYSICAL_DPI=0|1 +QT_SCREEN_SCALE_FACTORS=N;N;N or QT_SCREEN_SCALE_FACTORS=name:N +QT_SCALE_FACTOR_ROUNDING_POLICY=Round|Ceil|Floor|RoundPreferFloor|PassThrough +QT_DPI_ADJUSTMENT_POLICY=AdjustDpi|DontAdjustDpi|AdjustUpOnly)"; + + resize(480, 360); + + QVBoxLayout *layout = new QVBoxLayout(); + setLayout(layout); + + m_textEdit = new QPlainTextEdit; + m_textEdit->setReadOnly(true); + layout->addWidget(m_textEdit); + } + + void updateMetrics() + { + QString text; + QTextStream str(&text); + + auto currentScreen = windowHandle()->screen(); + const auto screens = QGuiApplication::screens(); + for (int i = 0, size = screens.size(); i < size; ++i) { + auto screen = screens.at(i); + auto platformScreen = screen->handle(); + str << "Screen #" << i << " \"" << screen->name() << '"'; + if (screen == currentScreen) + str << " [current]"; + if (screen == QGuiApplication::primaryScreen()) + str << " [primary]"; + str << "\n screen geometry: " << screen->geometry() + << "\n platform screen geometry: " << platformScreen->geometry() + << "\n platform screen logicalDpi: " << platformScreen->logicalDpi().first; + +#ifdef HAVE_SCREEN_BASE_DPI + str << "\n platform screen logicalBaseDpi: " << platformScreen->logicalBaseDpi().first; +#endif + str << "\n platform screen devicePixelRatio: " <devicePixelRatio() + << "\n platform screen physicalDpi: " << screen->physicalDotsPerInch() + << "\n\n"; + } + + str << "widget devicePixelRatio: " << this->devicePixelRatioF() + << "\nwidget logicalDpi: " << this->logicalDpiX() + << "\n\nQT_FONT_DPI: " << qgetenv("QT_FONT_DPI") + << "\nQT_SCALE_FACTOR: " << qgetenv("QT_SCALE_FACTOR") + << "\nQT_ENABLE_HIGHDPI_SCALING: " << qgetenv("QT_ENABLE_HIGHDPI_SCALING") + << "\nQT_SCREEN_SCALE_FACTORS: " << qgetenv("QT_SCREEN_SCALE_FACTORS") + << "\nQT_USE_PHYSICAL_DPI: " << qgetenv("QT_USE_PHYSICAL_DPI") + << "\nQT_SCALE_FACTOR_ROUNDING_POLICY: " << qgetenv("QT_SCALE_FACTOR_ROUNDING_POLICY") + << "\nQT_DPI_ADJUSTMENT_POLICY: " << qgetenv("QT_DPI_ADJUSTMENT_POLICY") + << '\n'; + + m_textEdit->setPlainText(text); + } + + void paintEvent(QPaintEvent *ev) + { + // We get a paint event on screen change, so this is a convenient place + // to update the metrics, at the possible risk of doing something else + // than painting in a paint event. + updateMetrics(); + QWidget::paintEvent(ev); + } +}; + int main(int argc, char **argv) { QApplication app(argc, argv); @@ -1212,6 +1300,7 @@ int main(int argc, char **argv) demoList << new DemoContainer("screens", "Test screen and window positioning"); demoList << new DemoContainer("physicalsize", "Test manual highdpi support using physicalDotsPerInch"); demoList << new DemoContainer("graphicsview", "Test QGraphicsView caching"); + demoList << new DemoContainer("metrics", "Show display metrics"); foreach (DemoContainerBase *demo, demoList) parser.addOption(demo->option()); -- cgit v1.2.3