Improve playlist view: focus on playlistview or search filter, depending on keyboard event. Fixes issue 606

This commit is contained in:
Arnaud Bienner 2011-02-23 22:21:17 +00:00
parent b04fbf226c
commit 9c0094b9a6
4 changed files with 41 additions and 2 deletions

View File

@ -90,6 +90,8 @@ PlaylistContainer::PlaylistContainer(QWidget *parent)
#else
filter_ = ui_->filter;
connect(ui_->filter, SIGNAL(textChanged(QString)), SLOT(UpdateFilter()));
connect(ui_->playlist, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
ui_->filter->installEventFilter(this);
#endif
}
@ -336,6 +338,11 @@ void PlaylistContainer::resizeEvent(QResizeEvent* e) {
RepositionNoMatchesLabel();
}
void PlaylistContainer::FocusOnFilter(QKeyEvent *event) {
ui_->filter->setFocus(Qt::OtherFocusReason);
QApplication::sendEvent(ui_->filter, event);
}
void PlaylistContainer::RepositionNoMatchesLabel(bool force) {
if (!force && !no_matches_label_->isVisible())
return;
@ -354,3 +361,27 @@ void PlaylistContainer::RepositionNoMatchesLabel(bool force) {
void PlaylistContainer::SelectionChanged() {
manager_->SelectionChanged(view()->selectionModel()->selection());
}
bool PlaylistContainer::eventFilter(QObject *objectWatched, QEvent *event) {
if(objectWatched == ui_->filter) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent *e = static_cast<QKeyEvent*>(event);
switch(e->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
case Qt::Key_Return:
case Qt::Key_Enter:
view()->setFocus(Qt::OtherFocusReason);
QApplication::sendEvent(ui_->playlist, event);
return true;
case Qt::Key_Escape:
ui_->filter->LineEditInterface::clear();
default:
break;
}
}
}
return QWidget::eventFilter(objectWatched, event);
}

View File

@ -46,6 +46,8 @@ public:
PlaylistView* view() const;
bool eventFilter(QObject *objectWatched, QEvent *event);
signals:
void TabChanged(int id);
void Rename(int id, const QString& new_name);
@ -80,6 +82,7 @@ private slots:
void SelectionChanged();
void UpdateFilter();
void FocusOnFilter(QKeyEvent *event);
private:
void UpdateActiveIcon(const QIcon& icon);

View File

@ -431,8 +431,7 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
QTreeView::keyPressEvent(event);
} else if (state() == QAbstractItemView::EditingState) {
QTreeView::keyPressEvent(event);
} else if (event->matches(QKeySequence::Delete) ||
event->key() == Qt::Key_Backspace) {
} else if (event->matches(QKeySequence::Delete)) {
RemoveSelected();
event->accept();
} else if (event->key() == Qt::Key_Enter ||
@ -445,6 +444,11 @@ void PlaylistView::keyPressEvent(QKeyEvent* event) {
emit SeekTrack(-1);
} else if(event->key() == Qt::Key_Right) {
emit SeekTrack(1);
} 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 )) {
emit FocusOnFilterSignal(event);
} else {
QTreeView::keyPressEvent(event);
}

View File

@ -89,6 +89,7 @@ class PlaylistView : public QTreeView {
void PlayPauseItem(const QModelIndex& index);
void RightClicked(const QPoint& global_pos, const QModelIndex& index);
void SeekTrack(int gap);
void FocusOnFilterSignal(QKeyEvent *event);
protected:
void contextMenuEvent(QContextMenuEvent* e);