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

List:       kde-commits
Subject:    KDE/kdegames/kpat
From:       Stephan Kulow <coolo () kde ! org>
Date:       2008-09-19 20:24:03
Message-ID: 1221855843.798217.30885.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 862779 by coolo:

redo (not in the toolbar)
BUG: 161142


 M  +64 -18    dealer.cpp  
 M  +4 -2      dealer.h  
 M  +15 -0     pwidget.cpp  
 M  +3 -1      pwidget.h  


--- trunk/KDE/kdegames/kpat/dealer.cpp #862778:862779
@@ -164,8 +164,15 @@
     qreal offx;
     qreal offy;
     bool m_autoDropOnce;
+    QList<State*> redoList;
+    QList<State*> undoList;
 };
 
+int DealerScene::getMoves() const
+{
+    return d->undoList.count();
+}
+
 void DealerScene::takeState()
 {
     // kDebug(11111) << "takeState" << waiting();
@@ -184,18 +191,18 @@
 
     State *n = getState();
 
-    if (!undoList.count()) {
+    if (!d->undoList.count()) {
         emit updateMoves();
-        undoList.append(n);
+        d->undoList.append(n);
     } else {
-        State *old = undoList.last();
+        State *old = d->undoList.last();
 
         if (*old == *n) {
             delete n;
             n = 0;
         } else {
             emit updateMoves();
-            undoList.append(n);
+            d->undoList.append(n);
         }
     }
 
@@ -228,7 +235,8 @@
     if (!demoActive() && !waiting())
         QTimer::singleShot( speedUpTime( TIME_BETWEEN_MOVES ), this, SLOT(startAutoDrop()));
 
-    emit undoPossible(undoList.count() > 1);
+    emit undoPossible(d->undoList.count() > 1);
+    emit redoPossible(d->redoList.count() > 1);
 }
 
 bool DealerScene::isInitialDeal() const { return d->initialDeal; }
@@ -365,10 +373,11 @@
     }
     setGameState( dealer.attribute("data") );
 
-    if (undoList.count() > 1) {
-        setState(undoList.takeLast());
+    if (d->undoList.count() > 1) {
+        setState(d->undoList.takeLast());
         takeState(); // copying it again
-        emit undoPossible(undoList.count() > 1);
+        eraseRedo();
+        emit undoPossible(d->undoList.count() > 1);
     }
 
     emit updateMoves();
@@ -379,14 +388,14 @@
 {
     unmarkAll();
     stopDemo();
-    kDebug(11111) << "::undo" << undoList.count();
-    if (undoList.count() > 1) {
-        delete undoList.last();
-        undoList.removeLast(); // the current state
-        setState(undoList.takeLast());
+    kDebug(11111) << "::undo" << d->undoList.count();
+    if (d->undoList.count() > 1) {
+        d->redoList.append( d->undoList.takeLast() );
+        setState(d->undoList.takeLast());
         emit updateMoves();
         takeState(); // copying it again
-        emit undoPossible(undoList.count() > 1);
+        emit undoPossible(d->undoList.count() > 1);
+        emit redoPossible(d->redoList.count() > 0);
         if ( d->toldAboutLostGame ) { // everything's possible again
             hintPossible( true );
             demoPossible( true );
@@ -397,7 +406,34 @@
     emit gameSolverUnknown();
 }
 
+void DealerScene::redo()
+{
+    unmarkAll();
+    stopDemo();
+    kDebug(11111) << "::redo" << d->redoList.count();
+    if (d->redoList.count() > 0) {
+        setState(d->redoList.takeLast());
+        emit updateMoves();
+        takeState(); // copying it again
+        emit undoPossible(d->undoList.count() > 1);
+        emit redoPossible(d->redoList.count() > 0);
+        if ( d->toldAboutLostGame ) { // everything's possible again
+            hintPossible( true );
+            demoPossible( true );
+            d->toldAboutLostGame = false;
+            d->toldAboutWonGame = false;
+        }
+    }
+    emit gameSolverUnknown();
+}
 
+void DealerScene::eraseRedo()
+{
+    qDeleteAll(d->redoList);
+    d->redoList.clear();
+    emit redoPossible( false );
+}
+
 // ================================================================
 //                         class DealerScene
 
@@ -774,8 +810,10 @@
     delete d->wonItem;
     d->wonItem = 0;
     d->gothelp = false;
-    qDeleteAll(undoList);
-    undoList.clear();
+    qDeleteAll(d->undoList);
+    d->undoList.clear();
+    qDeleteAll(d->redoList);
+    d->redoList.clear();
     d->toldAboutLostGame = false;
     d->toldAboutWonGame = false;
     emit updateMoves();
@@ -875,6 +913,7 @@
                     countGame();
                 }
                 takeState();
+                eraseRedo();
             }
             return;
         }
@@ -883,6 +922,7 @@
             assert(c);
             pileClicked(c);
             takeState();
+            eraseRedo();
             return;
         }
     }
