summaryrefslogtreecommitdiffstats
path: root/examples/widgets/animation/stickman/animation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/animation/stickman/animation.cpp')
-rw-r--r--examples/widgets/animation/stickman/animation.cpp18
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);
}