void MainWindowCar::setupImages() {
QPixmap p (":/Img/road.png");
if(!ui->Background->scene()) {
QGraphicsScene * s = new QGraphicsScene(this);
ui->Background->setScene(s);
}
ui->Background->scene()->addPixmap(p);
code
//preload car images
this->carIcon1 = QIcon(":/Img/mypolice.png");
this->carIcon2 = QIcon(":/Img/mypolice2.png");
this->updateCar();
}
void MainWindowCar::updateCar() {
code
//code to substitute image of a car
//each run to change image to another
if (this->carOneOrTwo)
ui->PushCar->setIcon(this->carIcon1);
else
ui->PushCar->setIcon(this->carIcon2);
carOneOrTwo = !carOneOrTwo;
ui->PushCar->setIconSize(QSize(100, 200));
//this->ui->pushButtonStart->setVisible(false);
int frame = 0;
bool ok = true;
this->car->setA(this->ui->lineEditAccel->text().toDouble(&ok));
if (!ok) {
QMessageBox::warning(this, "Error", "Please enter a good number for acceleration!");
return;
}
ok = true;
this->car->setMaxSpeed(this->ui->lineEditMaxSpeed->text().toDouble(&ok));
if (!ok) {
QMessageBox::warning(this, "Error", "Please enter a good number for max speed!");
return;
}
this->isStopped = false;
this->ui->pushButtonStart->setEnabled(false);
this->ui->lineEditAccel->setEnabled(false);
this->ui->lineEditMaxSpeed->setEnabled(false);
while(!this->isStopped) {
QCoreApplication::processEvents();
QThread::currentThread()->msleep(100);
this->stepUi();
if (frame % 5 == 0) this->updateCar(); //update each 5th frame
car->step();
qDebug() << car->getV();
frame++;
}