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
|
#include <QtGui>
#include <iostream>
#include "window.h"
using namespace Qt;
window::window(QWidget *parent)
:QWidget(parent) {
conway=new Board();
lblCount= new QLabel (tr("Loop Count:"));
// lblCount->move(Board::LENGTH*5 + 10,60);
leditCount = new QLineEdit;
// leditCount->move(Board::LENGTH*5 + 30,60);
startButton = new QPushButton(tr("&Start"));
startButton->setDefault(true);
// startButton->move (20,Board::LENGTH*5 + 10);
closeButton = new QPushButton(tr("&Close"));
// closeButton->move (Board::LENGTH*5 + 10,40);
connect(startButton, SIGNAL(clicked()), this, SLOT(game()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
Count = 0;
QHBoxLayout *boardLayout = new QHBoxLayout ;
boardLayout->addWidget(conway);
QVBoxLayout *topLayout = new QVBoxLayout;
topLayout->addWidget(startButton);
topLayout->addWidget(closeButton);
QHBoxLayout *bottomLayout = new QHBoxLayout ;
bottomLayout->addWidget(lblCount);
bottomLayout->addWidget(leditCount);
bottomLayout->addStretch();
QVBoxLayout *optionLayout= new QVBoxLayout;
optionLayout->addLayout(topLayout);
optionLayout->addLayout(bottomLayout);
QHBoxLayout *mainLayout= new QHBoxLayout;
mainLayout->addLayout(boardLayout);
mainLayout->addLayout(optionLayout);
setLayout(mainLayout);
setWindowTitle(tr("Conway's Game of Life"));
setFixedHeight(sizeHint().height());
}
void window::game() {
//std::cout << "I'm in" << std::endl;
while(conway->isEmpty()) {
Count+=1;
leditCount->text() = Count;
conway->nextLoop();
conway->repaint();
}
} |
Partager