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;
////////////////////////////////////////////////////////////////////////////////
PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
const QString &name) :
KListView(parent, name.latin1()),
const char *name) :
KListView(parent, name),
PlaylistCollection(playlistStack),
m_updatePlaylistStack(true),
m_viewModeIndex(0),
......@@ -53,7 +53,11 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
{
readConfig();
addColumn("Playlists", width());
header()->blockSignals(true);
header()->hide();
header()->blockSignals(false);
setSorting(0);
setFullWidth(true);
setItemMargin(3);
......@@ -118,6 +122,7 @@ PlaylistBox::PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
CollectionList::initialize(this);
Cache::loadPlaylists(this);
raise(CollectionList::instance());
QTimer::singleShot(0, object(), SLOT(slotScanFolders()));
}
......@@ -602,6 +607,11 @@ void PlaylistBox::Item::setText(int column, const QString &text)
KListViewItem::setText(column, text);
}
void PlaylistBox::Item::setup()
{
listView()->viewMode()->setupItem(this);
}
////////////////////////////////////////////////////////////////////////////////
// PlaylistBox::Item protected slots
////////////////////////////////////////////////////////////////////////////////
......@@ -627,7 +637,7 @@ void PlaylistBox::Item::slotSetName(const QString &name)
void PlaylistBox::Item::init()
{
PlaylistBox *list = static_cast<PlaylistBox *>(listView());
PlaylistBox *list = listView();
list->setupItem(this);
......
......@@ -51,7 +51,7 @@ public:
friend class TreeViewMode;
PlaylistBox(QWidget *parent, QWidgetStack *playlistStack,
const QString &name = QString::null);
const char *name = 0);
virtual ~PlaylistBox();
......@@ -151,9 +151,12 @@ protected:
virtual QString text(int column) const { return KListViewItem::text(column); }
virtual void setup();
static Item *collectionItem() { return m_collectionItem; }
static void setCollectionItem(Item *item) { m_collectionItem = item; }
protected slots:
void slotSetName(const QString &name);
......
......@@ -28,7 +28,8 @@
// ViewMode
////////////////////////////////////////////////////////////////////////////////
ViewMode::ViewMode(PlaylistBox *b) : QObject(b),
ViewMode::ViewMode(PlaylistBox *b) :
QObject(b),
m_playlistBox(b),
m_visible(false),
m_needsRefresh(false)
......@@ -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()
{
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 QFontMetrics fm = m_playlistBox->fontMetrics();
......@@ -139,7 +149,6 @@ void ViewMode::updateHeights()
m_lines[i] = lines(i, fm, width);
const int height = baseHeight + (fm.height() - fm.descent()) * m_lines[i].count();
i->setHeight(height);
i->invalidateHeight();
}
m_needsRefresh = false;
......@@ -163,7 +172,7 @@ void ViewMode::paintDropIndicator(QPainter *painter, int width, int height) // s
QStringList ViewMode::lines(const PlaylistBox::Item *item,
const QFontMetrics &fm,
int width) const
int width)
{
// Here 32 is a bit arbitrary, but that's the width of the icons in this
// mode and seems to a reasonable lower bound.
......
......@@ -47,6 +47,8 @@ public:
void queueRefresh() { m_needsRefresh = true; }
virtual void setupItem(PlaylistBox::Item *item) const;
protected:
PlaylistBox *playlistBox() const { return m_playlistBox; }
bool visible() const { return m_visible; }
......@@ -56,7 +58,7 @@ protected:
static void paintDropIndicator(QPainter *painter, int width, int height);
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;
bool m_visible;
......@@ -80,10 +82,9 @@ public:
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
virtual void setupItem(PlaylistBox::Item *item) const { item->KListViewItem::setup(); }
protected:
/**
* Override the implementation from the base class. This isn't needed here.
*/
virtual void updateHeights();
};
......
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