Skip to content

Commit

Permalink
[Music] Fix too long artist name
Browse files Browse the repository at this point in the history
  • Loading branch information
bugwelle committed Jun 18, 2018
1 parent 750b8c0 commit c44739e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions smallWidgets/MusicTreeView.cpp
Expand Up @@ -9,16 +9,15 @@ MusicTreeView::MusicTreeView(QWidget *parent) : QTreeView(parent)
{
}

MusicTreeView::~MusicTreeView() = default;

void MusicTreeView::drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const
{
#ifdef Q_OS_WIN
QTreeView::drawBranches(painter, rect, index);
return;
#endif
if (index.model()->data(index, MusicRoles::Type).toInt() != TypeArtist)
if (index.model()->data(index, MusicRoles::Type).toInt() != TypeArtist) {
return;
}

painter->save();

Expand Down Expand Up @@ -48,14 +47,16 @@ void MusicTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &optio
if (index.data(MusicRoles::Type).toInt() == TypeAlbum)
opt.rect.setX(opt.rect.x() + albumIndent - 4);
if (alternatingRowColors() && index.data(MusicRoles::Type).toInt() == TypeAlbum) {
if (index.row() % 2 == 0)
if (index.row() % 2 == 0) {
opt.features |= QStyleOptionViewItem::Alternate;
else
} else {
opt.features &= ~QStyleOptionViewItem::Alternate;
}
}

if (isSelected)
if (isSelected) {
opt.state |= QStyle::State_Selected;
}
style()->drawPrimitive(QStyle::PE_PanelItemViewRow, &opt, painter, this);

if (index.data(MusicRoles::Type).toInt() == TypeArtist) {
Expand Down Expand Up @@ -85,11 +86,14 @@ void MusicTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &optio
option.rect.width() - branchIndent - itemIndent,
textRowHeight);

font = index.data(Qt::FontRole).value<QFont>();
painter->setPen(index.data(isSelected ? MusicRoles::SelectionForeground : Qt::ForegroundRole).value<QColor>());
painter->setFont(index.data(Qt::FontRole).value<QFont>());
painter->drawText(artistRect, index.data(Qt::DisplayRole).toString(), QTextOption(Qt::AlignVCenter));
painter->setFont(font);

const QFontMetrics metrics(font);
const QString itemStr = metrics.elidedText(index.data().toString(), Qt::ElideRight, artistRect.width());
painter->drawText(artistRect, itemStr, QTextOption(Qt::AlignVCenter));

font = painter->font();
#ifdef Q_OS_MAC
font.setPointSize(font.pointSize() - 2);
#else
Expand Down
2 changes: 1 addition & 1 deletion smallWidgets/MusicTreeView.h
Expand Up @@ -10,7 +10,7 @@ class MusicTreeView : public QTreeView
Q_OBJECT
public:
explicit MusicTreeView(QWidget *parent = nullptr);
~MusicTreeView() override;
~MusicTreeView() override = default;

protected:
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override;
Expand Down

0 comments on commit c44739e

Please sign in to comment.