267 lines
7.3 KiB
C++
267 lines
7.3 KiB
C++
#include "windowrace.h"
|
|
#include "ui_windowrace.h"
|
|
#include <QObject>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#define FAHRZEIT 5;
|
|
|
|
using std::vector;
|
|
|
|
WindowRace::WindowRace(DataBase *db, QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::WindowRace)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
this->ui->pBNextRace->setEnabled(false);
|
|
|
|
this->finished = false;
|
|
|
|
this->db = db;
|
|
|
|
vector< vector< QString > > res;
|
|
res = db->getData("select id from fahrer", 1);
|
|
|
|
vector< vector< QString > > res2;
|
|
res2 = db->getData("select id from fahrer", 1);
|
|
firstTimeDea = true;
|
|
firstTimeShell = true;
|
|
started = false;
|
|
countdownValue = FAHRZEIT;
|
|
countdown = new Countdown;
|
|
|
|
startAmpelThread = new Ampel;
|
|
ampelCounter = 0;
|
|
|
|
ui->pBStart->setFocus();
|
|
|
|
paused = false;
|
|
|
|
Hardware = new HardwareSetup;
|
|
Hardware->start();
|
|
QObject::connect(Hardware, SIGNAL(Dea()), this, SLOT(deaSlot()));
|
|
QObject::connect(Hardware, SIGNAL(Shell()), this, SLOT(shellSlot()));
|
|
QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
|
|
QObject::connect(countdown, SIGNAL(CountdownUpdate()), this, SLOT(countdownUpdate()));
|
|
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(ampelSlot()));
|
|
QObject::connect(startAmpelThread, SIGNAL(ampelUpdate()), this, SLOT(laufcheck()));
|
|
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this, SLOT(breakCounter()));
|
|
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this, SLOT(prepareNextRace()));
|
|
|
|
|
|
|
|
|
|
ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
|
|
//Ampelsetup
|
|
ui->WAmpel15->hide();
|
|
ui->WAmpel25->hide();
|
|
ui->hW15->setVisible(true);
|
|
ui->hW25->setVisible(true);
|
|
ui->WAmpel14->hide();
|
|
ui->WAmpel24->hide();
|
|
ui->hW14->setVisible(true);
|
|
ui->hW24->setVisible(true);
|
|
ui->WAmpel13->hide();
|
|
ui->WAmpel23->hide();
|
|
ui->hW13->setVisible(true);
|
|
ui->hW23->setVisible(true);
|
|
ui->WAmpel12->hide();
|
|
ui->WAmpel22->hide();
|
|
ui->hW12->setVisible(true);
|
|
ui->hw22->setVisible(true);
|
|
ui->WAmpel11->hide();
|
|
ui->WAmpel21->hide();
|
|
ui->hW11->setVisible(true);
|
|
ui->hW21->setVisible(true);
|
|
|
|
}
|
|
void WindowRace::prepareNextRace(){
|
|
this->finished = false;
|
|
this->paused = false;
|
|
this->countdownValue = FAHRZEIT;
|
|
this->ampelCounter = 0;
|
|
this->startAmpelThread->terminate();
|
|
this->countdown->terminate();
|
|
this->ui->pBNextRace->setEnabled(false);
|
|
this->ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
}
|
|
|
|
void WindowRace::setWindowRennliste(WindowRennliste *ptrInstance){
|
|
this->wRennliste = ptrInstance;
|
|
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste, SLOT(changeSelection()));
|
|
}
|
|
|
|
void WindowRace::breakCounter(){
|
|
if(!paused){
|
|
paused = true;
|
|
ui->pBBreak->setText("Weiter");
|
|
}
|
|
else{
|
|
ui->pBBreak->setText("Pause");
|
|
paused = false;
|
|
}
|
|
|
|
}
|
|
|
|
void WindowRace::laufcheck(){
|
|
//std::cout << "thread lauft noch" << std::endl;
|
|
}
|
|
|
|
QString WindowRace::timeWrapper(long zahl){
|
|
|
|
long min = zahl / 60;
|
|
int sec = zahl % 60;
|
|
QString sec_q;
|
|
if(sec < 10){
|
|
sec_q = "0"+QString::number(sec);
|
|
}
|
|
else{
|
|
sec_q = QString::number(sec);
|
|
}
|
|
QString min_q = QString::number(min);
|
|
return min_q+":"+sec_q;
|
|
}
|
|
|
|
void WindowRace::countdownUpdate(){
|
|
if(!paused){
|
|
countdownValue -= 1;
|
|
if(countdownValue <= 15){
|
|
ui->lCountdown->setStyleSheet("QLabel { color: red; }");
|
|
}
|
|
if(countdownValue <= -1){
|
|
this->finished = true;
|
|
this->ui->pBNextRace->setEnabled(true);
|
|
}
|
|
else{
|
|
ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
}
|
|
}
|
|
}
|
|
|
|
WindowRace::~WindowRace()
|
|
{
|
|
delete ui;
|
|
}
|
|
void WindowRace::shellSlot(){
|
|
if(started && !paused && !this->finished){
|
|
if(firstTimeShell){
|
|
firstTimeShell = false;
|
|
counterShell.start();
|
|
}
|
|
else{
|
|
long zeit = counterShell.getTime();
|
|
VecShell.push_back(zeit);
|
|
QListWidgetItem *item = new QListWidgetItem;
|
|
if(getMinimum(VecShell) == zeit && VecShell.size() > 1){
|
|
item->setBackgroundColor(Qt::green);
|
|
}
|
|
item->setText(QString::number((double)zeit/1000));
|
|
ui->lWShellTime->addItem(item);
|
|
ui->lWShellTime->scrollToBottom();
|
|
ui->lBestZeitShell->setText(QString::number((double)getMinimum(VecShell)/1000));
|
|
ui->lCurRoundTimeShell->setText(QString::number((double)zeit/1000));
|
|
}
|
|
}
|
|
}
|
|
void WindowRace::deaSlot(){
|
|
if(started && !paused && !this->finished){
|
|
if(firstTimeDea){
|
|
firstTimeDea = false;
|
|
counterDea.start();
|
|
}
|
|
else{
|
|
long zeit = counterDea.getTime();
|
|
VecDea.push_back(zeit);
|
|
QListWidgetItem *item = new QListWidgetItem;
|
|
if(getMinimum(VecDea) == zeit && VecDea.size() > 1){
|
|
item->setBackgroundColor(Qt::green);
|
|
}
|
|
item->setText(QString::number((double)zeit/1000));
|
|
ui->lWDeaTime->addItem(item);
|
|
ui->lWDeaTime->scrollToBottom();
|
|
ui->lBestZeitDea->setText(QString::number((double)getMinimum(VecDea)/1000));
|
|
ui->lCurRoundDea->setText(QString::number((double)zeit/1000));
|
|
}
|
|
}
|
|
}
|
|
|
|
long WindowRace::getMinimum(std::vector<long> a){
|
|
long minimum = a[0];
|
|
for(unsigned int i = 0; i < a.size(); i++){
|
|
if(a[i] < minimum){
|
|
minimum = a[i];
|
|
}
|
|
}
|
|
return minimum;
|
|
}
|
|
void WindowRace::ampelSlot(){
|
|
if(ampelCounter == 5){
|
|
ui->WAmpel15->hide();
|
|
ui->WAmpel25->hide();
|
|
ui->hW15->setVisible(true);
|
|
ui->hW25->setVisible(true);
|
|
ui->WAmpel14->hide();
|
|
ui->WAmpel24->hide();
|
|
ui->hW14->setVisible(true);
|
|
ui->hW24->setVisible(true);
|
|
ui->WAmpel13->hide();
|
|
ui->WAmpel23->hide();
|
|
ui->hW13->setVisible(true);
|
|
ui->hW23->setVisible(true);
|
|
ui->WAmpel12->hide();
|
|
ui->WAmpel22->hide();
|
|
ui->hW12->setVisible(true);
|
|
ui->hw22->setVisible(true);
|
|
ui->WAmpel11->hide();
|
|
ui->WAmpel21->hide();
|
|
ui->hW11->setVisible(true);
|
|
ui->hW21->setVisible(true);
|
|
startAmpelThread->terminate();
|
|
started = true;
|
|
countdown->start();
|
|
}
|
|
if(ampelCounter == 4){
|
|
ampelCounter = 5;
|
|
ui->WAmpel15->setVisible(true);
|
|
ui->WAmpel25->setVisible(true);
|
|
ui->hW15->hide();
|
|
ui->hW25->hide();
|
|
}
|
|
if(ampelCounter == 3){
|
|
ampelCounter = 4;
|
|
ui->WAmpel14->setVisible(true);
|
|
ui->WAmpel24->setVisible(true);
|
|
ui->hW14->hide();
|
|
ui->hW24->hide();
|
|
}
|
|
if(ampelCounter == 2){
|
|
ampelCounter = 3;
|
|
ui->WAmpel13->setVisible(true);
|
|
ui->WAmpel23->setVisible(true);
|
|
ui->hW13->hide();
|
|
ui->hW23->hide();
|
|
}
|
|
if(ampelCounter == 1){
|
|
ampelCounter = 2;
|
|
ui->WAmpel12->setVisible(true);
|
|
ui->WAmpel22->setVisible(true);
|
|
ui->hW12->hide();
|
|
ui->hw22->hide();
|
|
}
|
|
if(ampelCounter == 0){
|
|
ampelCounter = 1;
|
|
ui->WAmpel11->setVisible(true);
|
|
ui->WAmpel21->setVisible(true);
|
|
ui->hW11->hide();
|
|
ui->hW21->hide();
|
|
}
|
|
|
|
}
|
|
|
|
void WindowRace::go(){
|
|
startAmpelThread->start();
|
|
|
|
}
|