@@ -970,6 +1010,7 @@
         countGame();
         c->source()->moveCards(movingCards, (*best).source);
         takeState();
+        eraseRedo();
     }
     movingCards.clear();
 }
@@ -1000,6 +1041,7 @@
         countGame();
     }
     takeState();
+    eraseRedo();
 }
 
 bool DealerScene::cardClicked(Card *c) {
@@ -1337,6 +1379,7 @@
     c->disconnect();
     c->stopAnimation(); // should be a no-op
     takeState();
+    eraseRedo();
 }
 
 void DealerScene::waitForWonAnim(Card *c)
@@ -1376,8 +1419,10 @@
 {
     // Deal in the range of 1 to INT_MAX.
     gamenumber = ((gmn < 1) ? 1 : ((gmn > 0x7FFFFFFF) ? 0x7FFFFFFF : gmn));
-    qDeleteAll(undoList);
-    undoList.clear();
+    qDeleteAll(d->undoList);
+    d->undoList.clear();
+    qDeleteAll(d->redoList);
+    d->redoList.clear();
 }
 
 void DealerScene::addPile(Pile *p)
@@ -1615,6 +1660,7 @@
 
     emit demoActive( true );
     takeState();
+    eraseRedo();
 }
 
 Card *DealerScene::demoNewCards()
--- trunk/KDE/kdegames/kpat/dealer.h #862778:862779
@@ -147,7 +147,7 @@
 
     void won();
     bool demoActive() const;
-    int getMoves() const { return undoList.count(); }
+    int getMoves() const;
 
     enum { None = 0, Hint = 1, Demo = 2, Redeal = 4 } Actions;
 
@@ -180,7 +180,9 @@
     void relayoutPiles();
     void slotShowGame(bool);
     void takeState();
+    void eraseRedo();
     void undo();
+    void redo();
     void slotSolverEnded();
     void slotSolverFinished();
     void slotAutoDrop();
@@ -195,6 +197,7 @@
 
 signals:
     void undoPossible(bool poss);
+    void redoPossible(bool poss);
     void hintPossible(bool poss);
     void demoPossible(bool poss);
     void redealPossible(bool poss);
@@ -224,7 +227,6 @@
 
 private:
     QList<QGraphicsItem *> marked;
-    QList<State*> undoList;
 
     bool moved;
     CardList movingCards;
--- trunk/KDE/kdegames/kpat/pwidget.cpp #862778:862779
@@ -92,6 +92,10 @@
     undo = KStandardGameAction::undo(this, SLOT(undoMove()), actionCollection());
     undo->setEnabled(false);
 
+    // Move
+    redo = KStandardGameAction::redo(this, SLOT(redoMove()), actionCollection());
+    redo->setEnabled(false);
+
     a = actionCollection()->addAction("choose_game");
     a->setText(i18n("&Choose Game..."));
     connect( a, SIGNAL( triggered( bool ) ), SLOT( chooseGame() ) );
@@ -191,6 +195,11 @@
         dill->dscene()->undo();
 }
 
+void pWidget::redoMove() {
+    if( dill && dill->dscene() )
+        dill->dscene()->redo();
+}
+
 void pWidget::helpGame()
 {
     if (!dill)
@@ -203,6 +212,11 @@
     undo->setEnabled(poss);
 }
 
+void pWidget::redoPossible(bool poss)
+{
+    redo->setEnabled(poss);
+}
+
 void pWidget::enableAutoDrop()
 {
     bool drop = dropaction->isChecked();
@@ -369,6 +383,7 @@
 
     kDebug(11111) << "dill" << dill << " " << dill->dscene();
     connect(dill->dscene(), SIGNAL(undoPossible(bool)), SLOT(undoPossible(bool)));
+    connect(dill->dscene(), SIGNAL(redoPossible(bool)), SLOT(redoPossible(bool)));
     connect(dill->dscene(), SIGNAL(gameLost()), SLOT(gameLost()));
     connect(dill->dscene(), SIGNAL(gameInfo(const QString&)),
             SLOT(slotGameInfo(const QString &)));
--- trunk/KDE/kdegames/kpat/pwidget.h #862778:862779
@@ -47,6 +47,7 @@
 
 public slots:
     void undoMove();
+    void redoMove();
     void newGameType();
     void slotNewGameType();
     void restart();
@@ -58,6 +59,7 @@
     void newGame();
     void chooseGame();
     void undoPossible(bool poss);
+    void redoPossible(bool poss);
     void gameLost();
     void slotGameInfo(const QString &);
     void slotUpdateMoves();
@@ -90,7 +92,7 @@
     PatienceView   *dill;
 
     KSelectAction  *games;
-    QAction        *undo;
+    QAction        *undo, *redo;
     KToggleAction  *dropaction;
     KToggleAction  *solveraction;
     QAction        *stats;
[prev in list] [next in list] [prev in thread] [next in thread] 

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