When doing a keyboard search in the library view, scroll so that the index is at the top of the viewport instead of at the bottom. Fixes issue #354

This commit is contained in:
David Sansome 2010-05-28 12:52:22 +00:00
parent 98c97d13d6
commit 48830f2acc
2 changed files with 21 additions and 1 deletions

View File

@ -79,7 +79,8 @@ LibraryView::LibraryView(QWidget* parent)
library_(NULL),
total_song_count_(-1),
nomusic_(":nomusic.png"),
context_menu_(new QMenu(this))
context_menu_(new QMenu(this)),
is_in_keyboard_search_(false)
{
setItemDelegate(new LibraryItemDelegate(this));
@ -208,3 +209,16 @@ void LibraryView::AddToPlaylist() {
emit AddToPlaylist(context_menu_index_);
}
void LibraryView::keyboardSearch(const QString &search) {
is_in_keyboard_search_ = true;
QTreeView::keyboardSearch(search);
is_in_keyboard_search_ = false;
}
void LibraryView::scrollTo(const QModelIndex &index, ScrollHint hint) {
if (is_in_keyboard_search_)
QTreeView::scrollTo(index, QAbstractItemView::PositionAtTop);
else
QTreeView::scrollTo(index, hint);
}

View File

@ -39,6 +39,10 @@ class LibraryView : public AutoExpandingTreeView {
void SetLibrary(LibraryModel* library);
// QTreeView
void keyboardSearch(const QString &search);
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
public slots:
void TotalSongCountUpdated(int count);
void ReloadSettings();
@ -76,6 +80,8 @@ class LibraryView : public AutoExpandingTreeView {
QAction* add_to_playlist_;
QAction* show_in_various_;
QAction* no_show_in_various_;
bool is_in_keyboard_search_;
};
#endif // LIBRARYVIEW_H