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

List:       kde-commits
Subject:    KDE/kdegames/kpat
From:       Parker Coates <parker.coates () gmail ! com>
Date:       2009-03-27 4:17:37
Message-ID: 1238127457.524621.26641.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 945182 by coates:

Fixed a minor issue that caused changes to game action (Hint, Demo, Redeal, Drop) \
shortcuts to be forgotten.

In the process moved the game actions to pWidget. This allowed for greater \
consistency and greatly simplified action updates.

 M  +95 -48    pwidget.cpp  
 M  +10 -3     pwidget.h  
 M  +0 -77     view.cpp  
 M  +0 -7      view.h  


--- trunk/KDE/kdegames/kpat/pwidget.cpp #945181:945182
@@ -80,36 +80,27 @@
     current_pwidget = this;
     // KCrash::setEmergencySaveFunction(::saveGame);
 
-    KAction *a;
     // Game
-    a = KStandardGameAction::gameNew(this, SLOT(newGame()), actionCollection());
-    a->setEnabled( false );
-    a = KStandardGameAction::restart(this, SLOT(restart()), actionCollection());
-    a->setEnabled( false );
+    KStandardGameAction::gameNew(this, SLOT(newGame()), actionCollection());
+    KStandardGameAction::restart(this, SLOT(restart()), actionCollection());
     KStandardGameAction::load(this, SLOT(openGame()), actionCollection());
     recent = KStandardGameAction::loadRecent(this, SLOT(openGame(const KUrl&)), \
actionCollection());  recent->loadEntries( KGlobal::config()->group( QString() ));
-    a = KStandardGameAction::save(this, SLOT(saveGame()), actionCollection());
-    a->setEnabled( false );
+    KStandardGameAction::save(this, SLOT(saveGame()), actionCollection());
     KStandardGameAction::quit(this, SLOT(close()), actionCollection());
 
     // Move
     undo = KStandardGameAction::undo(this, SLOT(undoMove()), actionCollection());
-    undo->setEnabled(false);
-
-    // Move
     redo = KStandardGameAction::redo(this, SLOT(redoMove()), actionCollection());
-    redo->setEnabled(false);
 
+    KAction *a;
     a = actionCollection()->addAction("choose_game");
     a->setText(i18n("&Choose Game..."));
     connect( a, SIGNAL( triggered( bool ) ), SLOT( chooseGame() ) );
-    a->setEnabled( false );
 
     a = actionCollection()->addAction("change_game_type");
     a->setText(i18n("Change Game Type..."));
     connect( a, SIGNAL( triggered( bool ) ), SLOT( slotShowGameSelectionScreen() ) \
                );
-    a->setEnabled( false );
 
     a = actionCollection()->addAction("random_set");
     a->setText(i18n("Random Cards"));
@@ -134,22 +125,32 @@
     a->setText(i18n("Statistics"));
     connect( a, SIGNAL( triggered( bool ) ), SLOT(showStats()) );
 
+    hintaction = KStandardGameAction::hint( 0, 0, actionCollection() );
+
+    demoaction = KStandardGameAction::demo( 0, 0, actionCollection() );
+
+    redealaction = actionCollection()->addAction("game_redeal");
+    redealaction->setText( i18n("&Redeal") );
+    redealaction->setIcon( KIcon("roll") );
+
+    dropaction = actionCollection()->addAction("game_drop");
+    dropaction->setText( i18n("Drop") );
+    dropaction->setIcon( KIcon("legalmoves") );
+
     gamehelpaction = actionCollection()->addAction("help_game");
     connect( gamehelpaction, SIGNAL( triggered( bool ) ), SLOT(helpGame()));
     gamehelpaction->setShortcuts( KShortcut( Qt::Key_F2 ) );
 
     KConfigGroup cg(KGlobal::config(), settings_group );
 
-    dropaction = new KToggleAction(i18n("&Enable Autodrop"), this);
-    actionCollection()->addAction("enable_autodrop", dropaction);
-    connect( dropaction, SIGNAL( triggered( bool ) ), SLOT(enableAutoDrop()) );
-    dropaction->setEnabled( false );
-    dropaction->setChecked( cg.readEntry("Autodrop", true) );
+    autodropaction = new KToggleAction(i18n("&Enable Autodrop"), this);
+    actionCollection()->addAction("enable_autodrop", autodropaction);
+    connect( autodropaction, SIGNAL( triggered( bool ) ), SLOT(enableAutoDrop()) );
+    autodropaction->setChecked( cg.readEntry("Autodrop", true) );
 
     solveraction = new KToggleAction(i18n("E&nable Solver"), this);
     actionCollection()->addAction("enable_solver", solveraction);
     connect( solveraction, SIGNAL( triggered( bool ) ), SLOT( enableSolver() ) );
