Commit e1d4aa77 authored by Scott Wheeler's avatar Scott Wheeler

Ok, finally got a desgin in place that I like for this tree view search

playlist thing-a-ma-bob.  There are still some parts left to implement and
a few bugs to work out, but it's relatively fast, clean and stable (note the
"relatively").

svn path=/trunk/kdemultimedia/juk/; revision=231901
parent 355d3f51
......@@ -31,6 +31,7 @@
#include "playlistbox.h"
#include "playlistsplitter.h"
#include "viewmode.h"
#include "searchplaylist.h"
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox public methods
......@@ -107,10 +108,6 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const QString &name) :
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, bool sortedFirst)
......@@ -119,7 +116,8 @@ void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise, b
return;
Item *i = new Item(this, icon, playlist->name(), playlist);
m_playlistDict.insert(playlist, i);
setupItem(i, playlist);
if(raise) {
setSingleItem(i);
......@@ -128,6 +126,12 @@ void PlaylistBox::createItem(Playlist *playlist, const char *icon, bool raise, b
i->setSortedFirst(sortedFirst);
}
void PlaylistBox::createSearchItem(SearchPlaylist *playlist, const QString &searchCategory)
{
Item *i = m_viewModes[m_viewModeIndex]->createSearchItem(this, playlist, searchCategory);
setupItem(i, playlist);
}
void PlaylistBox::raise(Playlist *playlist)
{
if(!playlist)
......@@ -417,6 +421,11 @@ void PlaylistBox::slotSetViewMode(int index)
viewMode()->setShown(true);
}
void PlaylistBox::setupItem(Item *item, Playlist *playlist)
{
m_playlistDict.insert(playlist, item);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item protected methods
////////////////////////////////////////////////////////////////////////////////
......
......@@ -29,6 +29,8 @@
class PlaylistItem;
class PlaylistSplitter;
class ViewMode;
class PlaylistSearch;
class SearchPlaylist;
class KPopupMenu;
class KSelectAction;
......@@ -49,6 +51,8 @@ public:
void createItem(Playlist *playlist, const char *icon = 0,
bool raise = false, bool sortedFirst = false);
void createSearchItem(SearchPlaylist *playlist, const QString &searchCategory);
void raise(Playlist *playlist);
QStringList names() const { return m_names; }
......@@ -80,6 +84,9 @@ public slots:
signals:
void signalCurrentChanged(const PlaylistList &);
void signalDoubleClicked();
void signalCreateSearchList(const PlaylistSearch &search,
const QString &searchCategory,
const QString &name);
private:
void readConfig();
......@@ -106,6 +113,8 @@ private:
void setSingleItem(QListViewItem *item);
void ensureCurrentVisible() { ensureItemVisible(currentItem()); }
void setupItem(Item *item, Playlist *playlist);
private slots:
/**
* Catches QListBox::currentChanged(QListBoxItem *), does a cast and then re-emits
......
......@@ -28,6 +28,7 @@
#include "directorylist.h"
#include "playlistsearch.h"
#include "dynamicplaylist.h"
#include "searchplaylist.h"
#include "mediafiles.h"
////////////////////////////////////////////////////////////////////////////////
......@@ -395,6 +396,9 @@ void PlaylistSplitter::setupLayout()
m_playlistBox = new PlaylistBox(this, "playlistBox");
connect(m_playlistBox, SIGNAL(signalCreateSearchList(const PlaylistSearch &, const QString &, const QString &)),
this, SLOT(slotCreateSearchList(const PlaylistSearch &, const QString &, const QString &)));
// Create a splitter to go between the playlists and the editor.
QSplitter *editorSplitter = new QSplitter(Qt::Vertical, this, "editorSplitter");
......@@ -708,6 +712,15 @@ void PlaylistSplitter::slotVisibleColumnsChanged()
slotShowSearchResults();
}
void PlaylistSplitter::slotCreateSearchList(const PlaylistSearch &search,
const QString &searchCategory,
const QString &name)
{
SearchPlaylist *p = new SearchPlaylist(search, m_playlistStack, name);
m_playlistBox->createSearchItem(p, searchCategory);
setupPlaylist(p, false, 0);
}
#include "playlistsplitter.moc"
// vim:ts=8
......@@ -300,6 +300,8 @@ private slots:
void slotCreatePlaylist(const PlaylistItemList &items);
void slotShowSearchResults();
void slotVisibleColumnsChanged();
void slotCreateSearchList(const PlaylistSearch &search, const QString &searchCategory,
const QString &name);
private:
PlaylistItem *m_playingItem;
......
......@@ -30,11 +30,12 @@
// ViewMode
////////////////////////////////////////////////////////////////////////////////
ViewMode::ViewMode(PlaylistBox *b) :
ViewMode::ViewMode(PlaylistBox *b) : QObject(b),
m_playlistBox(b),
m_visible(false)
{
connect(this, SIGNAL(signalCreateSearchList(const PlaylistSearch &, const QString &, const QString &)),
b, SIGNAL(signalCreateSearchList(const PlaylistSearch &, const QString &, const QString &)));
}
ViewMode::~ViewMode()
......@@ -102,6 +103,12 @@ void ViewMode::paintCell(PlaylistBox::Item *i,
item->setHeight(height);
}
PlaylistBox::Item *ViewMode::createSearchItem(PlaylistBox *box, SearchPlaylist *playlist,
const QString &)
{
return new PlaylistBox::Item(box, "midi", playlist->name(), playlist);
}
void ViewMode::setShown(bool shown)
{
m_visible = shown;
......@@ -193,55 +200,64 @@ void TreeViewMode::setShown(bool show)
if(!collectionItem)
kdDebug(65432) << "TreeViewMode::setShown() - the CollectionList isn't initialized yet." << endl;
if(collectionItem && m_categories.isEmpty()) {
if(collectionItem && m_searchCategories.isEmpty()) {
PlaylistBox::Item *i;
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists"));
m_categories.insert("artists", i);
setupCategory(i, CollectionList::instance()->viewModeItems()["artists"].values());
m_searchCategories.insert("artists", i);
setupCategory("artists", CollectionList::instance()->viewModeItems()["artists"].values(), 1);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums"));
m_categories.insert("albums", i);
setupCategory(i, CollectionList::instance()->viewModeItems()["albums"].values());
m_searchCategories.insert("albums", i);
setupCategory("albums", CollectionList::instance()->viewModeItems()["albums"].values(), 2);
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setSortedFirst(true);
}
else {
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setVisible(true);
}
}
else {
for(QDictIterator<PlaylistBox::Item> it(m_categories); it.current(); ++it)
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setVisible(false);
}
}
void TreeViewMode::setupCategory(PlaylistBox::Item *parent, const QStringList &members) const
PlaylistBox::Item *TreeViewMode::createSearchItem(PlaylistBox *, SearchPlaylist *playlist,
const QString &searchCategory)
{
return new PlaylistBox::Item(m_searchCategories[searchCategory], "midi", playlist->name(), playlist);
}
void TreeViewMode::setupCategory(const QString &searchCategory, const QStringList &members, int column)
{
CollectionList *collection = CollectionList::instance();
QValueList<int> columns;
columns.append(column);
KApplication::setOverrideCursor(Qt::waitCursor);
for(QStringList::ConstIterator it = members.begin(); it != members.end(); ++it) {
PlaylistSearch::ComponentList components;
components.append(PlaylistSearch::Component(*it));
components.append(PlaylistSearch::Component(*it, false, columns));
PlaylistList playlists;
playlists.append(collection);
PlaylistSearch s(playlists, components, PlaylistSearch::MatchAny, false);
SearchPlaylist *p = new SearchPlaylist(s, static_cast<QWidget *>(collection->parent()), *it);
new PlaylistBox::Item(parent, "midi", *it, p);
emit signalCreateSearchList(s, searchCategory, *it);
static int i = 0;
if(++i % 5 == 0)
kapp->processEvents();
static int i = 0;
if(++i % 5 == 0)
kapp->processEvents();
}
KApplication::restoreOverrideCursor();
}
#include "viewmode.moc"
......@@ -20,6 +20,7 @@
#include <klocale.h>
#include <qobject.h>
#include <qstring.h>
#include <qdict.h>
......@@ -28,8 +29,12 @@
class QPainter;
class QColorGroup;
class ViewMode
class SearchPlaylist;
class ViewMode : public QObject
{
Q_OBJECT
public:
ViewMode(PlaylistBox *b);
virtual ~ViewMode();
......@@ -41,12 +46,21 @@ public:
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
virtual PlaylistBox::Item *createSearchItem(PlaylistBox *box,
SearchPlaylist *playlist,
const QString &searchCategory);
protected:
PlaylistBox *playlistBox() const { return m_playlistBox; }
bool visible() const { return m_visible; }
void updateIcons(int size);
signals:
void signalCreateSearchList(const PlaylistSearch &search,
const QString &searchCategory,
const QString &name);
private:
PlaylistBox *m_playlistBox;
bool m_visible;
......@@ -80,10 +94,14 @@ public:
virtual QString name() const { return i18n("Tree"); }
virtual void setShown(bool shown);
virtual PlaylistBox::Item *createSearchItem(PlaylistBox *box,
SearchPlaylist *playlist,
const QString &searchCategory);
private:
void setupCategory(PlaylistBox::Item *parent, const QStringList &members) const;
void setupCategory(const QString &searchCategory, const QStringList &members, int column);
QDict<PlaylistBox::Item> m_categories;
QDict<PlaylistBox::Item> m_searchCategories;
};
#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