diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2016-08-25 13:09:27 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2016-09-19 00:42:20 +0000 |
commit | 6ce96fdbf59138bebadbd8157d8285327a1a3796 (patch) | |
tree | 31efd5cf69b24f93e07169c08f974966f1c3e311 /tests/manual | |
parent | bcbc8120b30a3d94d6a131ad936a8270657ffd96 (diff) |
multiwindow: React to mouse press to allow debugging UI responsiveness
The animated FPS counter should be enough to observe smooth animations,
so we use the color of the window to visualize frame latency.
Change-Id: I1171a1c4bdc261ca8655771290c6735357821781
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/qopenglwindow/multiwindow/main.cpp | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp index 66ebb73c56..31688d717e 100644 --- a/tests/manual/qopenglwindow/multiwindow/main.cpp +++ b/tests/manual/qopenglwindow/multiwindow/main.cpp @@ -31,14 +31,7 @@ ** ****************************************************************************/ -#include <QGuiApplication> -#include <QOpenGLWindow> -#include <QOpenGLContext> -#include <QOpenGLFunctions> -#include <QPainter> -#include <QElapsedTimer> -#include <QCommandLineParser> -#include <QScreen> +#include <QtGui> const char applicationDescription[] = "\n\ This application opens multiple windows and continuously schedules updates for\n\ @@ -67,40 +60,26 @@ class Window : public QOpenGLWindow { Q_OBJECT public: - Window(int n) : idx(n) { - r = g = b = fps = 0; - y = 0; + Window(int index) : windowNumber(index + 1), y(0), fps(0) { + + color = QColor::fromHsl((index * 30) % 360, 255, 127).toRgb(); + resize(200, 200); + setObjectName(QString("Window %1").arg(windowNumber)); + connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped())); fpsTimer.start(); } void paintGL() { QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glClearColor(r, g, b, 1); + f->glClearColor(color.redF(), color.greenF(), color.blueF(), 1); f->glClear(GL_COLOR_BUFFER_BIT); - switch (idx % 3) { - case 0: - r += 0.005f; - break; - case 1: - g += 0.005f; - break; - case 2: - b += 0.005f; - break; - } - if (r > 1) - r = 0; - if (g > 1) - g = 0; - if (b > 1) - b = 0; QPainter p(this); p.setPen(Qt::white); - p.drawText(QPoint(20, y), QString(QLatin1String("Window %1 (%2 FPS)")).arg(idx).arg(fps)); + p.drawText(QPoint(20, y), QString(QLatin1String("Window %1 (%2 FPS)")).arg(windowNumber).arg(fps)); y += 1; if (y > height() - 20) y = 20; @@ -118,9 +97,17 @@ public slots: } } +protected: + void mousePressEvent(QMouseEvent *event) { + qDebug() << this << event; + color.setHsl((color.hue() + 90) % 360, color.saturation(), color.lightness()); + color = color.toRgb(); + } + private: - int idx; - GLfloat r, g, b; + int windowNumber; + QColor color; + int y; int framesSwapped; @@ -163,7 +150,7 @@ int main(int argc, char **argv) int numberOfWindows = qMax(parser.value(numWindowsOption).toInt(), 1); QList<QWindow *> windows; for (int i = 0; i < numberOfWindows; ++i) { - Window *w = new Window(i + 1); + Window *w = new Window(i); windows << w; if (i == 0 && parser.isSet(vsyncOneOption)) { |