void MainWindow::setWorld(World* world) { timer = new QTimer(this); this->world = world; pushButtons = new QPushButton*[world->getHeight() * world->getWidth()]; QPushButton* pushButton; for (int i =0;i<world->getHeight();i++) { for(int j=0;j < world->getWidth();j++) { pushButton = new QPushButton(ui->widget); pushButton->setGeometry(i*BUTTON_HEIGHT, j*BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_WIDTH); setButtonColor(pushButton, QString::fromStdString(deathColor)); pushButton->setProperty("cellPositionX", QVariant(i)); pushButton->setProperty("cellPositionY", QVariant(j)); QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(buttonChanged())); pushButtons[i * world->getHeight() + j] = pushButton; } } QObject::connect(ui->pushButtonStep, SIGNAL(clicked()), this, SLOT(doStepWorld())); QObject::connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(btnClear())); QObject::connect(ui->pushButtonRun, SIGNAL(clicked()), this, SLOT(btnRun())); QObject::connect(ui->pushButtonStop, SIGNAL(clicked()), this, SLOT(btnStop())); QObject::connect(ui->pushButtonRand, SIGNAL(clicked()), this, SLOT(btnRand())); setWindowTitle("The World of Empress"); world->doStep(); world->doStep(); updateView(); }
MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui -> btStart, SIGNAL(clicked()), this, SLOT(btnStart())); connect(ui -> btStop, SIGNAL(clicked()), this, SLOT(btnStop())); connect(ui -> btPause, SIGNAL(clicked()), this, SLOT(btnPause())); connect(ui -> btContinue, SIGNAL(clicked()), this, SLOT(btnContinue())); connect(ui -> btApllySets, SIGNAL(clicked()), this, SLOT(apllySets())); connect(ui -> sbInterval, SIGNAL(editingFinished()), this, SLOT(applySpeed())); connect(&timer, SIGNAL(timeout()), this, SLOT(timerEvent())); int rowsNum = ui -> samplesNumEdit -> value(); ui -> samplesTable -> setRowCount(rowsNum); for(int i = 0; i < rowsNum; ++i) { ui -> samplesTable -> setItem(i, 0, new QTableWidgetItem(QString::number(0.0))); ui -> samplesTable -> setItem(i, 1, new QTableWidgetItem(QString::number(0.0))); } timer.setInterval(200); timer.stop(); ui -> lStatus -> setText("<font color=\"red\">Stopped</font>"); apllySets(); }