-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
54 lines (43 loc) · 1.86 KB
/
main.cpp
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
#include <QtMath>
#include <QtWidgets>
#include "trafficlights.h"
#include "vehicles.h"
#include <QRandomGenerator>
static constexpr int VehicleCount = 3;
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
QGraphicsView view(&scene);
view.QWidget::setFixedSize(900, 700);
scene.setSceneRect(0, 0, 800, 600);
view.setRenderHint(QPainter::Antialiasing);
view.setBackgroundBrush(QPixmap("C:/Users/brand/Pictures/Intersection.png")); //fix this
for(int i = 0; i < VehicleCount; ++i) {
Vehicles *vehicle = new Vehicles;
scene.addItem(vehicle);
}
//slot and direction will be randomized for now, speed later.
//Trafficlights *tf1 = new Trafficlights;
//Trafficlights *tf2 = new Trafficlights;
//Trafficlights *tf3 = new Trafficlights;
//Trafficlights *tf4 = new Trafficlights;
view.setCacheMode(QGraphicsView::CacheBackground);
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
QPen border = QPen(Qt::transparent);
QLineF TopLine(scene.sceneRect().topLeft(), scene.sceneRect().topRight());
QLineF LeftLine(scene.sceneRect().topLeft(), scene.sceneRect().bottomLeft());
QLineF RightLine(scene.sceneRect().topRight(), scene.sceneRect().bottomRight());
QLineF BottomLine(scene.sceneRect().bottomLeft(), scene.sceneRect().bottomRight());
scene.addLine(TopLine, border);
scene.addLine(LeftLine, border);
scene.addLine(RightLine, border);
scene.addLine(BottomLine, border);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Traffic Simulator"));
view.show();
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, &scene, &QGraphicsScene::advance);
timer.start(1000 / 66);
return app.exec();
}