Newer
Older
Grégoire Payen de La Garanderie
committed
#include "simul/main_window.h"
#include "simul/table.h"
#include <QTimer>
#include <iostream>
#include <QVBoxLayout>
#include <QResizeEvent>
hilnius
committed
#include <QShortcut>
#include <QApplication>
#include <QStyle>
#include <QDebug>
Grégoire Payen de La Garanderie
committed
MainWindow::MainWindow(bool isYellow)
Grégoire Payen de La Garanderie
committed
{
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
Grégoire Payen de La Garanderie
committed
timer->start(dt);
QWidget* inter = new QWidget(this);
Grégoire Payen de La Garanderie
committed
setCentralWidget(inter);
inter->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
Grégoire Payen de La Garanderie
committed
table = new Table(this, inter, isYellow);
this->setFixedSize(900,600);
DebugWindow::getInstance()->show();
postStartTimer.start(1000);
connect(&postStartTimer, SIGNAL(timeout()), this, SLOT(postStart()));
Grégoire Payen de La Garanderie
committed
}
MainWindow::~MainWindow()
Grégoire Payen de La Garanderie
committed
void MainWindow::update()
{
table->update(dt);
}
void MainWindow::postStart()
{
DebugWindow::getInstance()->setReady(true);
Grégoire Payen de La Garanderie
committed
}
void MainWindow::mousePressEvent(QMouseEvent* evt)
{
table->mousePressEvent(evt,true);
}
void MainWindow::keyPressEvent(QKeyEvent* evt)
{
table->keyPressEvent(evt,true);
}
void MainWindow::keyReleaseEvent(QKeyEvent* evt)
{
hilnius
committed
if (evt->key() == Qt::Key_Escape)
exit(0);
table->keyPressEvent(evt,false);
}
Grégoire Payen de La Garanderie
committed
void MainWindow::resizeEvent(QResizeEvent* event)
{
float proportion = (float)table->tableWidth/table->tableHeight;
QSize s = event->size();
if(s.width() < s.height()*proportion)
table->resize(s.width(),s.width()/proportion);
else
table->resize(proportion*s.height(),s.height());
}
{
if (DebugWindow::getInstance()->isAttached())
DebugWindow::getInstance()->moveWithoutEvent(this->mapToGlobal(QPoint()) + QPoint(this->width() + 16, -QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight)));
}
{
DebugWindow::getInstance()->close();
}
/// #include "main_window.moc"