Commit a7de1d16 authored by Scott Wheeler's avatar Scott Wheeler

Much more polished startup appearance for the default view mode. Previously

the size for the first iteration of painting was incorrect and it was only
updated later.  This gets the size right on the first paint and gets rid
of the annoying flicker with subsequent updates.

svn path=/trunk/kdemultimedia/juk/; revision=322089
parent b41accee
...@@ -41,8 +41,8 @@ using namespace ActionCollection; ...@@ -41,8 +41,8 @@ using namespace ActionCollection;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
const QString &name) : const char *name) :
KListView(parent, name.latin1()), KListView(parent, name),
PlaylistCollection(playlistStack), PlaylistCollection(playlistStack),
m_updatePlaylistStack(true), m_updatePlaylistStack(true),
m_viewModeIndex(0), m_viewModeIndex(0),
...@@ -53,7 +53,11 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -53,7 +53,11 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
{ {
readConfig(); readConfig();
addColumn("Playlists", width()); addColumn("Playlists", width());
header()->blockSignals(true);
header()->hide(); header()->hide();
header()->blockSignals(false);
setSorting(0); setSorting(0);
setFullWidth(true); setFullWidth(true);
setItemMargin(3); setItemMargin(3);
...@@ -118,6 +122,7 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, ...@@ -118,6 +122,7 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
CollectionList::initialize(this); CollectionList::initialize(this);
Cache::loadPlaylists(this); Cache::loadPlaylists(this);
raise(CollectionList::instance()); raise(CollectionList::instance());
QTimer::singleShot(0, object(), SLOT(slotScanFolders())); QTimer::singleShot(0, object(), SLOT(slotScanFolders()));
} }
...@@ -602,6 +607,11 @@ void PlaylistBox::Item::setText(int column, const QString &text) ...@@ -602,6 +607,11 @@ void PlaylistBox::Item::setText(int column, const QString &text)
KListViewItem::setText(column, text); KListViewItem::setText(column, text);
} }
void PlaylistBox::Item::setup()
{
listView()->viewMode()->setupItem(this);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item protected slots // PlaylistBox::Item protected slots
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -627,7 +637,7 @@ void PlaylistBox::Item::slotSetName(const QString &name) ...@@ -627,7 +637,7 @@ void PlaylistBox::Item::slotSetName(const QString &name)
void PlaylistBox::Item::init() void PlaylistBox::Item::init()
{ {
PlaylistBox *list = static_cast<PlaylistBox *>(listView()); PlaylistBox *list = listView();
list->setupItem(this); list->setupItem(this);
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
friend class TreeViewMode; friend class TreeViewMode;
PlaylistBox(QWidget *parent, QWidgetStack *playlistStack, PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
const QString &name = QString::null); const char *name = 0);
virtual ~PlaylistBox(); virtual ~PlaylistBox();
...@@ -151,9 +151,12 @@ protected: ...@@ -151,9 +151,12 @@ protected:
virtual QString text(int column) const { return KListViewItem::text(column); } virtual QString text(int column) const { return KListViewItem::text(column); }
virtual void setup();
static Item *collectionItem() { return m_collectionItem; } static Item *collectionItem() { return m_collectionItem; }
static void setCollectionItem(Item *item) { m_collectionItem = item; } static void setCollectionItem(Item *item) { m_collectionItem = item; }
protected slots: protected slots:
void slotSetName(const QString &name); void slotSetName(const QString &name);
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
// ViewMode // ViewMode
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ViewMode::ViewMode(PlaylistBox *b) : QObject(b), ViewMode::ViewMode(PlaylistBox *b) :
QObject(b),
m_playlistBox(b), m_playlistBox(b),
m_visible(false), m_visible(false),
m_needsRefresh(false) m_needsRefresh(false)
...@@ -106,7 +107,7 @@ bool ViewMode::eventFilter(QObject *watched, QEvent *e) ...@@ -106,7 +107,7 @@ bool ViewMode::eventFilter(QObject *watched, QEvent *e)
if(e->type() == QEvent::Hide) if(e->type() == QEvent::Hide)
m_needsRefresh = true; m_needsRefresh = true;
return QObject::eventFilter(watched, e); return QObject::eventFilter(watched, e);
} }
...@@ -127,9 +128,18 @@ void ViewMode::updateIcons(int size) ...@@ -127,9 +128,18 @@ void ViewMode::updateIcons(int size)
} }
} }
void ViewMode::setupItem(PlaylistBox::Item *item) const
{
const PlaylistBox *box = item->listView();
const int width = box->width() - box->verticalScrollBar()->width() - border * 2;
const int baseHeight = 2 * box->itemMargin() + 32 + border * 2;
const QFontMetrics fm = box->fontMetrics();
item->setHeight(baseHeight + (fm.height() - fm.descent()) * lines(item, fm, width).count());
}
void ViewMode::updateHeights() void ViewMode::updateHeights()
{ {
const int width = m_playlistBox->viewport()->width() - border * 2; const int width = m_playlistBox->width() - m_playlistBox->verticalScrollBar()->width() - border * 2;
const int baseHeight = 2 * m_playlistBox->itemMargin() + 32 + border * 2; const int baseHeight = 2 * m_playlistBox->itemMargin() + 32 + border * 2;
const QFontMetrics fm = m_playlistBox->fontMetrics(); const QFontMetrics fm = m_playlistBox->fontMetrics();
...@@ -139,7 +149,6 @@ void ViewMode::updateHeights() ...@@ -139,7 +149,6 @@ void ViewMode::updateHeights()
m_lines[i] = lines(i, fm, width); m_lines[i] = lines(i, fm, width);
const int height = baseHeight + (fm.height() - fm.descent()) * m_lines[i].count(); const int height = baseHeight + (fm.height() - fm.descent()) * m_lines[i].count();
i->setHeight(height); i->setHeight(height);
i->invalidateHeight();
} }
m_needsRefresh = false; m_needsRefresh = false;
...@@ -163,7 +172,7 @@ void ViewMode::paintDropIndicator(QPainter *painter, int width, int height) // s ...@@ -163,7 +172,7 @@ void ViewMode::paintDropIndicator(QPainter *painter, int width, int height) // s
QStringList ViewMode::lines(const PlaylistBox::Item *item, QStringList ViewMode::lines(const PlaylistBox::Item *item,
const QFontMetrics &fm, const QFontMetrics &fm,
int width) const int width)
{ {
// Here 32 is a bit arbitrary, but that's the width of the icons in this // Here 32 is a bit arbitrary, but that's the width of the icons in this
// mode and seems to a reasonable lower bound. // mode and seems to a reasonable lower bound.
...@@ -265,7 +274,7 @@ void TreeViewMode::setShown(bool show) ...@@ -265,7 +274,7 @@ void TreeViewMode::setShown(bool show)
else { else {
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it) for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setVisible(true); it.current()->setVisible(true);
} }
} }
else { else {
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it) for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
...@@ -285,11 +294,11 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis ...@@ -285,11 +294,11 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis
PlaylistSearch::ComponentList components; PlaylistSearch::ComponentList components;
PlaylistSearch::Component::MatchMode mode; PlaylistSearch::Component::MatchMode mode;
if(exact) if(exact)
mode = PlaylistSearch::Component::Exact; mode = PlaylistSearch::Component::Exact;
else else
mode = PlaylistSearch::Component::ContainsWord; mode = PlaylistSearch::Component::ContainsWord;
components.append(PlaylistSearch::Component(*it, true, columns, mode)); components.append(PlaylistSearch::Component(*it, true, columns, mode));
...@@ -298,9 +307,9 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis ...@@ -298,9 +307,9 @@ void TreeViewMode::setupCategory(const QString &searchCategory, const QStringLis
PlaylistSearch s(playlists, components, PlaylistSearch::MatchAny, false); PlaylistSearch s(playlists, components, PlaylistSearch::MatchAny, false);
SearchPlaylist *p = new SearchPlaylist(playlistBox(), s, *it, false); SearchPlaylist *p = new SearchPlaylist(playlistBox(), s, *it, false);
playlistBox()->setupPlaylist(p, "midi", m_searchCategories[searchCategory]); playlistBox()->setupPlaylist(p, "midi", m_searchCategories[searchCategory]);
processEvents(); processEvents();
} }
KApplication::restoreOverrideCursor(); KApplication::restoreOverrideCursor();
...@@ -314,17 +323,17 @@ void TreeViewMode::setupCategories() ...@@ -314,17 +323,17 @@ void TreeViewMode::setupCategories()
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists")); i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Artists"));
m_searchCategories.insert("artists", i); m_searchCategories.insert("artists", i);
setupCategory("artists", CollectionList::instance()->uniqueSet(CollectionList::Artists), setupCategory("artists", CollectionList::instance()->uniqueSet(CollectionList::Artists),
PlaylistItem::ArtistColumn, false); PlaylistItem::ArtistColumn, false);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums")); i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Albums"));
m_searchCategories.insert("albums", i); m_searchCategories.insert("albums", i);
setupCategory("albums", CollectionList::instance()->uniqueSet(CollectionList::Albums), setupCategory("albums", CollectionList::instance()->uniqueSet(CollectionList::Albums),
PlaylistItem::AlbumColumn); PlaylistItem::AlbumColumn);
i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Genres")); i = new PlaylistBox::Item(collectionItem, "cdimage", i18n("Genres"));
m_searchCategories.insert("genres", i); m_searchCategories.insert("genres", i);
setupCategory("genres", CollectionList::instance()->uniqueSet(CollectionList::Genres), setupCategory("genres", CollectionList::instance()->uniqueSet(CollectionList::Genres),
PlaylistItem::GenreColumn); PlaylistItem::GenreColumn);
for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it) for(QDictIterator<PlaylistBox::Item> it(m_searchCategories); it.current(); ++it)
it.current()->setSortedFirst(true); it.current()->setSortedFirst(true);
......
...@@ -47,6 +47,8 @@ public: ...@@ -47,6 +47,8 @@ public:
void queueRefresh() { m_needsRefresh = true; } void queueRefresh() { m_needsRefresh = true; }
virtual void setupItem(PlaylistBox::Item *item) const;
protected: protected:
PlaylistBox *playlistBox() const { return m_playlistBox; } PlaylistBox *playlistBox() const { return m_playlistBox; }
bool visible() const { return m_visible; } bool visible() const { return m_visible; }
...@@ -56,7 +58,7 @@ protected: ...@@ -56,7 +58,7 @@ protected:
static void paintDropIndicator(QPainter *painter, int width, int height); static void paintDropIndicator(QPainter *painter, int width, int height);
private: private:
QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width) const; static QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width);
PlaylistBox *m_playlistBox; PlaylistBox *m_playlistBox;
bool m_visible; bool m_visible;
...@@ -80,10 +82,9 @@ public: ...@@ -80,10 +82,9 @@ public:
QPainter *painter, QPainter *painter,
const QColorGroup &colorGroup, const QColorGroup &colorGroup,
int column, int width, int align); int column, int width, int align);
virtual void setupItem(PlaylistBox::Item *item) const { item->KListViewItem::setup(); }
protected: protected:
/**
* Override the implementation from the base class. This isn't needed here.
*/
virtual void updateHeights(); virtual void updateHeights();
}; };
...@@ -103,7 +104,7 @@ public: ...@@ -103,7 +104,7 @@ public:
private: private:
void setupCategory(const QString &searchCategory, const QStringList &members, void setupCategory(const QString &searchCategory, const QStringList &members,
int column, bool exact = true); int column, bool exact = true);
private: private:
QDict<PlaylistBox::Item> m_searchCategories; QDict<PlaylistBox::Item> m_searchCategories;
}; };
......
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