From 387a22f9f84fd673febfbdf4f8ffccd6556e11ae Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 31 Dec 2017 12:48:42 +0100 Subject: 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! --- playerwidget.cpp | 21 +++++++-------------- 1 file 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 #include #include +#include #include #include @@ -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() << curSong << curAlbum << curArtist); + root->appendRow(QList() << curSong); } - mView->resizeColumnToContents(2); - mView->resizeColumnToContents(1); - mView->resizeColumnToContents(0); mView->setSortingEnabled(true); mView->sortByColumn(0, Qt::AscendingOrder); } -- cgit v1.2.3-70-g09d2