main-window.cpp

Ir para a documentação deste ficheiro.
00001 #include <QtGui>
00002 #include "main-window.h"
00003 
00004 MainWindow * MainWindow::instance = NULL;
00005 
00006 MainWindow::MainWindow(QMainWindow *parent, Qt::WFlags f) : QMainWindow(parent, f)
00007 {
00008     setupUi(this); // this sets up GUI
00009     setWindowFlags(f & (~Qt::WindowMaximizeButtonHint));
00010 
00011     /* Cria tela de opcoes */
00012     opcoes = new Opcoes(parent, f);
00013     opcoes->setMundo(widget);
00014     opcoes->setBarras(horizontalScrollBar, verticalScrollBar);
00015 
00016     /* Cria tela de ajuda */
00017     ajuda = new Ajuda(parent, f);
00018 
00019     /* Cria tela de informacoes */
00020     info = new Info(parent, f);
00021     widget->setInfo(info);
00022 
00023     /* Cria tela de estatisticas */
00024     stat = new Stat(parent, f);
00025     widget->setStat(stat);
00026 
00027     /* Cria toolbares */
00028     QToolBar *toolBar1 = new QToolBar(tr("Tool bar"), this);
00029     toolBar1->addAction(abrirSimulacaoAct);
00030     toolBar1->addAction(salvarSimulacaoAct);
00031     toolBar1->addSeparator();
00032     toolBar1->addAction(limparAct);
00033     toolBar1->addAction(reiniciarAct);
00034     toolBar1->addAction(pauseAct);
00035     toolBar1->addSeparator();
00036     toolBar1->addAction(estatisticasAct);
00037     toolBar1->addAction(opcoesAct);
00038     toolBar1->addSeparator();
00039     toolBar1->addSeparator();
00040     toolBar1->addAction(ajudaAct);
00041     toolBar1->addAction(sairAct);
00042 
00043     QToolBar *toolBar2 = new QToolBar(tr("Search Biot"), this);
00044     toolBar2->addAction(maisVelhoAct);
00045     toolBar2->addAction(maisEnergiaAct);
00046     toolBar2->addAction(geracaoMaisNovaAct);
00047     toolBar2->addAction(geracaoMaisAntigaAct);
00048     toolBar2->addAction(maisFilhosAct);
00049     toolBar2->addSeparator();
00050     toolBar2->addAction(fixarSelecionadoAct);
00051     toolBar2->addAction(autoSelecionarAct);
00052 
00053     /* Inclui toolbares */
00054     addToolBar(Qt::TopToolBarArea, toolBar1);
00055     addToolBar(Qt::LeftToolBarArea, toolBar2);
00056 
00057     /* Cria status bar */
00058     QStatusBar *barraStatus = new QStatusBar(this);
00059     setStatusBar(barraStatus);
00060 
00061     /* Associa movimento das barras de rolagem */
00062     QObject::connect(horizontalScrollBar, SIGNAL(valueChanged(int)), widget, SLOT(offsetxChanged(int)));
00063     QObject::connect(verticalScrollBar, SIGNAL(valueChanged(int)), widget, SLOT(offsetyChanged(int)));
00064     QObject::connect(widget, SIGNAL(changeVerticalBar(int)), verticalScrollBar, SLOT(setValue(int)));
00065     QObject::connect(widget, SIGNAL(changeHorizontalBar(int)), horizontalScrollBar, SLOT(setValue(int)));
00066 
00067     /* Associa acoes */
00068     QObject::connect(limparAct, SIGNAL(triggered()), widget, SLOT(limpar()));
00069     QObject::connect(reiniciarAct, SIGNAL(triggered()), widget, SLOT(reiniciar()));
00070     QObject::connect(pauseAct, SIGNAL(triggered()), this, SLOT(startStop()));
00071     QObject::connect(sairAct, SIGNAL(triggered()), this, SLOT(close()));
00072     QObject::connect(ajudaAct, SIGNAL(triggered()), ajuda, SLOT(show()));
00073     QObject::connect(opcoesAct, SIGNAL(triggered()), opcoes, SLOT(show()));
00074     QObject::connect(estatisticasAct, SIGNAL(triggered()), stat, SLOT(show()));
00075     QObject::connect(salvarSimulacaoAct, SIGNAL(triggered()), widget, SLOT(salvarSimulacao()));
00076     QObject::connect(abrirSimulacaoAct, SIGNAL(triggered()), widget, SLOT(abrirSimulacao()));
00077     QObject::connect(widget, SIGNAL(estadoModificado(QString)), barraStatus, SLOT(showMessage(QString)));
00078 
00079     QObject::connect(maisVelhoAct, SIGNAL(triggered()), widget, SLOT(maisVelho()));
00080     QObject::connect(maisEnergiaAct, SIGNAL(triggered()), widget, SLOT(maisEnergia()));
00081     QObject::connect(geracaoMaisNovaAct, SIGNAL(triggered()), widget, SLOT(geracaoMaisNova()));
00082     QObject::connect(geracaoMaisAntigaAct, SIGNAL(triggered()), widget, SLOT(geracaoMaisAntiga()));
00083     QObject::connect(maisFilhosAct, SIGNAL(triggered()), widget, SLOT(maisFilhos()));
00084     QObject::connect(fixarSelecionadoAct, SIGNAL(triggered()), widget, SLOT(fixarSelecionado()));
00085     QObject::connect(autoSelecionarAct, SIGNAL(triggered()), widget, SLOT(autoSelecionar()));
00086 
00087     /* Cria menu popup de biota */
00088     QMenu *menuBiota = new QMenu(tr("Biot"), widget);
00089     menuBiota->addAction(salvarBiotaAct);
00090     menuBiota->addAction(mutacaoAct);
00091     menuBiota->addAction(matarBiotaAct);
00092     menuBiota->addAction(informacoesAct);
00093 
00094     /* Associa conexoes */
00095     QObject::connect(mutacaoAct, SIGNAL(triggered()), widget, SLOT(mutacaoBiota()));
00096     QObject::connect(salvarBiotaAct, SIGNAL(triggered()), widget, SLOT(salvarBiota()));
00097     QObject::connect(matarBiotaAct, SIGNAL(triggered()), widget, SLOT(removerBiota()));
00098     QObject::connect(informacoesAct, SIGNAL(triggered()), info, SLOT(show()));
00099 
00100     /* Cria menu popup vazio */
00101     QMenu *menuVoid = new QMenu(tr("Options"), widget);
00102     menuVoid->addAction(novaParedeAct);
00103     menuVoid->addSeparator();
00104     menuVoid->addAction(novoBiotaAct);
00105     menuVoid->addAction(carregarBiotaAct);
00106     menuVoid->addSeparator();
00107     menuVoid->addAction(novoGraoAct);
00108 
00109     /* Associa conexoes */
00110     QObject::connect(novaParedeAct, SIGNAL(triggered()), widget, SLOT(novaParede()));
00111     QObject::connect(novoBiotaAct, SIGNAL(triggered()), widget, SLOT(novoBiota()));
00112     QObject::connect(carregarBiotaAct, SIGNAL(triggered()), widget, SLOT(abrirBiota()));
00113     QObject::connect(novoGraoAct, SIGNAL(triggered()), widget, SLOT(novoGrao()));
00114 
00115     /* Cria menu popup do grao */
00116     QMenu *menuGrao = new QMenu(tr("Grain"), widget);
00117     menuGrao->addAction(removerGraoAct);
00118 
00119     /* Associa conexao */
00120     QObject::connect(removerGraoAct, SIGNAL(triggered()), widget, SLOT(removerGrao()));
00121 
00122     /* Cria menu popup da parede */
00123     QMenu *menuParede  = new QMenu(tr("Wall"), widget);
00124     menuParede->addAction(removerParedeAct);
00125 
00126     /* Associa conexao */
00127     QObject::connect(removerParedeAct, SIGNAL(triggered()), widget, SLOT(removerParede()));
00128 
00129     /* Associa menus ao widget */
00130     widget->setMenuBiota(menuBiota);
00131     widget->setMenuGrao(menuGrao);
00132     widget->setMenuParede(menuParede);
00133     widget->setMenuVoid(menuVoid);
00134 
00135     /* Muda tamanho das barras */
00136     horizontalScrollBar->setRange(0, widget->propriedades.tamanho_x);
00137     verticalScrollBar->setRange(0, widget->propriedades.tamanho_y);
00138 
00139     horizontalScrollBar->setSliderPosition(widget->propriedades.tamanho_x/2);
00140     verticalScrollBar->setSliderPosition(widget->propriedades.tamanho_y/2);
00141 
00142     /* Seta mutex */
00143     widget->setMutex(new QMutex(QMutex::Recursive));
00144 
00145     /* Seta timers para atualizar, pintar e atualizar estatistica */
00146     timerA = new QTimer(this);
00147     QObject::connect(timerA, SIGNAL(timeout()), widget, SLOT(atualizar()));
00148 
00149     timerP = new QTimer(this);
00150     QObject::connect(timerP, SIGNAL(timeout()), widget, SLOT(repaint()));
00151 
00152     timerS = new QTimer(this);
00153     QObject::connect(timerS, SIGNAL(timeout()), widget, SLOT(estatistica()));
00154 
00155     /* Inicia timers */
00156     timerA->start(50);
00157     timerP->start(50);
00158     timerS->start(500);
00159 
00160     MainWindow::instance = this;
00161 }
00162 
00163 void MainWindow::startStop()
00164 {
00165     if (timerP->isActive())
00166         timerP->stop();
00167     else
00168         timerP->start();
00169 
00170     if (timerA->isActive())
00171         timerA->stop();
00172     else
00173         timerA->start();
00174 
00175     if (timerS->isActive())
00176         timerS->stop();
00177     else
00178         timerS->start();
00179 
00180     widget->executando = !widget->executando;
00181 }

Gerado em Mon May 4 14:52:59 2009 para Simvida por  doxygen 1.5.8