summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp10
-rw-r--r--examples/widgets/effects/lighting/lighting.cpp7
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp4
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp8
-rw-r--r--examples/widgets/itemviews/chart/pieview.cpp8
5 files changed, 12 insertions, 25 deletions
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
index 7a4629c4d2..b7a2d87ada 100644
--- a/examples/widgets/animation/stickman/stickman.cpp
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -53,13 +53,7 @@
#include <QPainter>
#include <QTimer>
-
-#define _USE_MATH_DEFINES
-#include <math.h>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
+#include <qmath.h>
static const qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
@@ -300,7 +294,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
QPointF dist = node2->pos() - node1->pos();
qreal sinAngle = dist.x() / sqrt(pow(dist.x(), 2) + pow(dist.y(), 2));
- qreal angle = asin(sinAngle) * 180.0 / M_PI;
+ qreal angle = qRadiansToDegrees(asin(sinAngle));
QPointF headPos = node1->pos();
painter->translate(headPos);
diff --git a/examples/widgets/effects/lighting/lighting.cpp b/examples/widgets/effects/lighting/lighting.cpp
index 68350f32b7..1ba7dd9ce7 100644
--- a/examples/widgets/effects/lighting/lighting.cpp
+++ b/examples/widgets/effects/lighting/lighting.cpp
@@ -49,14 +49,9 @@
****************************************************************************/
#include "lighting.h"
-
#include <QtWidgets>
#include <QtCore/qmath.h>
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
Lighting::Lighting(QWidget *parent): QGraphicsView(parent), angle(0.0)
{
setScene(&m_scene);
@@ -120,7 +115,7 @@ void Lighting::setupScene()
void Lighting::animate()
{
- angle += (M_PI / 30);
+ angle += qDegreesToRadians(qreal(6));
qreal xs = 200 * qSin(angle) - 40 + 25;
qreal ys = 200 * qCos(angle) - 40 + 25;
m_lightSource->setPos(xs, ys);
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp
index 1481292e76..851cd17796 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.cpp
+++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp
@@ -50,11 +50,11 @@
#include "glbuffers.h"
#include <QtGui/qmatrix4x4.h>
-
+#include <QtCore/qmath.h>
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
- const GLdouble ymax = zNear * tan(fovy * M_PI / 360.0);
+ const GLdouble ymax = zNear * tan(qDegreesToRadians(fovy) / 2.0);
const GLdouble ymin = -ymax;
const GLdouble xmin = ymin * aspect;
const GLdouble xmax = ymax * aspect;
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
index 15f3af77d1..c350f6adee 100644
--- a/examples/widgets/graphicsview/boxes/trackball.cpp
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -50,6 +50,7 @@
#include "trackball.h"
#include "scene.h"
+#include <qmath.h>
#include <cmath>
//============================================================================//
@@ -101,10 +102,11 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
case Plane:
{
QLineF delta(m_lastPos, p);
- m_angularVelocity = 180*delta.length() / (PI*msecs);
+ const float angleDelta = qRadiansToDegrees(float(delta.length()));
+ m_angularVelocity = angleDelta / msecs;
m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
m_axis = transformation.rotatedVector(m_axis);
- m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation;
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angleDelta) * m_rotation;
}
break;
case Sphere:
@@ -124,7 +126,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
currentPos3D.normalize();
m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
- float angle = 180 / PI * std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis)));
+ float angle = qRadiansToDegrees(std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis))));
m_angularVelocity = angle / msecs;
m_axis.normalize();
diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp
index 942bbe5ca5..3f85e397ee 100644
--- a/examples/widgets/itemviews/chart/pieview.cpp
+++ b/examples/widgets/itemviews/chart/pieview.cpp
@@ -49,12 +49,8 @@
****************************************************************************/
#include <QtWidgets>
+#include <qmath.h>
#include <cmath>
-
-#ifndef M_PI
-#define M_PI 3.1415927
-#endif
-
#include "pieview.h"
PieView::PieView(QWidget *parent)
@@ -125,7 +121,7 @@ QModelIndex PieView::indexAt(const QPoint &point) const
return QModelIndex();
// Determine the angle of the point.
- double angle = (180 / M_PI) * std::atan2(cy, cx);
+ double angle = qRadiansToDegrees(std::atan2(cy, cx));
if (angle < 0)
angle = 360 + angle;