Commit 6a1d0ec4 authored by Michael Pyne's avatar Michael Pyne

Merge branch 'Applications/18.12'

parents bcf4f68b 468a5169
...@@ -77,12 +77,15 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget ...@@ -77,12 +77,15 @@ PlaylistBox::PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
setDropIndicatorShown(true); setDropIndicatorShown(true);
setColumnCount(2); // Use fake column for sorting
setColumnHidden(1, true);
setSortingEnabled(true);
sortByColumn(1, Qt::AscendingOrder);
header()->blockSignals(true); header()->blockSignals(true);
header()->hide(); header()->hide();
header()->blockSignals(false); header()->blockSignals(false);
sortByColumn(0);
viewport()->setAcceptDrops(true); viewport()->setAcceptDrops(true);
setDropIndicatorShown(true); setDropIndicatorShown(true);
setSelectionMode(QAbstractItemView::ExtendedSelection); setSelectionMode(QAbstractItemView::ExtendedSelection);
...@@ -648,7 +651,7 @@ PlaylistBox::Item *PlaylistBox::Item::m_collectionItem = 0; ...@@ -648,7 +651,7 @@ PlaylistBox::Item *PlaylistBox::Item::m_collectionItem = 0;
PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l) PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l)
: QObject(listBox), QTreeWidgetItem(listBox, QStringList(text)), : QObject(listBox), QTreeWidgetItem(listBox, QStringList(text)),
PlaylistObserver(l), PlaylistObserver(l),
m_playlist(l), m_text(text), m_iconName(icon), m_sortedFirst(false) m_playlist(l), m_iconName(icon), m_sortedFirst(false)
{ {
init(); init();
} }
...@@ -656,7 +659,7 @@ PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString ...@@ -656,7 +659,7 @@ PlaylistBox::Item::Item(PlaylistBox *listBox, const QString &icon, const QString
PlaylistBox::Item::Item(Item *parent, const QString &icon, const QString &text, Playlist *l) PlaylistBox::Item::Item(Item *parent, const QString &icon, const QString &text, Playlist *l)
: QObject(parent->listView()), QTreeWidgetItem(parent, QStringList(text)), : QObject(parent->listView()), QTreeWidgetItem(parent, QStringList(text)),
PlaylistObserver(l), PlaylistObserver(l),
m_playlist(l), m_text(text), m_iconName(icon), m_sortedFirst(false) m_playlist(l), m_iconName(icon), m_sortedFirst(false)
{ {
init(); init();
} }
...@@ -666,37 +669,13 @@ PlaylistBox::Item::~Item() ...@@ -666,37 +669,13 @@ PlaylistBox::Item::~Item()
} }
int PlaylistBox::Item::compare(QTreeWidgetItem *i, int col, bool) const // FIXME paintcell
{
Item *otherItem = static_cast<Item *>(i);
PlaylistBox *playlistBox = static_cast<PlaylistBox *>(treeWidget());
if(m_playlist == playlistBox->upcomingPlaylist() && otherItem->m_playlist != CollectionList::instance())
return -1;
if(otherItem->m_playlist == playlistBox->upcomingPlaylist() && m_playlist != CollectionList::instance())
return 1;
if(m_sortedFirst && !otherItem->m_sortedFirst)
return -1;
else if(otherItem->m_sortedFirst && !m_sortedFirst)
return 1;
return text(col).toLower().localeAwareCompare(i->text(col).toLower());
}
// FIXME paintcell
/*void PlaylistBox::Item::paintCell(QPainter *painter, const QColorGroup &colorGroup, int column, int width, int align) /*void PlaylistBox::Item::paintCell(QPainter *painter, const QColorGroup &colorGroup, int column, int width, int align)
{ {
PlaylistBox *playlistBox = static_cast<PlaylistBox *>(listView()); PlaylistBox *playlistBox = static_cast<PlaylistBox *>(listView());
playlistBox->viewMode()->paintCell(this, painter, colorGroup, column, width, align); playlistBox->viewMode()->paintCell(this, painter, colorGroup, column, width, align);
}*/ }*/
void PlaylistBox::Item::setText(int column, const QString &text)
{
m_text = text;
QTreeWidgetItem::setText(column, text);
}
void PlaylistBox::Item::setup() void PlaylistBox::Item::setup()
{ {
listView()->viewMode()->setupItem(this); listView()->viewMode()->setupItem(this);
...@@ -708,15 +687,13 @@ void PlaylistBox::Item::setup() ...@@ -708,15 +687,13 @@ void PlaylistBox::Item::setup()
void PlaylistBox::Item::slotSetName(const QString &name) void PlaylistBox::Item::slotSetName(const QString &name)
{ {
if(listView()) { setText(0, name); // Display name
setText(0, name); setText(1, sortTextFor(name));
setSelected(true); setSelected(true);
treeWidget()->sortItems(0, Qt::AscendingOrder); treeWidget()->scrollToItem(this);
treeWidget()->scrollToItem(treeWidget()->currentItem()); //FIXME viewmode
//FIXME viewmode //listView()->viewMode()->queueRefresh();
//listView()->viewMode()->queueRefresh();
}
} }
void PlaylistBox::Item::playingItemHasChanged() void PlaylistBox::Item::playingItemHasChanged()
...@@ -741,8 +718,9 @@ void PlaylistBox::Item::init() ...@@ -741,8 +718,9 @@ void PlaylistBox::Item::init()
list->setupItem(this); list->setupItem(this);
const QString itemText(text());
setIcon(0, QIcon::fromTheme(m_iconName)); setIcon(0, QIcon::fromTheme(m_iconName));
list->addNameToDict(m_text); list->addNameToDict(itemText);
if(m_playlist) { if(m_playlist) {
connect(m_playlist, SIGNAL(signalNameChanged(QString)), connect(m_playlist, SIGNAL(signalNameChanged(QString)),
...@@ -759,6 +737,22 @@ void PlaylistBox::Item::init() ...@@ -759,6 +737,22 @@ void PlaylistBox::Item::init()
if(m_playlist == list->historyPlaylist() || m_playlist == list->upcomingPlaylist()) if(m_playlist == list->historyPlaylist() || m_playlist == list->upcomingPlaylist())
m_sortedFirst = true; m_sortedFirst = true;
setText(1, sortTextFor(itemText));
}
QString PlaylistBox::Item::sortTextFor(const QString &name) const
{
// Collection List goes before everything, then
// playlists that 'sort first', then remainder of
// playlists.
const auto prefix
= (playlist() == CollectionList::instance())
? QStringLiteral("0")
: m_sortedFirst
? QStringLiteral("1")
: QStringLiteral("2");
return prefix + name;
} }
// vim: set et sw=4 tw=0 sta: // vim: set et sw=4 tw=0 sta:
...@@ -157,21 +157,19 @@ public: ...@@ -157,21 +157,19 @@ public:
virtual ~Item(); virtual ~Item();
protected: protected:
using QTreeWidgetItem::text;
Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l = 0); Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l = 0);
Item(Item *parent, const QString &icon, const QString &text, Playlist *l = 0); Item(Item *parent, const QString &icon, const QString &text, Playlist *l = 0);
Playlist *playlist() const { return m_playlist; } Playlist *playlist() const { return m_playlist; }
PlaylistBox *listView() const { return static_cast<PlaylistBox *>(QTreeWidgetItem::treeWidget()); } PlaylistBox *listView() const { return static_cast<PlaylistBox *>(QTreeWidgetItem::treeWidget()); }
QString iconName() const { return m_iconName; } QString iconName() const { return m_iconName; }
QString text() const { return m_text; } QString text() const { return QTreeWidgetItem::text(0); }
void setSortedFirst(bool first = true) { m_sortedFirst = first; } void setSortedFirst(bool first = true) { m_sortedFirst = first; }
virtual int compare(QTreeWidgetItem *i, int col, bool) const;
/*virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align); /*virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align);
virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}*/ virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}*/
virtual void setText(int column, const QString &text);
virtual QString text(int column) const { return QTreeWidgetItem::text(column); }
virtual void setup(); virtual void setup();
...@@ -194,9 +192,9 @@ protected slots: ...@@ -194,9 +192,9 @@ protected slots:
private: private:
// setup() was already taken. // setup() was already taken.
void init(); void init();
QString sortTextFor(const QString &name) const;
Playlist *m_playlist; Playlist *m_playlist;
QString m_text;
QString m_iconName; QString m_iconName;
bool m_sortedFirst; bool m_sortedFirst;
static Item *m_collectionItem; static Item *m_collectionItem;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment