Qt: add some hotkeys to some user account interactions

This commit is contained in:
Megamouse 2018-07-26 23:33:58 +02:00
parent c39bd490ba
commit f84883223b
2 changed files with 36 additions and 2 deletions

View File

@ -69,6 +69,7 @@ void user_manager_dialog::Init()
m_table->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
m_table->horizontalHeader()->setStretchLastSection(true);
m_table->horizontalHeader()->setDefaultSectionSize(150);
m_table->installEventFilter(this);
QPushButton* push_remove_user = new QPushButton(tr("Delete User"), this);
push_remove_user->setAutoDefault(false);
@ -83,7 +84,7 @@ void user_manager_dialog::Init()
push_rename_user->setAutoDefault(false);
QPushButton* push_close = new QPushButton(tr("&Close"), this);
push_close->setAutoDefault(true);
push_close->setAutoDefault(false);
// Button Layout
QHBoxLayout* hbox_buttons = new QHBoxLayout();
@ -109,7 +110,7 @@ void user_manager_dialog::Init()
// Use this in multiple connects to protect the current user from deletion/rename.
auto enableButtons = [=]()
{
u32 key = GetUserKey();
const u32 key = GetUserKey();
if (key == 0)
{
push_login_user->setEnabled(false);
@ -461,3 +462,35 @@ void user_manager_dialog::closeEvent(QCloseEvent *event)
m_gui_settings->SetValue(gui::um_geometry, saveGeometry());
QDialog::closeEvent(event);
}
bool user_manager_dialog::eventFilter(QObject *object, QEvent *event)
{
const u32 key = GetUserKey();
if (key == 0 || object != m_table || m_user_list[key].GetUserId() == m_active_user)
{
return QDialog::eventFilter(object, event);
}
if (event->type() == QEvent::KeyRelease)
{
const QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
switch (key_event->key())
{
case Qt::Key_F2:
OnUserRename();
break;
case Qt::Key_Delete:
OnUserRemove();
break;
case Qt::Key_Return:
case Qt::Key_Enter:
OnUserLogin();
break;
default:
break;
}
}
return QDialog::eventFilter(object, event);
}

View File

@ -42,6 +42,7 @@ private:
void ShowContextMenu(const QPoint &pos);
void closeEvent(QCloseEvent* event) override;
bool eventFilter(QObject* object, QEvent* event) override;
u32 GetUserKey();