-    solveraction->setEnabled( false );
     solveraction->setChecked( cg.readEntry("Solver", true) );
 
     rememberstateaction = new KToggleAction(i18n("&Remember State on Exit"), this);
@@ -218,11 +219,12 @@
 
 void pWidget::enableAutoDrop()
 {
-    bool drop = dropaction->isChecked();
+    bool drop = autodropaction->isChecked();
     KConfigGroup cg(KGlobal::config(), settings_group );
     cg.writeEntry( "Autodrop", drop);
     if ( dill )
         dill->setAutoDropEnabled(drop);
+    updateActions();
 }
 
 void pWidget::enableSolver()
@@ -379,15 +381,6 @@
         dill->setScene( DealerInfoList::self()->games().first()->createGame() );
     }
 
-    actionCollection()->action( "choose_game" )->setEnabled( true );
-    actionCollection()->action( "enable_autodrop" )->setEnabled( true );
-    actionCollection()->action( "enable_solver" )->setEnabled( true );
-    actionCollection()->action( "game_new" )->setEnabled( true );
-    actionCollection()->action( "game_restart" )->setEnabled( true );
-    actionCollection()->action( "game_save" )->setEnabled( true );
-    actionCollection()->action( "change_game_type" )->setEnabled( true );
-    actionCollection()->action( "help_game" )->setEnabled( true );
-
     enableAutoDrop();
     enableSolver();
 
@@ -395,21 +388,16 @@
     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 &)));
+    connect(dill->dscene(), SIGNAL(gameInfo(QString)), SLOT(slotGameInfo(QString)));
     connect(dill->dscene(), SIGNAL(updateMoves()), SLOT(slotUpdateMoves()));
     connect(dill->dscene(), SIGNAL(gameSolverStart()), SLOT(slotGameSolverStart()));
     connect(dill->dscene(), SIGNAL(gameSolverWon()), SLOT(slotGameSolverWon()));
     connect(dill->dscene(), SIGNAL(gameSolverLost()), SLOT(slotGameSolverLost()));
     connect(dill->dscene(), SIGNAL(gameSolverUnknown()), \
SLOT(slotGameSolverUnknown()));  
-    dill->setAutoDropEnabled(dropaction->isChecked());
-
     m_stack->setCurrentWidget(dill);
 
-    // it's a bit tricky - we have to do this here as the
-    // base class constructor runs before the derived class's
-    // dill->takeState();
+    updateActions();
 
     QTimer::singleShot( 0, this, SLOT( show() ) );
 }
@@ -427,26 +415,85 @@
             m_stack->addWidget(m_bubbles);
             connect( m_bubbles, SIGNAL( gameSelected( int ) ), SLOT( \
slotGameSelected( int ) ) );  }
+        m_stack->setCurrentWidget(m_bubbles);
 
-        guiFactory()->unplugActionList( this, QString::fromLatin1("game_actions") );
-
-        actionCollection()->action( "choose_game" )->setEnabled( false );
-        actionCollection()->action( "enable_autodrop" )->setEnabled( false );
-        actionCollection()->action( "enable_solver" )->setEnabled( false );
-        actionCollection()->action( "game_new" )->setEnabled( false );
-        actionCollection()->action( "game_restart" )->setEnabled( false );
-        actionCollection()->action( "game_save" )->setEnabled( false );
-        actionCollection()->action( "change_game_type" )->setEnabled( false );
-        actionCollection()->action( "help_game" )->setEnabled( false );
-
         gamehelpaction->setText(i18n("Help &with Current Game"));
 
-        m_stack->setCurrentWidget(m_bubbles);
+        updateActions();
 
         setGameCaption();
     }
 }
 
