/
mainwindow.cpp
89 lines (75 loc) · 2.26 KB
/
mainwindow.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
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
#include "mainwindow.h"
#include "trafficLightLayout.h"
#include "mythread.h"
#include <QGridLayout>
#include <QLabel>
#include <QImage>
#include <QDir>
MainWindow::MainWindow(int argc, char** argv, std::string& imageDir)
: QMainWindow(nullptr), imageDir(imageDir)
{
setup();
MyThread::Instance().argcnt = argc;
MyThread::Instance().argvv = argv;
MyThread::Instance().start();
connect(&MyThread::Instance(), SIGNAL(OnRedLight()), this, SLOT(TurnOnRedLight()));
connect(&MyThread::Instance(), SIGNAL(OnYellowLight()), this, SLOT(TurnOnYellowLight()));
connect(&MyThread::Instance(), SIGNAL(OnGreenLight()), this, SLOT(TurnOnGreenLight()));
connect(&MyThread::Instance(), SIGNAL(OnStop()), this, SLOT(TurnOnStop()));
connect(&MyThread::Instance(), SIGNAL(OnWalk()), this, SLOT(TurnOnWalk()));
connect(mButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::TurnOnRedLight()
{
widget.turnOffGreen();
widget.turnOffYellow();
widget.turnOnRed();
}
void MainWindow::TurnOnYellowLight()
{
widget.turnOffGreen();
widget.turnOffRed();
widget.turnOnYellow();
}
void MainWindow::TurnOnGreenLight()
{
widget.turnOffRed();
widget.turnOffYellow();
widget.turnOnGreen();
}
void MainWindow::TurnOnStop()
{
std::string path = imageDir + "/stop.png";
QPixmap pixMap(path.c_str());
image->setPixmap(pixMap);
}
void MainWindow::TurnOnWalk()
{
std::string path = imageDir + "/walk.png";
QPixmap pixMap(path.c_str());
image->setPixmap(pixMap);
}
void MainWindow::setup()
{
QWidget *mainWidget = new QWidget();
mainWidget->setFixedSize(QSize(350,350));
mButton = new QPushButton("Pedestrian wants to cross", this);
QGridLayout *glayout = widget.getTrafficLightLayout();
glayout->addWidget(mButton, 1, 1);
glayout->addWidget(new QLabel("Push the button --->"), 1, 0);
image = new QLabel();
std::string path = imageDir + "/stop.png";
QPixmap pixMap(path.c_str());
image->setPixmap(pixMap);
image->setScaledContents(false);
glayout->addWidget(image, 0, 1);
mainWidget->setLayout(glayout);
setCentralWidget(mainWidget);
}
void MainWindow::onButtonClicked()
{
MyThread::Instance().pushButtonClicked();
}