Qt interface: First version of a dialog for preferences.

The preferences are not peristent yet.
This commit is contained in:
Olivier Teulière 2008-01-25 18:42:59 +00:00
parent cba81de777
commit f0b41f7ee7
9 changed files with 431 additions and 81 deletions

View file

@ -30,6 +30,7 @@ EXTRA_DIST = \
ui/main_window.ui \
ui/new_game.ui \
ui/training_widget.ui \
ui/prefs_dialog.ui \
ui/player_widget.ui
BUILT_SOURCES = \
@ -37,6 +38,7 @@ BUILT_SOURCES = \
ui/new_game.ui.h \
ui/player_widget.ui.h \
ui/training_widget.ui.h \
ui/prefs_dialog.ui.h \
new_game.moc.cpp \
bag_widget.moc.cpp \
score_widget.moc.cpp \
@ -44,6 +46,7 @@ BUILT_SOURCES = \
history_widget.moc.cpp \
player_widget.moc.cpp \
training_widget.moc.cpp \
prefs_dialog.moc.cpp \
aux_window.moc.cpp \
main_window.moc.cpp
@ -56,6 +59,7 @@ qeliot_SOURCES = \
history_widget.cpp history_widget.h \
player_widget.cpp player_widget.h \
training_widget.cpp training_widget.h \
prefs_dialog.cpp prefs_dialog.h \
aux_window.cpp aux_window.h \
main_window.cpp main_window.h \
main.cpp

View file

@ -33,6 +33,7 @@
#include "player.h"
#include "debug.h"
#include "new_game.h"
#include "prefs_dialog.h"
#include "bag_widget.h"
#include "board_widget.h"
#include "score_widget.h"
@ -48,7 +49,7 @@
MainWindow::MainWindow(QWidget *iParent)
: QMainWindow(iParent), m_dic(NULL), m_game(NULL), m_newGameDialog(NULL),
m_bagWindow(NULL)
m_prefsDialog(NULL), m_bagWindow(NULL)
{
m_ui.setupUi(this);
@ -87,18 +88,8 @@ MainWindow::MainWindow(QWidget *iParent)
QObject::connect(this, SIGNAL(gameUpdated()), players, SLOT(refresh()));
QObject::connect(players, SIGNAL(gameUpdated()), this, SIGNAL(gameUpdated()));
QObject::connect(players, SIGNAL(playingWord(unsigned int, QString, QString)),
this, SLOT(playerPlays(unsigned int, QString, QString)));
QObject::connect(players, SIGNAL(passing(unsigned int, QString)),
this, SLOT(playerPasses(unsigned int, QString)));
// XXX: temp: Training widget
//TrainingWidget *trWidget = new TrainingWidget(NULL);
//m_ui.groupBoxPlayers->layout()->addWidget(trWidget);
//QObject::connect(this, SIGNAL(gameChangedNonConst(Game*)),
// trWidget, SLOT(setGame(Game*)));
//QObject::connect(this, SIGNAL(gameUpdated()), trWidget, SLOT(refresh()));
//QObject::connect(trWidget, SIGNAL(gameUpdated()), this, SIGNAL(gameUpdated()));
QObject::connect(players, SIGNAL(notifyProblem(QString)),
this, SLOT(displayErrorMsg(QString)));
// Players score
ScoreWidget *scores = new ScoreWidget;
@ -238,49 +229,11 @@ void MainWindow::on_action_New_Game_triggered()
}
void MainWindow::playerPlays(unsigned int p, QString iWord, QString iCoord)
void MainWindow::on_action_Preferences_triggered()
{
cerr << "Player " << p << " plays \"" << convertToMb(qtw(iWord))
<< "\" in " << convertToMb(qtw(iCoord)) << endl;
int res = m_game->play(qtw(iCoord), qtw(iWord));
if (res)
{
// XXX: tmp
QString error;
error.sprintf("Error: %d", res);
displayErrorMsg(error, qfl("playing word"));
return;
}
emit gameUpdated();
}
void MainWindow::playerPasses(unsigned int p, QString iChangedLetters)
{
if (iChangedLetters == "")
{
cerr << "Player " << p << " passes" << endl;
}
else
{
cerr << "Player " << p << " changes \""
<< convertToMb(qtw(iChangedLetters)) << "\"" << endl;
}
FreeGame *free = dynamic_cast<FreeGame*>(m_game);
ASSERT(free != NULL,
"MainWindow::playerPasses() called while not in a free game");
int res = free->pass(qtw(iChangedLetters));
if (res)
{
// XXX: tmp
QString error;
error.sprintf("Error: %d", res);
displayErrorMsg(error, qfl("playing word"));
return;
}
emit gameUpdated();
if (m_prefsDialog == NULL)
m_prefsDialog = new PrefsDialog(this);
m_prefsDialog->exec();
}

