diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-11-30 00:51:32 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-11-30 00:51:32 +0000 |
commit | 498ef7f9d77fca75bcba2f657aaac38c8dc78aea (patch) | |
tree | 025636092945c4d8c0e9de6fa69db15da204b648 /examples/touch/pinchzoom/mouse.cpp | |
parent | 4d0add31fd0a69aca7c7c852f22531dd98922c62 (diff) | |
parent | 153e8b49adfe210cb00490284a14c94c08e03c3f (diff) |
Merge "Merge remote-tracking branch 'origin/5.10' into dev" into refs/staging/dev
Diffstat (limited to 'examples/touch/pinchzoom/mouse.cpp')
-rw-r--r-- | examples/touch/pinchzoom/mouse.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/examples/touch/pinchzoom/mouse.cpp b/examples/touch/pinchzoom/mouse.cpp index 7f8c238e6f..1e6814be13 100644 --- a/examples/touch/pinchzoom/mouse.cpp +++ b/examples/touch/pinchzoom/mouse.cpp @@ -52,6 +52,7 @@ #include <QGraphicsScene> #include <QPainter> +#include <QRandomGenerator> #include <QStyleOption> #include <qmath.h> @@ -70,9 +71,9 @@ static qreal normalizeAngle(qreal angle) //! [0] Mouse::Mouse() : angle(0), speed(0), mouseEyeDirection(0), - color(qrand() % 256, qrand() % 256, qrand() % 256) + color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) { - setTransform(QTransform().rotate(qrand() % (360 * 16)), true); + setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true); startTimer(1000 / 33); } //! [0] @@ -184,16 +185,16 @@ void Mouse::timerEvent(QTimerEvent *) // Add some random movement //! [10] - if (dangerMice.size() > 1 && (qrand() % 10) == 0) { - if (qrand() % 1) - angle += (qrand() % 100) / 500.0; + if (dangerMice.size() > 1 && QRandomGenerator::global()->bounded(10) == 0) { + if (QRandomGenerator::global()->bounded(1)) + angle += QRandomGenerator::global()->bounded(1 / 500.0); else - angle -= (qrand() % 100) / 500.0; + angle -= QRandomGenerator::global()->bounded(1 / 500.0); } //! [10] //! [11] - speed += (-50 + qrand() % 100) / 100.0; + speed += (-50 + QRandomGenerator::global()->bounded(100)) / 100.0; qreal dx = ::sin(angle) * 10; mouseEyeDirection = (qAbs(dx / 5) < 1) ? 0 : dx / 5; |