Search simple providers properly, use the bigger album cover icon, disable the divider items, align the dividers' icons properly

This commit is contained in:
David Sansome 2012-06-10 17:36:40 +01:00
parent 41fab25569
commit b669dd64fa
3 changed files with 34 additions and 15 deletions

View File

@ -137,6 +137,7 @@ void GlobalSearchView::AddResults(int id, const SearchProvider::ResultList& resu
QStandardItem* divider = new QStandardItem(provider->icon(), provider->name()); QStandardItem* divider = new QStandardItem(provider->icon(), provider->name());
divider->setData(true, LibraryModel::Role_IsDivider); divider->setData(true, LibraryModel::Role_IsDivider);
divider->setData(sort_index, Role_ProviderIndex); divider->setData(sort_index, Role_ProviderIndex);
divider->setFlags(Qt::ItemIsEnabled);
current_model_->appendRow(divider); current_model_->appendRow(divider);
provider_sort_indices_[provider] = sort_index; provider_sort_indices_[provider] = sort_index;
@ -170,7 +171,8 @@ QStandardItem* GlobalSearchView::BuildContainers(
return parent; return parent;
} }
QIcon icon; bool has_artist_icon = false;
bool has_album_icon = false;
QString display_text; QString display_text;
QString sort_text; QString sort_text;
int year = 0; int year = 0;
@ -179,14 +181,14 @@ QStandardItem* GlobalSearchView::BuildContainers(
case LibraryModel::GroupBy_Artist: case LibraryModel::GroupBy_Artist:
display_text = LibraryModel::TextOrUnknown(s.artist()); display_text = LibraryModel::TextOrUnknown(s.artist());
sort_text = LibraryModel::SortTextForArtist(s.artist()); sort_text = LibraryModel::SortTextForArtist(s.artist());
icon = artist_icon_; has_artist_icon = true;
break; break;
case LibraryModel::GroupBy_YearAlbum: case LibraryModel::GroupBy_YearAlbum:
year = qMax(0, s.year()); year = qMax(0, s.year());
display_text = LibraryModel::PrettyYearAlbum(year, s.album()); display_text = LibraryModel::PrettyYearAlbum(year, s.album());
sort_text = LibraryModel::SortTextForYear(year) + s.album(); sort_text = LibraryModel::SortTextForYear(year) + s.album();
icon = album_icon_; has_album_icon = true;
break; break;
case LibraryModel::GroupBy_Year: case LibraryModel::GroupBy_Year:
@ -201,7 +203,7 @@ QStandardItem* GlobalSearchView::BuildContainers(
case LibraryModel::GroupBy_AlbumArtist: if (display_text.isNull()) display_text = s.effective_albumartist(); case LibraryModel::GroupBy_AlbumArtist: if (display_text.isNull()) display_text = s.effective_albumartist();
display_text = LibraryModel::TextOrUnknown(display_text); display_text = LibraryModel::TextOrUnknown(display_text);
sort_text = LibraryModel::SortTextForArtist(display_text); sort_text = LibraryModel::SortTextForArtist(display_text);
icon = album_icon_; has_album_icon = true;
break; break;
case LibraryModel::GroupBy_FileType: case LibraryModel::GroupBy_FileType:
@ -217,11 +219,21 @@ QStandardItem* GlobalSearchView::BuildContainers(
key->group_[level] = display_text; key->group_[level] = display_text;
QStandardItem* container = containers_[*key]; QStandardItem* container = containers_[*key];
if (!container) { if (!container) {
container = new QStandardItem(icon, display_text); container = new QStandardItem(display_text);
container->setData(key->provider_index_, Role_ProviderIndex); container->setData(key->provider_index_, Role_ProviderIndex);
container->setData(sort_text, LibraryModel::Role_SortText); container->setData(sort_text, LibraryModel::Role_SortText);
container->setData(group_by_[level], LibraryModel::Role_ContainerType); container->setData(group_by_[level], LibraryModel::Role_ContainerType);
if (has_artist_icon) {
container->setIcon(artist_icon_);
} else if (has_album_icon) {
if (app_->library_model()->use_pretty_covers()) {
container->setData(no_cover_icon_, Qt::DecorationRole);
} else {
container->setIcon(album_icon_);
}
}
parent->appendRow(container); parent->appendRow(container);
containers_[*key] = container; containers_[*key] = container;
} }
@ -240,14 +252,21 @@ void GlobalSearchView::SwapModels() {
} }
void GlobalSearchView::LazyLoadArt(const QModelIndex& proxy_index) { void GlobalSearchView::LazyLoadArt(const QModelIndex& proxy_index) {
if (!proxy_index.isValid() || proxy_index.data(Role_LazyLoadingArt).isValid()) { if (!proxy_index.isValid() || proxy_index.model() != front_proxy_) {
return;
}
if (proxy_index.model() != front_proxy_) {
return; return;
} }
// Only load art for albums // Already loading art for this item?
if (proxy_index.data(Role_LazyLoadingArt).isValid()) {
return;
}
// Should we even load art at all?
if (!app_->library_model()->use_pretty_covers()) {
return;
}
// Is this an album?
const LibraryModel::GroupBy container_type = LibraryModel::GroupBy( const LibraryModel::GroupBy container_type = LibraryModel::GroupBy(
proxy_index.data(LibraryModel::Role_ContainerType).toInt()); proxy_index.data(LibraryModel::Role_ContainerType).toInt());
if (container_type != LibraryModel::GroupBy_Album && if (container_type != LibraryModel::GroupBy_Album &&
@ -280,7 +299,9 @@ void GlobalSearchView::ArtLoaded(int id, const QPixmap& pixmap) {
return; return;
QModelIndex index = art_requests_.take(id); QModelIndex index = art_requests_.take(id);
front_model_->itemFromIndex(index)->setData(pixmap, Qt::DecorationRole); if (!pixmap.isNull()) {
front_model_->itemFromIndex(index)->setData(pixmap, Qt::DecorationRole);
}
} }
void GlobalSearchView::LoadTracks() { void GlobalSearchView::LoadTracks() {

View File

@ -67,11 +67,10 @@ SearchProvider::ResultList SimpleSearchProvider::Search(int id, const QString& q
QMutexLocker l(&items_mutex_); QMutexLocker l(&items_mutex_);
foreach (const Item& item, items_) { foreach (const Item& item, items_) {
Result result(this);
bool matched = true; bool matched = true;
foreach (const QString& token, tokens) { foreach (const QString& token, tokens) {
if (!item.keyword_.contains(token, Qt::CaseInsensitive) && if (!item.keyword_.contains(token, Qt::CaseInsensitive) &&
!item.metadata_.title().contains(token, Qt::CaseInsensitive) &&
!safe_words_.contains(token, Qt::CaseInsensitive)) { !safe_words_.contains(token, Qt::CaseInsensitive)) {
matched = false; matched = false;
break; break;
@ -79,6 +78,7 @@ SearchProvider::ResultList SimpleSearchProvider::Search(int id, const QString& q
} }
if (matched) { if (matched) {
Result result(this);
result.group_automatically_ = false; result.group_automatically_ = false;
result.metadata_ = item.metadata_; result.metadata_ = item.metadata_;
ret << result; ret << result;

View File

@ -77,8 +77,6 @@ void LibraryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
// Draw the icon at the left of the text rectangle // Draw the icon at the left of the text rectangle
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
text_rect.setLeft(text_rect.left() + 15);
QRect icon_rect(text_rect.topLeft(), opt.decorationSize); QRect icon_rect(text_rect.topLeft(), opt.decorationSize);
const int padding = (text_rect.height() - icon_rect.height()) / 2; const int padding = (text_rect.height() - icon_rect.height()) / 2;
icon_rect.adjust(padding, padding, padding, padding); icon_rect.adjust(padding, padding, padding, padding);