View file

@ -32,6 +32,7 @@ class Board;
class History;
class Game;
class NewGame;
class PrefsDialog;
class AuxWindow;
class MainWindow: public QMainWindow
@ -49,14 +50,15 @@ signals:
void gameUpdated();
public slots:
void playerPlays(unsigned int p, QString iWord, QString iCoord);
void playerPasses(unsigned int p, QString iLetters);
/// Display an error message to the user
void displayErrorMsg(QString iMsg, QString iContext = "");
private slots:
void on_action_About_triggered();
void on_action_Bag_triggered();
void on_action_ChooseDic_triggered();
void on_action_New_Game_triggered();
void on_action_Preferences_triggered();
private:
/// Current dictionary
@ -71,12 +73,12 @@ private:
/// Dialog for creating a new game
NewGame *m_newGameDialog;
/// Dialog for the preferences
PrefsDialog *m_prefsDialog;
/// Bag window
AuxWindow *m_bagWindow;
/// Display an error message to the user
void displayErrorMsg(QString iMsg, QString iContext = QString());
/// Destroy the current game (if any) and the associated widgets
void destroyCurrentGame();

View file

@ -27,6 +27,7 @@
#include "training_widget.h"
#include "qtcommon.h"
#include "game.h"
#include "freegame.h"
#include "player.h"
#include "pldrack.h"
#include "coord.h"
@ -62,8 +63,7 @@ private:
};
PlayerWidget::PlayerWidget(QWidget *parent, unsigned int iPlayerNb,
const Game *iGame)
PlayerWidget::PlayerWidget(QWidget *parent, unsigned int iPlayerNb, Game *iGame)
: QWidget(parent), m_game(iGame), m_player(iPlayerNb)
{
setupUi(this);
@ -108,7 +108,6 @@ void PlayerWidget::refresh()
if (m_game == NULL)
{
// XXX
lineEditRack->clear();
return;
}
@ -122,7 +121,7 @@ void PlayerWidget::refresh()
void PlayerWidget::on_pushButtonShuffle_clicked()
{
// TODO
// TODO: (not supported in the core yet)
}
@ -144,13 +143,44 @@ void PlayerWidget::on_lineEditPlay_returnPressed()
{
QStringList items = lineEditPlay->text().split(' ', QString::SkipEmptyParts);
ASSERT(items.size() == 2, "Bug found in the validator");
emit playingWord(m_player, items[0], items[1]);
// Play the word
int res = m_game->play(qtw(items[1]), qtw(items[0]));
if (res == 0)
{
emit gameUpdated();
}
else
{
// FIXME: the error is too generic
QString msg = _q("Cannot play '%1' at position '%2': incorrect or misplaced word (%3)")
.arg(items[0]).arg(items[1]).arg(res);
emit notifyProblem(msg);
}
}
void PlayerWidget::on_lineEditChange_returnPressed()
{
emit passing(m_player, lineEditChange->text());
FreeGame *free = dynamic_cast<FreeGame*>(m_game);
ASSERT(free != NULL,
"Trying to pass or change letters while not in free game mode");
// Pass the turn (and possibly change letters)
QString letters = lineEditChange->text();
int res = free->pass(qtw(letters));
if (res == 0)
emit gameUpdated();
else
{
// FIXME: the error is too generic
QString msg;
if (letters == "")
msg = _q("Cannot pass turn (%1)").arg(res);
else
msg = _q("Cannot change letters '%1' (%2)").arg(letters).arg(res);
emit notifyProblem(msg);
}
}
@ -221,13 +251,16 @@ PlayerTabWidget::PlayerTabWidget(QWidget *parent)
void PlayerTabWidget::setGame(Game *iGame)
{
// Cut all the connections with the pages
disconnect();
// Remove all the tabs
int nbTabs = count();
for (int i = 0; i < nbTabs; ++i)
{
setCurrentWidget(0);
// Cut all the connections with the page (needed because removeTab()
// doesn't really destroy the widget)
disconnect(currentWidget());
removeTab(0);
}
if (iGame != NULL)
{
@ -246,17 +279,17 @@ void PlayerTabWidget::setGame(Game *iGame)
}
else
{
// Add one tab per player
for (unsigned int i = 0; i < iGame->getNPlayers(); ++i)
{
const Player &player = iGame->getPlayer(i);
PlayerWidget *p = new PlayerWidget(NULL, i, iGame);
QObject::connect(this, SIGNAL(refreshSignal()), p, SLOT(refresh()));
QObject::connect(p, SIGNAL(passing(unsigned int, QString)),
this, SIGNAL(passing(unsigned int, QString)));
QObject::connect(p, SIGNAL(playingWord(unsigned int, QString, QString)),
this, SIGNAL(playingWord(unsigned int, QString, QString)));
// Forward signals to the outside
QObject::connect(p, SIGNAL(notifyProblem(QString)),
this, SIGNAL(notifyProblem(QString)));
QObject::connect(p, SIGNAL(gameUpdated()),
this, SIGNAL(gameUpdated()));
addTab(p, qfw(player.getName()));
}
}

View file

@ -36,11 +36,11 @@ class PlayerWidget: public QWidget, private Ui::PlayerWidget
public:
explicit PlayerWidget(QWidget *parent = 0,
unsigned int iPlayerNb = 0,
const Game *iGame = NULL);
Game *iGame = NULL);
signals:
void playingWord(unsigned int iPlayer, QString iWord, QString iCoord);
void passing(unsigned int iPlayer, QString iChangedLetters);
void gameUpdated();
void notifyProblem(QString iMsg);
public slots:
void refresh();
@ -60,7 +60,7 @@ private slots:
private:
/// Encapsulated game, can be NULL
const Game *m_game;
Game *m_game;
/// Encapsulated player, valid iff m_game is not NULL
unsigned int m_player;
@ -82,8 +82,7 @@ public slots:
signals:
void refreshSignal();
void gameUpdated();
void playingWord(unsigned int iPlayer, QString iWord, QString iCoord);
void passing(unsigned int iPlayer, QString iChangedLetters);
void notifyProblem(QString iMsg);
};
#endif

