Seascene map setup places rocks, octopuses and the ship now
[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
26     //the boundaries of the scene are set to match the size of the view window, which is not
27     //available in the constructor --> timer needed
28     QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
29
30
31 }
32
33 MainWindow::~MainWindow()
34 {
35
36 }
37
38 void MainWindow::initializeBoundaries()
39 {
40         //the boundaries of the scene are set to match the size of the view window, and
41         //the view is set to show exactly the whole scene area
42
43     QPoint topleft (0,0);
44     QSize windowsize = pView_->size();
45     QRectF rectangle (topleft,windowsize);
46
47
48     pScene_->setSceneRect(rectangle);
49     pView_->setSceneRect(rectangle);
50
51     qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
52
53     pScene_->setupMap(5,5,5);
54 }
55
56 void MainWindow::pause(bool paused)
57 {
58 //    qDebug() << "pause pressed " << paused;
59     if (paused_ == paused)
60             return;
61
62     paused_ = paused;
63
64     if (paused == false)
65     {
66  //       qDebug() << "starting to move again";
67         pTursas_->startMoving();
68     }
69
70     else
71     {
72         qDebug("about to stop movement");
73         pTursas_->stopMoving();
74     }
75 }