mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-16 07:47:39 +01:00
The Training widget is not in a tab anymore
This commit is contained in:
parent
50b55fb7f0
commit
a899df5e46
4 changed files with 109 additions and 80 deletions
|
@ -52,6 +52,7 @@
|
|||
#include "board_widget.h"
|
||||
#include "score_widget.h"
|
||||
#include "player_widget.h"
|
||||
#include "training_widget.h"
|
||||
#include "history_widget.h"
|
||||
#include "dic_tools_widget.h"
|
||||
#include "dic_wizard.h"
|
||||
|
@ -69,7 +70,7 @@ const char *MainWindow::m_windowName = "MainWindow";
|
|||
MainWindow::MainWindow(QWidget *iParent)
|
||||
: QMainWindow(iParent), m_dic(NULL), m_game(NULL),
|
||||
m_newGameDialog(NULL), m_prefsDialog(NULL),
|
||||
m_playersWidget(NULL), m_scoresWidget(NULL),
|
||||
m_playersWidget(NULL), m_trainingWidget(NULL), m_scoresWidget(NULL),
|
||||
m_bagWindow(NULL), m_boardWindow(NULL),
|
||||
m_historyWindow(NULL), m_dicToolsWindow(NULL), m_dicNameLabel(NULL)
|
||||
{
|
||||
|
@ -229,17 +230,20 @@ void MainWindow::prefsUpdated()
|
|||
LOG_DEBUG("Preferences updated");
|
||||
// Disconnect the training rack updates from the "Plus 1" tab of the
|
||||
// dictionary tools
|
||||
m_playersWidget->disconnect(SIGNAL(trainingRackUpdated(const QString&)));
|
||||
// Reconnect it only if needed
|
||||
if (m_dicToolsWindow != NULL)
|
||||
if (m_trainingWidget != NULL)
|
||||
{
|
||||
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
||||
if (qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
|
||||
m_trainingWidget->disconnect(SIGNAL(rackUpdated(const QString&)));
|
||||
// Reconnect it only if needed
|
||||
if (m_dicToolsWindow != NULL)
|
||||
{
|
||||
QObject::connect(m_playersWidget,
|
||||
SIGNAL(trainingRackUpdated(const QString&)),
|
||||
&m_dicToolsWindow->getWidget(),
|
||||
SLOT(setPlus1Rack(const QString&)));
|
||||
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
||||
if (qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
|
||||
{
|
||||
QObject::connect(m_trainingWidget,
|
||||
SIGNAL(rackUpdated(const QString&)),
|
||||
&m_dicToolsWindow->getWidget(),
|
||||
SLOT(setPlus1Rack(const QString&)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,15 +277,27 @@ void MainWindow::updateForGame(PublicGame *iGame)
|
|||
{
|
||||
m_playersWidget->hide();
|
||||
disconnect(m_playersWidget);
|
||||
m_playersWidget->disconnect();
|
||||
m_playersWidget->deleteLater();
|
||||
m_playersWidget = NULL;
|
||||
}
|
||||
|
||||
// Destroy the training widget
|
||||
if (m_trainingWidget != NULL)
|
||||
{
|
||||
m_trainingWidget->hide();
|
||||
disconnect(m_trainingWidget);
|
||||
m_trainingWidget->disconnect();
|
||||
m_trainingWidget->deleteLater();
|
||||
m_trainingWidget = NULL;
|
||||
}
|
||||
|
||||
// Destroy the scores widget
|
||||
if (m_scoresWidget != NULL)
|
||||
{
|
||||
m_scoresWidget->hide();
|
||||
disconnect(m_scoresWidget);
|
||||
m_scoresWidget->disconnect();
|
||||
m_scoresWidget->deleteLater();
|
||||
m_scoresWidget = NULL;
|
||||
}
|
||||
|
@ -290,39 +306,73 @@ void MainWindow::updateForGame(PublicGame *iGame)
|
|||
{
|
||||
m_actionGamePrint->setEnabled(true);
|
||||
m_actionGameSaveAs->setEnabled(true);
|
||||
|
||||
if (iGame->getMode() == PublicGame::kTRAINING)
|
||||
{
|
||||
setWindowTitle(_q("Training mode") + " - Eliot");
|
||||
}
|
||||
else if (iGame->getMode() == PublicGame::kDUPLICATE)
|
||||
{
|
||||
setWindowTitle(_q("Duplicate game") + " - Eliot");
|
||||
m_ui.groupBoxPlayers->setTitle(_q("Training"));
|
||||
|
||||
// Training widget
|
||||
m_trainingWidget = new TrainingWidget(NULL, m_coordModel, iGame);
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_trainingWidget);
|
||||
QObject::connect(m_trainingWidget, SIGNAL(gameUpdated()),
|
||||
this, SIGNAL(gameUpdated()));
|
||||
QObject::connect(m_trainingWidget, SIGNAL(notifyInfo(QString)),
|
||||
this, SLOT(displayInfoMsg(QString)));
|
||||
QObject::connect(m_trainingWidget, SIGNAL(notifyProblem(QString)),
|
||||
this, SLOT(displayErrorMsg(QString)));
|
||||
QObject::connect(m_trainingWidget, SIGNAL(requestDefinition(QString)),
|
||||
this, SLOT(showDefinition(QString)));
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_trainingWidget, SLOT(refresh()));
|
||||
// Connect with the dictionary tools only if needed
|
||||
if (m_dicToolsWindow != NULL)
|
||||
{
|
||||
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
||||
if (qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
|
||||
{
|
||||
QObject::connect(m_trainingWidget,
|
||||
SIGNAL(rackUpdated(const QString&)),
|
||||
&m_dicToolsWindow->getWidget(),
|
||||
SLOT(setPlus1Rack(const QString&)));
|
||||
}
|
||||
}
|
||||
|
||||
// Players score
|
||||
m_scoresWidget = new ScoreWidget;
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_scoresWidget);
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_scoresWidget, SLOT(refresh()));
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindowTitle(_q("Free game") + " - Eliot");
|
||||
if (iGame->getMode() == PublicGame::kDUPLICATE)
|
||||
setWindowTitle(_q("Duplicate game") + " - Eliot");
|
||||
else
|
||||
setWindowTitle(_q("Free game") + " - Eliot");
|
||||
m_ui.groupBoxPlayers->setTitle(_q("Players"));
|
||||
|
||||
// Players widget
|
||||
m_playersWidget = new PlayerTabWidget(m_coordModel, NULL);
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_playersWidget);
|
||||
QObject::connect(m_playersWidget, SIGNAL(gameUpdated()),
|
||||
this, SIGNAL(gameUpdated()));
|
||||
QObject::connect(m_playersWidget, SIGNAL(notifyInfo(QString)),
|
||||
this, SLOT(displayInfoMsg(QString)));
|
||||
QObject::connect(m_playersWidget, SIGNAL(notifyProblem(QString)),
|
||||
this, SLOT(displayErrorMsg(QString)));
|
||||
QObject::connect(m_playersWidget, SIGNAL(requestDefinition(QString)),
|
||||
this, SLOT(showDefinition(QString)));
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_playersWidget, SLOT(refresh()));
|
||||
m_playersWidget->setGame(iGame);
|
||||
|
||||
// Players score
|
||||
m_scoresWidget = new ScoreWidget;
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_scoresWidget);
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_scoresWidget, SLOT(refresh()));
|
||||
}
|
||||
|
||||
// Players widget
|
||||
m_playersWidget = new PlayerTabWidget(m_coordModel, NULL);
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_playersWidget);
|
||||
QObject::connect(m_playersWidget, SIGNAL(gameUpdated()),
|
||||
this, SIGNAL(gameUpdated()));
|
||||
QObject::connect(m_playersWidget, SIGNAL(notifyInfo(QString)),
|
||||
this, SLOT(displayInfoMsg(QString)));
|
||||
QObject::connect(m_playersWidget, SIGNAL(notifyProblem(QString)),
|
||||
this, SLOT(displayErrorMsg(QString)));
|
||||
QObject::connect(m_playersWidget, SIGNAL(requestDefinition(QString)),
|
||||
this, SLOT(showDefinition(QString)));
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_playersWidget, SLOT(refresh()));
|
||||
m_playersWidget->setGame(iGame);
|
||||
|
||||
// Scores widget
|
||||
m_scoresWidget = new ScoreWidget;
|
||||
m_ui.groupBoxPlayers->layout()->addWidget(m_scoresWidget);
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
m_scoresWidget, SLOT(refresh()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -961,10 +1011,11 @@ void MainWindow::onWindowsDicTools()
|
|||
this, SLOT(showDefinition(QString)));
|
||||
// Link the training rack with the "Plus 1" one
|
||||
QSettings qs(ORGANIZATION, PACKAGE_NAME);
|
||||
if (qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
|
||||
if (m_trainingWidget != NULL &&
|
||||
qs.value(PrefsDialog::kINTF_LINK_TRAINING_7P1, false).toBool())
|
||||
{
|
||||
QObject::connect(m_playersWidget,
|
||||
SIGNAL(trainingRackUpdated(const QString&)),
|
||||
QObject::connect(m_trainingWidget,
|
||||
SIGNAL(rackUpdated(const QString&)),
|
||||
dicTools, SLOT(setPlus1Rack(const QString&)));
|
||||
}
|
||||
// Fake a dictionary selection
|
||||
|
|
|
@ -37,6 +37,7 @@ class NewGame;
|
|||
class PrefsDialog;
|
||||
class PlayerTabWidget;
|
||||
class ScoreWidget;
|
||||
class TrainingWidget;
|
||||
class AuxWindow;
|
||||
class QLabel;
|
||||
class QAction;
|
||||
|
@ -127,6 +128,9 @@ private:
|
|||
/// Widget for the players
|
||||
PlayerTabWidget *m_playersWidget;
|
||||
|
||||
/// Widget for the training mode
|
||||
TrainingWidget *m_trainingWidget;
|
||||
|
||||
/// Widget for the scores
|
||||
ScoreWidget *m_scoresWidget;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <QtCore/QStringList>
|
||||
|
||||
#include "player_widget.h"
|
||||
#include "training_widget.h"
|
||||
#include "play_word_mediator.h"
|
||||
#include "qtcommon.h"
|
||||
#include "public_game.h"
|
||||
|
@ -68,14 +67,13 @@ PlayerWidget::PlayerWidget(QWidget *parent, CoordModel &iCoordModel,
|
|||
QObject::connect(m_mediator, SIGNAL(notifyProblem(QString)),
|
||||
this, SIGNAL(notifyProblem(QString)));
|
||||
|
||||
lineEditRack->setReadOnly(true);
|
||||
|
||||
if (m_game)
|
||||
{
|
||||
// Do not allow messing with AI players
|
||||
if (!m_game->getPlayer(m_player).isHuman())
|
||||
setEnabled(false);
|
||||
|
||||
// Changing the rack is authorized only in training mode
|
||||
lineEditRack->setReadOnly(m_game->getMode() != PublicGame::kTRAINING);
|
||||
}
|
||||
if (m_game == NULL || m_game->getMode() != PublicGame::kFREEGAME)
|
||||
{
|
||||
|
@ -265,47 +263,24 @@ void PlayerTabWidget::setGame(PublicGame *iGame)
|
|||
|
||||
if (iGame != NULL)
|
||||
{
|
||||
// Training mode: use a dedicated widget
|
||||
if (iGame->getMode() == PublicGame::kTRAINING)
|
||||
// Add one tab per player
|
||||
for (unsigned int i = 0; i < iGame->getNbPlayers(); ++i)
|
||||
{
|
||||
const Player &player = iGame->getPlayer(0);
|
||||
TrainingWidget *trWidget = new TrainingWidget(NULL, m_coordModel, iGame);
|
||||
QObject::connect(this, SIGNAL(refreshSignal()),
|
||||
trWidget, SLOT(refresh()));
|
||||
const Player &player = iGame->getPlayer(i);
|
||||
PlayerWidget *p = new PlayerWidget(NULL, m_coordModel, i, iGame);
|
||||
QObject::connect(this, SIGNAL(refreshSignal()), p, SLOT(refresh()));
|
||||
// Forward signals to the outside
|
||||
QObject::connect(trWidget, SIGNAL(notifyProblem(QString)),
|
||||
QObject::connect(p, SIGNAL(notifyProblem(QString)),
|
||||
this, SIGNAL(notifyProblem(QString)));
|
||||
QObject::connect(trWidget, SIGNAL(notifyInfo(QString)),
|
||||
this, SIGNAL(notifyInfo(QString)));
|
||||
QObject::connect(trWidget, SIGNAL(gameUpdated()),
|
||||
QObject::connect(p, SIGNAL(gameUpdated()),
|
||||
this, SIGNAL(gameUpdated()));
|
||||
QObject::connect(trWidget, SIGNAL(rackUpdated(const QString&)),
|
||||
this, SIGNAL(trainingRackUpdated(const QString&)));
|
||||
QObject::connect(trWidget, SIGNAL(requestDefinition(QString)),
|
||||
this, SIGNAL(requestDefinition(QString)));
|
||||
addTab(trWidget, qfw(player.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add one tab per player
|
||||
for (unsigned int i = 0; i < iGame->getNbPlayers(); ++i)
|
||||
{
|
||||
const Player &player = iGame->getPlayer(i);
|
||||
PlayerWidget *p = new PlayerWidget(NULL, m_coordModel, i, iGame);
|
||||
QObject::connect(this, SIGNAL(refreshSignal()), p, SLOT(refresh()));
|
||||
// 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()));
|
||||
// Switching to a tab corresponding to an AI player
|
||||
// is forbidden
|
||||
if (!player.isHuman())
|
||||
setTabEnabled(i, false);
|
||||
}
|
||||
setCurrentIndex(iGame->getCurrentPlayer().getId());
|
||||
addTab(p, qfw(player.getName()));
|
||||
// Switching to a tab corresponding to an AI player
|
||||
// is forbidden
|
||||
if (!player.isHuman())
|
||||
setTabEnabled(i, false);
|
||||
}
|
||||
setCurrentIndex(iGame->getCurrentPlayer().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ signals:
|
|||
void gameUpdated();
|
||||
void notifyProblem(QString iMsg);
|
||||
void notifyInfo(QString iMsg);
|
||||
void trainingRackUpdated(const QString &iRack);
|
||||
void requestDefinition(QString iWord);
|
||||
|
||||
private slots:
|
||||
|
|
Loading…
Reference in a new issue