Factorize some code using a utility class

This commit is contained in:
Olivier Teulière 2012-03-18 02:45:15 +01:00
parent e77923674f
commit 7539cddf92
2 changed files with 3 additions and 45 deletions

View file

@ -32,6 +32,7 @@
#include "players_table_helper.h"
#include "custom_popup.h"
#include "misc_helpers.h"
#include "qtcommon.h"
@ -142,9 +143,9 @@ void PlayersTableHelper::addPopupRemoveAction()
// Install a custom event filter, to remove the selection when the
// "Delete" key is pressed
PlayersEventFilter *filter = new PlayersEventFilter(this);
KeyEventFilter *filter = new KeyEventFilter(this, Qt::Key_Delete);
m_tablePlayers->installEventFilter(filter);
QObject::connect(filter, SIGNAL(deletePressed()),
QObject::connect(filter, SIGNAL(keyPressed()),
this, SLOT(removeSelectedRows()));
}
@ -398,28 +399,3 @@ void PlayersLevelDelegate::updateEditorGeometry(QWidget *editor,
editor->setGeometry(option.rect);
}
PlayersEventFilter::PlayersEventFilter(QObject *parent)
: QObject(parent)
{
}
bool PlayersEventFilter::eventFilter(QObject *obj, QEvent *event)
{
// If the Delete key is pressed, remove the selected line, if any
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Delete)
{
emit deletePressed();
return true;
}
}
// Standard event processing
return QObject::eventFilter(obj, event);
}

View file

@ -143,23 +143,5 @@ public:
const QModelIndex &index) const;
};
/// Event filter used for the edition of the players display
class PlayersEventFilter: public QObject
{
Q_OBJECT;
public:
explicit PlayersEventFilter(QObject *parent = 0);
virtual ~PlayersEventFilter() {}
signals:
/// As its name indicates...
void deletePressed();
protected:
virtual bool eventFilter(QObject *obj, QEvent *event);
};
#endif