-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcar.h
111 lines (95 loc) · 2.79 KB
/
car.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef CAR_H
#define CAR_H
#include <QGraphicsPixmapItem>
#include <QPixmap>
#include <QString>
#include <QPoint>
#include <QtMath>
#include <QPropertyAnimation>
#include <QObject>
#include <QTime>
#include <QGraphicsSceneMouseEvent>
#include "path.h"
#include "parkingLotManager.h"
class ParkingLotManager;
//车身长宽
#define M_LEN (60)
#define M_WID (40)
class Car : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF m_pos READ getmPos WRITE setmPos)
Q_PROPERTY(int m_dir READ getDir WRITE setRotation)
public:
enum Status {waiting, moving, parking};
enum Color { Pink, Red, Yellow, RANDOM };
enum { Type = UserType + 3 };
explicit Car(ParkingLotManager * manager, QGraphicsItem *parent = Q_NULLPTR,
int dir = 0, Car::Color color = RANDOM);
//基础移动
void Forward(qreal vel = 3); //前进
void Backward(qreal vel = 3); //后退
void moveLeft(qreal vel = 3); //向左平移
void moveRight(qreal vel = 3); //向右平移
void Rotate(qreal ang = 30); //原地旋转
void turnLeft(int r, double ang); //左转
void turnRight(int r, double ang); //右转
void setPath(Path *path);
int getNum();
void setNum(int value);
int getEntryNum();
void setEntryNum(int value);
int getTargetFloor() const;
void setTargetFloor(int value);
int getCurrentFloor() const;
void setCurrentFloor(int value);
//动画
void moveTo(QPointF target);
void followPath();
//为了Property
QPointF getmPos();
void setmPos(QPointF pos);
Color getColor();
qreal getDir();
QPropertyAnimation *posAni;
QString getPosition() const;
QString getPlateNumber() const;
QString getFee() const;
Status getStatus() const;
void setStatus(const Status &value);
QTime getStartTime() const;
void setStartTime(const QTime &value);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
int type() const;
void leaveProbability(int p);
void setPlateNumber(const QString &number);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void requestSpace(void);
void go(void);
bool requested = false;
private:
Status m_status;
Color m_color; //车身颜色 N为0, 顺时针递增
QPixmap m_pic;
QString m_number;
QPointF m_pos;
qreal m_dir;
Path *m_path;
PathPoint m_target;
PathPoint m_current;
int entryNum;
int targetFloor;
int currentFloor;
int num;
QTime startTime;
ParkingLotManager* m_manager;
bool crash;
signals:
void entry(Car* car);
void stair(Car* car);
void exit(Car* car);
void queueHead(Car* car);
void out(Car *car ,int);
void back(Car*);
};
#endif // CAR_H