1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

More columns in the playlist

This commit is contained in:
David Sansome 2009-12-30 04:05:33 +00:00
parent 107e6210b7
commit 7749386aff
5 changed files with 88 additions and 10 deletions

2
TODO
View File

@ -6,10 +6,10 @@
- Edit tags in the playlist - Edit tags in the playlist
- Global shortcut keys - Global shortcut keys
- Make QSortFilterProxyModel on the library obey hasChildren() - Make QSortFilterProxyModel on the library obey hasChildren()
- More columns in playlist
Long-term: Long-term:
- iPod - iPod
- OSD
Windows: Windows:
- Playlist delegates - Playlist delegates

View File

@ -41,6 +41,15 @@ QVariant Playlist::headerData(int section, Qt::Orientation, int role) const {
case Column_Album: return "Album"; case Column_Album: return "Album";
case Column_Length: return "Length"; case Column_Length: return "Length";
case Column_Track: return "Track"; case Column_Track: return "Track";
case Column_Disc: return "Disc";
case Column_Year: return "Year";
case Column_Genre: return "Genre";
case Column_BPM: return "BPM";
case Column_Bitrate: return "Bit rate";
case Column_Samplerate: return "Sample rate";
case Column_Filename: return "File name";
case Column_Filesize: return "File size";
} }
return QVariant(); return QVariant();
@ -67,6 +76,15 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
case Column_Album: return song.album(); case Column_Album: return song.album();
case Column_Length: return song.length(); case Column_Length: return song.length();
case Column_Track: return song.track(); case Column_Track: return song.track();
case Column_Disc: return song.disc();
case Column_Year: return song.year();
case Column_Genre: return song.genre();
case Column_BPM: return song.bpm();
case Column_Bitrate: return song.bitrate();
case Column_Samplerate: return song.samplerate();
case Column_Filename: return song.filename();
case Column_Filesize: return song.filesize();
} }
} }

View File

@ -23,6 +23,15 @@ class Playlist : public QAbstractListModel {
Column_Album, Column_Album,
Column_Length, Column_Length,
Column_Track, Column_Track,
Column_Disc,
Column_Year,
Column_Genre,
Column_BPM,
Column_Bitrate,
Column_Samplerate,
Column_Filename,
Column_Filesize,
ColumnCount ColumnCount
}; };

View File

@ -24,6 +24,27 @@ PlaylistDelegateBase::PlaylistDelegateBase(QTreeView* view)
{ {
} }
QString PlaylistDelegateBase::displayText(const QVariant& value, const QLocale&) const {
switch (value.type()) {
case QVariant::Int: {
int v = value.toInt();
if (v <= 0)
return QString::null;
return QString::number(v);
}
case QVariant::Double: {
double v = value.toDouble();
if (v <= 0)
return QString::null;
return QString::number(v);
}
default:
return value.toString();
}
}
void PlaylistDelegateBase::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { void PlaylistDelegateBase::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
QStyledItemDelegate::paint(painter, Adjusted(option, index), index); QStyledItemDelegate::paint(painter, Adjusted(option, index), index);
@ -67,16 +88,10 @@ QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem
} }
LengthItemDelegate::LengthItemDelegate(QTreeView* view)
: PlaylistDelegateBase(view)
{
}
QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) const { QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) const {
bool ok = false; bool ok = false;
int seconds = value.toInt(&ok); int seconds = value.toInt(&ok);
QString ret = "-"; QString ret;
if (ok && seconds > 0) { if (ok && seconds > 0) {
int hours = seconds / (60*60); int hours = seconds / (60*60);
@ -92,6 +107,25 @@ QString LengthItemDelegate::displayText(const QVariant& value, const QLocale&) c
} }
QString SizeItemDelegate::displayText(const QVariant& value, const QLocale&) const {
bool ok = false;
int bytes = value.toInt(&ok);
QString ret;
if (ok && bytes > 0) {
if (bytes <= 1024)
ret.sprintf("%d bytes", bytes);
else if (bytes <= 1024*1024)
ret.sprintf("%.1f KB", float(bytes) / 1024);
else if (bytes <= 1024*1024*1024)
ret.sprintf("%.1f MB", float(bytes) / (1024*1024));
else
ret.sprintf("%.1f GB", float(bytes) / (1024*1024*1024));
}
return ret;
}
PlaylistView::PlaylistView(QWidget *parent) PlaylistView::PlaylistView(QWidget *parent)
: QTreeView(parent), : QTreeView(parent),
glow_enabled_(false), glow_enabled_(false),
@ -105,6 +139,7 @@ PlaylistView::PlaylistView(QWidget *parent)
{ {
setItemDelegate(new PlaylistDelegateBase(this)); setItemDelegate(new PlaylistDelegateBase(this));
setItemDelegateForColumn(Playlist::Column_Length, new LengthItemDelegate(this)); setItemDelegateForColumn(Playlist::Column_Length, new LengthItemDelegate(this));
setItemDelegateForColumn(Playlist::Column_Filesize, new SizeItemDelegate(this));
setHeader(new PlaylistHeader(Qt::Horizontal, this)); setHeader(new PlaylistHeader(Qt::Horizontal, this));
header()->setMovable(true); header()->setMovable(true);
@ -130,7 +165,16 @@ void PlaylistView::LoadGeometry() {
QSettings settings; QSettings settings;
settings.beginGroup(kSettingsGroup); settings.beginGroup(kSettingsGroup);
header()->restoreState(settings.value("state").toByteArray()); if (!header()->restoreState(settings.value("state").toByteArray())) {
header()->hideSection(Playlist::Column_Disc);
header()->hideSection(Playlist::Column_Year);
header()->hideSection(Playlist::Column_Genre);
header()->hideSection(Playlist::Column_BPM);
header()->hideSection(Playlist::Column_Bitrate);
header()->hideSection(Playlist::Column_Samplerate);
header()->hideSection(Playlist::Column_Filename);
header()->hideSection(Playlist::Column_Filesize);
}
} }
void PlaylistView::SaveGeometry() { void PlaylistView::SaveGeometry() {

View File

@ -10,6 +10,7 @@ class PlaylistDelegateBase : public QStyledItemDelegate {
public: public:
PlaylistDelegateBase(QTreeView* view); PlaylistDelegateBase(QTreeView* view);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QString displayText(const QVariant& value, const QLocale& locale) const;
QStyleOptionViewItemV4 Adjusted(const QStyleOptionViewItem& option, const QModelIndex& index) const; QStyleOptionViewItemV4 Adjusted(const QStyleOptionViewItem& option, const QModelIndex& index) const;
@ -19,7 +20,13 @@ class PlaylistDelegateBase : public QStyledItemDelegate {
class LengthItemDelegate : public PlaylistDelegateBase { class LengthItemDelegate : public PlaylistDelegateBase {
public: public:
LengthItemDelegate(QTreeView* view); LengthItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
QString displayText(const QVariant& value, const QLocale& locale) const;
};
class SizeItemDelegate : public PlaylistDelegateBase {
public:
SizeItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
QString displayText(const QVariant& value, const QLocale& locale) const; QString displayText(const QVariant& value, const QLocale& locale) const;
}; };