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