92
qt/prefs_dialog.cpp Normal file
View file

@ -0,0 +1,92 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2008 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <QtCore/QSettings>
#include "prefs_dialog.h"
#include "settings.h"
const QString PrefsDialog::kINTF_ALIGN_HISTORY = "AlignHistory";
PrefsDialog::PrefsDialog(QWidget *iParent)
: QDialog(iParent)
{
setupUi(this);
// Interface settings
QSettings qs;
qs.beginGroup("Interface");
checkBoxIntfAlignHistory->setChecked(qs.value(kINTF_ALIGN_HISTORY).toBool());
qs.endGroup();
// XXX: Hide the Interface settings until the "align history" is really
// taken into account by the HistoryWidget class
groupBoxInterface->hide();
// Duplicate settings
checkBoxDuplRefuseInvalid->setChecked(Settings::Instance().getBool("duplicate-reject-invalid"));
spinBoxDuplSoloPlayers->setValue(Settings::Instance().getInt("duplicate-solo-players"));
spinBoxDuplSoloValue->setValue(Settings::Instance().getInt("duplicate-solo-value"));
// Freegame settings
checkBoxFreeRefuseInvalid->setChecked(Settings::Instance().getBool("freegame-reject-invalid"));
// Training settings
// XXX: Hide them until there is something to show
groupBoxTraining->hide();
// Resize the dialog so that it gets its minimal size
resize(10, 10);
}
void PrefsDialog::accept()
{
updateSettings();
QDialog::accept();
}
void PrefsDialog::updateSettings()
{
// Interface settings
QSettings qs;
qs.beginGroup("Interface");
qs.setValue(kINTF_ALIGN_HISTORY, checkBoxIntfAlignHistory->isChecked());
qs.endGroup();
// Duplicate settings
Settings::Instance().setBool("duplicate-reject-invalid",
checkBoxDuplRefuseInvalid->isChecked());
Settings::Instance().setInt("duplicate-solo-players",
spinBoxDuplSoloPlayers->value());
Settings::Instance().setInt("duplicate-solo-value",
spinBoxDuplSoloValue->value());
// Freegame settings
Settings::Instance().setBool("freegame-reject-invalid",
checkBoxFreeRefuseInvalid->isChecked());
// Training settings
}

