| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#ifndef CAR_H |
| 5 |
#define CAR_H |
| 6 |
|
| 7 |
#include <QGraphicsObject> |
| 8 |
#include <QBrush> |
| 9 |
|
| 10 |
class Car : public QGraphicsObject |
| 11 |
{ |
| 12 |
Q_OBJECT |
| 13 |
public: |
| 14 |
Car(); |
| 15 |
QRectF boundingRect() const override; |
| 16 |
|
| 17 |
public slots: |
| 18 |
void accelerate(); |
| 19 |
void decelerate(); |
| 20 |
void turnLeft(); |
| 21 |
void turnRight(); |
| 22 |
|
| 23 |
protected: |
| 24 |
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, |
| 25 |
QWidget *widget = nullptr) override; |
| 26 |
void timerEvent(QTimerEvent *event) override; |
| 27 |
|
| 28 |
private: |
| 29 |
QBrush color = Qt::green; |
| 30 |
qreal wheelsAngle = 0; // used when applying rotation |
| 31 |
qreal speed = 0; // delta movement along the body axis |
| 32 |
}; |
| 33 |
|
| 34 |
#endif // CAR_H |