Commit f58b2880 authored by Denis Kuplyakov's avatar Denis Kuplyakov

Using colored chips at Start game dialog according to game preferences

parent fc38c705
......@@ -99,6 +99,10 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
m_view = new KReversiView(m_game, this, m_provider);
setCentralWidget(m_view);
// initialise dialog handler
m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
// initialise actions
setupActionsInit();
......@@ -108,10 +112,6 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
setupGUI(qApp->desktop()->availableGeometry().size() * 0.7);
m_historyDock->hide();
// initialise dialog handler
m_startDialog = new StartGameDialog(this, m_provider);
connect(m_startDialog, SIGNAL(startGame()), this, SLOT(slotDialogReady()));
}
KReversiMainWindow::~KReversiMainWindow()
......@@ -176,6 +176,7 @@ void KReversiMainWindow::loadSettings()
m_coloredChipsAct->setChecked(Preferences::useColoredChips());
m_view->setChipsPrefix(Preferences::useColoredChips() ?
KReversiView::Colored : KReversiView::BlackWhite);
m_startDialog->setColoredChips(Preferences::useColoredChips());
}
void KReversiMainWindow::levelChanged()
......@@ -204,6 +205,7 @@ void KReversiMainWindow::slotUseColoredChips(bool toggled)
KReversiView::Colored :
KReversiView::BlackWhite;
m_view->setChipsPrefix(chipsPrefix);
m_startDialog->setColoredChips(toggled);
Preferences::setUseColoredChips(toggled);
Preferences::self()->writeConfig();
}
......
......@@ -11,7 +11,7 @@
StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
KDialog(parent),
ui(new Ui::StartGameDialog), m_provider(provider)
ui(new Ui::StartGameDialog), m_provider(provider), m_useColoredChips(false)
{
setModal(true);
......@@ -27,37 +27,7 @@ StartGameDialog::StartGameDialog(QWidget *parent, KgThemeProvider *provider) :
setMainWidget(m_contents);
ui->setupUi(m_contents);
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);
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);
loadChipImages();
ui->whiteTypeGroup->setId(ui->whiteHuman, GameStartInformation::Human);
ui->whiteTypeGroup->setId(ui->whiteAI, GameStartInformation::AI);
......@@ -90,6 +60,43 @@ StartGameDialog::~StartGameDialog()
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)
{
if (button == KDialog::Ok)
......@@ -110,6 +117,12 @@ GameStartInformation StartGameDialog::createGameStartInformation() const
return info;
}
void StartGameDialog::setColoredChips(bool toogled)
{
m_useColoredChips = toogled;
loadChipImages();
}
void StartGameDialog::slotUpdateBlack(int clickedId)
{
......
......@@ -20,6 +20,7 @@ public:
~StartGameDialog();
GameStartInformation createGameStartInformation() const;
void setColoredChips(bool toogled);
signals:
void startGame();
......@@ -34,6 +35,8 @@ private:
QWidget *m_contents;
KUser m_user;
KgThemeProvider *m_provider;
bool m_useColoredChips;
void loadChipImages();
};
#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