void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) { QModelIndex index = currentIndex(); switch (e->key()) { case Qt::Key_Enter: case Qt::Key_Return: if (index.isValid()) emit doubleClicked(index); e->accept(); break; case Qt::Key_Backspace: case Qt::Key_Escape: emit FocusOnFilterSignal(e); e->accept(); break; case Qt::Key_Left: // Set focus on the root of the current branch if (index.isValid() && index.parent() != rootIndex() && (!isExpanded(index) || model()->rowCount(index) == 0)) { setCurrentIndex(index.parent()); setFocus(); e->accept(); } break; } QTreeView::keyPressEvent(e); }
void PlaylistView::keyPressEvent(QKeyEvent* event) { if (!model() || state() == QAbstractItemView::EditingState) { QTreeView::keyPressEvent(event); } else if (event == QKeySequence::Delete) { RemoveSelected(); event->accept(); #ifdef Q_OS_DARWIN } else if (event->key() == Qt::Key_Backspace) { RemoveSelected(); event->accept(); #endif } else if (event == QKeySequence::Copy) { CopyCurrentSongToClipboard(); } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { if (currentIndex().isValid()) emit PlayItem(currentIndex()); event->accept(); } else if (event->modifiers() != Qt::ControlModifier // Ctrl+Space selects // the item && event->key() == Qt::Key_Space) { emit PlayPause(); event->accept(); } else if (event->key() == Qt::Key_Left) { emit SeekTrack(-1); event->accept(); } else if (event->key() == Qt::Key_Right) { emit SeekTrack(1); event->accept(); } else if (event->modifiers() == Qt::NoModifier // No modifier keys currently pressed... // ... and key pressed is something related to text && ((event->key() >= Qt::Key_A && event->key() <= Qt::Key_Z) || event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Escape)) { emit FocusOnFilterSignal(event); event->accept(); } else { QTreeView::keyPressEvent(event); } }