diff options
author | Arno <arno@disconnect.de> | 2017-12-31 12:48:42 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-12-31 12:48:42 +0100 |
commit | 387a22f9f84fd673febfbdf4f8ffccd6556e11ae (patch) | |
tree | 1d0fcb69df677ca9f2f9da2a64a929bd02270ef8 /playerwidget.cpp | |
parent | bfcc8b9e09d6a25a8ad12e3dc73db3fbc3c975bf (diff) | |
download | BeetPlayer-387a22f9f84fd673febfbdf4f8ffccd6556e11ae.tar.gz BeetPlayer-387a22f9f84fd673febfbdf4f8ffccd6556e11ae.tar.bz2 BeetPlayer-387a22f9f84fd673febfbdf4f8ffccd6556e11ae.zip |
Revamp favorites
The previous display of song - album - artist wasn't really a good
choice. Artist - album - song is more to my liking. At first I tried to
save headers, but that turned out to be much more difficult than expected.
First, as it turns out the first column in a QTreeView is not movable by
design. Second, having more than one column with the current Model/View
design is a pain in the ass. E.g. adding to the playlist always selects
column 0, so all relevant data had to be in the decoration column. Much
too complicated.
So I took the easy way out: Simply format the song title like several
columns. Since "courier" is hardcoded as a font it wasn't even a problem
to elide the song title in the center. KISS!
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r-- | playerwidget.cpp | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index b3bda18..6da2401 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -26,6 +26,7 @@ #include <QApplication> #include <QDateTime> #include <QRegularExpression> +#include <QFontMetrics> #include <algorithm> #include <taglib/tag.h> @@ -812,7 +813,7 @@ void PlayerWidget::doPopulateByFavorites(){ mView->setModel(mViewModel); mCurrentModel = mViewModel; mViewModel->clear(); - mViewModel->setHorizontalHeaderLabels(QStringList() << tr("Song") << tr("Album") << tr("Artist")); + mViewModel->setHorizontalHeaderLabels(QStringList() << tr("Song")); QStandardItem *root = mViewModel->invisibleRootItem(); emit message(QString(tr("Populating by Favorites... Please wait!"))); qApp->processEvents(); @@ -835,8 +836,6 @@ void PlayerWidget::populateByFavorites(QStandardItem *parent){ favQ1.exec(); while(favQ1.next()){ QStandardItem *curSong = new QStandardItem; - QStandardItem *curAlbum = new QStandardItem; - QStandardItem *curArtist = new QStandardItem; curSong->setEditable(false); curSong->setFont(QFont("courier")); favQ2.bindValue(":song", favQ1.value(2)); @@ -844,7 +843,10 @@ void PlayerWidget::populateByFavorites(QStandardItem *parent){ favQ2.bindValue(":artist", favQ1.value(0)); favQ2.exec(); favQ2.next(); - curSong->setText(favQ1.value(2).toString()); + QFontMetrics fm(QFont("courier")); + QString songTitle = fm.elidedText(favQ1.value(2).toString(), Qt::ElideRight, fm.width('X') * 28); + QString songText = QString("%1 - %2 - %3").arg(favQ1.value(0).toString(), -25).arg(songTitle, -30).arg(favQ1.value(1).toString()); + curSong->setText(songText); curSong->setIcon(songIcon); curSong->setData(Song, TypeRole); curSong->setData(favQ2.value(0), IdRole); @@ -854,17 +856,8 @@ void PlayerWidget::populateByFavorites(QStandardItem *parent){ curSong->setData(favQ1.value(2), TitleRole); curSong->setData(favQ1.value(1), AlbumRole); curSong->setData(favQ2.value(5), LengthRole); - curAlbum->setText(favQ1.value(1).toString()); - curAlbum->setFont(QFont("courier")); - curAlbum->setEditable(false); - curArtist->setText(favQ1.value(0).toString()); - curArtist->setFont(QFont("courier")); - curArtist->setEditable(false); - root->appendRow(QList<QStandardItem*>() << curSong << curAlbum << curArtist); + root->appendRow(QList<QStandardItem*>() << curSong); } - mView->resizeColumnToContents(2); - mView->resizeColumnToContents(1); - mView->resizeColumnToContents(0); mView->setSortingEnabled(true); mView->sortByColumn(0, Qt::AscendingOrder); } |