Arbitration: when a player is selected, automatically switch to the corresponding history tab

This commit is contained in:
Olivier Teulière 2012-05-06 23:23:19 +02:00
parent 1ad1ef7425
commit f7a7eab3a3
6 changed files with 42 additions and 5 deletions

View file

@ -97,6 +97,11 @@ ArbitAssignments::ArbitAssignments(QWidget *parent, PublicGame *iGame)
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(enableAssignmentButtons())); this, SLOT(enableAssignmentButtons()));
// Emit the "playerSelected" signal when appropriate
QObject::connect(treeViewPlayers->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(emitPlayerSelected()));
// Move assignment // Move assignment
QObject::connect(buttonSelectMaster, SIGNAL(clicked()), QObject::connect(buttonSelectMaster, SIGNAL(clicked()),
this, SLOT(assignMasterMove())); this, SLOT(assignMasterMove()));
@ -304,6 +309,14 @@ bool ArbitAssignments::hasSelectedPlayer() const
} }
void ArbitAssignments::emitPlayerSelected()
{
QSet<unsigned int> playersIdSet = getSelectedPlayers();
if (playersIdSet.size() == 1)
emit playerSelected(*playersIdSet.begin());
}
QSet<unsigned int> ArbitAssignments::getSelectedPlayers() const QSet<unsigned int> ArbitAssignments::getSelectedPlayers() const
{ {
QSet<unsigned int> playersIdSet; QSet<unsigned int> playersIdSet;

View file

@ -60,6 +60,7 @@ signals:
void notifyProblem(QString iMsg); void notifyProblem(QString iMsg);
void notifyInfo(QString iMsg); void notifyInfo(QString iMsg);
void endOfTurn(); void endOfTurn();
void playerSelected(unsigned playerId);
public slots: public slots:
void refresh(); void refresh();
@ -72,6 +73,7 @@ public slots:
private slots: private slots:
void on_checkBoxHideAssigned_toggled(bool); void on_checkBoxHideAssigned_toggled(bool);
void emitPlayerSelected();
void showMasterPreview(); void showMasterPreview();
void populatePlayersMenu(QMenu &iMenu, const QPoint &iPoint); void populatePlayersMenu(QMenu &iMenu, const QPoint &iPoint);
void assignTopMove(); void assignTopMove();

View file

@ -69,6 +69,8 @@ ArbitrationWidget::ArbitrationWidget(QWidget *parent,
this, SIGNAL(notifyInfo(QString))); this, SIGNAL(notifyInfo(QString)));
QObject::connect(m_assignmentsWidget, SIGNAL(endOfTurn()), QObject::connect(m_assignmentsWidget, SIGNAL(endOfTurn()),
this, SLOT(endOfTurnRefresh())); this, SLOT(endOfTurnRefresh()));
QObject::connect(m_assignmentsWidget, SIGNAL(playerSelected(unsigned)),
this, SIGNAL(playerSelected(unsigned)));
m_keyAccum = new KeyAccumulator(this, 400); m_keyAccum = new KeyAccumulator(this, 400);

View file

@ -54,6 +54,7 @@ signals:
void notifyInfo(QString iMsg); void notifyInfo(QString iMsg);
void rackUpdated(const QString &iRack); void rackUpdated(const QString &iRack);
void requestDefinition(QString iWord); void requestDefinition(QString iWord);
void playerSelected(unsigned playerId);
public slots: public slots:
void refresh(); void refresh();

View file

@ -157,15 +157,15 @@ MainWindow::MainWindow(QWidget *iParent)
#if 1 #if 1
// History // History
HistoryTabWidget *historyTab = new HistoryTabWidget; m_historyTabWidget = new HistoryTabWidget;
QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)), QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)),
historyTab, SLOT(setGame(const PublicGame*))); m_historyTabWidget, SLOT(setGame(const PublicGame*)));
QObject::connect(this, SIGNAL(gameUpdated()), QObject::connect(this, SIGNAL(gameUpdated()),
historyTab, SLOT(refresh())); m_historyTabWidget, SLOT(refresh()));
QObject::connect(historyTab, SIGNAL(requestDefinition(QString)), QObject::connect(m_historyTabWidget, SIGNAL(requestDefinition(QString)),
this, SLOT(showDefinition(QString))); this, SLOT(showDefinition(QString)));
QHBoxLayout *hlayout2 = new QHBoxLayout; QHBoxLayout *hlayout2 = new QHBoxLayout;
hlayout2->addWidget(historyTab); hlayout2->addWidget(m_historyTabWidget);
m_ui.groupBoxHistory->setLayout(hlayout2); m_ui.groupBoxHistory->setLayout(hlayout2);
#else #else
m_ui.groupBoxHistory->hide(); m_ui.groupBoxHistory->hide();
@ -412,6 +412,10 @@ void MainWindow::updateForGame(PublicGame *iGame)
m_arbitrationWidget, SLOT(refresh())); m_arbitrationWidget, SLOT(refresh()));
// Connect with the dictionary tools only if needed // Connect with the dictionary tools only if needed
linkArbitrationAnd7P1(); linkArbitrationAnd7P1();
// When a player is selected, show his history
QObject::connect(m_arbitrationWidget, SIGNAL(playerSelected(unsigned)),
this, SLOT(onPlayerSelected(unsigned)));
} }
else else
{ {
@ -497,6 +501,14 @@ void MainWindow::showDefinition(QString iWord)
} }
void MainWindow::onPlayerSelected(unsigned iPlayerId)
{
// Select the corresponding tab in the history widget
// Note: we don't do the same for the external history widget...
m_historyTabWidget->setCurrentIndex(1 + iPlayerId);
}
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (m_game) if (m_game)

View file

@ -37,6 +37,7 @@ class Bag;
class Board; class Board;
class History; class History;
class PublicGame; class PublicGame;
class HistoryTabWidget;
class PlayerTabWidget; class PlayerTabWidget;
class ScoreWidget; class ScoreWidget;
class TrainingWidget; class TrainingWidget;
@ -109,6 +110,9 @@ private slots:
/** Perform work when the preferences were updated */ /** Perform work when the preferences were updated */
void prefsUpdated(); void prefsUpdated();
/** Select the correct tab in the history widget when the player changes */
void onPlayerSelected(unsigned iPlayerId);
/** /**
* Perform several updates when the game changes (title bar, status bar, * Perform several updates when the game changes (title bar, status bar,
* grey out some menu items, ...) * grey out some menu items, ...)
@ -131,6 +135,9 @@ private:
/// The UI file generated with Qt Designer /// The UI file generated with Qt Designer
Ui::MainWindow m_ui; Ui::MainWindow m_ui;
/// Widget for the game history
HistoryTabWidget *m_historyTabWidget;
/// Widget for the players /// Widget for the players
PlayerTabWidget *m_playersWidget; PlayerTabWidget *m_playersWidget;