Commit af441659 authored by Scott Wheeler's avatar Scott Wheeler

Moving closer to having stuff working in the tree view again...

svn path=/trunk/kdemultimedia/juk/; revision=231194
parent 17d053c6
......@@ -417,19 +417,23 @@ void PlaylistBox::slotSetViewMode(int index)
}
////////////////////////////////////////////////////////////////////////////////
// protected methods
// PlaylistBox::Item protected methods
////////////////////////////////////////////////////////////////////////////////
PlaylistBox::Item *PlaylistBox::Item::m_collectionItem = 0;
PlaylistBox::Item::Item(PlaylistBox *listBox, const char *icon, const QString &text, Playlist *l)
: QObject(listBox), KListViewItem(listBox, text),
m_list(l), m_text(text), m_iconName(icon), m_sortedFirst(false)
{
int iconSize = listBox->viewModeIndex() == 0 ? 32 : 16;
setPixmap(0, SmallIcon(icon, iconSize));
listBox->addName(text);
init();
}
if(l)
connect(l, SIGNAL(signalNameChanged(const QString &)), this, SLOT(slotSetName(const QString &)));
PlaylistBox::Item::Item(Item *parent, const char *icon, const QString &text, Playlist *l)
: QObject(parent->listView()), KListViewItem(parent, text),
m_list(l), m_text(text), m_iconName(icon), m_sortedFirst(false)
{
init();
}
PlaylistBox::Item::~Item()
......@@ -475,4 +479,21 @@ void PlaylistBox::Item::slotSetName(const QString &name)
}
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item private methods
////////////////////////////////////////////////////////////////////////////////
void PlaylistBox::Item::init()
{
int iconSize = static_cast<PlaylistBox *>(listView())->viewModeIndex() == 0 ? 32 : 16;
setPixmap(0, SmallIcon(m_iconName, iconSize));
static_cast<PlaylistBox *>(listView())->addName(m_text);
if(m_list)
connect(m_list, SIGNAL(signalNameChanged(const QString &)), this, SLOT(slotSetName(const QString &)));
if(m_list == CollectionList::instance())
m_collectionItem = this;
}
#include "playlistbox.moc"
......@@ -143,6 +143,7 @@ public:
protected:
Item(PlaylistBox *listBox, const char *icon, const QString &text, Playlist *l = 0);
Item(Item *parent, const char *icon, const QString &text, Playlist *l = 0);
Playlist *playlist() const { return m_list; }
PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
......@@ -156,14 +157,20 @@ protected:
virtual QString text(int column) const { return KListViewItem::text(column); }
static Item *collectionItem() { return m_collectionItem; }
protected slots:
void slotSetName(const QString &name);
private:
// setup() was already taken.
void init();
Playlist *m_list;
QString m_text;
const char *m_iconName;
bool m_sortedFirst;
static Item *m_collectionItem;
};
#endif
......@@ -16,6 +16,7 @@
***************************************************************************/
#include <kiconloader.h>
#include <kdebug.h>
#include <qpixmap.h>
#include <qpainter.h>
......@@ -128,15 +129,15 @@ CompactViewMode::~CompactViewMode()
}
void CompactViewMode::paintCell(PlaylistBox::Item *i,
void CompactViewMode::paintCell(PlaylistBox::Item *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align)
{
if(width < i->pixmap(column)->width())
return;
#if 0 // don't think this code is needed anymore
PlaylistBox::Item *item = static_cast<PlaylistBox::Item *>(i);
if(width < item->pixmap(column)->width())
return;
QFontMetrics fm = painter->fontMetrics();
QString line = item->text();
......@@ -153,6 +154,8 @@ void CompactViewMode::paintCell(PlaylistBox::Item *i,
line = "...";
}
item->KListViewItem::setText(column, line);
#endif
item->KListViewItem::paintCell(painter, colorGroup, column, width, align);
}
......@@ -180,24 +183,35 @@ void TreeViewMode::setShown(bool show)
{
if(show) {
updateIcons(16);
PlaylistBox::Item *collectionItem = PlaylistBox::Item::collectionItem();
if(!collectionItem)
kdDebug(65432) << "TreeViewMode::setShown() - the CollectionList isn't initialized yet." << endl;
if(m_categories.isEmpty()) {
m_categories.append(new PlaylistBox::Item(playlistBox(), "midi", i18n("Artists")));
m_categories.append(new PlaylistBox::Item(playlistBox(), "midi", i18n("Albums")));
if(collectionItem && m_categories.isEmpty()) {
PlaylistBox::Item *i;
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists"));
m_categories.insert("artists", i);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums"));
m_categories.insert("albums", i);
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setSortedFirst(true);
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
it.current()->setSortedFirst(true);
}
else {
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setVisible(true);
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
it.current()->setVisible(true);
}
}
else {
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setVisible(false);
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
it.current()->setVisible(false);
}
playlistBox()->setRootIsDecorated(show);
}
......@@ -21,6 +21,7 @@
#include <klocale.h>
#include <qstring.h>
#include <qdict.h>
#include "playlistbox.h"
......@@ -80,7 +81,7 @@ public:
virtual void setShown(bool shown);
private:
QValueList<PlaylistBox::Item *> m_categories;
QDict<PlaylistBox::Item> m_categories;
};
#endif
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