diff --git a/kreversiview.cpp b/kreversiview.cpp index b444533d27b4a68ce6417a93c9c99b2218d64415..2ee4274de2ca84a0f6606745016264fc79d87095 100644 --- a/kreversiview.cpp +++ b/kreversiview.cpp @@ -19,17 +19,15 @@ #include "kreversiview.h" -KReversiView::KReversiView(KReversiGame* game, QWidget *parent) : +KReversiView::KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider) : KgDeclarativeView(parent), m_delay(ANIMATION_SPEED_NORMAL), m_game(0), m_showLastMove(false), m_showLegalMoves(false), - m_showLabels(false) + m_showLabels(false), m_provider(provider) { - qmlRegisterType("ColorScheme", 1, 0, "ColorScheme"); - - m_provider = new KgThemeProvider(); - m_provider->discoverThemes("appdata", QLatin1String("pics")); m_provider->setDeclarativeEngine("themeProvider", engine()); + qmlRegisterType("ColorScheme", 1, 0, "ColorScheme"); + QString path = KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml")); setSource(QUrl::fromLocalFile(path)); diff --git a/kreversiview.h b/kreversiview.h index e93145cfce61676d1d11c5331930af311bd07a19..d49a82cf93dba6536a5ac4cc7dc3e5b771004f1e 100644 --- a/kreversiview.h +++ b/kreversiview.h @@ -44,7 +44,7 @@ class KReversiView : public KgDeclarativeView Q_OBJECT public: enum ChipsPrefix { Colored, BlackWhite }; - explicit KReversiView(KReversiGame* game, QWidget *parent = 0); + explicit KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider); /** * Sets the game object which this view will visualize/use diff --git a/mainwindow.cpp b/mainwindow.cpp index bf544bc75f189679e25bad597f049f2ba6582af1..65930522b9f99fd3d636a024191fe921f980bf14 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -78,10 +78,13 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) : KXmlGuiWindow(parent), m_view(0), m_game(0), m_historyDock(0), m_historyView(0), m_firstShow(true), m_startInDemoMode(startDemo), /*m_lowestSkill(6),*/ - m_undoAct(0), m_hintAct(0), m_demoAct(0) + m_undoAct(0), m_hintAct(0), /*m_demoAct(0),*/ m_startDialog(0) { memset(m_player, 0, sizeof(m_player)); + m_provider = new KgThemeProvider(); + m_provider->discoverThemes("appdata", QLatin1String("pics")); + statusBar()->insertItem(i18n("Press start game!"), COMMON_STATUSBAR_ID); statusBar()->insertItem("", BLACK_STATUSBAR_ID); statusBar()->insertItem("", WHITE_STATUSBAR_ID); @@ -105,7 +108,7 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) addDockWidget(Qt::RightDockWidgetArea, m_historyDock); // create main game view - m_view = new KReversiView(m_game, this); + m_view = new KReversiView(m_game, this, m_provider); setCentralWidget(m_view); // initialise actions @@ -118,8 +121,14 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) m_historyDock->hide(); - // initialise dialog handlers - connect(&m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady())); + // initialise dialog handler + m_startDialog = new StartGameDialog(this, m_provider); + connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady())); +} + +KReversiMainWindow::~KReversiMainWindow() +{ + delete m_provider; } void KReversiMainWindow::setupActionsInit() @@ -222,7 +231,8 @@ void KReversiMainWindow::slotShowMovesHistory(bool toggled) // if (m_game && m_game->isGameOver()) // slotNewGame(); -// toggled = true; +// toggled = true +// m_undoAct->setEnabled(m_game->canUndo());; // m_demoAct->setIcon(KIcon(QLatin1String("media-playback-pause"))); // m_demoAct->setChecked(true); // } @@ -243,7 +253,7 @@ void KReversiMainWindow::slotNewGame() // if (m_undoAct) // m_undoAct->setEnabled(false); - m_startDialog.exec(); + m_startDialog->exec(); } void KReversiMainWindow::slotGameOver() @@ -251,9 +261,6 @@ void KReversiMainWindow::slotGameOver() m_hintAct->setEnabled(false); m_undoAct->setEnabled(m_game->canUndo()); -// //TODO: only if it is not computer-computer match -// m_undoAct->setEnabled(m_game->canUndo()); - int blackScore = m_game->playerScore(Black); int whiteScore = m_game->playerScore(White); @@ -330,8 +337,6 @@ void KReversiMainWindow::slotGameOver() void KReversiMainWindow::slotMoveFinished() { -// m_undoAct->setEnabled(m_game->canUndo()); - updateHistory(); updateStatusBar(); @@ -372,7 +377,7 @@ void KReversiMainWindow::slotHighscores() void KReversiMainWindow::slotDialogReady() { - GameStartInformation info = m_startDialog.createGameStartInformation(); + GameStartInformation info = m_startDialog->createGameStartInformation(); receivedGameStartInformation(info); } diff --git a/mainwindow.h b/mainwindow.h index 10285ebac243e7f73174b89cb631233f87f8c3a6..458b40422743e9a73148bb850cf22e87ef790363 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -70,6 +70,7 @@ class KReversiMainWindow : public KXmlGuiWindow Q_OBJECT public: explicit KReversiMainWindow(QWidget* parent = 0, bool startDemo = false); + ~KReversiMainWindow(); public slots: void slotNewGame(); void levelChanged(); @@ -94,7 +95,7 @@ private: void receivedGameStartInformation(GameStartInformation info); KReversiPlayer *m_player[2]; - StartGameDialog m_startDialog; + StartGameDialog *m_startDialog; GameStartInformation m_nowPlayingInfo; @@ -106,9 +107,11 @@ private: bool m_firstShow; bool m_startInDemoMode; + KgThemeProvider *m_provider; + QAction *m_undoAct; QAction *m_hintAct; - QAction *m_demoAct; +// QAction *m_demoAct; KToggleAction *m_showLast; KToggleAction *m_showLegal; KToggleAction *m_showMovesAct; diff --git a/startgamedialog.cpp b/startgamedialog.cpp index c645c0c466e543e8d1bfd127dfb73094a87d8c85..bea9301ea5ed89f76b5181bf1d30ef56e8736069 100644 --- a/startgamedialog.cpp +++ b/startgamedialog.cpp @@ -3,10 +3,12 @@ #include #include +#include +#include -StartGameDialog::StartGameDialog(QWidget *parent) : +StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) : KDialog(parent), - ui(new Ui::StartGameDialog) + ui(new Ui::StartGameDialog), m_provider(provider) { setModal(true); @@ -28,6 +30,19 @@ StartGameDialog::StartGameDialog(QWidget *parent) : ui->blackTypeGroup->setId(ui->blackHuman, GameStartInformation::Human); ui->blackTypeGroup->setId(ui->blackAI, GameStartInformation::AI); + QList< const KgDifficultyLevel * > diffList = Kg::difficulty()->levels(); + const KIcon icon("games-difficult"); + + for (int i = 0; i < diffList.size(); i++) { + ui->blackSkill->addItem(icon, diffList.at(i)->title()); + ui->whiteSkill->addItem(icon, diffList.at(i)->title()); + if (diffList.at(i)->isDefault()) + { + ui->whiteSkill->setCurrentIndex(i); + ui->blackSkill->setCurrentIndex(i); + } + } + connect(ui->blackTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateBlack(int))); connect(ui->whiteTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateWhite(int))); diff --git a/startgamedialog.h b/startgamedialog.h index bba58899501c76d1660875c9cfff41d254a6fd57..7d0e26cb9750eca183760d805bfd74912a67beb2 100644 --- a/startgamedialog.h +++ b/startgamedialog.h @@ -5,6 +5,7 @@ #include "gamestartinformation.h" #include "commondefs.h" #include +#include namespace Ui { class StartGameDialog; @@ -15,7 +16,7 @@ class StartGameDialog : public KDialog Q_OBJECT public: - explicit StartGameDialog(QWidget *parent = 0); + explicit StartGameDialog(QWidget *parent, KgThemeProvider *provider); ~StartGameDialog(); GameStartInformation createGameStartInformation() const; @@ -32,6 +33,7 @@ private: Ui::StartGameDialog *ui; QWidget *m_contents; KUser m_user; + KgThemeProvider *m_provider; }; #endif // STARTGAMEDIALOG_H