diff options
Diffstat (limited to 'examples/widgets')
9 files changed, 32 insertions, 54 deletions
diff --git a/examples/widgets/doc/src/painterpaths.qdoc b/examples/widgets/doc/src/painterpaths.qdoc index 2cc5ff410a..bd821ac1bf 100644 --- a/examples/widgets/doc/src/painterpaths.qdoc +++ b/examples/widgets/doc/src/painterpaths.qdoc @@ -98,14 +98,9 @@ \section1 Window Class Implementation - In the implementation of the \c Window class we first declare the - constant \c Pi with six significant figures: - - \snippet painting/painterpaths/window.cpp 0 - - In the constructor, we then define the various painter paths and - create corresponding \c RenderArea widgets which will render the - graphical shapes: + In the \c Window constructor, we define the various painter paths + and create corresponding \c RenderArea widgets which will render + the graphical shapes: \snippet painting/painterpaths/window.cpp 1 diff --git a/examples/widgets/effects/blurpicker/blurpicker.cpp b/examples/widgets/effects/blurpicker/blurpicker.cpp index 43823bed30..a00af2144a 100644 --- a/examples/widgets/effects/blurpicker/blurpicker.cpp +++ b/examples/widgets/effects/blurpicker/blurpicker.cpp @@ -52,13 +52,9 @@ #include <QtWidgets> #include <QtCore/qmath.h> - +#include <qmath.h> #include "blureffect.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index") { setBackgroundBrush(QPixmap(":/images/background.jpg")); @@ -84,9 +80,10 @@ void BlurPicker::setIndex(qreal index) m_index = index; qreal baseline = 0; + const qreal iconAngle = 2 * M_PI / m_icons.count(); for (int i = 0; i < m_icons.count(); ++i) { QGraphicsItem *icon = m_icons[i]; - qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count(); + qreal a = (i + m_index) * iconAngle; qreal xs = 170 * qSin(a); qreal ys = 100 * qCos(a); QPointF pos(xs, ys); diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 9ac429c667..31b9553c75 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -52,7 +52,7 @@ #include "scene.h" #include <QtGui/qmatrix4x4.h> #include <QtGui/qvector3d.h> -#include <cmath> +#include <qmath.h> #include "3rdparty/fbm.h" @@ -868,11 +868,12 @@ void Scene::renderCubemaps() QVector3D center; + const float eachAngle = 2 * M_PI / m_cubemaps.size(); for (int i = m_frame % N; i < m_cubemaps.size(); i += N) { if (0 == m_cubemaps[i]) continue; - float angle = 2.0f * PI * i / m_cubemaps.size(); + float angle = i * eachAngle; center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f)); diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h index a2ba1d0b5a..ccb6f368cd 100644 --- a/examples/widgets/graphicsview/boxes/scene.h +++ b/examples/widgets/graphicsview/boxes/scene.h @@ -63,8 +63,6 @@ #include "glbuffers.h" #include "qtbox.h" -#define PI 3.14159265358979 - QT_BEGIN_NAMESPACE class QMatrix4x4; QT_END_NAMESPACE diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp index cc1a15cd82..298e4aae64 100644 --- a/examples/widgets/graphicsview/collidingmice/mouse.cpp +++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp @@ -53,11 +53,10 @@ #include <QGraphicsScene> #include <QPainter> #include <QStyleOption> +#include <qmath.h> -#include <cmath> - -static const double Pi = 3.14159265358979323846264338327950288419717; -static double TwoPi = 2.0 * Pi; +const qreal Pi = M_PI; +const qreal TwoPi = 2 * M_PI; static qreal normalizeAngle(qreal angle) { diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp index ae7fa7af90..88160d9399 100644 --- a/examples/widgets/graphicsview/diagramscene/arrow.cpp +++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp @@ -51,13 +51,10 @@ #include "arrow.h" -#include <cmath> - +#include <qmath.h> #include <QPen> #include <QPainter> -const qreal Pi = 3.14; - //! [0] Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent) : QGraphicsLineItem(parent) @@ -134,10 +131,10 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, double angle = std::atan2(-line().dy(), line().dx()); - QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, - cos(angle + Pi / 3) * arrowSize); - QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, - cos(angle + Pi - Pi / 3) * arrowSize); + QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp index d9e4c62e34..aec12b4225 100644 --- a/examples/widgets/graphicsview/elasticnodes/edge.cpp +++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp @@ -51,12 +51,9 @@ #include "edge.h" #include "node.h" -#include <cmath> - +#include <qmath.h> #include <QPainter> -static const double Pi = 3.14159265358979323846264338327950288419717; - //! [0] Edge::Edge(Node *sourceNode, Node *destNode) : arrowSize(10) @@ -140,14 +137,14 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) // Draw the arrows double angle = std::atan2(-line.dy(), line.dx()); - QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize, - cos(angle + Pi / 3) * arrowSize); - QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, - cos(angle + Pi - Pi / 3) * arrowSize); - QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize, - cos(angle - Pi / 3) * arrowSize); - QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize, - cos(angle - Pi + Pi / 3) * arrowSize); + QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); + QPointF destArrowP1 = destPoint + QPointF(sin(angle - M_PI / 3) * arrowSize, + cos(angle - M_PI / 3) * arrowSize); + QPointF destArrowP2 = destPoint + QPointF(sin(angle - M_PI + M_PI / 3) * arrowSize, + cos(angle - M_PI + M_PI / 3) * arrowSize); painter->setBrush(Qt::black); painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2); diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp index 7122411a6c..a987937b39 100644 --- a/examples/widgets/painting/painterpaths/window.cpp +++ b/examples/widgets/painting/painterpaths/window.cpp @@ -53,11 +53,7 @@ #include <QtWidgets> -#include <cmath> - -//! [0] -const float Pi = 3.14159f; -//! [0] +#include <qmath.h> //! [1] Window::Window() @@ -133,8 +129,8 @@ Window::Window() QPainterPath starPath; starPath.moveTo(90, 50); for (int i = 1; i < 5; ++i) { - starPath.lineTo(50 + 40 * std::cos(0.8 * i * Pi), - 50 + 40 * std::sin(0.8 * i * Pi)); + starPath.lineTo(50 + 40 * std::cos(0.8 * i * M_PI), + 50 + 40 * std::sin(0.8 * i * M_PI)); } starPath.closeSubpath(); //! [9] diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp index c929ff6922..740d007d44 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 { @@ -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...")) { |