summaryrefslogtreecommitdiffstats
path: root/tests/manual/highdpi/main.cpp
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@theqtcompany.com>2015-05-26 22:22:37 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-05-29 15:41:38 +0000
commitf9b1596fe1aeacf4f3d977c32e74b7ad585d3d3e (patch)
tree82c04fce2ef3a56540ebb6e06df5b29a4f1fa71b /tests/manual/highdpi/main.cpp
parentc2d5ecf8766d3da70b17348e92cda31b00e204a7 (diff)
Refactor QHighDpiScaling internals and usage
Overall goal is to simplify, separate concerns, and improve cross-platform-ness and testability. QT_SCALE_FACTOR is now a pure cross-platform global scale factor setter has no "auto". "auto" requires input from the platform plugin via QPlatformScreen:: pixelDensity() and gets a separate environment variable: QT_AUTO_SCREEN_SCALE_FACTOR The effective scale factor (aka devicePixelRatio) is now computed as the product of the global, screen, and window scale factors. This matches how devicePixelRatio is computed in general (the window system devicePixelRatio is also a factor), and makes QT_SCALE_FACTOR work consistently regardless if there is a window scale factor set or not. This also means we can remove the if/else casing from the nativePixels conversion functions. Add QHighDpiScaling initializer which reads the environment variables and sets the "active" variables. Call it during QGuiApplication construction, before the platform plugin is created Add per-screen scale factor setting capability to the manual test. This makes it possible to test this logic on all platforms. The command line argument is --screen-scale-factor. Change-Id: I054337cbae37a01cdd731d26d9cb628fcecdb652 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'tests/manual/highdpi/main.cpp')
-rw-r--r--tests/manual/highdpi/main.cpp127
1 files changed, 63 insertions, 64 deletions
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index b6305ba1d4..fb5ff33232 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -56,69 +56,64 @@
#include <QDebug>
#include <private/qhighdpiscaling_p.h>
-class ScaleFactorSetter : public QWidget
+class ScreenScaleFactorSetter : public QWidget
{
Q_OBJECT
public:
- ScaleFactorSetter();
- QLabel *label;
- QSlider *slider;
- QLabel *scaleFactorLabel;
- QHBoxLayout *layout;
-private Q_SLOTS:
- void scaleFactorChanged(int scaleFactor);
+ ScreenScaleFactorSetter();
};
-// Shows a slider which sets the scale factor for all windows.
-ScaleFactorSetter::ScaleFactorSetter()
+ScreenScaleFactorSetter::ScreenScaleFactorSetter()
{
- label = new QLabel("Scale Factor");
- slider = new QSlider();
- slider->setOrientation(Qt::Horizontal);
- slider->setMinimum(1);
- slider->setMaximum(40);
- slider->setValue(10);
- slider->setTracking(true);
- slider->setTickInterval(5);
- slider->setTickPosition(QSlider::TicksBelow);
- scaleFactorLabel = new QLabel("1.0");
-
- layout = new QHBoxLayout();
- layout->addWidget(label);
- layout->addWidget(slider);
- layout->addWidget(scaleFactorLabel);
- setLayout(layout);
+ setWindowTitle("screen scale factors");
+ setObjectName("controller"); // make WindowScaleFactorSetter skip this window
- connect(slider, SIGNAL(valueChanged(int)), this, SLOT(scaleFactorChanged(int)));
-}
+ QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
-void ScaleFactorSetter::scaleFactorChanged(int scaleFactor)
-{
- // slider value is scale factor times ten;
- qreal scalefactorF = qreal(scaleFactor) / 10.0;
-
- // update label, add ".0" if needed.
- QString number = QString::number(scalefactorF);
- if (!number.contains("."))
- number.append(".0");
- scaleFactorLabel->setText(number);
-
- // set scale factor on all top-level windows
- QWindowList windows = QGuiApplication::topLevelWindows();
- foreach (QWindow *window, windows) {
-
- // skip this controller window
- if (window == this->windowHandle())
- continue;
-
- qDebug() << "set scale factor on" << window;
- qreal oldFactor = QHighDpiScaling::factor(window);
- QHighDpiScaling::setWindowFactor(window, scalefactorF);
- qreal newFactor = QHighDpiScaling::factor(window);
- qDebug() << "factor was / is" << oldFactor << newFactor;
-
- // resize window to keep showing the same amount of content.
- window->resize(window->size() / oldFactor * newFactor);
+ // set up one scale control line per screen
+ QList<QScreen *> screens = QGuiApplication::screens();
+ foreach (QScreen *screen, screens) {
+ // create scale control line
+ QHBoxLayout *row = new QHBoxLayout;
+ QSize screenSize = screen->geometry().size();
+ QString screenId = screen->name() + " " + QString::number(screenSize.width())
+ + " " + QString::number(screenSize.height());
+ QLabel *label = new QLabel(screenId);
+ QSlider *slider = new QSlider();
+ slider->setOrientation(Qt::Horizontal);
+ slider->setMinimum(1);
+ slider->setMaximum(40);
+ slider->setValue(10);
+ slider->setTracking(true);
+ slider->setTickInterval(5);
+ slider->setTickPosition(QSlider::TicksBelow);
+ QLabel *scaleFactorLabel = new QLabel("1.0");
+
+ // set up layouts
+ row->addWidget(label);
+ row->addWidget(slider);
+ row->addWidget(scaleFactorLabel);
+ layout->addLayout(row);
+
+ // handle slider value change
+ connect(slider, &QSlider::valueChanged, [scaleFactorLabel, screen](int scaleFactor){
+ // slider value is scale factor times ten;
+ qreal scalefactorF = qreal(scaleFactor) / 10.0;
+
+ // update label, add ".0" if needed.
+ QString number = QString::number(scalefactorF);
+ if (!number.contains("."))
+ number.append(".0");
+ scaleFactorLabel->setText(number);
+
+ // set scale factor for screen
+ qreal oldFactor = QHighDpiScaling::factor(screen);
+ QHighDpiScaling::setScreenFactor(screen, scalefactorF);
+ qreal newFactor = QHighDpiScaling::factor(screen);
+
+ qDebug() << "factor was / is" << oldFactor << newFactor;
+ });
}
}
@@ -272,7 +267,7 @@ public:
int dy = 50;
int maxX = 500;
- for (int iconIndex = QStyle::SP_TitleBarMenuButton; iconIndex < QStyle::SP_MediaVolumeMuted; ++iconIndex) {
+ for (uint 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));
@@ -607,11 +602,15 @@ int main(int argc, char **argv)
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
QCommandLineParser parser;
- parser.setApplicationDescription("High DPI tester");
+ parser.setApplicationDescription("High DPI tester. Pass one or more of the options to\n"
+ "test various high-dpi aspects. \n"
+ "--sceen-scale-factor is a special option and opens a configuration"
+ " window for setting window and screen scale factors.");
parser.addHelpOption();
parser.addVersionOption();
- QCommandLineOption scaleFactorOption("window-scale-factor", "Show Scale Factor Slider");
- parser.addOption(scaleFactorOption);
+ QCommandLineOption screenScaleFactorOption("screen-scale-factor", "Show screen scale factor setter.");
+ parser.addOption(screenScaleFactorOption);
+
QCommandLineOption pixmapPainterOption("pixmap", "Test pixmap painter");
parser.addOption(pixmapPainterOption);
QCommandLineOption labelOption("label", "Test Labels");
@@ -633,13 +632,13 @@ int main(int argc, char **argv)
QCommandLineOption linePainterOption("linepainter", "Test line painting");
parser.addOption(linePainterOption);
-
parser.process(app);
- QScopedPointer<ScaleFactorSetter> scaleFactorSetter;
- if (parser.isSet(scaleFactorOption)) {
- scaleFactorSetter.reset(new ScaleFactorSetter);
- scaleFactorSetter->show();
+ // special screen scale factor controller
+ QScopedPointer<ScreenScaleFactorSetter> screeScaleFactorSetter;
+ if (parser.isSet(screenScaleFactorOption)) {
+ screeScaleFactorSetter.reset(new ScreenScaleFactorSetter);
+ screeScaleFactorSetter->show();
}
QScopedPointer<PixmapPainter> pixmapPainter;