+void pWidget::updateActions()
+{
+    bool gameInProgress = dill && dill->dscene() && m_stack->currentWidget() == \
dill; +
+    actionCollection()->action( "game_new" )->setEnabled( gameInProgress );
+    actionCollection()->action( "game_restart" )->setEnabled( gameInProgress );
+    actionCollection()->action( "game_save" )->setEnabled( gameInProgress );
+    actionCollection()->action( "choose_game" )->setEnabled( gameInProgress );
+    actionCollection()->action( "change_game_type" )->setEnabled( gameInProgress );
+    autodropaction->setEnabled( gameInProgress );
+    solveraction->setEnabled( gameInProgress );
+    gamehelpaction->setEnabled( gameInProgress );
+
+    hintaction->setEnabled( false );
+    demoaction->setEnabled( false );
+    redealaction->setEnabled( false );
+    dropaction->setEnabled( false );
+    guiFactory()->unplugActionList( this, "game_actions" );
+
+    if ( gameInProgress )
+    {
+        QList<QAction*> actionList;
+
+        if ( dill->dscene()->actions() & DealerScene::Hint )
+        {
+            hintaction->setEnabled( true );
+            hintaction->disconnect();
+            connect( hintaction, SIGNAL(triggered(bool)), dill, SLOT(hint()) );
+            connect( dill->dscene(), SIGNAL(hintPossible(bool)), hintaction, \
SLOT(setEnabled(bool)) ); +            actionList.append( hintaction );
+        }
+
+        if ( dill->dscene()->actions() & DealerScene::Demo )
+        {
+            demoaction->setEnabled( true );
+            demoaction->disconnect();
+            connect( demoaction, SIGNAL(triggered(bool)), dill->dscene(), \
SLOT(toggleDemo()) ); +            connect( dill->dscene(), SIGNAL(demoActive(bool)), \
this, SLOT(toggleDemoAction(bool)) ); +            connect( dill->dscene(), \
SIGNAL(demoPossible(bool)), demoaction, SLOT(setEnabled(bool)) ); +            \
actionList.append( demoaction ); +        }
+
+        if ( dill->dscene()->actions() & DealerScene::Redeal )
+        {
+            redealaction->setEnabled( true );
+            redealaction->disconnect();
+            connect( dill->dscene(), SIGNAL(redealPossible(bool)), redealaction, \
SLOT(setEnabled(bool)) ); +            connect( redealaction, \
SIGNAL(triggered(bool)), dill->dscene(), SLOT(redeal()) ); +            \
actionList.append( redealaction ); +        }
+
+        if ( !dill->dscene()->autoDrop() )
+        {
+            dropaction->setEnabled( true );
+            dropaction->disconnect();
+            connect( dropaction, SIGNAL(triggered(bool)), dill->dscene(), \
SLOT(slotAutoDrop()) ); +            actionList.append( dropaction );
+        }
+
+        guiFactory()->plugActionList( this, "game_actions", actionList );
+    }
+}
+
+void pWidget::toggleDemoAction(bool active) 
+{
+    demoaction->setChecked( active );
+    demoaction->setIcon( KIcon( active ? "media-playback-pause" : \
"media-playback-start" ) ); +}
+
 void pWidget::closeEvent(QCloseEvent *e)
 {
     QFile savedState(KStandardDirs::locateLocal("appdata", saved_state_file));
--- trunk/KDE/kdegames/kpat/pwidget.h #945181:945182
@@ -72,6 +72,7 @@
     void enableAutoDrop();
     void enableSolver();
     void enableRememberState();
+    void toggleDemoAction(bool active);
     void showStats();
 
     void slotGameSolverStart();
@@ -96,15 +97,21 @@
     void setGameCaption();
     bool allowedToStartNewGame();
     void startNew(long gameNumber);
+    void updateActions();
 
 private:
     // Members
-    KAction        *undo, *redo;
-    KToggleAction  *dropaction;
+    KAction        *undo;
+    KAction        *redo;
+    KAction        *demoaction;
+    KAction        *hintaction;
+    KAction        *redealaction;
+    KAction        *dropaction;
+    KAction        *gamehelpaction;
+    KToggleAction  *autodropaction;
     KToggleAction  *solveraction;
     KToggleAction  *rememberstateaction;
     KRecentFilesAction  *recent;
-    KAction        *gamehelpaction;
 
     cardMap        *m_cards; // possibly move to PatienceView
     QMap<int, const DealerInfo*>  m_dealer_map;
--- trunk/KDE/kdegames/kpat/view.cpp #945181:945182
@@ -77,10 +77,6 @@
 
 PatienceView::PatienceView( KXmlGuiWindow* _window, QWidget* _parent )
   : QGraphicsView( _parent ),
-    ademo(0),
-    ahint(0),
-    aredeal(0),
-    adrop(0),
     m_shown( true ),
     m_window( _window )
 {
@@ -125,8 +121,6 @@
 
     if ( oldscene )
         dscene()->relayoutPiles();
-
-    setupActions();
 }
 
 PatienceView *PatienceView::instance()
@@ -134,63 +128,6 @@
     return s_instance;
 }
 
