mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-29 02:29:56 +01:00
Make escape and backspace work in the library and radio views. Fixes issue 1510
This commit is contained in:
parent
d7dbd21438
commit
3d593e696c
@ -126,6 +126,11 @@ LibraryFilterWidget::~LibraryFilterWidget() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::FocusOnFilter(QKeyEvent *event) {
|
||||
ui_->filter->setFocus(Qt::OtherFocusReason);
|
||||
QApplication::sendEvent(ui_->filter, event);
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::SetLibraryModel(LibraryModel *model) {
|
||||
if (model_) {
|
||||
disconnect(model_, 0, this, 0);
|
||||
@ -223,6 +228,11 @@ void LibraryFilterWidget::keyReleaseEvent(QKeyEvent* e) {
|
||||
emit DownPressed();
|
||||
e->accept();
|
||||
break;
|
||||
|
||||
case Qt::Key_Escape:
|
||||
ui_->filter->LineEditInterface::clear();
|
||||
e->accept();
|
||||
break;
|
||||
}
|
||||
|
||||
QWidget::keyReleaseEvent(e);
|
||||
|
@ -55,6 +55,7 @@ class LibraryFilterWidget : public QWidget {
|
||||
|
||||
public slots:
|
||||
void SetQueryMode(QueryOptions::QueryMode view);
|
||||
void FocusOnFilter(QKeyEvent* e);
|
||||
|
||||
signals:
|
||||
void UpPressed();
|
||||
|
@ -485,18 +485,6 @@ void LibraryView::CopyToDevice() {
|
||||
organise_dialog_->show();
|
||||
}
|
||||
|
||||
void LibraryView::keyPressEvent(QKeyEvent* e) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
if (currentIndex().isValid())
|
||||
emit doubleClicked(currentIndex());
|
||||
break;
|
||||
}
|
||||
|
||||
QTreeView::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void LibraryView::DeleteFinished(const SongList& songs_with_errors) {
|
||||
if (songs_with_errors.isEmpty())
|
||||
return;
|
||||
@ -506,16 +494,6 @@ void LibraryView::DeleteFinished(const SongList& songs_with_errors) {
|
||||
// It deletes itself when the user closes it
|
||||
}
|
||||
|
||||
void LibraryView::UpAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void LibraryView::DownAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void LibraryView::FilterReturnPressed() {
|
||||
if (!currentIndex().isValid()) {
|
||||
// Pick the first thing that isn't a divider
|
||||
|
@ -79,8 +79,6 @@ class LibraryView : public AutoExpandingTreeView {
|
||||
void TotalSongCountUpdated(int count);
|
||||
void ReloadSettings();
|
||||
|
||||
void UpAndFocus();
|
||||
void DownAndFocus();
|
||||
void FilterReturnPressed();
|
||||
|
||||
signals:
|
||||
@ -91,7 +89,6 @@ class LibraryView : public AutoExpandingTreeView {
|
||||
void paintEvent(QPaintEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* e);
|
||||
void contextMenuEvent(QContextMenuEvent* e);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
|
||||
private slots:
|
||||
void Load();
|
||||
|
@ -27,6 +27,7 @@ LibraryViewContainer::LibraryViewContainer(QWidget* parent)
|
||||
connect(filter(), SIGNAL(UpPressed()), view(), SLOT(UpAndFocus()));
|
||||
connect(filter(), SIGNAL(DownPressed()), view(), SLOT(DownAndFocus()));
|
||||
connect(filter(), SIGNAL(ReturnPressed()), view(), SLOT(FilterReturnPressed()));
|
||||
connect(view(), SIGNAL(FocusOnFilterSignal(QKeyEvent*)), filter(), SLOT(FocusOnFilter(QKeyEvent*)));
|
||||
}
|
||||
|
||||
LibraryViewContainer::~LibraryViewContainer() {
|
||||
|
@ -71,6 +71,11 @@ IcecastFilterWidget::~IcecastFilterWidget() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void IcecastFilterWidget::FocusOnFilter(QKeyEvent *event) {
|
||||
ui_->filter->setFocus(Qt::OtherFocusReason);
|
||||
QApplication::sendEvent(ui_->filter, event);
|
||||
}
|
||||
|
||||
void IcecastFilterWidget::SetIcecastModel(IcecastModel* model) {
|
||||
model_ = model;
|
||||
connect(filter_->widget(), SIGNAL(textChanged(QString)),
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
|
||||
void SetIcecastModel(IcecastModel* model);
|
||||
|
||||
public slots:
|
||||
void FocusOnFilter(QKeyEvent* e);
|
||||
|
||||
private slots:
|
||||
void SortModeChanged(int mode);
|
||||
|
||||
|
@ -21,8 +21,9 @@
|
||||
#include "ui_radioviewcontainer.h"
|
||||
#include "core/mergedproxymodel.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QMetaMethod>
|
||||
#include <QTimeLine>
|
||||
#include <QtDebug>
|
||||
|
||||
const int RadioViewContainer::kAnimationDuration = 500;
|
||||
|
||||
@ -37,6 +38,7 @@ RadioViewContainer::RadioViewContainer(QWidget *parent)
|
||||
|
||||
connect(ui_->tree, SIGNAL(collapsed(QModelIndex)), SLOT(Collapsed(QModelIndex)));
|
||||
connect(ui_->tree, SIGNAL(expanded(QModelIndex)), SLOT(Expanded(QModelIndex)));
|
||||
connect(ui_->tree, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
|
||||
}
|
||||
|
||||
RadioViewContainer::~RadioViewContainer() {
|
||||
@ -113,6 +115,19 @@ void RadioViewContainer::SetHeaderVisible(QWidget* header, bool visible) {
|
||||
d.animation_->start();
|
||||
}
|
||||
|
||||
void RadioViewContainer::FocusOnFilter(QKeyEvent* event) {
|
||||
// Beware: magic
|
||||
|
||||
if (current_header_) {
|
||||
int slot = current_header_->metaObject()->indexOfSlot(
|
||||
QMetaObject::normalizedSignature("FocusOnFilter(QKeyEvent*)"));
|
||||
if (slot != -1) {
|
||||
current_header_->metaObject()->method(slot).invoke(
|
||||
current_header_, Q_ARG(QKeyEvent*, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RadioViewContainer::SetHeaderHeight(int height) {
|
||||
QTimeLine* animation = qobject_cast<QTimeLine*>(sender());
|
||||
QWidget* header = NULL;
|
||||
|
@ -49,6 +49,8 @@ class RadioViewContainer : public QWidget {
|
||||
void CurrentIndexChanged(const QModelIndex& index);
|
||||
void SetHeaderHeight(int height);
|
||||
|
||||
void FocusOnFilter(QKeyEvent* event);
|
||||
|
||||
private:
|
||||
void ServiceChanged(const QModelIndex& index);
|
||||
void SetHeaderVisible(QWidget* header, bool visible);
|
||||
|
@ -112,3 +112,32 @@ void AutoExpandingTreeView::mousePressEvent(QMouseEvent* event) {
|
||||
emit AddToPlaylistSignal(data);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
if (currentIndex().isValid())
|
||||
emit doubleClicked(currentIndex());
|
||||
e->accept();
|
||||
break;
|
||||
|
||||
case Qt::Key_Backspace:
|
||||
case Qt::Key_Escape:
|
||||
emit FocusOnFilterSignal(e);
|
||||
e->accept();
|
||||
break;
|
||||
}
|
||||
|
||||
QTreeView::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void AutoExpandingTreeView::UpAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void AutoExpandingTreeView::DownAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
@ -33,9 +33,12 @@ public:
|
||||
|
||||
public slots:
|
||||
void RecursivelyExpand(const QModelIndex &index);
|
||||
void UpAndFocus();
|
||||
void DownAndFocus();
|
||||
|
||||
signals:
|
||||
void AddToPlaylistSignal(QMimeData* data);
|
||||
void FocusOnFilterSignal(QKeyEvent* event);
|
||||
|
||||
protected:
|
||||
// QAbstractItemView
|
||||
@ -43,6 +46,7 @@ protected:
|
||||
|
||||
// QWidget
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
virtual bool CanRecursivelyExpand(const QModelIndex& index) const { return true; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user