bool FindWidget::eventFilter(QObject *watched, QEvent *event) { if (watched == this && event->type() == QEvent::KeyPress) { QKeyEvent *e = static_cast<QKeyEvent*>(event); if (e->matches(QKeySequence::Find) || e->matches(QKeySequence::FindNext)) { ChatNotify::start(Notify::Find, ChatCore::currentId()); return true; } else if (e->matches(QKeySequence::FindPrevious)) { ChatNotify::start(Notify::FindPrevious, ChatCore::currentId()); return true; } else if (e->key() == Qt::Key_Escape) { hide(); emit hidden(); ChatNotify::start(Notify::SetSendFocus); return true; } } else if (watched == m_editFind && event->type() == QEvent::KeyPress) { if (static_cast<QKeyEvent*>(event)->matches(QKeySequence::Copy)) { if (!m_editFind->hasSelectedText()) { ChatNotify::start(Notify::CopyRequest); return true; } } } return QWidget::eventFilter(watched, event); }
bool csFontResizer::eventFilter(QObject *watched, QEvent *event) { if( event->type() == QEvent::KeyPress ) { QKeyEvent *keyEvent = dynamic_cast<QKeyEvent*>(event); if( keyEvent->matches(QKeySequence::ZoomIn) || (keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == Qt::Key_BracketRight) ) { resizeFont(watched, 0, incSize); return true; } else if( keyEvent->matches(QKeySequence::ZoomOut) ) { resizeFont(watched, 0, -incSize); return true; } else if( keyEvent->modifiers() == Qt::ControlModifier && keyEvent->key() == Qt::Key_0 ) { resizeFont(watched, defSize.value(dynamic_cast<QWidget*>(watched), 0)); return true; } } else if( event->type() == QEvent::Wheel ) { QWheelEvent *wheelEvent = dynamic_cast<QWheelEvent*>(event); if( wheelEvent->modifiers() == Qt::ControlModifier && wheelEvent->delta() > 0 ) { resizeFont(watched, 0, incSize); return true; } else if( wheelEvent->modifiers() == Qt::ControlModifier && wheelEvent->delta() < 0 ) { resizeFont(watched, 0, -incSize); return true; } } return QObject::eventFilter(watched, event); }
bool MainWindow::eventFilter(QObject *watched, QEvent *event) { if (ui->treeView->hasFocus() && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->matches(QKeySequence::Delete)) { const QModelIndexList indexes = ui->treeView->selectionModel()->selectedRows(); if (indexes.count() == 1) { const QModelIndex index = indexes.first(); if (index.isValid()) { m_model->removeKey(index); return true; } } } } if (event->type() == QEvent::WindowActivate) { // Effectively delay the foreground process transformation from QApplication construction to // when the UI is shown - this prevents the application icon from popping up in the Dock // when running `qbs help`, and QCoreApplication::arguments() requires the application // object to be constructed, so it is not easily worked around #if defined(Q_OS_MACOS) || defined(Q_OS_OSX) qt_macos_forceTransformProcessToForegroundApplicationAndActivate(); #endif } return QMainWindow::eventFilter(watched, event); }
bool InputWidget::eventFilter(QObject *watched, QEvent *event) { if (event->type() != QEvent::KeyPress) return false; QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); // keys from BufferView should be sent to (and focus) the input line BufferView *view = qobject_cast<BufferView *>(watched); if (view) { if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press QChar c = keyEvent->text().at(0); if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) { setFocus(); QCoreApplication::sendEvent(inputLine(), keyEvent); return true; } } return false; } else if (watched == ui.inputEdit) { if (keyEvent->matches(QKeySequence::Find)) { QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar"); if (act) { act->toggle(); return true; } } return false; } return false; }
// The following keyboard shortcuts should work (although // they may not work consistently depending on focus): // / (slash), Ctrl-F - Focus and highlight the search box // Ctrl-G, Ctrl-N, F3 - Find next // Should we make it so that typing any text starts searching? bool FollowStreamDialog::eventFilter(QObject *, QEvent *event) { if (ui->teStreamContent->hasFocus() && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->matches(QKeySequence::SelectAll) || keyEvent->matches(QKeySequence::Copy) || keyEvent->text().isEmpty()) { return false; } ui->leFind->setFocus(); if (keyEvent->matches(QKeySequence::Find)) { return true; } else if (keyEvent->matches(QKeySequence::FindNext)) { findText(); return true; } } return false; }
bool DatumTextItem::eventFilter(QObject* obj, QEvent* event) { if (obj == this && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Tab) emit tabPressed(this); else if (keyEvent->key() == Qt::Key_Backtab) emit shiftTabPressed(this); else if (keyEvent->matches(QKeySequence::Undo)) App::instance()->undo(); else if (keyEvent->matches(QKeySequence::Redo)) App::instance()->redo(); else return false; return true; } return false; }
bool Note::eventFilter(QObject * object, QEvent * event) { if (event->type() == QEvent::Shortcut || event->type() == QEvent::ShortcutOverride) { if (!object->inherits("QGraphicsView")) { event->accept(); return true; } } if (event->type() == QEvent::KeyPress) { QKeyEvent * kevent = static_cast<QKeyEvent *>(event); if (kevent->matches(QKeySequence::Bold)) { QTextCursor textCursor = m_graphicsTextItem->textCursor(); QTextCharFormat cf = textCursor.charFormat(); bool isBold = cf.fontWeight() == QFont::Bold; QTextCharFormat textCharFormat; textCharFormat.setFontWeight(isBold ? QFont::Normal : QFont::Bold); textCursor.mergeCharFormat(textCharFormat); event->accept(); return true; } if (kevent->matches(QKeySequence::Italic)) { QTextCursor textCursor = m_graphicsTextItem->textCursor(); QTextCharFormat cf = textCursor.charFormat(); QTextCharFormat textCharFormat; textCharFormat.setFontItalic(!cf.fontItalic()); textCursor.mergeCharFormat(textCharFormat); event->accept(); return true; } if ((kevent->key() == Qt::Key_L) && (kevent->modifiers() & Qt::ControlModifier)) { QTimer::singleShot(75, this, SLOT(linkDialog())); event->accept(); return true; } } return false; }
bool PropertiesDock::event(QEvent *event) { switch (event->type()) { case QEvent::ShortcutOverride: { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if (keyEvent->matches(QKeySequence::Delete) || keyEvent->key() == Qt::Key_Backspace || keyEvent->matches(QKeySequence::Cut) || keyEvent->matches(QKeySequence::Copy) || keyEvent->matches(QKeySequence::Paste)) { event->accept(); return true; } break; } case QEvent::LanguageChange: retranslateUi(); break; default: break; } return QDockWidget::event(event); }
bool KTreeWidgetSearchLine::event(QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if(keyEvent->matches(QKeySequence::MoveToNextLine) || keyEvent->matches(QKeySequence::SelectNextLine) || keyEvent->matches(QKeySequence::MoveToPreviousLine) || keyEvent->matches(QKeySequence::SelectPreviousLine) || keyEvent->matches(QKeySequence::MoveToNextPage) || keyEvent->matches(QKeySequence::SelectNextPage) || keyEvent->matches(QKeySequence::MoveToPreviousPage) || keyEvent->matches(QKeySequence::SelectPreviousPage) || keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) { QTreeWidget *first = d->treeWidgets.first(); if(first) { QApplication::sendEvent(first, event); return true; } } } return KLineEdit::event(event); }
bool MainWindow::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); // TODO: Perhaps enable backspace on OSX too? if (keyEvent->matches(QKeySequence::Delete)) { if (object == ui->eventsView) { ui->actionDelete_Event->trigger(); return true; } if (object == ui->conversationsView) { ui->actionDelete_Conversation->trigger(); return true; } } } return QMainWindow::eventFilter(object, event); }
bool LS3SelectionDisplayModelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if (index.column() == 0) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); QPoint pixtl=option.rect.topRight()+QPoint(-selDeleteImage.width(), (double)(option.rect.height()-selDeleteImage.height())/2.0); QRect r(pixtl, selDeleteImage.size()); if (r.contains(mouseEvent->pos())) { QString uuid=model->data(model->index(index.row(), 1)).toString(); datastore->deselect(uuid); } return false; //so that the selection can change } else if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->matches(QKeySequence::Delete)) { QString uuid=model->data(model->index(index.row(), 1)).toString(); datastore->deselect(uuid); } return false; //so that the selection can change } } return QStyledItemDelegate::editorEvent(event, model, option, index); }
//------------------------------------------------------------------------------ bool IgnoreUndoRedo::eventFilter(QObject* watched, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->matches(QKeySequence::Undo) || keyEvent->matches(QKeySequence::Redo)) { QCoreApplication::postEvent(recipient, new QKeyEvent( keyEvent->type(), keyEvent->key(), keyEvent->modifiers(), keyEvent->nativeScanCode(), keyEvent->nativeVirtualKey(), keyEvent->nativeModifiers(), keyEvent->text(), keyEvent->isAutoRepeat(), keyEvent->count() )); return true; } else { return false; } } else return QObject::eventFilter(watched, event); }
bool TableEventHandler::eventFilter(QObject *o, QEvent *e) { if( !o ) qWarning("TableEventHandler::eventFilter called with 0 object?"); if( QString(o->metaObject()->className()) != tr("QTableWidget") ) { #ifdef EI_DEBUG qDebug("Only QTableWidget objects accepted! Returning!"); #endif return false; } QTableWidget *to = (QTableWidget *)o; if( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if(ke->matches(QKeySequence::Copy) ){ QString cellText; itemCopy.clear(); copyRange.clear(); QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for ( int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++){ for ( int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++){ QTableWidgetItem *w = to->item(irow,icol); if(w) cellText = w->text(); if ( !cellText.isEmpty() ){ itemCopy << cellText; } else itemCopy << " "; } } copyRange = ts; //cout << itemCopy.join(", ").toLatin1().data() << endl; } else { QTableWidgetItem *w = to->item(to->currentRow(), to->currentColumn()); if (w) cellText = w->text(); if ( !cellText.isEmpty() ) itemCopy << cellText; else itemCopy << ""; } return true; } else if(ke->matches(QKeySequence::Paste) && !itemCopy.isEmpty() && !copyRange.isEmpty()){ QList<QTableWidgetSelectionRange> cs = to->selectedRanges(); int top = cs.first().topRow(), left = cs.first().leftColumn(), icount = 0; QTableWidgetSelectionRange ts = QTableWidgetSelectionRange( top , left, top + copyRange.first().rowCount()-1, left + copyRange.first().columnCount()-1); for ( int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){ for ( int icol = ts.leftColumn(); icol <= ts.rightColumn(); icol++){ if ( ++icount <= itemCopy.size() ) to->setItem(irow, icol, new QTableWidgetItem(itemCopy[icount-1])); } } return true; } else if(ke->matches(QKeySequence::Cut) ){ QString cellText; itemCopy.clear(); copyRange.clear(); QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) { for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) { QTableWidgetItem *w = to->item(irow,icol); if(w) cellText = w->text(); if ( !cellText.isEmpty() ){ itemCopy << cellText; } else itemCopy << ""; to->setItem(irow,icol,0); } } copyRange = ts; //cout << itemCopy.join(", ").toLatin1().data() << endl; } return true; } else if(ke->matches(QKeySequence::Delete) ){ QList<QTableWidgetSelectionRange> ts = to->selectedRanges(); if(!ts.isEmpty()) { for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) { for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) { to->setItem(irow,icol,0); } } } return true; } else to->eventFilter(o, e); } return false; }
bool KeyboardFilter::eventFilter(QObject *object, QEvent *event) { commandLine = (CommandLine*)object; if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent*)event; if(keyEvent->modifiers().testFlag(Qt::KeypadModifier)) { #ifdef Q_OS_MAC switch(keyEvent->key()) { case Qt::Key_Up: commandLine->historyBack(); break; case Qt::Key_Down: commandLine->historyForward(); break; } #endif QString cmd = macroSettings->getParameter("keypad/" + QString::number(keyEvent->modifiers() | keyEvent->key()), "").toString(); return commandLine->runMacro(cmd); } else { if(keyEvent->modifiers() == Qt::NoModifier) { switch(keyEvent->key()) { #ifndef Q_OS_MAC case Qt::Key_Up: commandLine->historyBack(); break; case Qt::Key_Down: commandLine->historyForward(); break; #endif case Qt::Key_Escape: commandLine->clear(); commandLine->historyCounter = -1; commandLine->abortScript(); commandLine->abortSequence(); break; case Qt::Key_Tab: commandLine->completeCommand(); return true; break; default: QString cmd = macroSettings->getParameter("function/" + QString::number(keyEvent->modifiers() | keyEvent->key()), "").toString(); return commandLine->runMacro(cmd); break; } return false; } else { if(keyEvent->modifiers() == Qt::ControlModifier) { QString cmd = macroSettings->getParameter("ctrl/" + QString::number(keyEvent->modifiers() | keyEvent->key()), "").toString(); if(cmd.isEmpty() && keyEvent->matches(QKeySequence::Copy)) { commandLine->doCopy(); return true; } else { return commandLine->runMacro(cmd); } } else if (keyEvent->modifiers() == Qt::AltModifier) { QString cmd = macroSettings->getParameter("alt/" + QString::number(keyEvent->modifiers() | keyEvent->key()), "").toString(); return commandLine->runMacro(cmd); } } } return false; } /* workaround to give back focus to * command line from alt -> menu */ if (event->type() == QEvent::FocusOut) { commandLine->setFocus(); return true; } return false; }
bool CmdPromptInput::eventFilter(QObject* obj, QEvent* event) { if(event->type() == QEvent::KeyPress) { QKeyEvent* pressedKey = (QKeyEvent*)event; //NOTE: These shortcuts need to be caught since QLineEdit uses them if(pressedKey->matches(QKeySequence::Cut)) { pressedKey->accept(); emit cutPressed(); return true; } else if(pressedKey->matches(QKeySequence::Copy)) { pressedKey->accept(); emit copyPressed(); return true; } else if(pressedKey->matches(QKeySequence::Paste)) { pressedKey->accept(); emit pastePressed(); return true; } else if(pressedKey->matches(QKeySequence::SelectAll)) { pressedKey->accept(); emit selectAllPressed(); return true; } else if(pressedKey->matches(QKeySequence::Undo)) { pressedKey->accept(); emit undoPressed(); return true; } else if(pressedKey->matches(QKeySequence::Redo)) { pressedKey->accept(); emit redoPressed(); return true; } int key = pressedKey->key(); switch(key) { case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Space: pressedKey->accept(); processInput(QChar(key)); return true; break; case Qt::Key_Delete: pressedKey->accept(); emit deletePressed(); return true; break; case Qt::Key_Tab: pressedKey->accept(); emit tabPressed(); return true; break; case Qt::Key_Escape: pressedKey->accept(); prefix = "Command: "; clear(); emit appendHistory(curText + tr("*Cancel*")); emit escapePressed(); return true; break; case Qt::Key_F1: pressedKey->accept(); emit F1Pressed(); return true; break; case Qt::Key_F2: pressedKey->accept(); emit F2Pressed(); return true; break; case Qt::Key_F3: pressedKey->accept(); emit F3Pressed(); return true; break; case Qt::Key_F4: pressedKey->accept(); emit F4Pressed(); return true; break; case Qt::Key_F5: emit F5Pressed(); pressedKey->accept(); return true; break; case Qt::Key_F6: pressedKey->accept(); emit F6Pressed(); return true; break; case Qt::Key_F7: pressedKey->accept(); emit F7Pressed(); return true; break; case Qt::Key_F8: pressedKey->accept(); emit F8Pressed(); return true; break; case Qt::Key_F9: pressedKey->accept(); emit F9Pressed(); return true; break; case Qt::Key_F10: pressedKey->accept(); emit F10Pressed(); return true; break; case Qt::Key_F11: pressedKey->accept(); emit F11Pressed(); return true; break; case Qt::Key_F12: pressedKey->accept(); emit F12Pressed(); return true; break; default: pressedKey->ignore(); } } return QObject::eventFilter(obj, event); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RiuTreeViewEventFilter::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent *>(event); std::vector<caf::PdmUiItem*> uiItems; caf::SelectionManager::instance()->selectedItems(uiItems); if (uiItems.size() > 0) { std::vector<caf::CmdFeature*> matches; if (keyEvent->matches(QKeySequence::Copy)) { matches.push_back(caf::CmdFeatureManager::instance()->getCommandFeature("RicCopyReferencesToClipboardFeature")); } else if (keyEvent->matches(QKeySequence::Cut)) { matches.push_back(caf::CmdFeatureManager::instance()->getCommandFeature("RicCutReferencesToClipboardFeature")); } else if (keyEvent->matches(QKeySequence::Paste)) { if (uiItems.size() == 1) { matches = caf::CmdFeatureManager::instance()->commandFeaturesMatchingSubString("Paste"); } } for (caf::CmdFeature* feature : matches) { if (feature->canFeatureBeExecuted()) { feature->actionTriggered(false); keyEvent->setAccepted(true); return true; } } } // Do not toggle state if currently editing a name in the tree view bool toggleStateForSelection = true; if (RiuMainWindow::instance()->projectTreeView() && RiuMainWindow::instance()->projectTreeView()->isTreeItemEditWidgetActive()) { toggleStateForSelection = false; } else if (RiaApplication::instance()->mainPlotWindow() && RiaApplication::instance()->mainPlotWindow()->projectTreeView() && RiaApplication::instance()->mainPlotWindow()->projectTreeView()->isTreeItemEditWidgetActive()) { toggleStateForSelection = false; } if (toggleStateForSelection) { switch (keyEvent->key()) { case Qt::Key_Space: case Qt::Key_Enter: case Qt::Key_Return: case Qt::Key_Select: { RicToggleItemsFeatureImpl::setObjectToggleStateForSelection(RicToggleItemsFeatureImpl::TOGGLE); keyEvent->setAccepted(true); return true; } } } } // standard event processing return QObject::eventFilter(obj, event); }
bool KindleMainWindow::eventFilter( QObject * obj, QEvent * ev ) { if ( obj == ui->translateLine ) { qDebug() << "TRANSLATE_LINE_EVENT: " << ev; if ( ev->type() == QEvent::KeyPress ) { QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); // move to the next suggestion if ( keyEvent->matches(QKeySequence::MoveToNextLine) ) { if (wordList->count() != 0) { int rowToJump = (wordList->currentRow() + 1) % wordList->count(); wordList->setCurrentRow(rowToJump, QItemSelectionModel::ClearAndSelect); } return true; } // move to the previous suggestion if ( keyEvent->matches(QKeySequence::MoveToPreviousLine) ) { if (wordList->count() != 0) { int currRow = wordList->currentRow(); if (currRow < 0) { currRow = 0; } int rowToJump = (wordList->count() + currRow - 1) % wordList->count(); wordList->setCurrentRow(rowToJump, QItemSelectionModel::ClearAndSelect); } return true; } } if ( ev->type() == QEvent::FocusIn ) { // QFocusEvent * focusEvent = static_cast< QFocusEvent * >( ev ); // select all on mouse click //if ( focusEvent->reason() == Qt::MouseFocusReason ) { ui->translateLine->selectAll(); QTimer::singleShot(0, this, SLOT(focusTranslateLine())); //} return false; } } else if ( obj == wordList ) { // qDebug() << ev; if ( ev->type() == QEvent::KeyPress ) { QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); qDebug() << keyEvent; if ( keyEvent->matches(QKeySequence::MoveToNextLine) ) { qDebug() << "current wordList index: " << wordList->currentIndex(); wordList->setCurrentRow(wordList->currentRow() + 1, QItemSelectionModel::ClearAndSelect); return true; } if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) && !wordList->currentRow() ) { qDebug() << "!!!!!+++!!!"; wordList->setCurrentRow( 0, QItemSelectionModel::Clear ); ui->translateLine->setFocus( Qt::ShortcutFocusReason ); return true; } qDebug() << "!!!!!+++!!!-2"; if ( keyEvent->matches( QKeySequence::InsertParagraphSeparator ) && wordList->selectedItems().size() ) { getCurrentArticleView()->focus(); return false; } // Handle typing events used to initiate new lookups // TODO: refactor to eliminate duplication (see below) if ( keyEvent->modifiers() & ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) ) return false; // A non-typing modifier is pressed if ( keyEvent->key() == Qt::Key_Space || keyEvent->key() == Qt::Key_Backspace || keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab ) return false; // Those key have other uses than to start typing // or don't make sense QString text = keyEvent->text(); qDebug() << "text:" << text; if ( text.size() ) { typingEvent( text ); return true; } } } return QMainWindow::eventFilter( obj, ev ); }