From 4065037abaac309abe2eba88531dc72fcce1d71e Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 17 Sep 2011 16:21:08 +0100 Subject: [PATCH] Show a big track count indicator and provider icons in global search results --- src/globalsearch/globalsearchitemdelegate.cpp | 42 ++++++++++++++++--- src/globalsearch/globalsearchitemdelegate.h | 1 + 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/globalsearch/globalsearchitemdelegate.cpp b/src/globalsearch/globalsearchitemdelegate.cpp index 5a87265c1..b961805de 100644 --- a/src/globalsearch/globalsearchitemdelegate.cpp +++ b/src/globalsearch/globalsearchitemdelegate.cpp @@ -27,6 +27,7 @@ const int GlobalSearchItemDelegate::kHeight = SearchProvider::kArtHeight; const int GlobalSearchItemDelegate::kMargin = 2; const int GlobalSearchItemDelegate::kArtMargin = 6; +const int GlobalSearchItemDelegate::kProviderIconSize = 16; GlobalSearchItemDelegate::GlobalSearchItemDelegate(GlobalSearchWidget* widget) : QStyledItemDelegate(widget), @@ -55,6 +56,9 @@ void GlobalSearchItemDelegate::paint(QPainter* p, QFont bold_font = option.font; bold_font.setBold(true); + QFont big_font(bold_font); + big_font.setPointSizeF(big_font.pointSizeF() + 2); + QColor pen = option.palette.color(selected ? QPalette::HighlightedText : QPalette::Text); QColor light_pen = pen; pen.setAlpha(200); @@ -76,9 +80,36 @@ void GlobalSearchItemDelegate::paint(QPainter* p, p->drawPixmap(art_rect, art); + // Draw a track count indicator next to the art. + QRect count_rect(art_rect.right() + kArtMargin, art_rect.top(), + kHeight, kHeight); + + QString count; + switch (result.type_) { + case SearchProvider::Result::Type_Track: + break; + + case SearchProvider::Result::Type_Album: + if (result.album_size_ <= 0) + count = "-"; + else + count = QString::number(result.album_size_); + break; + } + + p->setPen(light_pen); + p->setFont(big_font); + p->drawText(count_rect, Qt::TextSingleLine | Qt::AlignCenter, count); + + // Draw a provider icon on the right. + QRect icon_rect(rect.right() - kArtMargin - kProviderIconSize, + rect.top() + (rect.height() - kProviderIconSize) / 2, + kProviderIconSize, kProviderIconSize); + p->drawPixmap(icon_rect, result.provider_->icon().pixmap(kProviderIconSize)); + // Position text - QRect text_rect(art_rect.right() + kArtMargin, art_rect.top(), - rect.right() - art_rect.right() - kArtMargin, kHeight); + QRect text_rect(count_rect.right() + kArtMargin, count_rect.top(), + icon_rect.left() - count_rect.right() - kArtMargin*2, kHeight); QRect text_rect_1(text_rect.adjusted(0, 0, 0, -kHeight/2)); QRect text_rect_2(text_rect.adjusted(0, kHeight/2, 0, 0)); @@ -130,13 +161,14 @@ void GlobalSearchItemDelegate::paint(QPainter* p, else line_1 += m.album(); - // Line 2 is tracks - line_2 += QString::number(result.album_size_) + " "; - line_2 += tr(result.album_size_ == 1 ? "track" : "tracks"); break; } } + if (line_2.isEmpty()) { + text_rect_1 = text_rect; + } + p->setFont(bold_font); p->setPen(pen); p->drawText(text_rect_1, Qt::TextSingleLine | Qt::AlignVCenter, line_1); diff --git a/src/globalsearch/globalsearchitemdelegate.h b/src/globalsearch/globalsearchitemdelegate.h index dca1c73ea..c9a7095da 100644 --- a/src/globalsearch/globalsearchitemdelegate.h +++ b/src/globalsearch/globalsearchitemdelegate.h @@ -30,6 +30,7 @@ public: static const int kHeight; static const int kMargin; static const int kArtMargin; + static const int kProviderIconSize; QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option,