diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-11 16:16:29 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-10-11 16:23:19 +0200 |
commit | f4b4c4f79b629498f3cddbbc10df8c1b4d6020d9 (patch) | |
tree | 4119707660438ff58bd51f9cbe0f9e2a33f4b806 /examples/widgets/animation/stickman/animation.cpp | |
parent | 9bd6cec74dbbc5aece55dc0c8808494db29b9963 (diff) | |
parent | 93f2f33a49f6c96a4f94f344edf03164ed944d02 (diff) |
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I3a1d7673c3c20019ab12a2ea0a60f1619920a34c
Diffstat (limited to 'examples/widgets/animation/stickman/animation.cpp')
-rw-r--r-- | examples/widgets/animation/stickman/animation.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/examples/widgets/animation/stickman/animation.cpp b/examples/widgets/animation/stickman/animation.cpp index 5c2d1682af..73d79adc84 100644 --- a/examples/widgets/animation/stickman/animation.cpp +++ b/examples/widgets/animation/stickman/animation.cpp @@ -50,16 +50,13 @@ #include "animation.h" -#include <QPointF> -#include <QVector> #include <QIODevice> #include <QDataStream> class Frame { public: - Frame() { - } + Frame() = default; int nodeCount() const { @@ -85,9 +82,8 @@ private: QVector<QPointF> m_nodePositions; }; -Animation::Animation() +Animation::Animation() : m_currentFrame(0) { - m_currentFrame = 0; m_frames.append(new Frame); } @@ -103,6 +99,8 @@ void Animation::setTotalFrames(int totalFrames) while (totalFrames < m_frames.size()) delete m_frames.takeLast(); + + setCurrentFrame(m_currentFrame); } int Animation::totalFrames() const @@ -112,7 +110,7 @@ int Animation::totalFrames() const void Animation::setCurrentFrame(int currentFrame) { - m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0); + m_currentFrame = qBound(0, currentFrame, totalFrames() - 1); } int Animation::currentFrame() const @@ -177,18 +175,16 @@ void Animation::load(QIODevice *device) int frameCount; stream >> frameCount; - for (int i=0; i<frameCount; ++i) { - + for (int i = 0; i < frameCount; ++i) { int nodeCount; stream >> nodeCount; Frame *frame = new Frame; frame->setNodeCount(nodeCount); - for (int j=0; j<nodeCount; ++j) { + for (int j = 0; j < nodeCount; ++j) { QPointF pos; stream >> pos; - frame->setNodePos(j, pos); } |