Commit f58b2880 authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Using colored chips at Start game dialog according to game preferences

parent fc38c705
...@@ -99,6 +99,10 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) ...@@ -99,6 +99,10 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
m_view = new KReversiView(m_game, this, m_provider); m_view = new KReversiView(m_game, this, m_provider);
setCentralWidget(m_view); setCentralWidget(m_view);
// initialise dialog handler
m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
// initialise actions // initialise actions
setupActionsInit(); setupActionsInit();
...@@ -108,10 +112,6 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo) ...@@ -108,10 +112,6 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
setupGUI(qApp->desktop()->availableGeometry().size() * 0.7); setupGUI(qApp->desktop()->availableGeometry().size() * 0.7);
m_historyDock->hide(); m_historyDock->hide();
// initialise dialog handler
m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
} }
KReversiMainWindow::~KReversiMainWindow() KReversiMainWindow::~KReversiMainWindow()
...@@ -176,6 +176,7 @@ void KReversiMainWindow::loadSettings() ...@@ -176,6 +176,7 @@ void KReversiMainWindow::loadSettings()
m_coloredChipsAct->setChecked(Preferences::useColoredChips()); m_coloredChipsAct->setChecked(Preferences::useColoredChips());
m_view->setChipsPrefix(Preferences::useColoredChips() ? m_view->setChipsPrefix(Preferences::useColoredChips() ?
KReversiView::Colored : KReversiView::BlackWhite); KReversiView::Colored : KReversiView::BlackWhite);
m_startDialog->setColoredChips(Preferences::useColoredChips());
} }
void KReversiMainWindow::levelChanged() void KReversiMainWindow::levelChanged()
...@@ -204,6 +205,7 @@ void KReversiMainWindow::slotUseColoredChips(bool toggled) ...@@ -204,6 +205,7 @@ void KReversiMainWindow::slotUseColoredChips(bool toggled)
KReversiView::Colored : KReversiView::Colored :
KReversiView::BlackWhite; KReversiView::BlackWhite;
m_view->setChipsPrefix(chipsPrefix); m_view->setChipsPrefix(chipsPrefix);
m_startDialog->setColoredChips(toggled);
Preferences::setUseColoredChips(toggled); Preferences::setUseColoredChips(toggled);
Preferences::self()->writeConfig(); Preferences::self()->writeConfig();
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) : StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
KDialog(parent), KDialog(parent),
ui(new Ui::StartGameDialog), m_provider(provider) ui(new Ui::StartGameDialog), m_provider(provider), m_useColoredChips(false)
{ {
setModal(true); setModal(true);
...@@ -27,37 +27,7 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) : ...@@ -27,37 +27,7 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
setMainWidget(m_contents); setMainWidget(m_contents);
ui->setupUi(m_contents); ui->setupUi(m_contents);
QSvgRenderer svgRenderer; loadChipImages();
svgRenderer.load(m_provider->currentTheme()->graphicsPath());
QPixmap blackChip(QSize(46, 46));
blackChip.fill(Qt::transparent);
QPixmap whiteChip(QSize(46, 46));
whiteChip.fill(Qt::transparent);
QPainter *painter = new QPainter(&blackChip);
svgRenderer.render(painter, "chip_bw_1");
delete painter;
painter = new QPainter(&whiteChip);
svgRenderer.render(painter, "chip_bw_12");
delete painter;
ui->blackLabel->setPixmap(blackChip);
ui->whiteLabel->setPixmap(whiteChip);
QGraphicsDropShadowEffect *blackShadow = new QGraphicsDropShadowEffect(this);
blackShadow->setBlurRadius(10.0);
blackShadow->setColor(Qt::black);
blackShadow->setOffset(0.0);
QGraphicsDropShadowEffect *whiteShadow = new QGraphicsDropShadowEffect(this);
whiteShadow->setBlurRadius(10.0);
whiteShadow->setColor(Qt::black);
whiteShadow->setOffset(0.0);
ui->blackLabel->setGraphicsEffect(blackShadow);
ui->whiteLabel->setGraphicsEffect(whiteShadow);
ui->whiteTypeGroup->setId(ui->whiteHuman, GameStartInformation::Human); ui->whiteTypeGroup->setId(ui->whiteHuman, GameStartInformation::Human);
ui->whiteTypeGroup->setId(ui->whiteAI, GameStartInformation::AI); ui->whiteTypeGroup->setId(ui->whiteAI, GameStartInformation::AI);
...@@ -90,6 +60,43 @@ StartGameDialog::~StartGameDialog() ...@@ -90,6 +60,43 @@ StartGameDialog::~StartGameDialog()
delete ui; delete ui;
} }
void StartGameDialog::loadChipImages()
{
QSvgRenderer svgRenderer;
svgRenderer.load(m_provider->currentTheme()->graphicsPath());
QPixmap blackChip(QSize(46, 46));
blackChip.fill(Qt::transparent);
QPixmap whiteChip(QSize(46, 46));
whiteChip.fill(Qt::transparent);
QPainter *painter = new QPainter(&blackChip);
QString prefix = m_useColoredChips ? "chip_color" : "chip_bw";
svgRenderer.render(painter, prefix + "_1");
delete painter;
painter = new QPainter(&whiteChip);
svgRenderer.render(painter, prefix + "_12");
delete painter;
ui->blackLabel->setPixmap(blackChip);
ui->whiteLabel->setPixmap(whiteChip);
QGraphicsDropShadowEffect *blackShadow = new QGraphicsDropShadowEffect(this);
blackShadow->setBlurRadius(10.0);
blackShadow->setColor(Qt::black);
blackShadow->setOffset(0.0);
QGraphicsDropShadowEffect *whiteShadow = new QGraphicsDropShadowEffect(this);
whiteShadow->setBlurRadius(10.0);
whiteShadow->setColor(Qt::black);
whiteShadow->setOffset(0.0);
ui->blackLabel->setGraphicsEffect(blackShadow);
ui->whiteLabel->setGraphicsEffect(whiteShadow);
}
void StartGameDialog::slotButtonClicked(int button) void StartGameDialog::slotButtonClicked(int button)
{ {
if (button == KDialog::Ok) if (button == KDialog::Ok)
...@@ -110,6 +117,12 @@ GameStartInformation StartGameDialog::createGameStartInformation() const ...@@ -110,6 +117,12 @@ GameStartInformation StartGameDialog::createGameStartInformation() const
return info; return info;
} }
void StartGameDialog::setColoredChips(bool toogled)
{
m_useColoredChips = toogled;
loadChipImages();
}
void StartGameDialog::slotUpdateBlack(int clickedId) void StartGameDialog::slotUpdateBlack(int clickedId)
{ {
......
...@@ -20,6 +20,7 @@ public: ...@@ -20,6 +20,7 @@ public:
~StartGameDialog(); ~StartGameDialog();
GameStartInformation createGameStartInformation() const; GameStartInformation createGameStartInformation() const;
void setColoredChips(bool toogled);
signals: signals:
void startGame(); void startGame();
...@@ -34,6 +35,8 @@ private: ...@@ -34,6 +35,8 @@ private:
QWidget *m_contents; QWidget *m_contents;
KUser m_user; KUser m_user;
KgThemeProvider *m_provider; KgThemeProvider *m_provider;
bool m_useColoredChips;
void loadChipImages();
}; };
#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