diff options
| author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-07-13 20:39:05 +0200 |
|---|---|---|
| committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-08-17 09:51:32 +0200 |
| commit | 13426aff248c25b44ac377f37dc3e3a54ea0ea86 (patch) | |
| tree | 18dfc93c88f5a06460c9adddb681901711dacd30 /examples/widgets/animation/stickman/stickman.cpp | |
| parent | cb3e1e551f340ce1e6280123d8b5411b3c1c96d8 (diff) | |
Cleanup QtWidgets animation examples
Cleanup the QtWidgets animation examples:
- use nullptr
- use normalized includes, remove unused includes
- fix style
- fix crash of sub-attaq when the game ended (error during range-based
for loop porting)
- don't use keyword 'final' for a variable name
Change-Id: Id23be8ff8b1b310da005d13c052fe547f6a0d63a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/widgets/animation/stickman/stickman.cpp')
| -rw-r--r-- | examples/widgets/animation/stickman/stickman.cpp | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp index 5725f64eec2..3f373b6b52f 100644 --- a/examples/widgets/animation/stickman/stickman.cpp +++ b/examples/widgets/animation/stickman/stickman.cpp @@ -52,10 +52,9 @@ #include "node.h" #include <QPainter> -#include <QTimer> -#include <qmath.h> +#include <QtMath> -static const qreal Coords[NodeCount * 2] = { +static constexpr qreal Coords[NodeCount * 2] = { 0.0, -150.0, // head, #0 0.0, -100.0, // body pentagon, top->bottom, left->right, #1 - 5 @@ -81,7 +80,7 @@ static const qreal Coords[NodeCount * 2] = { }; -static const int Bones[BoneCount * 2] = { +static constexpr int Bones[BoneCount * 2] = { 0, 1, // neck 1, 2, // body @@ -117,19 +116,13 @@ static const int Bones[BoneCount * 2] = { StickMan::StickMan() { - m_sticks = true; - m_isDead = false; - m_pixmap = QPixmap("images/head.png"); - m_penColor = Qt::white; - m_fillColor = Qt::black; - // Set up start position of limbs - for (int i=0; i<NodeCount; ++i) { + for (int i = 0; i < NodeCount; ++i) { m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this); connect(m_nodes[i], &Node::positionChanged, this, &StickMan::childPositionChanged); } - for (int i=0; i<BoneCount; ++i) { + for (int i = 0; i < BoneCount; ++i) { int n1 = Bones[i * 2]; int n2 = Bones[i * 2 + 1]; @@ -137,16 +130,12 @@ StickMan::StickMan() Node *node2 = m_nodes[n2]; QPointF dist = node1->pos() - node2->pos(); - m_perfectBoneLengths[i] = sqrt(pow(dist.x(),2) + pow(dist.y(),2)); + m_perfectBoneLengths[i] = sqrt(pow(dist.x(), 2) + pow(dist.y(), 2)); } startTimer(10); } -StickMan::~StickMan() -{ -} - void StickMan::childPositionChanged() { prepareGeometryChange(); @@ -155,7 +144,7 @@ void StickMan::childPositionChanged() void StickMan::setDrawSticks(bool on) { m_sticks = on; - for (int i=0;i<nodeCount();++i) { + for (int i = 0; i < nodeCount(); ++i) { Node *node = m_nodes[i]; node->setVisible(on); } @@ -188,7 +177,7 @@ void StickMan::stabilize() { static const qreal threshold = 0.001; - for (int i=0; i<BoneCount; ++i) { + for (int i = 0; i < BoneCount; ++i) { int n1 = Bones[i * 2]; int n2 = Bones[i * 2 + 1]; @@ -236,7 +225,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge stabilize(); if (m_sticks) { painter->setPen(Qt::white); - for (int i=0; i<BoneCount; ++i) { + for (int i = 0; i < BoneCount; ++i) { int n1 = Bones[i * 2]; int n2 = Bones[i * 2 + 1]; |