-void PatienceView::setupActions()
-{
-    QList<QAction*> actionlist;
-
-    mainWindow()->guiFactory()->unplugActionList( mainWindow(), \
                QString::fromLatin1("game_actions"));
-
-    kDebug(11111) << "setupActions" << actions();
-
-    if (dscene()->actions() & DealerScene::Hint) {
-        ahint = KStandardGameAction::hint(this, SLOT(hint()), \
                mainWindow()->actionCollection());
-        connect( dscene(), SIGNAL( hintPossible( bool ) ), ahint, SLOT( setEnabled( \
                bool ) ) );
-        actionlist.append(ahint);
-    } else
-        ahint = 0;
-
-    if (dscene()->actions() & DealerScene::Demo) {
-        ademo = KStandardGameAction::demo(dscene(), SLOT(toggleDemo()), \
                mainWindow()->actionCollection());
-        connect( dscene(), SIGNAL( demoActive( bool ) ), this, SLOT( toggleDemo( \
                bool ) ) );
-        connect( dscene(), SIGNAL( demoPossible( bool ) ), ademo, SLOT( setEnabled( \
                bool ) ) );
-        actionlist.append(ademo);
-    } else
-        ademo = 0;
-
-    if (dscene()->actions() & DealerScene::Redeal) {
-        aredeal = mainWindow()->actionCollection()->addAction( "game_redeal" );
-        aredeal->setText( i18n("&Redeal") );
-        aredeal->setIcon( KIcon( "roll") );
-        connect( dscene(), SIGNAL( redealPossible( bool ) ), aredeal, SLOT( \
                setEnabled( bool ) ) );
-        connect( aredeal, SIGNAL( triggered( bool ) ), dscene(), SLOT( redeal() ) );
-        actionlist.append(aredeal);
-    } else
-        aredeal = 0;
-
-    delete adrop;
-    if ( !dscene()->autoDrop() ) {
-        adrop = mainWindow()->actionCollection()->addAction( "autodrop" );
-        adrop->setText( i18n("Drop!") );
-        adrop->setIcon( KIcon( "legalmoves") );
-        connect( adrop, SIGNAL( triggered( bool ) ), dscene(), SLOT( slotAutoDrop() \
                ) );
-        actionlist.append(adrop);
-    } else
-        adrop = 0;
-
-    mainWindow()->guiFactory()->plugActionList( mainWindow(), \
                QString::fromLatin1("game_actions"), actionlist);
-}
-
-
-void PatienceView::toggleDemo( bool flag )
-{
-    kDebug(11111) << flag;
-    ademo->setChecked( flag );
-    if ( !flag )
-        ademo->setIcon( KIcon( "media-playback-start") );
-    else
-        ademo->setIcon( KIcon( "media-playback-pause") );
-}
-
 void PatienceView::hint()
 {
     dscene()->hint();
@@ -204,27 +141,13 @@
 void PatienceView::setAutoDropEnabled(bool a)
 {
     dscene()->setAutoDropEnabled( a );
-    setupActions();
 }
 
 void PatienceView::startNew(long gameNumber)
 {
-    kDebug(11111) << "startnew\n";
-    if ( ahint )
-        ahint->setEnabled( true );
-    if ( ademo )
-        ademo->setEnabled( true );
-    if ( aredeal )
-        aredeal->setEnabled( true );
     dscene()->startNew( gameNumber );
 }
 
-void PatienceView::slotEnableRedeal( bool en )
-{
-    if ( aredeal )
-        aredeal->setEnabled( en );
-}
-
 DealerScene *PatienceView::dscene() const
 {
     return dynamic_cast<DealerScene*>( scene() );
--- trunk/KDE/kdegames/kpat/view.h #945181:945182
@@ -41,8 +41,6 @@
 
     void setViewSize(const QSize &size);
 
-    virtual void setupActions();
-
     void setSolverEnabled(bool a);
     void setAutoDropEnabled(bool a);
 
@@ -59,8 +57,6 @@
     // restart is pure virtual, so we need something else
     virtual void startNew(long gameNumber);
     void hint();
-    void slotEnableRedeal(bool);
-    void toggleDemo(bool);
 
 protected:
 
@@ -69,9 +65,6 @@
 
 protected:
 
-    QAction *ademo;
-    QAction *ahint, *aredeal, *adrop;
-
     static PatienceView *s_instance;
 
     bool m_shown;


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

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