-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
113 lines (99 loc) · 3.21 KB
/
Copy pathmainwindow.cpp
File metadata and controls
113 lines (99 loc) · 3.21 KB
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
112
113
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Cria o trem com seu (ID, posição X, posição Y)
trem1 = new Trem(1,140,30);
trem2 = new Trem(2,270,30);
trem3 = new Trem(3,400,30);
trem4 = new Trem(4,200,150);
trem5 = new Trem(5,330,150);
/*
* Conecta o sinal UPDATEGUI à função UPDATEINTERFACE.
* Ou seja, sempre que o sinal UPDATEGUI foi chamado, será executada a função UPDATEINTERFACE.
* Os 3 parâmetros INT do sinal serão utilizados na função.
* Trem1 e Trem2 são os objetos que podem chamar o sinal. Se um outro objeto chamar o
* sinal UPDATEGUI, não haverá execução da função UPDATEINTERFACE
*/
connect(trem1,SIGNAL(updateGUI(int,int,int)),SLOT(updateInterface(int,int,int)));
connect(trem2,SIGNAL(updateGUI(int,int,int)),SLOT(updateInterface(int,int,int)));
connect(trem3,SIGNAL(updateGUI(int,int,int)),SLOT(updateInterface(int,int,int)));
connect(trem4,SIGNAL(updateGUI(int,int,int)),SLOT(updateInterface(int,int,int)));
connect(trem5,SIGNAL(updateGUI(int,int,int)),SLOT(updateInterface(int,int,int)));
trem1->start();
trem2->start();
trem3->start();
trem4->start();
trem5->start();
}
//Função que será executada quando o sinal UPDATEGUI for emitido
void MainWindow::updateInterface(int id, int x, int y){
switch(id){
case 1: //Atualiza a posição do objeto da tela (quadrado) que representa o trem1
ui->label_trem1->setGeometry(x,y,21,17);
break;
case 2: //Atualiza a posição do objeto da tela (quadrado) que representa o trem2
ui->label_trem2->setGeometry(x,y,21,17);
break;
case 3: //Atualiza a posição do objeto da tela (quadrado) que representa o trem2
ui->label_trem3->setGeometry(x,y,21,17);
break;
case 4: //Atualiza a posição do objeto da tela (quadrado) que representa o trem2
ui->label_trem4->setGeometry(x,y,21,17);
break;
case 5: //Atualiza a posição do objeto da tela (quadrado) que representa o trem2
ui->label_trem5->setGeometry(x,y,21,17);
break;
default:
break;
}
}
MainWindow::~MainWindow()
{
delete ui;
}
/*
* Ao clicar, trens começam execução
*/
//void MainWindow::on_pushButton_clicked()
//{
// trem1->start();
// trem2->start();
// trem3->start();
// trem4->start();
// trem5->start();
//}
/*
* Ao clicar, trens param execução
*/
//void MainWindow::on_pushButton_2_clicked()
//{
// trem1->terminate();
// trem2->terminate();
// trem3->terminate();
// trem4->terminate();
// trem5->terminate();
//}
void MainWindow::on_horizontalSlider_sliderMoved(int position)
{
trem1->setVelocidade(position);
}
void MainWindow::on_horizontalSlider_2_sliderMoved(int position)
{
trem2->setVelocidade(position);
}
void MainWindow::on_horizontalSlider_3_sliderMoved(int position)
{
trem3->setVelocidade(position);
}
void MainWindow::on_horizontalSlider_4_sliderMoved(int position)
{
trem4->setVelocidade(position);
}
void MainWindow::on_horizontalSlider_5_sliderMoved(int position)
{
trem5->setVelocidade(position);
}