Pause works again
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 17:38:39 +0000 (20:38 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 14 Jun 2011 17:38:39 +0000 (20:38 +0300)
Pause re-created to fit current code and stop octopuses too.
(untested for octopuses)
Window title now correct.

mainwindow.cpp
mainwindow.h
seascene.cpp
seascene.h

index 84d3bfb..929b41c 100644 (file)
@@ -9,16 +9,15 @@
 #include <QApplication>
 #include <QLabel>
 #include <QPushButton>
- #include <QVBoxLayout>
+#include <QVBoxLayout>
 
 
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
 {
-    paused_ = false;
-
     setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
+    setWindowTitle("Ghosts Overboard");
 
     pScene_ = new SeaScene ();
     connect(pScene_,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
@@ -31,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent)
     QAction * pPauseAction = new QAction(tr("Pause"),this);
     pPauseAction->setCheckable(true);
     addAction(pPauseAction);
-    connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
+    connect(pPauseAction,SIGNAL(triggered(bool)),pScene_,SLOT(pause(bool)));
     menuBar()->addAction(pPauseAction);
 
     QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
@@ -80,31 +79,10 @@ void MainWindow::initializeBoundaries()
     restartLevel();
 }
 
-void MainWindow::pause(bool paused)
-{
-//    qDebug() << "pause pressed " << paused;
-    if (paused_ == paused)
-            return;
-
-    paused_ = paused;
-
-    if (paused == false)
-    {
- //       qDebug() << "starting to move again";
-        pTursas_->startMoving();
-    }
-
-    else
-    {
-        qDebug("about to stop movement");
-        pTursas_->stopMoving();
-    }
-
-}
 
 void MainWindow::restartLevel()
 {
-    pScene_->setupMap(5,5,5);
+    pScene_->setupMap(5,10,0);
 }
 
 void MainWindow::about()
index 2834154..c8b0e11 100644 (file)
@@ -16,7 +16,6 @@ public:
 
 public slots:
     void initializeBoundaries();
-    void pause(bool paused);
     void restartLevel();
     void about();
     void nextLevel();
@@ -26,8 +25,7 @@ private:
 
 SeaScene * pScene_;
 QGraphicsView * pView_;
-OrientationControlledGraphicsPixmapObject * pTursas_;
-bool paused_;
+
 
 
 
index 7a6a9db..eb14504 100644 (file)
@@ -14,6 +14,8 @@ const QString octopusImageFilename_= ":/pix/tursas.png";
 SeaScene::SeaScene(QObject *parent) :
     QGraphicsScene(parent)
 {
+    paused_ = false;
+
     //set background
 
     QPixmap waves (":/pix/meri.png");
@@ -101,6 +103,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     addItem(pOctopus);
     pOctopus->startMoving();
     movingItems_.append(pOctopus);
+    connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving()));
+    connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving()));
     delete pPosition;
 
     }
@@ -138,6 +142,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
     pShip->startMoving();
     movingItems_.append(pShip);
+    connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
+    connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving()));
     delete pPosition;
 }
 
@@ -250,3 +256,24 @@ void SeaScene::ghostsDropped(int ghosts)
 
     spreadGhosts(ghosts);
 }
+
+void SeaScene::pause(bool paused)
+{
+    //    qDebug() << "pause pressed " << paused;
+        if (paused_ == paused)
+                return;
+
+        paused_ = paused;
+
+        if (paused == false)
+        {
+     //       qDebug() << "starting to move again";
+            emit pauseOff();
+        }
+
+        else
+        {
+     //       qDebug("about to stop movement");
+            emit pauseOn();
+        }
+}
index a296710..ef1eac5 100644 (file)
@@ -12,6 +12,8 @@ public:
 signals:
 
     void allGhostsPicked();
+    void pauseOn();
+    void pauseOff();
 
 public slots:
 
@@ -29,6 +31,8 @@ public slots:
 
     void ghostsDropped(int ghosts);
 
+    void pause (bool paused);
+
 protected:
 
     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
@@ -48,6 +52,8 @@ protected:
 
     QList<QGraphicsItem*> movingItems_;
 
+    bool paused_;
+