1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
11 MainWindow::MainWindow(QWidget *parent)
16 pScene_ = new SeaScene ();
17 pView_ = new QGraphicsView ();
21 pView_->setScene(pScene_);
22 setCentralWidget(pView_);
24 QAction * pPauseAction = new QAction(tr("Pause"),this);
25 pPauseAction->setCheckable(true);
26 addAction(pPauseAction);
27 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
28 menuBar()->addAction(pPauseAction);
30 QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
31 pRestartLevelAction->setCheckable(true);
32 addAction(pRestartLevelAction);
33 connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
34 menuBar()->addAction(pRestartLevelAction);
38 //the boundaries of the scene are set to match the size of the view window, which is not
39 //available in the constructor --> timer needed
40 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
49 MainWindow::~MainWindow()
54 void MainWindow::initializeBoundaries()
56 //the boundaries of the scene are set to match the size of the view window, and
57 //the view is set to show exactly the whole scene area
60 QSize windowsize = pView_->size();
61 QRectF rectangle (topleft,windowsize);
64 pScene_->setSceneRect(rectangle);
65 pView_->setSceneRect(rectangle);
67 qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
69 pScene_->setupMap(5,5,5);
72 void MainWindow::pause(bool paused)
74 // qDebug() << "pause pressed " << paused;
75 if (paused_ == paused)
82 // qDebug() << "starting to move again";
83 pTursas_->startMoving();
88 qDebug("about to stop movement");
89 pTursas_->stopMoving();
94 void MainWindow::restartLevel()
96 pScene_->setupMap(5,5,5);