Debug code changes
[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
20
21     pView_->setScene(pScene_);
22     setCentralWidget(pView_);
23
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);
29
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);
35
36
37
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()));
41
42
43
44
45
46
47 }
48
49 MainWindow::~MainWindow()
50 {
51
52 }
53
54 void MainWindow::initializeBoundaries()
55 {
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
58
59     QPoint topleft (0,0);
60     QSize windowsize = pView_->size();
61     QRectF rectangle (topleft,windowsize);
62
63
64     pScene_->setSceneRect(rectangle);
65     pView_->setSceneRect(rectangle);
66
67     qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
68
69     pScene_->setupMap(5,5,5);
70 }
71
72 void MainWindow::pause(bool paused)
73 {
74 //    qDebug() << "pause pressed " << paused;
75     if (paused_ == paused)
76             return;
77
78     paused_ = paused;
79
80     if (paused == false)
81     {
82  //       qDebug() << "starting to move again";
83         pTursas_->startMoving();
84     }
85
86     else
87     {
88         qDebug("about to stop movement");
89         pTursas_->stopMoving();
90     }
91
92 }
93
94 void MainWindow::restartLevel()
95 {
96     pScene_->setupMap(5,5,5);
97 }