diff options
Diffstat (limited to 'tests/manual/highdpi')
-rw-r--r-- | tests/manual/highdpi/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/manual/highdpi/dprgadget/CMakeLists.txt | 28 | ||||
-rw-r--r-- | tests/manual/highdpi/dprgadget/main.cpp | 196 | ||||
-rw-r--r-- | tests/manual/highdpi/highdpi.pro | 3 | ||||
-rw-r--r-- | tests/manual/highdpi/kitchensink/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/manual/highdpi/kitchensink/dragwidget.cpp | 35 | ||||
-rw-r--r-- | tests/manual/highdpi/kitchensink/dragwidget.h | 29 | ||||
-rw-r--r-- | tests/manual/highdpi/kitchensink/main.cpp | 31 | ||||
-rw-r--r-- | tests/manual/highdpi/pixelgadget/CMakeLists.txt | 28 | ||||
-rw-r--r-- | tests/manual/highdpi/pixelgadget/main.cpp | 29 | ||||
-rw-r--r-- | tests/manual/highdpi/screengadget/CMakeLists.txt | 14 | ||||
-rw-r--r-- | tests/manual/highdpi/screengadget/main.cpp | 219 | ||||
-rw-r--r-- | tests/manual/highdpi/screengadget/screengadget.pro | 2 |
13 files changed, 413 insertions, 213 deletions
diff --git a/tests/manual/highdpi/CMakeLists.txt b/tests/manual/highdpi/CMakeLists.txt new file mode 100644 index 0000000000..d32e2a52fc --- /dev/null +++ b/tests/manual/highdpi/CMakeLists.txt @@ -0,0 +1,5 @@ + +add_subdirectory(dprgadget) +add_subdirectory(kitchensink) +add_subdirectory(pixelgadget) +add_subdirectory(screengadget) diff --git a/tests/manual/highdpi/dprgadget/CMakeLists.txt b/tests/manual/highdpi/dprgadget/CMakeLists.txt index 94e9833474..2c6bd91f0d 100644 --- a/tests/manual/highdpi/dprgadget/CMakeLists.txt +++ b/tests/manual/highdpi/dprgadget/CMakeLists.txt @@ -1,19 +1,13 @@ -# special case skip regeneration -cmake_minimum_required(VERSION 3.14) -project(dprgadget LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(dprgadget - main.cpp -) - -target_link_libraries(dprgadget PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets +##################################################################### +## dprgadget Binary: +##################################################################### + +qt_internal_add_manual_test(dprgadget + SOURCES + main.cpp + LIBRARIES + Qt::Gui + Qt::Widgets + Qt::GuiPrivate ) - diff --git a/tests/manual/highdpi/dprgadget/main.cpp b/tests/manual/highdpi/dprgadget/main.cpp index 1cb1134bde..26a653e849 100644 --- a/tests/manual/highdpi/dprgadget/main.cpp +++ b/tests/manual/highdpi/dprgadget/main.cpp @@ -1,33 +1,12 @@ -/**************************************************************************** - ** - ** Copyright (C) 2020 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** 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 The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtWidgets/QtWidgets> +#include <QtCore/qtversion.h> #include <QtGui/qpa/qplatformscreen.h> +#include <QtGui/qpa/qplatformwindow.h> +#include <QtGui/private/qhighdpiscaling_p.h> +#include <QtWidgets/QtWidgets> +#include <iostream> /* DprGadget: The focused High-DPI settings debug utility @@ -40,8 +19,13 @@ an utility which displays all inputs. */ -bool g_qtUsePhysicalDpi = false; bool g_qtScaleFactor = false; +bool g_qtUsePhysicalDpi = false; +bool g_qtFontDpi = false; +bool g_qtScaleFactorRoundingPolicy = false; +bool g_qtHighDpiDownscale = false; +bool g_displayEvents = false; + class DprGadget : public QWidget { @@ -49,10 +33,13 @@ public: std::function<void(void)> m_clearFn; std::function<void(void)> m_updateFn; qreal m_currentDpr = -1; + QString m_eventsText; DprGadget() { - setWindowTitle("DprGadget"); + setWindowTitle(QString("DprGadget - Qt %1").arg(qVersion())); + QFont tinyFont; + tinyFont.setPointSize(8); QFont smallFont; smallFont.setPointSize(12); QFont bigFont; @@ -68,71 +55,151 @@ public: dprValue->setFont(biggerFont); dprValue->setTextInteractionFlags(Qt::TextSelectableByMouse); - QLabel *dpiLabel = new QLabel("Logical DPI:"); - dpiLabel->setFont(smallFont); - dpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + QLabel *screenLabel = new QLabel("Current Screen:"); + screenLabel->setFont(smallFont); QLabel *sizeLabel = new QLabel("Window size:"); sizeLabel->setFont(smallFont); sizeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + QLabel *nativeSizeLabel = new QLabel("Native:"); + nativeSizeLabel->setFont(smallFont); + nativeSizeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + + QLabel *dpiLabel = new QLabel("Logical DPI:"); + dpiLabel->setFont(smallFont); + dpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + + QLabel *windowDpiLabel = new QLabel("Window DPI:"); + windowDpiLabel->setFont(smallFont); + windowDpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + QLabel *platformDpiLabel = new QLabel("Native Device Pixel Ratio:"); - QLabel *plarformDprLabel = new QLabel("Native Logical DPI:"); platformDpiLabel->setFont(smallFont); platformDpiLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + + QLabel *windowDprLabel = new QLabel("Window DPR:"); + windowDprLabel->setFont(smallFont); + windowDprLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); + + QLabel *plarformDprLabel = new QLabel("Native DPI:"); plarformDprLabel->setFont(smallFont); plarformDprLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); - QLabel *screenLabel = new QLabel("Current Screen:"); - screenLabel->setFont(smallFont); + QLabel *qtScaleFactorLabel = new QLabel("Qt Internal Scale Factor:"); + qtScaleFactorLabel->setFont(smallFont); + + QLabel *eventsLabel = new QLabel(m_eventsText); + eventsLabel->setFont(tinyFont); + eventsLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(dprLabel); layout->setAlignment(dprLabel, Qt::AlignHCenter); layout->addWidget(dprValue); layout->setAlignment(dprValue, Qt::AlignHCenter); - layout->addWidget(sizeLabel); bool displayLogicalDpi = false; if (displayLogicalDpi) layout->addWidget(dpiLabel); - if (g_qtScaleFactor) { - QString text = QString("QT_SCALE_FACTOR ") + qgetenv("QT_SCALE_FACTOR"); - layout->addWidget(new QLabel(text)); - } - layout->addStretch(); - layout->addWidget(screenLabel); - layout->addWidget(platformDpiLabel); - layout->addWidget(plarformDprLabel); + + QHBoxLayout *screenLabelLayout = new QHBoxLayout(); + screenLabelLayout->addStretch(); + screenLabelLayout->addWidget(screenLabel); + screenLabelLayout->addStretch(); + layout->addLayout(screenLabelLayout); + + QHBoxLayout *windowSizeLayout = new QHBoxLayout(); + windowSizeLayout->addWidget(sizeLabel); + windowSizeLayout->addStretch(); + windowSizeLayout->addWidget(nativeSizeLabel); + layout->addLayout(windowSizeLayout); + + QHBoxLayout *dpiLayout = new QHBoxLayout(); + dpiLayout->addWidget(windowDpiLabel); + dpiLayout->addStretch(); + dpiLayout->addWidget(platformDpiLabel); + layout->addLayout(dpiLayout); + + QHBoxLayout *dprLayout = new QHBoxLayout(); + dprLayout->addWidget(windowDprLabel); + dprLayout->addStretch(); + dprLayout->addWidget(plarformDprLabel); + layout->addLayout(dprLayout); + + QHBoxLayout *qtScaleFactorLabelLayout = new QHBoxLayout(); + qtScaleFactorLabelLayout->addStretch(); + qtScaleFactorLabelLayout->addWidget(qtScaleFactorLabel); + qtScaleFactorLabelLayout->addStretch(); + layout->addLayout(qtScaleFactorLabelLayout); + + if (g_displayEvents) + layout->addWidget(eventsLabel); + + bool activeEnvironment = g_qtScaleFactor || g_qtUsePhysicalDpi || g_qtFontDpi || g_qtScaleFactorRoundingPolicy || g_qtHighDpiDownscale; + if (activeEnvironment) { + layout->addWidget(new QLabel("Active Environment:")); + if (g_qtScaleFactor) { + QString text = QString("QT_SCALE_FACTOR=") + qgetenv("QT_SCALE_FACTOR"); + layout->addWidget(new QLabel(text)); + } + if (g_qtUsePhysicalDpi) { + QString text = QString("QT_USE_PHYSICAL_DPI=") + qgetenv("QT_USE_PHYSICAL_DPI"); + layout->addWidget(new QLabel(text)); + } + if (g_qtFontDpi) { + QString text = QString("QT_FONT_DPI=") + qgetenv("QT_FONT_DPI"); + layout->addWidget(new QLabel(text)); + } + if (g_qtScaleFactorRoundingPolicy) { + QString text = QString("QT_SCALE_FACTOR_ROUNDING_POLICY=") + qgetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); + layout->addWidget(new QLabel(text)); + } + if (g_qtHighDpiDownscale) { + QString text = QString("QT_WIDGETS_HIGHDPI_DOWNSCALE=") + qgetenv("QT_WIDGETS_HIGHDPI_DOWNSCALE"); + layout->addWidget(new QLabel(text)); + } + } auto updateValues = [=]() { dprValue->setText(QString("%1").arg(devicePixelRatioF())); + windowDpiLabel->setText(QString("QWindow DPI: %1").arg(logicalDpiX())); dpiLabel->setText(QString("Logical DPI: %1").arg(logicalDpiX())); - sizeLabel->setText(QString("Window size: %1 %2").arg(width()).arg(height())); + sizeLabel->setText(QString("QWindow size: %1 %2").arg(width()).arg(height())); + QPlatformWindow *platformWindow = windowHandle()->handle(); + nativeSizeLabel->setText(QString("native size %1 %2").arg(platformWindow->geometry().width()) + .arg(platformWindow->geometry().height())); QPlatformScreen *pscreen = screen()->handle(); + if (g_qtUsePhysicalDpi) { + int physicalDpi = qRound(pscreen->geometry().width() / pscreen->physicalSize().width() * qreal(25.4)); + platformDpiLabel->setText(QString("Native Physical DPI: %1").arg(physicalDpi)); + } else { + platformDpiLabel->setText(QString("native logical DPI: %1").arg(pscreen->logicalDpi().first)); + } - if (g_qtUsePhysicalDpi) - platformDpiLabel->setText(QString("Native Physical DPI: TODO")); - else - platformDpiLabel->setText(QString("Native Logical DPI: %1").arg(pscreen->logicalDpi().first)); - - plarformDprLabel->setText(QString("Native Device Pixel Ratio: %1").arg(pscreen->devicePixelRatio())); + windowDprLabel->setText(QString("QWindow DPR: %1").arg(windowHandle()->devicePixelRatio())); + plarformDprLabel->setText(QString("native DPR: %1").arg(pscreen->devicePixelRatio())); screenLabel->setText(QString("Current Screen: %1").arg(screen()->name())); + qtScaleFactorLabel->setText(QString("Qt Internal Scale Factor: %1").arg(QHighDpiScaling::factor(windowHandle()))); + eventsLabel->setText(QString(m_eventsText)); }; m_updateFn = updateValues; m_clearFn = [=]() { dprValue->setText(QString("")); + m_eventsText.clear(); }; create(); - QObject::connect(this->windowHandle(), &QWindow::screenChanged, [updateValues](QScreen *screen){ + QObject::connect(this->windowHandle(), &QWindow::screenChanged, [updateValues, this](QScreen *screen){ Q_UNUSED(screen); + this->m_eventsText.prepend(QString("ScreenChange ")); + this->m_eventsText.truncate(80); updateValues(); }); @@ -142,6 +209,12 @@ public: } void paintEvent(QPaintEvent *) override { + + // Update the UI in the paint event - normally not good + // practice but it looks like we can get away with it here + this->m_eventsText.prepend(QString("Paint ")); + this->m_eventsText.truncate(80); + // Dpr change should trigger a repaint, update display values here if (m_currentDpr == devicePixelRatioF()) return; @@ -150,7 +223,10 @@ public: m_updateFn(); } - void resizeEvent(QResizeEvent *) override { + void resizeEvent(QResizeEvent *event) override { + QSize size = event->size(); + m_eventsText.prepend(QString("Resize(%1 %2) ").arg(size.width()).arg(size.height())); + m_eventsText.truncate(80); m_updateFn(); } @@ -168,18 +244,16 @@ int main(int argc, char **argv) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); - // react to (some) high-dpi eviornment variables. - g_qtUsePhysicalDpi = qgetenv("QT_USE_PHYSICAL_DPI") == QByteArray("1"); + // Display any set high-dpi eviornment variable. g_qtScaleFactor = qEnvironmentVariableIsSet("QT_SCALE_FACTOR"); + g_qtUsePhysicalDpi = qgetenv("QT_USE_PHYSICAL_DPI") == QByteArray("1"); + g_qtFontDpi = qEnvironmentVariableIsSet("QT_FONT_DPI"); + g_qtScaleFactorRoundingPolicy = qEnvironmentVariableIsSet("QT_SCALE_FACTOR_ROUNDING_POLICY"); + g_qtHighDpiDownscale = qEnvironmentVariableIsSet("QT_WIDGETS_HIGHDPI_DOWNSCALE"); QApplication app(argc, argv); DprGadget dprGadget; - - // Set initial size. We expect this size to be preserved across screen - // and DPI changes - dprGadget.resize(560, 380); - dprGadget.show(); return app.exec(); diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro new file mode 100644 index 0000000000..fcf4a5f09e --- /dev/null +++ b/tests/manual/highdpi/highdpi.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS = dprgadget kitchensink pixelgadget screengadget diff --git a/tests/manual/highdpi/kitchensink/CMakeLists.txt b/tests/manual/highdpi/kitchensink/CMakeLists.txt index b8dfa9be37..8caf85983e 100644 --- a/tests/manual/highdpi/kitchensink/CMakeLists.txt +++ b/tests/manual/highdpi/kitchensink/CMakeLists.txt @@ -1,4 +1,3 @@ -# Generated from kitchensink.pro. ##################################################################### ## kitchensink Binary: @@ -12,7 +11,7 @@ qt_internal_add_manual_test(kitchensink HAVE_SCREEN_BASE_DPI INCLUDE_DIRECTORIES . - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Widgets @@ -34,7 +33,3 @@ qt_internal_add_resource(kitchensink "kitchensink" FILES ${kitchensink_resource_files} ) - - -#### Keys ignored in scope 1:.:.:kitchensink.pro:<TRUE>: -# TEMPLATE = "app" diff --git a/tests/manual/highdpi/kitchensink/dragwidget.cpp b/tests/manual/highdpi/kitchensink/dragwidget.cpp index bd65fcf81b..4088a56a80 100644 --- a/tests/manual/highdpi/kitchensink/dragwidget.cpp +++ b/tests/manual/highdpi/kitchensink/dragwidget.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** - ** - ** Copyright (C) 2016 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** 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 The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtWidgets> #include "dragwidget.h" @@ -109,8 +84,8 @@ void DragWidget::dropEvent(QDropEvent *event) { if (event->mimeData()->hasText()) { const QMimeData *mime = event->mimeData(); - QStringList pieces = mime->text().split(QRegularExpression("\\s+"), - Qt::SkipEmptyParts); + const QStringList pieces = mime->text().split(QRegularExpression("\\s+"), + Qt::SkipEmptyParts); QPoint position = event->pos(); QPoint hotSpot; @@ -123,7 +98,7 @@ void DragWidget::dropEvent(QDropEvent *event) dropTimer.start(500, this); update(); - foreach (QString piece, pieces) { + for (const QString &piece : pieces) { FramedLabel *newLabel = new FramedLabel(piece, this); newLabel->move(position - hotSpot); newLabel->show(); diff --git a/tests/manual/highdpi/kitchensink/dragwidget.h b/tests/manual/highdpi/kitchensink/dragwidget.h index 06663fc74a..d444f7f0a6 100644 --- a/tests/manual/highdpi/kitchensink/dragwidget.h +++ b/tests/manual/highdpi/kitchensink/dragwidget.h @@ -1,30 +1,5 @@ -/**************************************************************************** - ** - ** Copyright (C) 2016 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** 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 The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef DRAGWIDGET_H #define DRAGWIDGET_H diff --git a/tests/manual/highdpi/kitchensink/main.cpp b/tests/manual/highdpi/kitchensink/main.cpp index bdb4c3d571..5fe46828bd 100644 --- a/tests/manual/highdpi/kitchensink/main.cpp +++ b/tests/manual/highdpi/kitchensink/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** - ** - ** Copyright (C) 2016 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** 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 The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QMainWindow> #include <QMenuBar> @@ -1458,7 +1433,7 @@ int main(int argc, char **argv) demoList << new DemoContainer<GraphicsViewCaching>("graphicsview", "Test QGraphicsView caching"); demoList << new DemoContainer<MetricsTest>("metrics", "Show screen metrics"); - for (DemoContainerBase *demo : qAsConst(demoList)) + for (DemoContainerBase *demo : std::as_const(demoList)) parser.addOption(demo->option()); parser.process(app); diff --git a/tests/manual/highdpi/pixelgadget/CMakeLists.txt b/tests/manual/highdpi/pixelgadget/CMakeLists.txt index 38d61df618..2cc04225df 100644 --- a/tests/manual/highdpi/pixelgadget/CMakeLists.txt +++ b/tests/manual/highdpi/pixelgadget/CMakeLists.txt @@ -1,19 +1,13 @@ -# special case skip regeneration -cmake_minimum_required(VERSION 3.14) -project(pixelgadget LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Widgets) - -qt_add_executable(pixelgadget - main.cpp -) - -target_link_libraries(pixelgadget PUBLIC - Qt::Core - Qt::Gui - Qt::Widgets +##################################################################### +## pixelgadget Binary: +##################################################################### + +qt_internal_add_manual_test(pixelgadget + GUI + SOURCES + main.cpp + LIBRARIES + Qt::Gui + Qt::Widgets ) - diff --git a/tests/manual/highdpi/pixelgadget/main.cpp b/tests/manual/highdpi/pixelgadget/main.cpp index 2692f22a0e..51174bc6d9 100644 --- a/tests/manual/highdpi/pixelgadget/main.cpp +++ b/tests/manual/highdpi/pixelgadget/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** - ** - ** Copyright (C) 2020 The Qt Company Ltd. - ** Contact: https://www.qt.io/licensing/ - ** - ** This file is part of the test suite of the Qt Toolkit. - ** - ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ - ** 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 The Qt Company. For licensing terms - ** and conditions see https://www.qt.io/terms-conditions. For further - ** information use the contact form at https://www.qt.io/contact-us. - ** - ** GNU General Public License Usage - ** Alternatively, this file may be used under the terms of the GNU - ** General Public License version 3 as published by the Free Software - ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT - ** included in the packaging of this file. Please review the following - ** information to ensure the GNU General Public License requirements will - ** be met: https://www.gnu.org/licenses/gpl-3.0.html. - ** - ** $QT_END_LICENSE$ - ** - ****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui> #include <QtWidgets> diff --git a/tests/manual/highdpi/screengadget/CMakeLists.txt b/tests/manual/highdpi/screengadget/CMakeLists.txt new file mode 100644 index 0000000000..d9045541bb --- /dev/null +++ b/tests/manual/highdpi/screengadget/CMakeLists.txt @@ -0,0 +1,14 @@ + +##################################################################### +## screengadget Binary: +##################################################################### + +qt_internal_add_manual_test(screengadget + GUI + SOURCES + main.cpp + LIBRARIES + Qt::Gui + Qt::Widgets + Qt::GuiPrivate +) diff --git a/tests/manual/highdpi/screengadget/main.cpp b/tests/manual/highdpi/screengadget/main.cpp new file mode 100644 index 0000000000..68343a31c5 --- /dev/null +++ b/tests/manual/highdpi/screengadget/main.cpp @@ -0,0 +1,219 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtGui> +#include <QtWidgets> + +#include <QtGui/qpa/qplatformscreen.h> +#include <QtGui/qpa/qplatformwindow.h> +#include <QtGui/qpa/qplatformcursor.h> + +// This test app optionally doubles as a manual test for QScreen::mapToNative() +// #define TEST_MAP_TO_NATIVE + +// ScreenDisplayer based on original impl from qtbase/tests/manual/highdpi +class ScreenDisplayer : public QWidget +{ +public: + ScreenDisplayer() = default; + + void setTitle() { + + QPoint deviceIndependentPos = pos(); + QPlatformWindow *platformWindow = windowHandle()->handle(); + QPoint nativePos = platformWindow->geometry().topLeft(); + + QString windowDebug = QString("pos ") + + QString("device independent %1 %2 ").arg(deviceIndependentPos.x()).arg(deviceIndependentPos.y()) + + QString("native %1 %2 ").arg(nativePos.x()).arg(nativePos.y()) + ; + + setWindowTitle(windowDebug); + } + + void updateMapToNative(QPointF pos) + { +#ifdef TEST_MAP_TO_NATIVE + mappedToNative = QGuiApplication::mapToNative(QRectF(pos, QPointF(1,1))).topLeft(); // there + mappedFromNative = QGuiApplication::mapFromNative(QRectF(mappedToNative, QPointF(1,1))).topLeft(); // and back again +#endif + } + + void timerEvent(QTimerEvent *) override + { + update(); + setTitle(); + } + + void mousePressEvent(QMouseEvent *) override + { + displayMappedToNativeCursor = true; + } + + void mouseMoveEvent(QMouseEvent *e) override + { + setTitle(); + updateMapToNative(e->globalPosition()); + } + + void mouseReleaseEvent(QMouseEvent *) override + { + } + + void showEvent(QShowEvent *) override + { + refreshTimer.start(60, this); + } + + void hideEvent(QHideEvent *) override + { + refreshTimer.stop(); + } + + void paintScreensInRect(QPainter &p, QRect rect, bool native) { + p.save(); + + QRectF total; + const auto screens = QGuiApplication::screens(); + for (const QScreen *screen : screens) + total |= native ? screen->handle()->geometry() : screen->geometry(); + if (total.isEmpty()) + return; + + qreal scaleMargin = 0.9; + scaleFactor = scaleMargin * qMin(rect.width()/total.width(), rect.height()/total.height()); + + // p.fillRect(rect, Qt::black); + int margin = 20; + p.translate(margin, margin + rect.y()); + p.scale(scaleFactor, scaleFactor); + p.translate(-total.topLeft()); + p.setPen(QPen(Qt::white, 10)); + p.setBrush(Qt::gray); + + for (const QScreen *screen : screens) { + QRect geometry = native ? screen->handle()->geometry() : screen->geometry(); + p.drawRect(geometry); + QFont f("Courier New"); + f.setPixelSize(geometry.height() / 16); + p.setFont(f); + + if (displayInfo) { + QString text = "Name: " + screen->name() + "\n"; + text += QString("\nGeometry: %1 %2 %3 %4 \n ").arg(geometry.x()).arg(geometry.y()).arg(geometry.width()).arg(geometry.height()); + p.save(); + p.translate(20, 0); + p.drawText(geometry, Qt::AlignLeft | Qt::AlignVCenter, text); + p.restore(); + } + } + p.setBrush(QColor(200,220,255,127)); + + const auto topLevels = QApplication::topLevelWidgets(); + for (QWidget *widget : topLevels) { + if (!widget->isHidden()) + p.drawRect(native ? widget->windowHandle()->handle()->geometry() : widget->geometry()); + } + + QPolygon cursorShape; + cursorShape << QPoint(0,0) << QPoint(20, 60) + << QPoint(30, 50) << QPoint(60, 80) + << QPoint(80, 60) << QPoint(50, 30) + << QPoint(60, 20); + + p.save(); + p.translate(native ? qApp->primaryScreen()->handle()->cursor()->pos() : QCursor::pos()); + p.drawPolygon(cursorShape); + p.restore(); + +#ifdef TEST_MAP_TO_NATIVE + // Draw red "mapped to native" cursor. We expect this + // cursor to track the normal blue cursor if everything + // works out ok. + if (displayMappedToNativeCursor) { + p.save(); + p.setBrush(QColor(230,120,155,127)); + p.translate(native ? mappedToNative: mappedFromNative); + p.drawPolygon(cursorShape); + p.restore(); + } +#endif + + p.restore(); + } + + void paintEvent(QPaintEvent *) override + { + QPainter p(this); + + QRect g = geometry(); + int halfHeight = g.height() / 2; + QRect topHalf = QRect(0, 0, g.width(), halfHeight); + QRect bottomHalf = QRect(0, halfHeight, g.width(), halfHeight); + + if (displayDeviceIndependentGeometry) + paintScreensInRect(p, topHalf, false); + if (displayNativeGeometry) + paintScreensInRect(p, bottomHalf, true); + } + + bool displayInfo = false; + bool displayDeviceIndependentGeometry = true; + bool displayNativeGeometry = false; +private: + bool displayMappedToNativeCursor = false; + QPointF mappedToNative; + QPointF mappedFromNative; + qreal scaleFactor = 1; + QBasicTimer refreshTimer; +}; + +class Controller : public QWidget { +public: + Controller(ScreenDisplayer *displayer) { + setWindowTitle("Controller"); + + QVBoxLayout *layout = new QVBoxLayout(); + setLayout(layout); + + layout->addWidget(new QLabel("Coordinate System:")); + + QCheckBox *deviceIndpendentGeometry = new QCheckBox("Device Independent"); + deviceIndpendentGeometry->setChecked(true); + connect(deviceIndpendentGeometry, &QCheckBox::stateChanged, [displayer](int checked){ displayer->displayDeviceIndependentGeometry = checked > 0; }); + layout->addWidget(deviceIndpendentGeometry); + + QCheckBox *nativeGeometry = new QCheckBox("Native"); + nativeGeometry->setChecked(false); + connect(nativeGeometry, &QCheckBox::stateChanged, [displayer](int checked){ displayer->displayNativeGeometry = checked > 0; }); + layout->addWidget(nativeGeometry); + + layout->addSpacing(40); + + QCheckBox *debug = new QCheckBox("Debug!"); + debug->setChecked(false); + connect(debug, &QCheckBox::stateChanged, [displayer](int checked){ displayer->displayInfo = checked > 0; }); + layout->addWidget(debug); + + layout->addStretch(); + } +}; + +int main(int argc, char **argv) { + + QApplication app(argc, argv); + + ScreenDisplayer displayer; + displayer.resize(300, 200); + displayer.show(); + + Controller controller(&displayer); + controller.resize(100, 200); + + QTimer::singleShot(300, [&controller, &displayer](){ + controller.move(displayer.pos() + QPoint(displayer.width(), 0) + QPoint(50, 0)); + controller.show(); + }); + + return app.exec(); +} diff --git a/tests/manual/highdpi/screengadget/screengadget.pro b/tests/manual/highdpi/screengadget/screengadget.pro new file mode 100644 index 0000000000..cdbaa8c2a1 --- /dev/null +++ b/tests/manual/highdpi/screengadget/screengadget.pro @@ -0,0 +1,2 @@ +QT += widgets gui_private +SOURCES += main.cpp |