diff options
Diffstat (limited to 'examples/widgets/tools')
3 files changed, 11 insertions, 13 deletions
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp index c929ff6922..92620ddd8c 100644 --- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp +++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp @@ -50,13 +50,11 @@ #include <QtWidgets> -#include <cmath> +#include <qmath.h> #include <stdlib.h> #include "basictoolsplugin.h" -const float Pi = 3.14159f; - //! [0] QStringList BasicToolsPlugin::brushes() const { @@ -103,7 +101,7 @@ QRect BasicToolsPlugin::mouseMove(const QString &brush, QPainter &painter, thickness, thickness); } } else if (brush == tr("Random Letters")) { - QChar ch('A' + (qrand() % 26)); + QChar ch(QRandomGenerator::global()->bounded('A', 'Z' + 1)); QFont biggerFont = painter.font(); biggerFont.setBold(true); @@ -149,8 +147,8 @@ QPainterPath BasicToolsPlugin::generateShape(const QString &shape, } else if (shape == tr("Star")) { path.moveTo(90, 50); for (int i = 1; i < 5; ++i) { - path.lineTo(50 + 40 * std::cos(0.8 * i * Pi), - 50 + 40 * std::sin(0.8 * i * Pi)); + path.lineTo(50 + 40 * std::cos(0.8 * i * M_PI), + 50 + 40 * std::sin(0.8 * i * M_PI)); } path.closeSubpath(); } else if (shape == tr("Text...")) { diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp index aa570caa80..5976163f3f 100644 --- a/examples/widgets/tools/undo/mainwindow.cpp +++ b/examples/widgets/tools/undo/mainwindow.cpp @@ -52,6 +52,7 @@ #include <QUndoStack> #include <QFileDialog> #include <QMessageBox> +#include <QRandomGenerator> #include <QTextStream> #include <QToolButton> #include "document.h" @@ -321,7 +322,7 @@ void MainWindow::newDocument() static QColor randomColor() { - int r = (int) (3.0*(rand()/(RAND_MAX + 1.0))); + int r = QRandomGenerator::global()->bounded(3); switch (r) { case 0: return Qt::red; @@ -337,10 +338,10 @@ static QRect randomRect(const QSize &s) { QSize min = Shape::minSize; - int left = (int) ((0.0 + s.width() - min.width())*(rand()/(RAND_MAX + 1.0))); - int top = (int) ((0.0 + s.height() - min.height())*(rand()/(RAND_MAX + 1.0))); - int width = (int) ((0.0 + s.width() - left - min.width())*(rand()/(RAND_MAX + 1.0))) + min.width(); - int height = (int) ((0.0 + s.height() - top - min.height())*(rand()/(RAND_MAX + 1.0))) + min.height(); + int left = (int) ((0.0 + s.width() - min.width())*(QRandomGenerator::global()->bounded(1.0))); + int top = (int) ((0.0 + s.height() - min.height())*(QRandomGenerator::global()->bounded(1.0))); + int width = (int) ((0.0 + s.width() - left - min.width())*(QRandomGenerator::global()->bounded(1.0))) + min.width(); + int height = (int) ((0.0 + s.height() - top - min.height())*(QRandomGenerator::global()->bounded(1.0))) + min.height(); return QRect(left, top, width, height); } diff --git a/examples/widgets/tools/undoframework/diagramitem.cpp b/examples/widgets/tools/undoframework/diagramitem.cpp index 754baa2377..723645c9b2 100644 --- a/examples/widgets/tools/undoframework/diagramitem.cpp +++ b/examples/widgets/tools/undoframework/diagramitem.cpp @@ -65,8 +65,7 @@ DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item) setPolygon(trianglePolygon); } - QColor color(static_cast<int>(qrand()) % 256, - static_cast<int>(qrand()) % 256, static_cast<int>(qrand()) % 256); + QColor color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)); QBrush brush(color); setBrush(brush); setFlag(QGraphicsItem::ItemIsSelectable); |