mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-27 09:58:08 +01:00
Factorize some code using a utility class
This commit is contained in:
parent
e77923674f
commit
7539cddf92
2 changed files with 3 additions and 45 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue