Commit 04051bf8 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Extracted ChipsPrefix enum to global definitions for unified code

Now such strings as "chip_bw" are declared at one place among c++ files.
parent ab9bf1b1
......@@ -25,6 +25,13 @@
#include <KLocale>
static QString chipPrefixString[2] = {"chip_bw", "chip_color"};
QString Utils::chipPrefixToString(ChipsPrefix prefix) {
return chipPrefixString[prefix];
}
ChipColor Utils::opponentColorFor(ChipColor color)
{
if (color == NoColor)
......
......@@ -60,8 +60,13 @@ struct KReversiMove: public KReversiPos {
}
};
typedef QList<KReversiMove> MoveList;
enum ChipsPrefix { BlackWhite = 0, Colored = 1 };
namespace Utils
{
QString chipPrefixToString(ChipsPrefix prefix);
ChipColor opponentColorFor(ChipColor color);
QString colorToString(const ChipColor &color);
QString moveToString(const KReversiMove& move);
......@@ -69,6 +74,5 @@ int difficultyLevelToInt();
const KgDifficultyLevel *intToDifficultyLevel(int skill);
}
typedef QList<KReversiMove> MoveList;
#endif
......@@ -77,13 +77,8 @@ void KReversiView::setGame(KReversiGame *game)
void KReversiView::setChipsPrefix(ChipsPrefix chipsPrefix)
{
QString string;
if (chipsPrefix == Colored)
string = "chip_color";
else
string = "chip_bw";
m_qml_root->setProperty("chipsImagePrefix", string);
m_qml_root->setProperty("chipsImagePrefix",
Utils::chipPrefixToString(chipsPrefix));
}
void KReversiView::setShowBoardLabels(bool show)
......
......@@ -24,6 +24,7 @@
#include <KgDeclarativeView>
#include <KgThemeProvider>
#include <commondefs.h>
#include <kreversigame.h>
/**
......@@ -40,7 +41,6 @@ class KReversiView : public KgDeclarativeView
{
Q_OBJECT
public:
enum ChipsPrefix { Colored, BlackWhite };
explicit KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider *provider);
/**
......
......@@ -34,6 +34,7 @@
#include <KStandardGameAction>
#include <KExtHighscore>
#include <commondefs.h>
#include <kreversihumanplayer.h>
#include <kreversicomputerplayer.h>
......@@ -156,8 +157,9 @@ void KReversiMainWindow::loadSettings()
// Chip's color
m_coloredChipsAct->setChecked(Preferences::useColoredChips());
m_view->setChipsPrefix(Preferences::useColoredChips() ?
KReversiView::Colored : KReversiView::BlackWhite);
m_startDialog->setColoredChips(Preferences::useColoredChips());
Colored : BlackWhite);
m_startDialog->setChipsPrefix(Preferences::useColoredChips() ?
Colored : BlackWhite);
}
void KReversiMainWindow::levelChanged()
......@@ -182,11 +184,11 @@ void KReversiMainWindow::slotAnimSpeedChanged(int speed)
void KReversiMainWindow::slotUseColoredChips(bool toggled)
{
KReversiView::ChipsPrefix chipsPrefix = m_coloredChipsAct->isChecked() ?
KReversiView::Colored :
KReversiView::BlackWhite;
ChipsPrefix chipsPrefix = m_coloredChipsAct->isChecked() ?
Colored :
BlackWhite;
m_view->setChipsPrefix(chipsPrefix);
m_startDialog->setColoredChips(toggled);
m_startDialog->setChipsPrefix(chipsPrefix);
Preferences::setUseColoredChips(toggled);
Preferences::self()->writeConfig();
}
......
......@@ -10,7 +10,7 @@
StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
KDialog(parent),
ui(new Ui::StartGameDialog), m_provider(provider), m_useColoredChips(false)
ui(new Ui::StartGameDialog), m_provider(provider), m_chipsPrefix(BlackWhite)
{
setModal(true);
......@@ -72,7 +72,7 @@ void StartGameDialog::loadChipImages()
whiteChip.fill(Qt::transparent);
QPainter *painter = new QPainter(&blackChip);
QString prefix = m_useColoredChips ? "chip_color" : "chip_bw";
QString prefix = Utils::chipPrefixToString(m_chipsPrefix);
svgRenderer.render(painter, prefix + "_1");
delete painter;
......@@ -117,9 +117,9 @@ GameStartInformation StartGameDialog::createGameStartInformation() const
return info;
}
void StartGameDialog::setColoredChips(bool toogled)
void StartGameDialog::setChipsPrefix(ChipsPrefix prefix)
{
m_useColoredChips = toogled;
m_chipsPrefix = prefix;
loadChipImages();
}
......
......@@ -22,7 +22,7 @@ public:
~StartGameDialog();
GameStartInformation createGameStartInformation() const;
void setColoredChips(bool toogled);
void setChipsPrefix(ChipsPrefix prefix);
signals:
void startGame();
......@@ -37,7 +37,7 @@ private:
QWidget *m_contents;
KUser m_user;
KgThemeProvider *m_provider;
bool m_useColoredChips;
ChipsPrefix m_chipsPrefix;
void loadChipImages();
};
......
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