Commit 368e343e authored by Denis Kuplyakov's avatar Denis Kuplyakov

Difficulty selector works on StartGameDialog now.

You can select computer skill on StartGameDialog. Also KgThemeProvider
is now stored in KReversiMainWindow to allow StartGameDialog use it.
parent 6b44917b
...@@ -19,17 +19,15 @@ ...@@ -19,17 +19,15 @@
#include "kreversiview.h" #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), KgDeclarativeView(parent), m_delay(ANIMATION_SPEED_NORMAL), m_game(0),
m_showLastMove(false), m_showLegalMoves(false), m_showLastMove(false), m_showLegalMoves(false),
m_showLabels(false) m_showLabels(false), m_provider(provider)
{ {
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
m_provider = new KgThemeProvider();
m_provider->discoverThemes("appdata", QLatin1String("pics"));
m_provider->setDeclarativeEngine("themeProvider", engine()); m_provider->setDeclarativeEngine("themeProvider", engine());
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
QString path = QString path =
KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml")); KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
setSource(QUrl::fromLocalFile(path)); setSource(QUrl::fromLocalFile(path));
......
...@@ -44,7 +44,7 @@ class KReversiView : public KgDeclarativeView ...@@ -44,7 +44,7 @@ class KReversiView : public KgDeclarativeView
Q_OBJECT Q_OBJECT
public: public:
enum ChipsPrefix { Colored, BlackWhite }; 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 * Sets the game object which this view will visualize/use
......
...@@ -78,10 +78,13 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) ...@@ -78,10 +78,13 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
: KXmlGuiWindow(parent), m_view(0), m_game(0), : KXmlGuiWindow(parent), m_view(0), m_game(0),
m_historyDock(0), m_historyView(0), m_historyDock(0), m_historyView(0),
m_firstShow(true), m_startInDemoMode(startDemo), /*m_lowestSkill(6),*/ 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)); 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(i18n("Press start game!"), COMMON_STATUSBAR_ID);
statusBar()->insertItem("", BLACK_STATUSBAR_ID); statusBar()->insertItem("", BLACK_STATUSBAR_ID);
statusBar()->insertItem("", WHITE_STATUSBAR_ID); statusBar()->insertItem("", WHITE_STATUSBAR_ID);
...@@ -105,7 +108,7 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) ...@@ -105,7 +108,7 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
addDockWidget(Qt::RightDockWidgetArea, m_historyDock); addDockWidget(Qt::RightDockWidgetArea, m_historyDock);
// create main game view // create main game view
m_view = new KReversiView(m_game, this); m_view = new KReversiView(m_game, this, m_provider);
setCentralWidget(m_view); setCentralWidget(m_view);
// initialise actions // initialise actions
...@@ -118,8 +121,14 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) ...@@ -118,8 +121,14 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
m_historyDock->hide(); m_historyDock->hide();
// initialise dialog handlers // initialise dialog handler
connect(&m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady())); m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
}
KReversiMainWindow::~KReversiMainWindow()
{
delete m_provider;
} }
void KReversiMainWindow::setupActionsInit() void KReversiMainWindow::setupActionsInit()
...@@ -222,7 +231,8 @@ void KReversiMainWindow::slotShowMovesHistory(bool toggled) ...@@ -222,7 +231,8 @@ void KReversiMainWindow::slotShowMovesHistory(bool toggled)
// if (m_game && m_game->isGameOver()) // if (m_game && m_game->isGameOver())
// slotNewGame(); // slotNewGame();
// toggled = true; // toggled = true
// m_undoAct->setEnabled(m_game->canUndo());;
// m_demoAct->setIcon(KIcon(QLatin1String("media-playback-pause"))); // m_demoAct->setIcon(KIcon(QLatin1String("media-playback-pause")));
// m_demoAct->setChecked(true); // m_demoAct->setChecked(true);
// } // }
...@@ -243,7 +253,7 @@ void KReversiMainWindow::slotNewGame() ...@@ -243,7 +253,7 @@ void KReversiMainWindow::slotNewGame()
// if (m_undoAct) // if (m_undoAct)
// m_undoAct->setEnabled(false); // m_undoAct->setEnabled(false);
m_startDialog.exec(); m_startDialog->exec();
} }
void KReversiMainWindow::slotGameOver() void KReversiMainWindow::slotGameOver()
...@@ -251,9 +261,6 @@ void KReversiMainWindow::slotGameOver() ...@@ -251,9 +261,6 @@ void KReversiMainWindow::slotGameOver()
m_hintAct->setEnabled(false); m_hintAct->setEnabled(false);
m_undoAct->setEnabled(m_game->canUndo()); 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 blackScore = m_game->playerScore(Black);
int whiteScore = m_game->playerScore(White); int whiteScore = m_game->playerScore(White);
...@@ -330,8 +337,6 @@ void KReversiMainWindow::slotGameOver() ...@@ -330,8 +337,6 @@ void KReversiMainWindow::slotGameOver()
void KReversiMainWindow::slotMoveFinished() void KReversiMainWindow::slotMoveFinished()
{ {
// m_undoAct->setEnabled(m_game->canUndo());
updateHistory(); updateHistory();
updateStatusBar(); updateStatusBar();
...@@ -372,7 +377,7 @@ void KReversiMainWindow::slotHighscores() ...@@ -372,7 +377,7 @@ void KReversiMainWindow::slotHighscores()
void KReversiMainWindow::slotDialogReady() void KReversiMainWindow::slotDialogReady()
{ {
GameStartInformation info = m_startDialog.createGameStartInformation(); GameStartInformation info = m_startDialog->createGameStartInformation();
receivedGameStartInformation(info); receivedGameStartInformation(info);
} }
......
...@@ -70,6 +70,7 @@ class KReversiMainWindow : public KXmlGuiWindow ...@@ -70,6 +70,7 @@ class KReversiMainWindow : public KXmlGuiWindow
Q_OBJECT Q_OBJECT
public: public:
explicit KReversiMainWindow(QWidget* parent = 0, bool startDemo = false); explicit KReversiMainWindow(QWidget* parent = 0, bool startDemo = false);
~KReversiMainWindow();
public slots: public slots:
void slotNewGame(); void slotNewGame();
void levelChanged(); void levelChanged();
...@@ -94,7 +95,7 @@ private: ...@@ -94,7 +95,7 @@ private:
void receivedGameStartInformation(GameStartInformation info); void receivedGameStartInformation(GameStartInformation info);
KReversiPlayer *m_player[2]; KReversiPlayer *m_player[2];
StartGameDialog m_startDialog; StartGameDialog *m_startDialog;
GameStartInformation m_nowPlayingInfo; GameStartInformation m_nowPlayingInfo;
...@@ -106,9 +107,11 @@ private: ...@@ -106,9 +107,11 @@ private:
bool m_firstShow; bool m_firstShow;
bool m_startInDemoMode; bool m_startInDemoMode;
KgThemeProvider *m_provider;
QAction *m_undoAct; QAction *m_undoAct;
QAction *m_hintAct; QAction *m_hintAct;
QAction *m_demoAct; // QAction *m_demoAct;
KToggleAction *m_showLast; KToggleAction *m_showLast;
KToggleAction *m_showLegal; KToggleAction *m_showLegal;
KToggleAction *m_showMovesAct; KToggleAction *m_showMovesAct;
......
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
#include <QMessageBox> #include <QMessageBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <KgDifficulty>
#include <kdebug.h>
StartGameDialog::StartGameDialog(QWidget *parent) : StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
KDialog(parent), KDialog(parent),
ui(new Ui::StartGameDialog) ui(new Ui::StartGameDialog), m_provider(provider)
{ {
setModal(true); setModal(true);
...@@ -28,6 +30,19 @@ StartGameDialog::StartGameDialog(QWidget *parent) : ...@@ -28,6 +30,19 @@ StartGameDialog::StartGameDialog(QWidget *parent) :
ui->blackTypeGroup->setId(ui->blackHuman, GameStartInformation::Human); ui->blackTypeGroup->setId(ui->blackHuman, GameStartInformation::Human);
ui->blackTypeGroup->setId(ui->blackAI, GameStartInformation::AI); 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->blackTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateBlack(int)));
connect(ui->whiteTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateWhite(int))); connect(ui->whiteTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotUpdateWhite(int)));
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "gamestartinformation.h" #include "gamestartinformation.h"
#include "commondefs.h" #include "commondefs.h"
#include <KUser> #include <KUser>
#include <KgThemeProvider>
namespace Ui { namespace Ui {
class StartGameDialog; class StartGameDialog;
...@@ -15,7 +16,7 @@ class StartGameDialog : public KDialog ...@@ -15,7 +16,7 @@ class StartGameDialog : public KDialog
Q_OBJECT Q_OBJECT
public: public:
explicit StartGameDialog(QWidget *parent = 0); explicit StartGameDialog(QWidget *parent, KgThemeProvider *provider);
~StartGameDialog(); ~StartGameDialog();
GameStartInformation createGameStartInformation() const; GameStartInformation createGameStartInformation() const;
...@@ -32,6 +33,7 @@ private: ...@@ -32,6 +33,7 @@ private:
Ui::StartGameDialog *ui; Ui::StartGameDialog *ui;
QWidget *m_contents; QWidget *m_contents;
KUser m_user; KUser m_user;
KgThemeProvider *m_provider;
}; };
#endif // STARTGAMEDIALOG_H #endif // STARTGAMEDIALOG_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment