mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Allow shorter playlist column names if header size is too small.
Fixes issue 201.
This commit is contained in:
parent
4daae2249e
commit
5c6f9e625b
@ -1108,6 +1108,20 @@ QString Playlist::column_name(Column column) {
|
||||
return "";
|
||||
}
|
||||
|
||||
QString Playlist::abbreviated_column_name(Column column) {
|
||||
const QString& column_name = Playlist::column_name(column);
|
||||
switch (column) {
|
||||
case Column_Disc:
|
||||
case Column_PlayCount:
|
||||
case Column_SkipCount:
|
||||
case Column_Track:
|
||||
return QString("%1#").arg(column_name[0]);
|
||||
default:
|
||||
return column_name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void Playlist::sort(int column, Qt::SortOrder order) {
|
||||
if (ignore_sorting_)
|
||||
return;
|
||||
|
@ -147,6 +147,8 @@ class Playlist : public QAbstractListModel {
|
||||
PlaylistItemPtr a, PlaylistItemPtr b);
|
||||
|
||||
static QString column_name(Column column);
|
||||
static QString abbreviated_column_name(Column column);
|
||||
|
||||
static bool column_is_editable(Playlist::Column column);
|
||||
static bool set_column_value(Song& song, Column column, const QVariant& value);
|
||||
|
||||
|
@ -49,6 +49,22 @@ PlaylistProxyStyle::PlaylistProxyStyle(QStyle* base)
|
||||
void PlaylistProxyStyle::drawControl(
|
||||
ControlElement element, const QStyleOption* option, QPainter* painter,
|
||||
const QWidget* widget) const {
|
||||
if (element == CE_Header) {
|
||||
const QStyleOptionHeader* header_option = qstyleoption_cast<const QStyleOptionHeader*>(option);
|
||||
const QRect& rect = header_option->rect;
|
||||
const QString& text = header_option->text;
|
||||
const QFontMetrics& font_metrics = header_option->fontMetrics;
|
||||
|
||||
// spaces added to make transition less abrupt
|
||||
if (rect.width() < font_metrics.width(text + " ")) {
|
||||
const Playlist::Column column = static_cast<Playlist::Column>(header_option->section);
|
||||
QStyleOptionHeader new_option(*header_option);
|
||||
new_option.text = Playlist::abbreviated_column_name(column);
|
||||
QProxyStyle::drawControl(element, &new_option, painter, widget);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (element == CE_ItemViewItem)
|
||||
cleanlooks_->drawControl(element, option, painter, widget);
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user