1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
11 MainWindow::MainWindow(QWidget *parent)
16 pScene_ = new SeaScene ();
17 pView_ = new QGraphicsView ();
19 QPixmap waves (":/pix/meri.png");
20 pScene_->setBackgroundBrush(QBrush(waves));
22 pView_->setScene(pScene_);
23 setCentralWidget(pView_);
25 QAction * pPauseAction = new QAction(tr("Pause"),this);
26 pPauseAction->setCheckable(true);
27 addAction(pPauseAction);
28 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
29 menuBar()->addAction(pPauseAction);
31 QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
32 pRestartLevelAction->setCheckable(true);
33 addAction(pRestartLevelAction);
34 connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
35 menuBar()->addAction(pRestartLevelAction);
39 //the boundaries of the scene are set to match the size of the view window, which is not
40 //available in the constructor --> timer needed
41 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
50 MainWindow::~MainWindow()
55 void MainWindow::initializeBoundaries()
57 //the boundaries of the scene are set to match the size of the view window, and
58 //the view is set to show exactly the whole scene area
61 QSize windowsize = pView_->size();
62 QRectF rectangle (topleft,windowsize);
65 pScene_->setSceneRect(rectangle);
66 pView_->setSceneRect(rectangle);
68 qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
70 pScene_->setupMap(5,5,5);
73 void MainWindow::pause(bool paused)
75 // qDebug() << "pause pressed " << paused;
76 if (paused_ == paused)
83 // qDebug() << "starting to move again";
84 pTursas_->startMoving();
89 qDebug("about to stop movement");
90 pTursas_->stopMoving();
95 void MainWindow::restartLevel()
97 pScene_->setupMap(5,5,5);