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 ();
23 QPixmap waves (":/pix/meri.png");
24 pScene_->setBackgroundBrush(QBrush(waves));
26 pView_->setScene(pScene_);
27 setCentralWidget(pView_);
29 QAction * pPauseAction = new QAction(tr("Pause"),this);
30 pPauseAction->setCheckable(true);
31 addAction(pPauseAction);
32 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
33 menuBar()->addAction(pPauseAction);
35 QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
36 addAction(pRestartLevelAction);
37 connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
38 menuBar()->addAction(pRestartLevelAction);
41 QAction * pAboutAction = new QAction(tr("About"),this);
42 addAction(pAboutAction);
43 connect(pAboutAction,SIGNAL(triggered()),this,SLOT(about()));
44 menuBar()->addAction(pAboutAction);
47 //the boundaries of the scene are set to match the size of the view window, which is not
48 //available in the constructor --> timer needed
49 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
58 MainWindow::~MainWindow()
63 void MainWindow::initializeBoundaries()
65 //the boundaries of the scene are set to match the size of the view window, and
66 //the view is set to show exactly the whole scene area
69 QSize windowsize = pView_->size();
70 QRectF rectangle (topleft,windowsize);
73 pScene_->setSceneRect(rectangle);
74 pView_->setSceneRect(rectangle);
76 qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
78 pScene_->setupMap(11,5,5);
81 void MainWindow::pause(bool paused)
83 // qDebug() << "pause pressed " << paused;
84 if (paused_ == paused)
91 // qDebug() << "starting to move again";
92 pTursas_->startMoving();
97 qDebug("about to stop movement");
98 pTursas_->stopMoving();
103 void MainWindow::restartLevel()
105 pScene_->setupMap(5,5,5);
108 void MainWindow::about()
110 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
112 "<p>Copyright 2011 Heli Hyvättinen"
113 "<p>License: General Public License v2"
114 ).arg(QApplication::applicationVersion()));