Browse Source

Improve RPC console key event behaviour

- Paging using PageUp / PageDown now works when entry widget has focus
- Typing or pasting while the messages widget has focus auto-selects entry widget
0.8
Wladimir J. van der Laan 12 years ago
parent
commit
62904b33f3
  1. 32
      src/qt/rpcconsole.cpp

32
src/qt/rpcconsole.cpp

@ -199,6 +199,7 @@ RPCConsole::RPCConsole(QWidget *parent) :
// Install event filter for up and down arrow // Install event filter for up and down arrow
ui->lineEdit->installEventFilter(this); ui->lineEdit->installEventFilter(this);
ui->messagesWidget->installEventFilter(this);
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
@ -218,15 +219,34 @@ RPCConsole::~RPCConsole()
bool RPCConsole::eventFilter(QObject* obj, QEvent *event) bool RPCConsole::eventFilter(QObject* obj, QEvent *event)
{ {
if(obj == ui->lineEdit) if(event->type() == QEvent::KeyPress) // Special key handling
{
QKeyEvent *keyevt = static_cast<QKeyEvent*>(event);
int key = keyevt->key();
Qt::KeyboardModifiers mod = keyevt->modifiers();
switch(key)
{ {
if(event->type() == QEvent::KeyPress) case Qt::Key_Up: if(obj == ui->lineEdit) { browseHistory(-1); return true; } break;
case Qt::Key_Down: if(obj == ui->lineEdit) { browseHistory(1); return true; } break;
case Qt::Key_PageUp: /* pass paging keys to messages widget */
case Qt::Key_PageDown:
if(obj == ui->lineEdit)
{ {
QKeyEvent *key = static_cast<QKeyEvent*>(event); QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt));
switch(key->key()) return true;
}
break;
default:
// Typing in messages widget brings focus to line edit, and redirects key there
// Exclude most combinations and keys that emit no text, except paste shortcuts
if(obj == ui->messagesWidget && (
(!mod && !keyevt->text().isEmpty() && key != Qt::Key_Tab) ||
((mod & Qt::ControlModifier) && key == Qt::Key_V) ||
((mod & Qt::ShiftModifier) && key == Qt::Key_Insert)))
{ {
case Qt::Key_Up: browseHistory(-1); return true; ui->lineEdit->setFocus();
case Qt::Key_Down: browseHistory(1); return true; QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt));
return true;
} }
} }
} }

Loading…
Cancel
Save