blob: 94ff79e298fcee36f16c7437960be166c219d558 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef STICKMAN_H
#define STICKMAN_H
#include <QGraphicsObject>
static const int NodeCount = 16;
static const int BoneCount = 24;
class Node;
class StickMan: public QGraphicsObject
{
Q_OBJECT
Q_PROPERTY(QColor penColor WRITE setPenColor READ penColor)
Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
Q_PROPERTY(bool isDead WRITE setIsDead READ isDead)
public:
StickMan();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
int nodeCount() const;
Node *node(int idx) const;
void setDrawSticks(bool on);
bool drawSticks() const { return m_sticks; }
QColor penColor() const { return m_penColor; }
void setPenColor(const QColor &color) { m_penColor = color; }
QColor fillColor() const { return m_fillColor; }
void setFillColor(const QColor &color) { m_fillColor = color; }
bool isDead() const { return m_isDead; }
void setIsDead(bool isDead) { m_isDead = isDead; }
public slots:
void stabilize();
void childPositionChanged();
protected:
void timerEvent(QTimerEvent *e) override;
private:
QPointF posFor(int idx) const;
Node *m_nodes[NodeCount];
qreal m_perfectBoneLengths[BoneCount];
bool m_sticks = true;
bool m_isDead = false;
QColor m_penColor = Qt::white;
QColor m_fillColor = Qt::black;
};
#endif // STICKMAN_H
|