1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
9 #include <QApplication>
13 MainWindow::MainWindow(QWidget *parent)
18 setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
20 pScene_ = new SeaScene ();
21 pView_ = new QGraphicsView ();
25 pView_->setScene(pScene_);
26 setCentralWidget(pView_);
28 QAction * pPauseAction = new QAction(tr("Pause"),this);
29 pPauseAction->setCheckable(true);
30 addAction(pPauseAction);
31 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
32 menuBar()->addAction(pPauseAction);
34 QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
35 addAction(pRestartLevelAction);
36 connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
37 menuBar()->addAction(pRestartLevelAction);
40 QAction * pAboutAction = new QAction(tr("About"),this);
41 addAction(pAboutAction);
42 connect(pAboutAction,SIGNAL(triggered()),this,SLOT(about()));
43 menuBar()->addAction(pAboutAction);
46 //the boundaries of the scene are set to match the size of the view window, which is not
47 //available in the constructor --> timer needed
48 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
57 MainWindow::~MainWindow()
62 void MainWindow::initializeBoundaries()
64 //the boundaries of the scene are set to match the size of the view window, and
65 //the view is set to show exactly the whole scene area
68 QSize windowsize = pView_->size();
69 QRectF rectangle (topleft,windowsize);
72 pScene_->setSceneRect(rectangle);
73 pView_->setSceneRect(rectangle);
75 qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
77 pScene_->setupMap(11,5,5);
80 void MainWindow::pause(bool paused)
82 // qDebug() << "pause pressed " << paused;
83 if (paused_ == paused)
90 // qDebug() << "starting to move again";
91 pTursas_->startMoving();
96 qDebug("about to stop movement");
97 pTursas_->stopMoving();
102 void MainWindow::restartLevel()
104 pScene_->setupMap(5,5,5);
107 void MainWindow::about()
109 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
111 "<p>Copyright 2011 Heli Hyvättinen"
112 "<p>License: General Public License v2"
113 ).arg(QApplication::applicationVersion()));