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