#include "simul/main_window.h" #include "simul/table.h" #include #include #include #include #include #include #include #include MainWindow::MainWindow(bool isYellow) { QTimer* timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); dt = 1; timer->start(dt); QWidget* inter = new QWidget(this); setCentralWidget(inter); inter->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding)); table = new Table(this, inter, isYellow); this->setFixedSize(900,600); DebugWindow::getInstance()->show(); DebugWindow::getInstance()->setParent(this); postStartTimer.start(1000); connect(&postStartTimer, SIGNAL(timeout()), this, SLOT(postStart())); } MainWindow::~MainWindow() {} void MainWindow::update() { table->update(dt); } void MainWindow::postStart() { DebugWindow::getInstance()->setReady(true); } void MainWindow::mousePressEvent(QMouseEvent* evt) { table->mousePressEvent(evt,true); } void MainWindow::keyPressEvent(QKeyEvent* evt) { table->keyPressEvent(evt,true); } void MainWindow::keyReleaseEvent(QKeyEvent* evt) { if (evt->key() == Qt::Key_Escape) exit(0); table->keyPressEvent(evt,false); } 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()); } void MainWindow::moveEvent(QMoveEvent*) { if (DebugWindow::getInstance()->isAttached()) DebugWindow::getInstance()->moveWithoutEvent(this->mapToGlobal(QPoint()) + QPoint(this->width() + 16, -QApplication::style()->pixelMetric(QStyle::PM_TitleBarHeight))); } void MainWindow::closeEvent(QCloseEvent*) { DebugWindow::getInstance()->close(); } /// #include "main_window.moc"