Add rating and play count columns to the playlist

This commit is contained in:
David Sansome 2010-10-17 17:10:19 +00:00
parent f5750bc348
commit dd4afe9b06
43 changed files with 291 additions and 1 deletions

View File

@ -275,5 +275,8 @@
<file>providers/cdbaby.png</file>
<file>providers/echonest.png</file>
<file>lumberjacksong.txt</file>
<file>icons/22x22/rating.png</file>
<file>icons/32x32/rating.png</file>
<file>icons/48x48/rating.png</file>
</qresource>
</RCC>

BIN
data/icons/22x22/rating.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/icons/32x32/rating.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
data/icons/48x48/rating.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -202,6 +202,9 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
case Column_AlbumArtist: return song.albumartist();
case Column_Composer: return song.composer();
case Column_Rating: return song.rating();
case Column_PlayCount:return song.playcount();
case Column_BPM: return song.bpm();
case Column_Bitrate: return song.bitrate();
case Column_Samplerate: return song.samplerate();
@ -224,6 +227,7 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
case Column_Bitrate:
case Column_Samplerate:
case Column_Filesize:
case Column_PlayCount:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default:
@ -792,6 +796,9 @@ bool Playlist::CompareItems(int column, Qt::SortOrder order,
case Column_AlbumArtist: strcmp(albumartist);
case Column_Composer: strcmp(composer);
case Column_Rating: cmp(rating);
case Column_PlayCount: cmp(playcount);
case Column_BPM: cmp(bpm);
case Column_Bitrate: cmp(bitrate);
case Column_Samplerate: cmp(samplerate);
@ -822,6 +829,9 @@ QString Playlist::column_name(Column column) {
case Column_AlbumArtist: return tr("Album artist");
case Column_Composer: return tr("Composer");
case Column_Rating: return tr("Rating");
case Column_PlayCount:return tr("Play count");
case Column_BPM: return tr("BPM");
case Column_Bitrate: return tr("Bit rate");
case Column_Samplerate: return tr("Sample rate");

View File

@ -58,6 +58,7 @@ class Playlist : public QAbstractListModel {
QObject* parent = 0);
~Playlist();
// Always add new columns to the end of this enum - the values are persisted
enum Column {
Column_Title = 0,
Column_Artist,
@ -80,6 +81,9 @@ class Playlist : public QAbstractListModel {
Column_DateCreated,
Column_DateModified,
Column_Rating,
Column_PlayCount,
ColumnCount
};

View File

@ -19,6 +19,7 @@
#include "core/utilities.h"
#include "library/librarybackend.h"
#include "widgets/trackslider.h"
#include "ui/iconloader.h"
#include <QDateTime>
#include <QDir>
@ -39,7 +40,9 @@ const QRgb QueuedItemDelegate::kQueueBoxGradientColor2 = qRgb(77, 121, 200);
const int QueuedItemDelegate::kQueueOpacitySteps = 10;
const float QueuedItemDelegate::kQueueOpacityLowerBound = 0.4;
const int PlaylistDelegateBase::kMinHeight = 19;
const int PlaylistDelegateBase::kMinHeight = 19;
const int RatingItemDelegate::kStarCount = 5; // There are 4 stars
QueuedItemDelegate::QueuedItemDelegate(QObject *parent, int indicator_column)
: QStyledItemDelegate(parent),
@ -275,6 +278,56 @@ QWidget* TextItemDelegate::createEditor(
return new QLineEdit(parent);
}
RatingItemDelegate::RatingItemDelegate(QObject* parent)
: PlaylistDelegateBase(parent),
star_(IconLoader::Load("rating"))
{
}
void RatingItemDelegate::paint(
QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
const double rating = index.data().toDouble() * kStarCount;
const int star_size = option.rect.height();
const int width = star_size * kStarCount;
const QPixmap empty(star_.pixmap(star_size, QIcon::Disabled));
const QPixmap full(star_.pixmap(star_size));
int x = option.rect.x() + (option.rect.width() - width) / 2;
for (int i=0 ; i<kStarCount ; ++i, x+=star_size) {
const QRect rect(x, option.rect.y(), star_size, star_size);
if (rating - 0.25 <= i) {
// Totally empty
painter->drawPixmap(rect, empty);
} else if (rating - 0.75 <= i) {
// Half full
const QRect target_left(rect.x(), rect.y(), rect.width()/2, rect.height());
const QRect target_right(rect.x() + rect.width()/2, rect.y(), rect.width()/2, rect.height());
const QRect source_left(0, 0, empty.width()/2, empty.height());
const QRect source_right(empty.width()/2, 0, empty.width()/2, empty.height());
painter->drawPixmap(target_left, full, source_left);
painter->drawPixmap(target_right, empty, source_right);
} else {
// Totally full
painter->drawPixmap(rect, full);
}
}
}
QSize RatingItemDelegate::sizeHint(
const QStyleOptionViewItem& option, const QModelIndex& index) const {
QSize size = PlaylistDelegateBase::sizeHint(option, index);
size.setWidth(size.height() * kStarCount);
return size;
}
QString RatingItemDelegate::displayText(
const QVariant& value, const QLocale&) const {
// Round to the nearest .5
const float rating = float(int(value.toDouble() * kStarCount * 2 + 0.5)) / 2;
return QString::number(rating, 'f', 1);
}
TagCompletionModel::TagCompletionModel(LibraryBackend* backend, Playlist::Column column) :
QStringListModel() {

View File

@ -98,6 +98,19 @@ class TextItemDelegate : public PlaylistDelegateBase {
const QModelIndex& index) const;
};
class RatingItemDelegate : public PlaylistDelegateBase {
public:
RatingItemDelegate(QObject* parent);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
QString displayText(const QVariant& value, const QLocale& locale) const;
static const int kStarCount;
private:
QIcon star_;
};
class TagCompletionModel : public QStringListModel {
public:
TagCompletionModel(LibraryBackend* backend, Playlist::Column column);

View File

@ -123,6 +123,7 @@ void PlaylistView::SetItemDelegates(LibraryBackend* backend) {
setItemDelegateForColumn(Playlist::Column_Samplerate, new PlaylistDelegateBase(this, ("Hz")));
setItemDelegateForColumn(Playlist::Column_Bitrate, new PlaylistDelegateBase(this, tr("kbps")));
setItemDelegateForColumn(Playlist::Column_Filename, new NativeSeparatorsDelegate(this));
setItemDelegateForColumn(Playlist::Column_Rating, new RatingItemDelegate(this));
}
void PlaylistView::SetPlaylist(Playlist *playlist) {
@ -170,6 +171,8 @@ void PlaylistView::LoadGeometry() {
header_->HideSection(Playlist::Column_DateModified);
header_->HideSection(Playlist::Column_AlbumArtist);
header_->HideSection(Playlist::Column_Composer);
header_->HideSection(Playlist::Column_PlayCount);
header_->HideSection(Playlist::Column_Rating);
header_->moveSection(header_->visualIndex(Playlist::Column_Track), 0);
setting_initial_header_layout_ = true;

View File

@ -1370,6 +1370,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1479,6 +1482,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1371,6 +1371,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1480,6 +1483,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1400,6 +1400,9 @@ msgstr "Reprodueix Artista o Etiqueta"
msgid "Play artist radio..."
msgstr "Reprodueix la radio de l'artista"
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1509,6 +1512,9 @@ msgstr "Pluja"
msgid "Random visualization"
msgstr "Visualització al.leatòria"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Realment vol cancel·lar?"

View File

@ -1375,6 +1375,9 @@ msgstr "Přehrát umělce nebo značku"
msgid "Play artist radio..."
msgstr "Přehávat umělcovo rádio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1484,6 +1487,9 @@ msgstr "Déšť"
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1376,6 +1376,9 @@ msgstr "Spil kunstner eller mærke"
msgid "Play artist radio..."
msgstr "Spil kunstnerradio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1485,6 +1488,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1401,6 +1401,9 @@ msgstr "Spiele Künstler oder Stichwort"
msgid "Play artist radio..."
msgstr "Spiele Interpreten-Radio...."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1510,6 +1513,9 @@ msgstr "Regen"
msgid "Random visualization"
msgstr "Zufällige Visualisierung"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Wirklich abbrechen?"

View File

@ -1404,6 +1404,9 @@ msgstr "Αναπαραγωγή καλλιτέχνη ή ετικέτας"
msgid "Play artist radio..."
msgstr "Αναπαραγωγή ραδιοφώνου καλλιτέχνη..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1513,6 +1516,9 @@ msgstr "Βροχή"
msgid "Random visualization"
msgstr "Τυχαίο οπτικό εφέ"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Ακύρωση στ' αλήθεια;"

View File

@ -1375,6 +1375,9 @@ msgstr "Play Artist or Tag"
msgid "Play artist radio..."
msgstr "Play artist radio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1484,6 +1487,9 @@ msgstr ""
msgid "Random visualization"
msgstr "Random visualisation"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1372,6 +1372,9 @@ msgstr "Play Artist or Tag"
msgid "Play artist radio..."
msgstr "Play artist radio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1481,6 +1484,9 @@ msgstr ""
msgid "Random visualization"
msgstr "Random visualisation"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1405,6 +1405,9 @@ msgstr "Reproducir Artista o Etiqueta"
msgid "Play artist radio..."
msgstr "Reproducir radio del artista..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1514,6 +1517,9 @@ msgstr "Lluvia"
msgid "Random visualization"
msgstr "Visualización al azar"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "¿Desea cancelar realmente?"

View File

@ -1373,6 +1373,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1482,6 +1485,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1409,6 +1409,9 @@ msgstr "Écouter une radio par artiste ou par tag"
msgid "Play artist radio..."
msgstr "Écouter la radio d'un artiste..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1518,6 +1521,9 @@ msgstr "Pluie"
msgid "Random visualization"
msgstr "Visualisation aléatoire"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Êtes-vous sûr de vouloir annuler ?"

View File

@ -1377,6 +1377,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr "Reproduzir un artista na rádio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1486,6 +1489,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1398,6 +1398,9 @@ msgstr "Előadó vagy Címke lejátszása"
msgid "Play artist radio..."
msgstr "Előadó rádió lejátszása"
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1507,6 +1510,9 @@ msgstr "Eső"
msgid "Random visualization"
msgstr "Véletlenszerű megjelenítés"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Tényleg mégse?"

View File

@ -1409,6 +1409,9 @@ msgstr "Riproduci artista o tag"
msgid "Play artist radio..."
msgstr "Riproduci radio dell'artista..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1518,6 +1521,9 @@ msgstr "Pioggia"
msgid "Random visualization"
msgstr "Visualizzazione casuale"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Vuo davvero annullare?"

View File

@ -1372,6 +1372,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1481,6 +1484,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1371,6 +1371,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1480,6 +1483,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1374,6 +1374,9 @@ msgstr "Spill artist eller merkelapp"
msgid "Play artist radio..."
msgstr "Spill artistradio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1483,6 +1486,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1404,6 +1404,9 @@ msgstr "Artiest of tag afspelen"
msgid "Play artist radio..."
msgstr "Artiestradio afspelen"
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1513,6 +1516,9 @@ msgstr "Regen"
msgid "Random visualization"
msgstr "Willekeurige visualisatie"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Werkelijk annuleren?"

View File

@ -1370,6 +1370,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1479,6 +1482,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1400,6 +1400,9 @@ msgstr "Odtwarzaj Wykonawcę lub Znacznik"
msgid "Play artist radio..."
msgstr "Odtwarzaj radio wykonawcy..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1509,6 +1512,9 @@ msgstr "Deszcz"
msgid "Random visualization"
msgstr "Losowa wizualizacja"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Na pewno anulować?"

View File

@ -1401,6 +1401,9 @@ msgstr "Reproduzir artista ou etiqueta"
msgid "Play artist radio..."
msgstr "Reproduzir rádio do artista..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1510,6 +1513,9 @@ msgstr "Chuva"
msgid "Random visualization"
msgstr "Visualização aleatória"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Realmente cancelar?"

View File

@ -1389,6 +1389,9 @@ msgstr "Reproduzir Artista ou Marcador"
msgid "Play artist radio..."
msgstr "Reproduzir rádio do artista..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1498,6 +1501,9 @@ msgstr "Chuva"
msgid "Random visualization"
msgstr "Visualização aleatória"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Deseja realmente cancelar?"

View File

@ -1371,6 +1371,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1480,6 +1483,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1393,6 +1393,9 @@ msgstr "Проиграть исполнителя или тег"
msgid "Play artist radio..."
msgstr "Проиграть радио артиста..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1502,6 +1505,9 @@ msgstr "Дождь"
msgid "Random visualization"
msgstr "Случайная визуализация"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Действительно отменить?"

View File

@ -1394,6 +1394,9 @@ msgstr "Hrať interpréta alebo tag"
msgid "Play artist radio..."
msgstr "Hrať rádio interpréta..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1503,6 +1506,9 @@ msgstr "Dážď"
msgid "Random visualization"
msgstr "Náhodná vizualizácia"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Naozaj zrušiť?"

View File

@ -1394,6 +1394,9 @@ msgstr "Predvajaj izvajalca ali oznako"
msgid "Play artist radio..."
msgstr "Predvajaj radio izvajalca ..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1503,6 +1506,9 @@ msgstr "Dež"
msgid "Random visualization"
msgstr "Naključno predočenje"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Ali naj bo dejanje resnično preklicano?"

View File

@ -1376,6 +1376,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1485,6 +1488,9 @@ msgstr "Киша"
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Заиста одустајете?"

View File

@ -1380,6 +1380,9 @@ msgstr "Spela upp artist eller tagg"
msgid "Play artist radio..."
msgstr "Spela upp artistradio..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1489,6 +1492,9 @@ msgstr "Regn"
msgid "Random visualization"
msgstr "Slumpmässig visualisering"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Verkligen avbryta?"

View File

@ -1397,6 +1397,9 @@ msgstr "Sanatçı veya Etiket Çal"
msgid "Play artist radio..."
msgstr "Sanatçı radyosu çal..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1506,6 +1509,9 @@ msgstr "Yağmur"
msgid "Random visualization"
msgstr "Rastgele görseller"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Gerçekten iptal edeyim mi?"

View File

@ -1361,6 +1361,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1470,6 +1473,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1394,6 +1394,9 @@ msgstr "Відтворити «Виконавця» або «Позначку»"
msgid "Play artist radio..."
msgstr "Відтворити радіо виконавця..."
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1503,6 +1506,9 @@ msgstr "Дощ"
msgid "Random visualization"
msgstr "Випадкова візуалізація"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "Дійсно скасувати?"

View File

@ -1370,6 +1370,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1479,6 +1482,9 @@ msgstr ""
msgid "Random visualization"
msgstr ""
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr ""

View File

@ -1376,6 +1376,9 @@ msgstr ""
msgid "Play artist radio..."
msgstr ""
msgid "Play count"
msgstr ""
msgid "Play custom radio..."
msgstr ""
@ -1485,6 +1488,9 @@ msgstr "下雨"
msgid "Random visualization"
msgstr "隨機視覺化"
msgid "Rating"
msgstr ""
msgid "Really cancel?"
msgstr "真的要取消?"