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

List:       kde-commits
Subject:    playground/games/draughts/src
From:       Piotr Banasiak <piotrbanasiak () onet ! pl>
Date:       2006-10-31 21:40:18
Message-ID: 1162330818.654338.20589.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 600808 by banasiak:

pure qt replaced with KDE classes

 M  +3 -2      CMakeLists.txt  
 M  +79 -47    draughts.cpp  
 M  +18 -5     draughts.h  
 A             draughtsui.rc  
 D             fileopen.xpm  
 D             fileprint.xpm  
 D             filesave.xpm  
 M  +16 -7     main.cpp  
 D             mainwindow.ui  
 D             src.pro  


--- trunk/playground/games/draughts/src/CMakeLists.txt #600807:600808
@@ -1,7 +1,7 @@
 
 set(draughts_SRCS
+   main.cpp
    draughts.cpp
-   main.cpp
    config.cpp
    aengine.cpp
    boardmodel.cpp
@@ -29,7 +29,6 @@
 
 kde4_add_ui_files(draughts_SRCS
    settings.ui
-   mainwindow.ui
    networkgame.ui
    newgame.ui
    engineinfo.ui
@@ -45,3 +44,5 @@
 target_link_libraries(draughts ${KDE4_KDEUI_LIBS})
 
 install(TARGETS draughts DESTINATION ${BIN_INSTALL_DIR})
+
+install( FILES draughtsui.rc  DESTINATION  ${DATA_INSTALL_DIR}/draughts )
\ No newline at end of file
--- trunk/playground/games/draughts/src/draughts.cpp #600807:600808
@@ -18,11 +18,16 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#include <QtGui>
-#include <QTreeView>
-#include <QTcpSocket>
-#include <QTcpServer>
+#include <kmainwindow.h>
+#include <kstatusbar.h>
+#include <kstdaction.h>
+#include <ktoggleaction.h>
+#include <kicon.h>
+#include <kstdaccel.h>
+#include <kmenubar.h>
+#include <ktoolbar.h>
 
+
 #include "draughts.h"
 #include "settingsdialog.h"
 #include "config.h"
@@ -47,7 +52,21 @@
 
 draughts::draughts()
 {
-    ui.setupUi(this);
+    //ui.setupUi(this);
+    ui_actionStop_thinking=0;
+// ui_actionNew=0;
+// ui_actionBack=0;
+// ui_actionForward=0; 
+// ui_actionConfiguration=0;
+// ui_actionForce_move=0;
+// 
+// ui_actionOpen_Game=0;
+// ui_actionSave_As=0;
+// ui_actionSave_Game=0;
+// ui_actionSetPlayers=0;
+// ui_actionNetGame=0;
+// ui_actionInvert_board=0;
+
     
     pEngine=0;
     engineFactory();
@@ -55,20 +74,15 @@
 
     connect( pGame, SIGNAL(gameOver( int )), this, SLOT(onGameOver(int)));
     connect( pGame, SIGNAL(documentChanged()), this, SLOT(onDocumentChanged()));
-    connect( ui.actionStop_thinking, SIGNAL(triggered()), this, SLOT(stopThinking()) \
                );
-    pGame->newGame();
+    
+    
     //loadBook();
     
     createView();
     
+    pGame->newGame();
+    
     connectActions(  );
-    gameToolBar = addToolBar(tr("Game"));
-    gameToolBar->addAction(ui.actionNew);
-    gameToolBar->addAction(ui.actionBack);
-    gameToolBar->addAction(ui.actionForward); 
-    gameToolBar->addAction(ui.actionConfiguration);
-    gameToolBar->addAction(ui.actionForce_move);
-    gameToolBar->addAction(ui.actionStop_thinking);
     
     pWhitePlayer = new humanPlayer( this,boardModel );//new humanPlayer(this);
     connect( pWhitePlayer, SIGNAL(moveFinished(LegalMove)), this, \
SLOT(onMoveFinished(LegalMove))); @@ -78,9 +92,6 @@
     connect( pBlackPlayer, SIGNAL(moveFinished(LegalMove)), this, \
SLOT(onMoveFinished(LegalMove)));  pNetPlayer=0;
     wakeUp();
-    
-    
-
 }
 
 void draughts::loadBook()
@@ -109,27 +120,44 @@
 
 void draughts::connectActions()
 {
-    connect( ui.actionOpen_Game, SIGNAL(triggered()), this, SLOT(open()));
-    connect( ui.actionSave_As, SIGNAL(triggered()), this, SLOT(saveAs()));
-    connect( ui.actionSave_Game, SIGNAL(triggered()), this, SLOT(save()));
+    // File
+    KAction *quitAct = KStdAction::quit(this, SLOT(close()), actionCollection(), \
"quit"); +    KAction *ui_actionNew = KStdAction::openNew(this, SLOT(newGame()), \
actionCollection(), "newGame"); +    KAction *ui_actionOpen_Game = \
KStdAction::open(this, SLOT(open()), actionCollection(), "open"); +    KAction \
*ui_actionSave_Game = KStdAction::save(this, SLOT(save()), actionCollection(), \
"save"); +    KAction *ui_actionSave_As = KStdAction::saveAs(this, SLOT(saveAs()), \
actionCollection(), "saveAs");  
+    // GAME
+    KAction *ui_actionNetGame =  new KAction(KIcon(":/images/connect.png"), \
i18n("network game"), actionCollection(), "networkGame") ; +    \
connect(ui_actionNetGame, SIGNAL(triggered()), this, SLOT(onNetGame())); +    
+    KAction *ui_actionBack =KStdAction::undo(this, SLOT(takeBack()), \
actionCollection(), "takeBack"); +    KAction *ui_actionForward = \
KStdAction::redo(this, SLOT(forward()), actionCollection(), "forward"); +    ///@todo \
implement logic behind +    //ui_actionBack->setEnabled(false);
+    //ui_actionForward->setEnabled(false);
+    
+    KAction *ui_actionForce_move = new KAction( i18n("force move"), \
actionCollection(), "forceMove"); +    connect(ui_actionForce_move, \
SIGNAL(triggered()), this, SLOT(onForceMove()) );  
-    connect( ui.actionNew, SIGNAL(triggered()), this, SLOT(newGame()));
-    connect( ui.actionBack, SIGNAL(triggered()), this, SLOT(takeBack()));
-    connect( ui.actionForward, SIGNAL(triggered()), this, SLOT(forward()));
-
-    connect( ui.actionConfiguration , SIGNAL(triggered()), this, \
                SLOT(preferencesDialog()));
-
-    connect( ui.actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
-    connect( ui.actionAbout, SIGNAL(triggered()), this, SLOT(about()));
+    KAction *ui_actionSetPlayers = new KAction( i18n("set players"), \
actionCollection(), "setPlayers"); +    connect(ui_actionSetPlayers, \
SIGNAL(triggered()), this, SLOT(onSetPlayers()) );  
-    connect( ui.actionSetPlayers, SIGNAL(triggered()), this, SLOT(onSetPlayers()));
-    connect( ui.actionForce_move, SIGNAL(triggered()), this, SLOT(onForceMove()));
+    KAction *ui_actionConfiguration = KStdAction::preferences(this, \
SLOT(preferencesDialog()), actionCollection(), "Preferences");  
-    connect( ui.actionNetGame, SIGNAL(triggered()), this, SLOT(onNetGame()));
-
-    connect( pGame, SIGNAL(engineInfoChanged( const EngineInfo * )), \
                engineInfoWidget, SLOT(onEngineInfoChanged( const EngineInfo * )));
-    connect( ui.actionInvert_board, SIGNAL(toggled(bool)), boardView, \
SLOT(invertBoard(bool))); +    ui_actionStop_thinking =  new \
KAction(KIcon(":/images/stop.png"), i18n("stop thinking"), actionCollection(), \
"stopThinking") ; +    ui_actionStop_thinking->setEnabled(false);
+    connect(ui_actionStop_thinking, SIGNAL(triggered()), this, \
SLOT(stopThinking())); +    
+    // View
+    KAction *ui_actionInvert_board =  new KToggleAction(i18n("invert board"), \
actionCollection(), "invertBoard") ; +    connect(ui_actionInvert_board, \
SIGNAL(toggled(bool)), boardView, SLOT(invertBoard(bool))); +    
+     setupGUI();
+     
+    toolBar()->addAction(ui_actionBack);
+    toolBar()->addAction(ui_actionForward);
+    toolBar()->addAction(ui_actionStop_thinking);
 }
 
 void draughts::closeEvent(QCloseEvent *event)
@@ -182,7 +210,7 @@
 
 bool draughts::save()
 {
-    statusBar()->showMessage("save not implemented", 2000);
+    //statusBar()->showMessage("save not implemented", 2000);
     if (curFile.isEmpty()) 
     {
         return saveAs();
@@ -259,7 +287,7 @@
     pGame->load( file );
 
     setCurrentFile(fileName);
-    statusBar()->showMessage(tr("File loaded"), 2000);
+    //statusBar()->showMessage(tr("File loaded"), 2000);
 }
 
 bool draughts::saveFile(const QString &fileName)
@@ -280,7 +308,7 @@
     pGame->save( file );
     
     setCurrentFile(fileName);
-    statusBar()->showMessage(tr("File saved"), 2000);
+    //statusBar()->showMessage(tr("File saved"), 2000);
     return true;
 }
 
@@ -318,7 +346,7 @@
  */
 void draughts::newGame()
 {
-    statusBar()->showMessage("newGame", 2000);
+    //statusBar()->showMessage("newGame", 2000);
 
     int resp=0;
     newGameDialog *d=new newGameDialog(this);
@@ -352,7 +380,7 @@
 {
     if( pNetPlayer ) return;
     
-    statusBar()->showMessage("half move takeBack", 2000);
+    //statusBar()->showMessage("half move takeBack", 2000);
     if (pGame->takeBack())
     {
        AbstractPlayer *p=pWhitePlayer;
@@ -368,7 +396,7 @@
 {
     if( pNetPlayer ) return;
     
-    statusBar()->showMessage("half move FORWARD", 2000);
+    //statusBar()->showMessage("half move FORWARD", 2000);
     if (pGame->forward())
     {
        AbstractPlayer *p=pWhitePlayer;
@@ -414,6 +442,10 @@
  */
 void draughts::createView()
 {
+//menuBar ()->addMenu( new QMenu( "file" ) );
+//menuBar ()->addMenu( new QMenu( "game" ) );
+
+    setCentralWidget( new QWidget() );// uwaga to pomoglo zadzialal
     boardModel = new BoardModel( pGame );
 
     PieceDelegate *delegate = new PieceDelegate(this);
@@ -453,7 +485,6 @@
 
     centralWidget()->setLayout( layout );
     resize( sizeHint() );
-
 }
 
 
@@ -544,7 +575,6 @@
  */
 void draughts::onDocumentChanged()
 {
-
     Q_ASSERT( pGame );
     int whiteM, whiteK, blackM, blackK, moveNr,toDraw;
     int gameOver=pGame->getStatus( whiteM,  whiteK, blackM,  blackK,  \
moveNr,toDraw); @@ -554,7 +584,7 @@
     if(gameOver) toMove="Game Over";
     QString status=QString("White: (%1+%2) Black: (%3+%4). %5 .moves to draw: \
%6").arg(whiteM).arg(whiteK).arg(blackM).arg(blackK).arg(toMove).arg(toDraw);  
-    statusBar()->showMessage(status);
+    //statusBar()->showMessage(status);
 }
 
 /*!
@@ -575,7 +605,7 @@
       p=pBlackPlayer;
 
     if( p->getType() == AbstractPlayer::engineType )
-       ui.actionStop_thinking->setEnabled(true);
+       ui_actionStop_thinking->setEnabled(true);
     p->yourMove(&LM);
     
     if( pGame->isGameOver() )
@@ -583,7 +613,8 @@
        qDebug("is game over !!!");
        return;
     }
-    ui.actionStop_thinking->setEnabled(false);
+    
+    ui_actionStop_thinking->setEnabled(false);
 }
 
 void draughts::setPlayers( newGameDialog *d )
@@ -714,14 +745,15 @@
 {
    qDebug( "draughts::wakeUp()");
    
-   ui.actionStop_thinking->setEnabled(true);
+   ui_actionStop_thinking->setEnabled(true);
    Board *pB=pGame->getCurrentBoard();
    const LegalMove *pLastMove=pGame->getLastMove();
    if( pB->isWhiteTurn())
       pWhitePlayer->yourMove(pLastMove);
     else
       pBlackPlayer->yourMove(pLastMove);
-   ui.actionStop_thinking->setEnabled(false);
+
+   ui_actionStop_thinking->setEnabled(false);
 }
 
 
--- trunk/playground/games/draughts/src/draughts.h #600807:600808
@@ -22,7 +22,9 @@
 #ifndef DRAUGHTS_H
 #define DRAUGHTS_H
 
-#include "ui_mainwindow.h"
+#include <QObject>
+#include <kmainwindow.h>
+#include <kaction.h>
 #include "legalmove.h"
 
 
@@ -43,7 +45,7 @@
 class Game;
 class AEngine;
 
-class draughts : public QMainWindow
+class draughts : public KMainWindow
 {
     Q_OBJECT
 
@@ -71,9 +73,7 @@
     void stopThinking();
 
 private:
-    Ui::MainWindow ui;
     void connectActions();
-    void createMenus();
     void loadBook();
     bool maybeSave();
     void loadFile(const QString &fileName);
@@ -102,9 +102,22 @@
     AbstractPlayer *pBlackPlayer;
     AbstractPlayer*& getCurrentPlayer();
     AbstractPlayer*& getNextPlayer();
-    
 
+    KAction *ui_actionStop_thinking;
+//     KAction *ui_actionNew;
+//     KAction *ui_actionBack;
+//     KAction *ui_actionForward; 
+//     KAction *ui_actionConfiguration;
+//     KAction *ui_actionForce_move;
+// 
+//     KAction *ui_actionOpen_Game;
+//     KAction *ui_actionSave_As;
+//     KAction *ui_actionSave_Game;
+//     KAction *ui_actionSetPlayers;
+//     KAction *ui_actionNetGame;
+//     KAction *ui_actionInvert_board;
 
+
 public slots:
     void preferencesDialog();
     void onSizeChanged( int oldSize );
--- trunk/playground/games/draughts/src/main.cpp #600807:600808
@@ -18,17 +18,26 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
 
-#include <QApplication>
 #include "draughts.h"
 
 int main( int argc, char ** argv ) 
 {
    Q_INIT_RESOURCE(resources);
-   QApplication app(argc, argv);
-    draughts * mw = new draughts();
-    //mw->setCaption( "qqq" );
-    mw->show();
-    //a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
-    return app.exec();
+
+    KAboutData about("draughts", I18N_NOOP("Draughts"), "0.1", I18N_NOOP("A board \
game"), KAboutData::License_GPL, "Piotr Banasiak"); +    about.addAuthor("Piotr \
Banasiak", "", "piotrbanasiak@onet.pl"); +    KCmdLineArgs::init(argc, argv, &about);
+
+    KApplication application;
+    draughts *mainWin = new draughts;
+
+    //application.setMainWidget( mainWin );
+    mainWin->show();
+
+    return application.exec();
 }


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

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