Added the number of ghots to test ship images
[ghostsoverboard] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
3 #include <QPixmap>
4 #include <QTimer>
5 #include <QDebug>
6 #include <QAction>
7 #include <QMenuBar>
8
9
10
11 MainWindow::MainWindow(QWidget *parent)
12     : QMainWindow(parent)
13 {
14     paused_ = false;
15
16     pScene_ = new SeaScene ();
17     pView_  = new QGraphicsView ();
18
19     QPixmap waves (":/pix/meri.png");
20     pScene_->setBackgroundBrush(QBrush(waves));
21
22     pView_->setScene(pScene_);
23     setCentralWidget(pView_);
24
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);
30
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);
36
37
38
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()));
42
43
44
45
46
47
48 }
49
50 MainWindow::~MainWindow()
51 {
52
53 }
54
55 void MainWindow::initializeBoundaries()
56 {
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
59
60     QPoint topleft (0,0);
61     QSize windowsize = pView_->size();
62     QRectF rectangle (topleft,windowsize);
63
64
65     pScene_->setSceneRect(rectangle);
66     pView_->setSceneRect(rectangle);
67
68     qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
69
70     pScene_->setupMap(11,5,5);
71 }
72
73 void MainWindow::pause(bool paused)
74 {
75 //    qDebug() << "pause pressed " << paused;
76     if (paused_ == paused)
77             return;
78
79     paused_ = paused;
80
81     if (paused == false)
82     {
83  //       qDebug() << "starting to move again";
84         pTursas_->startMoving();
85     }
86
87     else
88     {
89         qDebug("about to stop movement");
90         pTursas_->stopMoving();
91     }
92
93 }
94
95 void MainWindow::restartLevel()
96 {
97     pScene_->setupMap(5,5,5);
98 }