From c1804bb5c198b3cc5364847ce2bb642161fa15f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 24 Aug 2016 13:53:10 +0200 Subject: multiwindow: Make it easier to test 1-N windows Changes the --extrawindows option to --numwindows with a default of 3, and layouts all windows in rows and columns so that they are all exposed at startup. Change-Id: I5e8d63a14b778bcddc2fee3bf7e78d6664532b5b Reviewed-by: Simon Hausmann --- tests/manual/qopenglwindow/multiwindow/main.cpp | 60 ++++++++++++++----------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'tests/manual/qopenglwindow') diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 4533167dd7..caa15078d5 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -38,6 +38,7 @@ #include #include #include +#include const char applicationDescription[] = "\n\ This application opens multiple windows and continuously schedules updates for\n\ @@ -143,8 +144,8 @@ int main(int argc, char **argv) "by setting swap interval to 1 for the first window and 0 for the others."); parser.addOption(vsyncOneOption); - QCommandLineOption extraWindowsOption("extrawindows", "Open windows in addition to the default 3.", "N", "0"); - parser.addOption(extraWindowsOption); + QCommandLineOption numWindowsOption("numwindows", "Open windows instead of the default 3.", "N", "3"); + parser.addOption(numWindowsOption); parser.process(app); @@ -157,35 +158,40 @@ int main(int argc, char **argv) } QSurfaceFormat::setDefaultFormat(fmt); - Window w1(0); - if (parser.isSet(vsyncOneOption)) { - qDebug("swap interval 1 for first window only"); - QSurfaceFormat w1fmt = fmt; - w1fmt.setSwapInterval(1); - w1.setFormat(w1fmt); - fmt.setSwapInterval(0); - QSurfaceFormat::setDefaultFormat(fmt); - } - Window w2(1); - Window w3(2); - w1.setGeometry(QRect(QPoint(10, 100), w1.size())); - w2.setGeometry(QRect(QPoint(300, 100), w2.size())); - w3.setGeometry(QRect(QPoint(600, 100), w3.size())); - w1.show(); - w2.show(); - w3.show(); - - QList extraWindows; - if (int extraWindowCount = parser.value(extraWindowsOption).toInt()) { - for (int i = 0; i < extraWindowCount; ++i) { - Window *w = new Window(3 + i); - extraWindows << w; - w->show(); + QRect availableGeometry = app.primaryScreen()->availableGeometry(); + + int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1); + QList windows; + for (int i = 0; i < numberOfWindows; ++i) { + Window *w = new Window(i + 1); + windows << w; + + if (i == 0 && parser.isSet(vsyncOneOption)) { + qDebug("swap interval 1 for first window only"); + QSurfaceFormat vsyncedSurfaceFormat = fmt; + vsyncedSurfaceFormat.setSwapInterval(1); + w->setFormat(vsyncedSurfaceFormat); + fmt.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(fmt); } + + static int windowWidth = w->width() + 20; + static int windowHeight = w->height() + 20; + + static int windowsPerRow = availableGeometry.width() / windowWidth; + + int col = i; + int row = col / windowsPerRow; + col -= row * windowsPerRow; + + QPoint position = availableGeometry.topLeft(); + position += QPoint(col * windowWidth, row * windowHeight); + w->setFramePosition(position); + w->show(); } int r = app.exec(); - qDeleteAll(extraWindows); + qDeleteAll(windows); return r; } -- cgit v1.2.3