49
qt/prefs_dialog.h Normal file
View file

@ -0,0 +1,49 @@
/*****************************************************************************
* Eliot
* Copyright (C) 2008 Olivier Teulière
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#ifndef PREFS_DIALOG_H_
#define PREFS_DIALOG_H_
#include <QtGui/QDialog>
#include <QtCore/QString>
#include <ui/prefs_dialog.ui.h>
class PrefsDialog: public QDialog, private Ui::PrefsDialog
{
Q_OBJECT;
public:
explicit PrefsDialog(QWidget *iParent = 0);
static const QString kINTF_ALIGN_HISTORY;
public slots:
/// Update the settings when the user selects "OK"
virtual void accept();
private:
void updateSettings();
};
#endif

View file

@ -79,6 +79,7 @@
<string>&amp;Settings</string>
</property>
<addaction name="action_ChooseDic" />
<addaction name="action_Preferences" />
</widget>
<widget class="QMenu" name="menu_Help" >
<property name="title" >
@ -112,7 +113,7 @@
</widget>
<action name="action_ChooseDic" >
<property name="text" >
<string>&amp;Choose dictionary...</string>
<string>_("Choose dictionary...")</string>
</property>
</action>
<action name="action_About" >
@ -144,6 +145,11 @@
<string>_("&amp;Bag")</string>
</property>
</action>
<action name="action_Preferences" >
<property name="text" >
<string>_("Preferences...")</string>
</property>
</action>
</widget>
<resources/>
<connections>

212
qt/ui/prefs_dialog.ui Normal file
View file

@ -0,0 +1,212 @@
<ui version="4.0" >
<class>PrefsDialog</class>
<widget class="QDialog" name="PrefsDialog" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<height>383</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBoxInterface" >
<property name="title" >
<string>_("Interface")</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="checkBoxIntfAlignHistory" >
<property name="text" >
<string>_("Align the rack and the solution in history")</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxDuplicate" >
<property name="title" >
<string>_("Duplicate mode")</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="checkBoxDuplRefuseInvalid" >
<property name="toolTip" >
<string>_("If checked, playing an invalid or misplaced word will not be possible. If unchecked, you will get 0 point and lose your turn.")</string>
</property>
<property name="text" >
<string>_("Refuse to play invalid moves")</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>_("Min. players for a solo:")</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinBoxDuplSoloPlayers" >
<property name="toolTip" >
<string>_("Minimum number of players needed to take into account the solo bonus")</string>
</property>
<property name="value" >
<number>16</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>_("Solo value:")</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="spinBoxDuplSoloValue" >
<property name="toolTip" >
<string>_("Value of the solo bonus. Set it to 0 if you don't want solo bonus")</string>
</property>
<property name="value" >
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxFreeGame" >
<property name="title" >
<string>_("Free game mode")</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="checkBoxFreeRefuseInvalid" >
<property name="toolTip" >
<string>_("If checked, playing an invalid or misplaced word will not be possible. If unchecked, you will get 0 point and lose your turn.")</string>
</property>
<property name="text" >
<string>_("Refuse to play invalid moves")</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxTraining" >
<property name="title" >
<string>_("Training mode")</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>_("Nothing yet")</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>checkBoxIntfAlignHistory</tabstop>
<tabstop>checkBoxDuplRefuseInvalid</tabstop>
<tabstop>spinBoxDuplSoloPlayers</tabstop>
<tabstop>spinBoxDuplSoloValue</tabstop>
<tabstop>checkBoxFreeRefuseInvalid</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PrefsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PrefsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>