summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-08-24 13:53:10 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-08-24 20:56:28 +0000
commitc1804bb5c198b3cc5364847ce2bb642161fa15f1 (patch)
treed3c6196f6fe09d9adabdbe403761981086ca9c27 /tests
parent10fe5091235fcff37e83d35e3c1b0040b60fe2a9 (diff)
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 <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/qopenglwindow/multiwindow/main.cpp60
1 files changed, 33 insertions, 27 deletions
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 <QPainter>
#include <QElapsedTimer>
#include <QCommandLineParser>
+#include <QScreen>
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 <N> windows in addition to the default 3.", "N", "0");
- parser.addOption(extraWindowsOption);
+ QCommandLineOption numWindowsOption("numwindows", "Open <N> 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<QWindow *> 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<QWindow *> 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;
}