mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
New game dialog: disable the up/down buttons when there is no selection
This commit is contained in:
parent
844105a8e8
commit
487dd213ce
3 changed files with 38 additions and 14 deletions
|
@ -66,6 +66,7 @@ NewGame::NewGame(QWidget *iParent)
|
|||
QObject::connect(addToFavAction, SIGNAL(triggered()),
|
||||
this, SLOT(addSelectedToFav()));
|
||||
m_helper->addPopupAction(addToFavAction);
|
||||
m_helper->setUpDown(buttonUp, buttonDown);
|
||||
|
||||
// Initialize the model of the default players
|
||||
QList<PlayerDef> fav = PlayersTableHelper::getFavPlayers();
|
||||
|
@ -109,10 +110,6 @@ NewGame::NewGame(QWidget *iParent)
|
|||
|
||||
QObject::connect(buttonAddFav, SIGNAL(clicked()),
|
||||
this, SLOT(addFavoritePlayers()));
|
||||
QObject::connect(buttonUp, SIGNAL(clicked()),
|
||||
m_helper, SLOT(moveSelectionUp()));
|
||||
QObject::connect(buttonDown, SIGNAL(clicked()),
|
||||
m_helper, SLOT(moveSelectionDown()));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
|||
bool showDefaultColumn)
|
||||
: QObject(parent), m_tablePlayers(tablePlayers),
|
||||
m_buttonAdd(addButton), m_buttonRemove(removeButton),
|
||||
m_showDefaultColumn(showDefaultColumn)
|
||||
m_showDefaultColumn(showDefaultColumn),
|
||||
m_buttonUp(0), m_buttonDown(0)
|
||||
{
|
||||
// Initialize the table headers
|
||||
tablePlayers->setColumnCount(m_showDefaultColumn ? 4 : 3);
|
||||
|
@ -101,11 +102,11 @@ PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
|||
}
|
||||
if (m_buttonRemove)
|
||||
{
|
||||
QObject::connect(tablePlayers, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(enableRemoveButton()));
|
||||
QObject::connect(m_buttonRemove, SIGNAL(clicked()),
|
||||
this, SLOT(removeSelectedRows()));
|
||||
}
|
||||
QObject::connect(tablePlayers, SIGNAL(itemSelectionChanged()),
|
||||
this, SLOT(enableSelDepButtons()));
|
||||
|
||||
PlayersTypeDelegate *typeDelegate = new PlayersTypeDelegate(this);
|
||||
m_tablePlayers->setItemDelegateForColumn(1, typeDelegate);
|
||||
|
@ -119,6 +120,21 @@ PlayersTableHelper::PlayersTableHelper(QObject *parent,
|
|||
}
|
||||
|
||||
|
||||
void PlayersTableHelper::setUpDown(QPushButton *iButtonUp, QPushButton *iButtonDown)
|
||||
{
|
||||
ASSERT(m_buttonUp == 0 && m_buttonDown == 0,
|
||||
"The up and down buttons can only be associated once");
|
||||
m_buttonUp = iButtonUp;
|
||||
m_buttonDown = iButtonDown;
|
||||
QObject::connect(m_buttonUp, SIGNAL(clicked()),
|
||||
this, SLOT(moveSelectionUp()));
|
||||
QObject::connect(m_buttonDown, SIGNAL(clicked()),
|
||||
this, SLOT(moveSelectionDown()));
|
||||
// Set a correct initial state
|
||||
enableSelDepButtons();
|
||||
}
|
||||
|
||||
|
||||
void PlayersTableHelper::populateMenu(QMenu &iMenu, const QPoint &iPoint)
|
||||
{
|
||||
const QModelIndex &index = m_tablePlayers->indexAt(iPoint);
|
||||
|
@ -156,9 +172,15 @@ void PlayersTableHelper::addPopupRemoveAction()
|
|||
}
|
||||
|
||||
|
||||
void PlayersTableHelper::enableRemoveButton()
|
||||
void PlayersTableHelper::enableSelDepButtons()
|
||||
{
|
||||
m_buttonRemove->setEnabled(!m_tablePlayers->selectedItems().isEmpty());
|
||||
bool hasSelection = !m_tablePlayers->selectedItems().isEmpty();
|
||||
if (m_buttonRemove)
|
||||
m_buttonRemove->setEnabled(hasSelection);
|
||||
if (m_buttonUp)
|
||||
m_buttonUp->setEnabled(hasSelection);
|
||||
if (m_buttonDown)
|
||||
m_buttonDown->setEnabled(hasSelection);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,6 +63,9 @@ public:
|
|||
QPushButton *removeButton = 0,
|
||||
bool showDefaultColumn = false);
|
||||
|
||||
/// Associate up/down buttons
|
||||
void setUpDown(QPushButton *iButtonUp, QPushButton *iButtonDown);
|
||||
|
||||
QList<PlayerDef> getPlayers(bool onlySelected) const;
|
||||
void addPlayers(const QList<PlayerDef> &iList);
|
||||
void addPlayer(const PlayerDef &iPlayer,
|
||||
|
@ -77,19 +80,18 @@ public:
|
|||
void addPopupAction(QAction *iAction);
|
||||
void addPopupRemoveAction();
|
||||
|
||||
public slots:
|
||||
void moveSelectionUp();
|
||||
void moveSelectionDown();
|
||||
|
||||
signals:
|
||||
void rowCountChanged();
|
||||
|
||||
private slots:
|
||||
void populateMenu(QMenu &, const QPoint &);
|
||||
void enableRemoveButton();
|
||||
/// Enable selection-dependent buttons
|
||||
void enableSelDepButtons();
|
||||
void removeSelectedRows();
|
||||
void addRow();
|
||||
void addRow(const PlayerDef &iDef);
|
||||
void moveSelectionUp();
|
||||
void moveSelectionDown();
|
||||
|
||||
private:
|
||||
QTableWidget *m_tablePlayers;
|
||||
|
@ -97,6 +99,9 @@ private:
|
|||
QPushButton *m_buttonRemove;
|
||||
QList<QAction*> m_popupActions;
|
||||
bool m_showDefaultColumn;
|
||||
// Up/down buttons (optional)
|
||||
QPushButton *m_buttonUp;
|
||||
QPushButton *m_buttonDown;
|
||||
|
||||
/// Return a "normalized" player def, i.e. with correct values
|
||||
PlayerDef normalize(const PlayerDef &iDef) const;
|
||||
|
|
Loading…
Reference in a new issue