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

List:       kde-commits
Subject:    kdegames/kreversi
From:       Inge Wallin <inge () lysator ! liu ! se>
Date:       2005-04-03 22:43:48
Message-ID: 20050403224348.1035C5FA () office ! kde ! org
[Download RAW message or body]

CVS commit by ingwa: 

More control of the view by signals


  M +5 -0      ChangeLog   1.71
  M +20 -15    kreversi.cpp   1.56
  M +2 -1      kreversi.h   1.32
  M +3 -0      qreversigameview.cpp   1.5


--- kdegames/kreversi/ChangeLog  #1.70:1.71
@@ -1,4 +1,9 @@
 2005-04-04  Inge Wallin  <inge@lysator.liu.se>
 
+        More control of the view by signals
+        * kreversi.cpp (showTurn): now catches sig_newGame and sig_update
+        from the game
+        (showTurn): new slot
+        
         Let the game view be updated by signals from the game instead of
         by explicit calls.

--- kdegames/kreversi/kreversi.cpp  #1.55:1.56
@@ -112,9 +112,14 @@ KReversi::KReversi()
   addWidget(m_gameView);
 
-  // Connect some signals from the game with slots of the view
+  // Connect the signals from the game with slots of the view
+  //
+  // The only part of the view that is left in this class is the
+  // indicator of whose turn it is in the status bar.  The rest is
+  // in the game view.
+  connect(m_game, SIGNAL(sig_newGame()),  this, SLOT(showTurn()));
   connect(m_game, SIGNAL(sig_move(uint, Move&)), 
           this,   SLOT(showMove(uint, Move&)));
+  connect(m_game, SIGNAL(sig_update()),   this, SLOT(showTurn()));
   connect(m_game, SIGNAL(sig_gameOver()), this, SLOT(slotGameOver()));
-  connect(m_game, SIGNAL(turn(Color)),    this, SLOT(showTurn(Color)));
 
   // Internal signal
@@ -249,7 +254,6 @@ void KReversi::slotNewGame()
   //kdDebug() << "Competitive: " << m_competitiveGame << endl;
 
-  // Show some data
+  // Set the state to waiting for the humans move.
   setState(Ready);
-  showTurn(Black);
 
   if (showLegalMovesAction->isChecked()) {
@@ -365,8 +369,6 @@ void KReversi::slotInterrupt()
   m_engine->setInterrupt(TRUE);
 
-  // At this point the engine has not returned yet and State has not
-  // yet been set to Ready, so the interrupted() test does not work
-  // here.
-  showTurn(m_game->toMove());
+  // Indicate that the computer was interrupted.
+  showTurn();
 }
 
@@ -467,4 +469,5 @@ void KReversi::slotSquareClicked(int row
 
 // Show the move in the move view.
+// FIXME: Move this to the gameview.
 
 void  KReversi::showMove(uint moveno, Move &move)
@@ -482,4 +485,6 @@ void  KReversi::showMove(uint moveno, Mo
   m_gameView->setCurrentMove(moveno - 1);
   m_gameView->ensureCurrentMoveVisible();
+
+  showTurn();
 }
 
@@ -488,4 +493,9 @@ void  KReversi::showMove(uint moveno, Mo
 //
 
+void KReversi::showTurn()
+{
+  showTurn(m_game->toMove());
+}
+
 void KReversi::showTurn(Color color)
 {
@@ -526,4 +536,6 @@ void KReversi::slotGameOver()
 
   showTurn(Nobody);
+
+  // FIXME: Remove
   m_gameView->quitShowLegalMoves();
 }
@@ -644,6 +656,4 @@ void KReversi::computerMakeMove()
   Color opponent = ::opponent(color);
 
-  showTurn(color);
-
   // Show legal moves for the computer.
   if (showLegalMovesAction->isChecked()) {
@@ -678,6 +688,4 @@ void KReversi::computerMakeMove()
   } while (!m_game->moveIsPossible(opponent));
 
-  // FIXME: Update from the game.
-  showTurn(opponent);
   setState(Ready);
 
@@ -778,7 +786,4 @@ bool KReversi::loadGame(KConfig *config)
     slotContinue();
   else {
-    // Make the view show who is to move.
-    showTurn(m_game->toMove());
-
     // Computer makes first move.
     if (m_humanColor != m_game->toMove())

--- kdegames/kreversi/kreversi.h  #1.31:1.32
@@ -138,5 +138,6 @@ private slots:
   // Slots for the view.
   void  showMove(uint moveno, Move &move);
-  void  showTurn(Color);
+  void  showTurn();
+  void  showTurn(Color color);
   void  slotGameOver();
   void  showGameOver(Color);

--- kdegames/kreversi/qreversigameview.cpp  #1.4:1.5
@@ -160,4 +160,7 @@ QReversiGameView::~QReversiGameView()
 }
 
+
+// Create the entire view.  Only called once from the constructor.
+
 void QReversiGameView::createView()
 {


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

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