[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmahjongg/qgraphic] /: Pause hides only tiles not the whole view.
From:       Christian Krippendorf <Coding () Christian-Krippendorf ! de>
Date:       2013-01-03 17:57:23
Message-ID: 20130103175723.7E82AA6091 () git ! kde ! org
[Download RAW message or body]

Git commit 97a2cd4fddb4f36477a1cb6d665782845fc6134a by Christian Krippendorf.
Committed on 03/01/2013 at 18:57.
Pushed by krippendorf into branch 'qgraphic'.

Pause hides only tiles not the whole view.

M  +13   -0    GameView.cpp
M  +4    -0    GameView.h
M  +13   -12   kmahjongg.cpp
M  +1    -0    kmahjongg.h

http://commits.kde.org/kmahjongg/97a2cd4fddb4f36477a1cb6d665782845fc6134a

diff --git a/GameView.cpp b/GameView.cpp
index cee38fe..d652ed6 100644
--- a/GameView.cpp
+++ b/GameView.cpp
@@ -430,6 +430,19 @@ bool GameView::validMovesAvailable(bool bSilent)
     return true;
 }
 
+void GameView::pause(bool isPaused)
+{
+    if (isPaused) {
+        foreach (GameItem *item, items()) {
+            item->hide();
+        }
+    } else {
+        foreach (GameItem *item, items()) {
+            item->show();
+        }
+    }
+}
+
 void GameView::shuffle()
 {
     m_pGameData->shuffle();
diff --git a/GameView.h b/GameView.h
index 9a77831..b3f3bda 100644
--- a/GameView.h
+++ b/GameView.h
@@ -195,6 +195,10 @@ public:
      * @return True if a legal move exist, else false. */
     bool validMovesAvailable(bool bSilent = false);
 
+    /**
+     * Hide/show tiles when game is paused/unpaused. */
+    void pause(bool isPaused);
+
 public slots:
     /**
      * Add a new item with teh given position and update imgages, position and order.
diff --git a/kmahjongg.cpp b/kmahjongg.cpp
index 40b7b3c..d546732 100644
--- a/kmahjongg.cpp
+++ b/kmahjongg.cpp
@@ -60,8 +60,6 @@
 static const char *gameMagic = "kmahjongg-gamedata";
 static int gameDataVersion = 1;
 
-int is_paused = 0;
-
 /**
  * This class implements
  *
@@ -82,6 +80,7 @@ public:
 
 KMahjongg::KMahjongg(QWidget *parent)
     : KXmlGuiWindow(parent),
+    m_bPaused(false),
     m_pBoardLayout(new KMahjonggLayout()),
     m_pGameData(NULL),
     m_pGameView(NULL)
@@ -325,15 +324,17 @@ void KMahjongg::demoMode()
 
 void KMahjongg::pause()
 {
-    if (is_paused) {
-        gameTimer->resume();
-    } else {
+    m_bPaused = !m_bPaused;
+
+    if (m_bPaused) {
         gameTimer->pause();
+    } else {
+        gameTimer->resume();
     }
 
-    is_paused = !is_paused;
+    m_pGameView->pause(m_bPaused);
+
     demoModeChanged(false);
-    m_pGameView->setVisible(!m_pGameView->isVisible());
 }
 
 void KMahjongg::showHighscores()
@@ -458,7 +459,7 @@ void KMahjongg::showItemNumber(int iMaximum, int iCurrent, int iLeft)
     tilesLeftLabel->setText(szBuffer);
 
     // update undo menu item, if demomode is inactive
-    if (!is_paused && !mFinished) {
+    if (!m_bPaused && !mFinished) {
         undoAction->setEnabled(m_pGameView->checkUndoAllowed());
         redoAction->setEnabled(m_pGameView->checkRedoAllowed());
     }
@@ -468,10 +469,10 @@ void KMahjongg::demoModeChanged(bool bActive)
 {
     bDemoModeActive = bActive;
 
-    pauseAction->setChecked(is_paused);
-    demoAction->setChecked(bActive || is_paused);
+    pauseAction->setChecked(m_bPaused);
+    demoAction->setChecked(bActive || m_bPaused);
 
-    if (is_paused) {
+    if (m_bPaused) {
         stateChanged("paused");
     } else if (mFinished) {
         stateChanged("finished");
@@ -496,7 +497,7 @@ void KMahjongg::restartGame()
         mFinished = false;
         demoModeChanged(false);
 
-        if (is_paused) {
+        if (m_bPaused) {
             pauseAction->setChecked(false);
             pause();
         }
diff --git a/kmahjongg.h b/kmahjongg.h
index fb2879d..511126e 100644
--- a/kmahjongg.h
+++ b/kmahjongg.h
@@ -137,6 +137,7 @@ private:
     unsigned long gameElapsedTime;
     bool bDemoModeActive;
     bool mFinished;
+    bool m_bPaused;
 
     GameView *m_pGameView;
     GameData *m_pGameData;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic