Commit d55b23fd authored by Scott Wheeler's avatar Scott Wheeler

Moving closer to porting the tree view mode over to the new design. Also

fixed some bugs introduced in the last commit.

svn path=/trunk/kdemultimedia/juk/; revision=230533
parent b969c93a
......@@ -248,7 +248,7 @@ void JuK::openFile(const QStringList &files)
void JuK::setupLayout()
{
m_splitter = new PlaylistSplitter(this, m_restore, "playlistSplitter");
m_splitter = new PlaylistSplitter(this, "playlistSplitter");
setCentralWidget(m_splitter);
// playlist item activation connection
......
......@@ -195,7 +195,6 @@ private:
// actions
KToggleAction *m_showSearchAction;
KToggleAction *m_showEditorAction;
KToggleAction *m_restoreOnLoadAction;
SliderAction *m_sliderAction;
KToggleAction *m_randomPlayAction;
KToggleAction *m_toggleSystemTrayAction;
......@@ -213,7 +212,6 @@ private:
bool m_trackPositionDragging;
bool m_noSeek;
bool m_restore;
bool m_showSplash;
bool m_shuttingDown;
bool m_muted;
......
......@@ -50,7 +50,7 @@ public:
static KCmdLineOptions options[] =
{
#ifndef NO_DEBUG
{ "restore", I18N_NOOP("Restore playlists. Use --norestore for debugging."), 0 },
{ "norestore", I18N_NOOP("Restore playlists. Use --norestore for debugging."), 0 },
#endif
{ "+[file(s)]", I18N_NOOP("File(s) to open"), 0 },
{ 0, 0, 0 }
......
......@@ -30,12 +30,14 @@
#include "playlistbox.h"
#include "playlistsplitter.h"
#include "viewmode.h"
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListView(parent, name),
PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) :
KListView(parent, name),
m_splitter(parent),
m_updatePlaylistStack(true),
m_viewModeIndex(0),
......@@ -80,12 +82,11 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListView
m_viewModes.append(new CompactViewMode(this));
m_viewModes.append(new TreeViewMode(this));
m_viewModes.setAutoDelete(true);
QStringList modeNames;
for(ViewMode *view = m_viewModes.first(); view; view = m_viewModes.next())
modeNames.append(view->name());
QValueListIterator<ViewMode *> it = m_viewModes.begin();
for(; it != m_viewModes.end(); ++it)
modeNames.append((*it)->name());
m_viewModeAction->setItems(modeNames);
m_viewModeAction->setCurrentItem(m_viewModeIndex);
......@@ -106,9 +107,13 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListView
PlaylistBox::~PlaylistBox()
{
saveConfig();
QValueListIterator<ViewMode *> it = m_viewModes.begin();
for(; it != m_viewModes.end(); ++it)
delete(*it);
}
void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise)
void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise, bool sortedFirst)
{
if(!playlist)
return;
......@@ -120,6 +125,7 @@ void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise)
setSingleItem(i);
ensureCurrentVisible();
}
i->setSortedFirst(sortedFirst);
}
void PlaylistBox::raise(Playlist *playlist)
......@@ -142,7 +148,7 @@ PlaylistList PlaylistBox::playlists()
for(QListViewItemIterator it(this); it.current(); ++it) {
Item *i = static_cast<Item *>(*it);
if(i->playlist() != CollectionList::instance())
if(i->playlist() && i->playlist() != CollectionList::instance())
l.append(i->playlist());
}
......@@ -382,8 +388,10 @@ void PlaylistBox::slotPlaylistChanged()
return;
QValueList<Playlist *> playlists;
for(QValueList<Item *>::iterator i = items.begin(); i != items.end(); ++i)
for(QValueList<Item *>::iterator i = items.begin(); i != items.end(); ++i) {
if((*i)->playlist())
playlists.append((*i)->playlist());
}
emit signalCurrentChanged(playlists);
}
......@@ -414,12 +422,13 @@ void PlaylistBox::slotSetViewMode(int index)
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_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);
if(l)
connect(l, SIGNAL(signalNameChanged(const QString &)), this, SLOT(slotSetName(const QString &)));
}
......@@ -430,9 +439,11 @@ PlaylistBox::Item::~Item()
int PlaylistBox::Item::compare(QListViewItem *i, int col, bool) const
{
if(playlist() == CollectionList::instance())
Item *otherItem = static_cast<Item *>(i);
if(m_sortedFirst && !otherItem->m_sortedFirst)
return -1;
else if(static_cast<Item *>(i)->playlist() == CollectionList::instance())
else if(otherItem->m_sortedFirst && !m_sortedFirst)
return 1;
return text(col).lower().localeAwareCompare(i->text(col).lower());
......
......@@ -25,10 +25,10 @@
#include <qmap.h>
#include "playlist.h"
#include "viewmode.h"
class PlaylistItem;
class PlaylistSplitter;
class ViewMode;
class KPopupMenu;
class KSelectAction;
......@@ -46,7 +46,8 @@ public:
PlaylistBox(PlaylistSplitter *parent = 0, const char *name = 0);
virtual ~PlaylistBox();
void createItem(Playlist *playlist, const char *icon = 0, bool raise = false);
void createItem(Playlist *playlist, const char *icon = 0,
bool raise = false, bool sortedFirst = false);
void raise(Playlist *playlist);
QStringList names() const { return m_names; }
......@@ -61,7 +62,7 @@ public:
bool hasSelection() const { return m_hasSelection; }
ViewMode *viewMode() { return m_viewModes.at(m_viewModeIndex); }
ViewMode *viewMode() { return m_viewModes[m_viewModeIndex]; }
int viewModeIndex() const { return m_viewModeIndex; }
class Item;
......@@ -117,7 +118,7 @@ private:
bool m_updatePlaylistStack;
QPtrDict<Item> m_playlistDict;
int m_viewModeIndex;
QPtrList<ViewMode> m_viewModes;
QValueList<ViewMode *> m_viewModes;
KSelectAction *m_viewModeAction;
bool m_hasSelection;
};
......@@ -129,6 +130,7 @@ class PlaylistBox::Item : public QObject, public KListViewItem
friend class PlaylistBox;
friend class ViewMode;
friend class CompactViewMode;
friend class TreeViewMode;
Q_OBJECT
......@@ -146,6 +148,7 @@ protected:
PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
const char *iconName() const { return m_iconName; }
QString text() const { return m_text; }
void setSortedFirst(bool first) { m_sortedFirst = first; }
virtual int compare(QListViewItem *i, int col, bool) const;
virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align);
......@@ -160,6 +163,7 @@ private:
Playlist *m_list;
QString m_text;
const char *m_iconName;
bool m_sortedFirst;
};
#endif
......@@ -46,9 +46,9 @@ void processEvents()
// public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistSplitter::PlaylistSplitter(QWidget *parent, bool restore, const char *name) :
PlaylistSplitter::PlaylistSplitter(QWidget *parent, const char *name) :
QSplitter(Qt::Horizontal, parent, name),
m_playingItem(0), m_searchWidget(0), m_dynamicList(0), m_restore(restore),
m_playingItem(0), m_searchWidget(0), m_dynamicList(0),
m_nextPlaylistItem(0)
{
#ifndef NO_DEBUG
......@@ -89,8 +89,7 @@ QString PlaylistSplitter::uniquePlaylistName(const QString &startingWith, bool u
return startingWith + " (" + QString::number(playlistNumber) + ")";
}
else
{
else {
while(names.contains(startingWith + ' ' + QString::number(playlistNumber)) != 0)
playlistNumber++;
......@@ -424,7 +423,7 @@ void PlaylistSplitter::setupLayout()
CollectionList::initialize(m_playlistStack, m_restore);
m_collection = CollectionList::instance();
setupPlaylist(m_collection, true, "folder_sound");
setupPlaylist(m_collection, true, "folder_sound", true);
connect(m_collection, SIGNAL(signalCollectionChanged()), m_editor, SLOT(slotUpdateCollection()));
connect(m_collection, SIGNAL(signalRequestPlaylistCreation(const PlaylistItemList &)),
this, SLOT(slotCreatePlaylist(const PlaylistItemList &)));
......@@ -552,7 +551,7 @@ void PlaylistSplitter::addImpl(const QString &file, Playlist *list)
}
}
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon, bool sortedFirst)
{
connect(p, SIGNAL(signalSelectionChanged(const PlaylistItemList &)),
m_editor, SLOT(slotSetItems(const PlaylistItemList &)));
......@@ -568,7 +567,7 @@ void PlaylistSplitter::setupPlaylist(Playlist *p, bool raise, const char *icon)
this, SLOT(slotSetNextItem(PlaylistItem *)));
if(icon)
m_playlistBox->createItem(p, icon, raise);
m_playlistBox->createItem(p, icon, raise, sortedFirst);
if(raise) {
PlaylistList l;
......
......@@ -48,7 +48,7 @@ class PlaylistSplitter : public QSplitter
Q_OBJECT
public:
PlaylistSplitter(QWidget *parent, bool restore = true, const char *name = 0);
PlaylistSplitter(QWidget *parent, const char *name = 0);
virtual ~PlaylistSplitter();
......@@ -253,7 +253,7 @@ private:
/**
* If NULL is passed for the icon, no entry is created in the PlaylistBox
*/
void setupPlaylist(Playlist *p, bool raise = false, const char *icon = "midi");
void setupPlaylist(Playlist *p, bool raise = false, const char *icon = "midi", bool sortedFirst = false);
/**
* Open the playlist (m3u file or simiar) at \a file.
......
......@@ -39,7 +39,7 @@ ViewMode::~ViewMode()
}
void ViewMode::paintCell(QListViewItem *i,
void ViewMode::paintCell(PlaylistBox::Item *i,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align)
......@@ -128,7 +128,7 @@ CompactViewMode::~CompactViewMode()
}
void CompactViewMode::paintCell(QListViewItem *i,
void CompactViewMode::paintCell(PlaylistBox::Item *i,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align)
......@@ -158,7 +158,6 @@ void CompactViewMode::paintCell(QListViewItem *i,
void CompactViewMode::setShown(bool shown)
{
// m_visible = shown;
if(shown)
updateIcons(16);
}
......@@ -179,5 +178,26 @@ TreeViewMode::~TreeViewMode()
void TreeViewMode::setShown(bool show)
{
CompactViewMode::setShown(show);
if(show) {
updateIcons(16);
if(m_categories.isEmpty()) {
m_categories.append(new PlaylistBox::Item(playlistBox(), "midi", i18n("Artists")));
m_categories.append(new PlaylistBox::Item(playlistBox(), "midi", i18n("Albums")));
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setSortedFirst(true);
}
else {
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setVisible(true);
}
}
else {
QValueListIterator<PlaylistBox::Item *> it = m_categories.begin();
for(; it != m_categories.end(); ++it)
(*it)->setVisible(false);
}
}
......@@ -22,11 +22,10 @@
#include <qstring.h>
#include "playlistbox.h"
class QPainter;
class QColorGroup;
class QListViewItem;
class PlaylistBox;
class ViewMode
{
......@@ -37,7 +36,7 @@ public:
virtual QString name() const { return i18n("Default"); }
virtual void setShown(bool shown);
virtual void paintCell(QListViewItem *item,
virtual void paintCell(PlaylistBox::Item *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
......@@ -63,7 +62,7 @@ public:
virtual QString name() const { return i18n("Compact"); }
virtual void setShown(bool shown);
virtual void paintCell(QListViewItem *item,
virtual void paintCell(PlaylistBox::Item *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
......@@ -79,6 +78,9 @@ public:
virtual QString name() const { return i18n("Tree"); }
virtual void setShown(bool shown);
private:
QValueList<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