1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Use a better spotify icon in the Source row, clean up pixmap drawing code

This commit is contained in:
David Sansome 2012-01-08 15:16:36 +00:00
parent 2e49e89e7b
commit 5b71ed0837

View File

@ -458,7 +458,7 @@ QPixmap SongSourceDelegate::LookupPixmap(const QUrl& url, const QSize& size) con
icon = handler->icon();
} else {
if (url.scheme() == "spotify") {
icon = IconLoader::Load("spotify");
icon = QIcon(":icons/22x22/spotify.png");
} else if (url.scheme() == "file") {
icon = IconLoader::Load("folder-sound");
}
@ -470,16 +470,19 @@ QPixmap SongSourceDelegate::LookupPixmap(const QUrl& url, const QSize& size) con
void SongSourceDelegate::paint(
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
// Draw the background
PlaylistDelegateBase::paint(painter, option, index);
QStyleOptionViewItem option_copy(option);
initStyleOption(&option_copy, index);
// Find the pixmap to use for this URL
const QUrl& url = index.data().toUrl();
QPixmap pixmap = LookupPixmap(url, option_copy.decorationSize);
const int margin = (option_copy.rect.width() - pixmap.width()) / 2;
QRect draw_rect(
margin + option_copy.rect.x(),
option_copy.rect.y(),
qMin(option_copy.decorationSize.width(), pixmap.width()),
qMin(option_copy.decorationSize.height(), pixmap.height()));
// Draw the pixmap in the middle of the rectangle
QRect draw_rect(QPoint(0, 0), option_copy.decorationSize);
draw_rect.moveCenter(option_copy.rect.center());
painter->drawPixmap(draw_rect, pixmap);
}