bool RPCConsole::eventFilter(QObject* obj, QEvent *event) { 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) { 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) { QApplication::postEvent(ui->messagesWidget, new QKeyEvent(*keyevt)); 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))) { ui->lineEdit->setFocus(); QApplication::postEvent(ui->lineEdit, new QKeyEvent(*keyevt)); return true; } } } return QDialog::eventFilter(obj, event); }
bool RPCConsole::eventFilter(QObject* obj, QEvent *event) { if(obj == ui->lineEdit) { if(event->type() == QEvent::KeyPress) { QKeyEvent *key = static_cast<QKeyEvent*>(event); switch(key->key()) { case Qt::Key_Up: browseHistory(-1); return true; case Qt::Key_Down: browseHistory(1); return true; } } } return QDialog::eventFilter(obj, event); }
// slot void TabPage::restoreScrollPos() { // scroll to recorded position folderView_->childView()->verticalScrollBar()->setValue(browseHistory().currentScrollPos()); // if the current folder is the parent folder of the last browsed folder, // select the folder item in current view. if(lastFolderPath_.parent() == path()) { QModelIndex index = folderView_->indexFromFolderPath(lastFolderPath_.data()); if(index.isValid()) { folderView_->childView()->scrollTo(index, QAbstractItemView::EnsureVisible); folderView_->childView()->setCurrentIndex(index); } } }