Remove all uses of KeyEventFilter.

Use the standard QShortcut instead (possibly combined with a
QSignalMapper).
This commit is contained in:
Olivier Teulière 2013-01-15 19:31:32 +01:00
parent 89efeffd9b
commit 820cd1509c
4 changed files with 54 additions and 65 deletions

View file

@ -23,11 +23,11 @@
#include <QtGui/QStandardItemModel> #include <QtGui/QStandardItemModel>
#include <QtGui/QSortFilterProxyModel> #include <QtGui/QSortFilterProxyModel>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QShortcut>
#include "arbit_assignments.h" #include "arbit_assignments.h"
#include "qtcommon.h" #include "qtcommon.h"
#include "custom_popup.h" #include "custom_popup.h"
#include "misc_helpers.h"
#include "prefs_dialog.h" #include "prefs_dialog.h"
#include "public_game.h" #include "public_game.h"
@ -76,35 +76,36 @@ ArbitAssignments::ArbitAssignments(QWidget *parent, PublicGame *iGame)
treeViewPlayers->setColumnWidth(6, 25); treeViewPlayers->setColumnWidth(6, 25);
treeViewPlayers->setColumnWidth(7, 25); treeViewPlayers->setColumnWidth(7, 25);
KeyEventFilter *filter = new KeyEventFilter(this, Qt::Key_A); QShortcut *shortcut;
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut = new QShortcut(QString("A"), treeViewPlayers);
shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(selectAllPlayers())); this, SLOT(selectAllPlayers()));
treeViewPlayers->installEventFilter(filter);
filter = new KeyEventFilter(this, Qt::Key_Delete); shortcut = new QShortcut(QKeySequence::Delete, treeViewPlayers);
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(suppressMove())); this, SLOT(suppressMove()));
treeViewPlayers->installEventFilter(filter);
filter = new KeyEventFilter(this, Qt::Key_T); shortcut = new QShortcut(QString("T"), treeViewPlayers);
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(assignTopMove())); this, SLOT(assignTopMove()));
treeViewPlayers->installEventFilter(filter);
filter = new KeyEventFilter(this, Qt::Key_S); shortcut = new QShortcut(QString("S"), treeViewPlayers);
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(addRemoveSolo())); this, SLOT(addRemoveSolo()));
treeViewPlayers->installEventFilter(filter);
filter = new KeyEventFilter(this, Qt::Key_W); shortcut = new QShortcut(QString("W"), treeViewPlayers);
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(addRemoveWarning())); this, SLOT(addRemoveWarning()));
treeViewPlayers->installEventFilter(filter);
filter = new KeyEventFilter(this, Qt::Key_P); shortcut = new QShortcut(QString("P"), treeViewPlayers);
QObject::connect(filter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
this, SLOT(addRemovePenalty())); this, SLOT(addRemovePenalty()));
treeViewPlayers->installEventFilter(filter);
// Display a preview of the master word when clicked // Display a preview of the master word when clicked
QObject::connect(labelMasterMove, SIGNAL(clicked()), QObject::connect(labelMasterMove, SIGNAL(clicked()),

View file

@ -21,7 +21,9 @@
#include <QtGui/QStandardItemModel> #include <QtGui/QStandardItemModel>
#include <QtGui/QSortFilterProxyModel> #include <QtGui/QSortFilterProxyModel>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QShortcut>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QSignalMapper>
#include "arbitration_widget.h" #include "arbitration_widget.h"
#include "arbit_assignments.h" #include "arbit_assignments.h"
@ -30,7 +32,6 @@
#include "validator_factory.h" #include "validator_factory.h"
#include "play_word_mediator.h" #include "play_word_mediator.h"
#include "custom_popup.h" #include "custom_popup.h"
#include "misc_helpers.h"
#include "play_model.h" #include "play_model.h"
#include "public_game.h" #include "public_game.h"
@ -115,30 +116,30 @@ ArbitrationWidget::ArbitrationWidget(QWidget *parent,
treeViewResults->setColumnWidth(1, 40); treeViewResults->setColumnWidth(1, 40);
treeViewResults->setColumnWidth(2, 70); treeViewResults->setColumnWidth(2, 70);
KeyEventFilter *masterFilter = new KeyEventFilter(this, Qt::Key_M, Qt::SHIFT); QShortcut *shortcut;
QObject::connect(masterFilter, SIGNAL(keyPressed(int, int)), shortcut = new QShortcut(QString("Shift+M"), treeViewResults);
shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
m_assignmentsWidget, SLOT(assignMasterMove())); m_assignmentsWidget, SLOT(assignMasterMove()));
treeViewResults->installEventFilter(masterFilter);
KeyEventFilter *selectAllFilter = new KeyEventFilter(this, Qt::Key_A, Qt::SHIFT); shortcut = new QShortcut(QString("Shift+A"), treeViewResults);
QObject::connect(selectAllFilter, SIGNAL(keyPressed(int, int)), shortcut->setContext(Qt::WidgetWithChildrenShortcut);
QObject::connect(shortcut, SIGNAL(activated()),
m_assignmentsWidget, SLOT(selectAllPlayers())); m_assignmentsWidget, SLOT(selectAllPlayers()));
treeViewResults->installEventFilter(selectAllFilter);
KeyEventFilter *numFilter = new KeyEventFilter(this, Qt::Key_0); // React to digits (0 to 9)
numFilter->addKey(Qt::Key_1); m_signalMapper = new QSignalMapper(this);
numFilter->addKey(Qt::Key_2); for (int i = 0; i <= 9; ++i)
numFilter->addKey(Qt::Key_3); {
numFilter->addKey(Qt::Key_4); QString numStr = QString("%1").arg(i);
numFilter->addKey(Qt::Key_5); shortcut = new QShortcut(numStr, treeViewResults);
numFilter->addKey(Qt::Key_6); shortcut->setContext(Qt::WidgetWithChildrenShortcut);
numFilter->addKey(Qt::Key_7); QObject::connect(shortcut, SIGNAL(activated()),
numFilter->addKey(Qt::Key_8); m_signalMapper, SLOT(map()));
numFilter->addKey(Qt::Key_9); m_signalMapper->setMapping(shortcut, numStr);
numFilter->setIgnoreModifiers(); }
QObject::connect(numFilter, SIGNAL(keyPressed(int, int)), QObject::connect(m_signalMapper, SIGNAL(mapped(const QString&)),
this, SLOT(selectTableNumber(int))); this, SLOT(selectTableNumber(const QString&)));
treeViewResults->installEventFilter(numFilter);
// Validate manual rack changes // Validate manual rack changes
QObject::connect(lineEditRack, SIGNAL(textEdited(const QString&)), QObject::connect(lineEditRack, SIGNAL(textEdited(const QString&)),
@ -619,23 +620,10 @@ void ArbitrationWidget::selectAndFocusResult(int iRowNum, bool logical)
} }
void ArbitrationWidget::selectTableNumber(int key) void ArbitrationWidget::selectTableNumber(const QString &iKey)
{ {
QString keyStr = "";
if (key == Qt::Key_0) keyStr = "0";
else if (key == Qt::Key_1) keyStr = "1";
else if (key == Qt::Key_2) keyStr = "2";
else if (key == Qt::Key_3) keyStr = "3";
else if (key == Qt::Key_4) keyStr = "4";
else if (key == Qt::Key_5) keyStr = "5";
else if (key == Qt::Key_6) keyStr = "6";
else if (key == Qt::Key_7) keyStr = "7";
else if (key == Qt::Key_8) keyStr = "8";
else if (key == Qt::Key_9) keyStr = "9";
ASSERT(keyStr != "", "Unexpected key");
// Build (and retrieve) the table number // Build (and retrieve) the table number
QString tableNum = m_keyAccum->addText(keyStr); QString tableNum = m_keyAccum->addText(iKey);
// Select the player with this table number // Select the player with this table number
LOG_DEBUG("Selecting player with table number: " + lfq(tableNum)); LOG_DEBUG("Selecting player with table number: " + lfq(tableNum));

View file

@ -38,6 +38,7 @@ class QSortFilterProxyModel;
class QMenu; class QMenu;
class QPoint; class QPoint;
class QValidator; class QValidator;
class QSignalMapper;
class ArbitrationWidget: public QWidget, private Ui::ArbitrationWidget class ArbitrationWidget: public QWidget, private Ui::ArbitrationWidget
{ {
@ -74,7 +75,7 @@ private slots:
void updateCoordText(const Coord&); void updateCoordText(const Coord&);
void updatePlayModel(const QString&); void updatePlayModel(const QString&);
void populateResultsMenu(QMenu &iMenu, const QPoint &iPoint); void populateResultsMenu(QMenu &iMenu, const QPoint &iPoint);
void selectTableNumber(int key); void selectTableNumber(const QString &iKey);
void endOfTurnRefresh(); void endOfTurnRefresh();
private: private:
@ -101,6 +102,9 @@ private:
/// Container for the moves manually entered in the interface /// Container for the moves manually entered in the interface
QVector<Move> m_addedMoves; QVector<Move> m_addedMoves;
/// Signal mapper used to react to some shortcuts (digits for the table number)
QSignalMapper *m_signalMapper;
/// Accumulator used to build the table number /// Accumulator used to build the table number
KeyAccumulator *m_keyAccum; KeyAccumulator *m_keyAccum;

View file

@ -28,11 +28,11 @@
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QShortcut>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include "players_table_helper.h" #include "players_table_helper.h"
#include "custom_popup.h" #include "custom_popup.h"
#include "misc_helpers.h"
#include "qtcommon.h" #include "qtcommon.h"
#include "debug.h" #include "debug.h"
@ -158,17 +158,13 @@ void PlayersTableHelper::addPopupRemoveAction()
{ {
QAction *removeAction = new QAction(_q("Remove selected player(s)"), this); QAction *removeAction = new QAction(_q("Remove selected player(s)"), this);
removeAction->setStatusTip(_q("Remove the selected player(s) from the list")); removeAction->setStatusTip(_q("Remove the selected player(s) from the list"));
removeAction->setShortcut(Qt::Key_Delete); removeAction->setShortcut(QKeySequence::Delete);
QObject::connect(removeAction, SIGNAL(triggered()), QObject::connect(removeAction, SIGNAL(triggered()),
this, SLOT(removeSelectedRows())); this, SLOT(removeSelectedRows()));
// Add the action to the popup menu...
addPopupAction(removeAction); addPopupAction(removeAction);
// ... and to the table itself
// Install a custom event filter, to remove the selection when the m_tablePlayers->addAction(removeAction);
// "Delete" key is pressed
KeyEventFilter *filter = new KeyEventFilter(this, Qt::Key_Delete);
m_tablePlayers->installEventFilter(filter);
QObject::connect(filter, SIGNAL(keyPressed(int, int)),
this, SLOT(removeSelectedRows()));
} }