MCPcopy Create free account
hub / github.com/KDE/kdevelop / eventFilter

Method eventFilter

plugins/quickopen/quickopenwidget.cpp:370–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

368}
369
370bool QuickOpenWidget::eventFilter(QObject* watched, QEvent* event)
371{
372 auto getInterface = [this]() {
373 const QModelIndex index = m_proxy->mapToSource(ui.list->currentIndex());
374 QWidget* widget = m_model->expandingWidget(index);
375 return dynamic_cast<KDevelop::QuickOpenEmbeddedWidgetInterface*>(widget);
376 };
377
378 auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
379
380 if (event->type() == QEvent::KeyRelease) {
381 if (keyEvent->key() == Qt::Key_Alt) {
382 if ((m_expandedTemporary && m_altDownTime.msecsTo(QTime::currentTime()) > 300) || (!m_expandedTemporary && m_altDownTime.msecsTo(QTime::currentTime()) < 300 && m_hadNoCommandSinceAlt)) {
383 //Unexpand the item
384 QModelIndex row = m_proxy->mapToSource(ui.list->selectionModel()->currentIndex());
385 if (row.isValid()) {
386 row = row.sibling(row.row(), 0);
387 if (m_model->isExpanded(row)) {
388 m_model->setExpanded(row, false);
389 }
390 }
391 }
392 m_expandedTemporary = false;
393 }
394 }
395
396 if (event->type() == QEvent::KeyPress) {
397 m_hadNoCommandSinceAlt = false;
398 if (keyEvent->key() == Qt::Key_Alt) {
399 avoidMenuAltFocus();
400 m_hadNoCommandSinceAlt = true;
401 //Expand
402 QModelIndex row = m_proxy->mapToSource(ui.list->selectionModel()->currentIndex());
403 if (row.isValid()) {
404 row = row.sibling(row.row(), 0);
405 m_altDownTime = QTime::currentTime();
406 if (!m_model->isExpanded(row)) {
407 m_expandedTemporary = true;
408 m_model->setExpanded(row, true);
409 }
410 }
411 }
412
413 switch (keyEvent->key()) {
414 case Qt::Key_Tab:
415 if (keyEvent->modifiers() == Qt::NoModifier) {
416 // Tab should work just like Down
417 QKeyEvent keyDownPress(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
418 QCoreApplication::sendEvent(ui.list, &keyDownPress);
419 QKeyEvent keyDownRelease(QEvent::KeyRelease, Qt::Key_Down, Qt::NoModifier);
420 QCoreApplication::sendEvent(ui.list, &keyDownRelease);
421 return true; // eat event
422 }
423 break;
424 case Qt::Key_Backtab:
425 if (keyEvent->modifiers() == Qt::ShiftModifier) {
426 // Shift + Tab should work just like Up
427 QKeyEvent keyUpPress(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);

Callers

nothing calls this directly

Calls 15

siblingMethod · 0.80
isExpandedMethod · 0.80
modifiersMethod · 0.80
stopMethod · 0.80
eventFilterFunction · 0.50
mapToSourceMethod · 0.45
currentIndexMethod · 0.45
expandingWidgetMethod · 0.45
typeMethod · 0.45
keyMethod · 0.45
isValidMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected