Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9be49087 authored by Scott Wheeler's avatar Scott Wheeler

Just for danimo: moved the painting code from ListBox to PlaylistBox, i.e.

de-uglified the KListView painting...

svn path=/trunk/kdemultimedia/juk/; revision=220319
parent a9f054a4
......@@ -28,6 +28,8 @@
#include <qdrawutil.h>
#include <qclipboard.h>
#include <qheader.h>
#include <qpainter.h>
#include <qregexp.h>
#include "playlistbox.h"
#include "collectionlist.h"
......@@ -41,9 +43,12 @@ PlaylistBox::PlaylistBox(PlaylistSplitter *parent, const char *name) : KListView
m_splitter(parent),
m_updatePlaylistStack(true)
{
addColumn("Playlists");
addColumn("Playlists", width());
header()->hide();
setSorting(0);
setFullWidth(true);
// setAlternateBackground(QColor());
setItemMargin(3);
// Sadly the actions from the main menu can't be reused because these require being enabled and disabled at
// different times.
......@@ -421,7 +426,7 @@ void PlaylistBox::Item::slotSetName(const QString &name)
PlaylistBox::Item::Item(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l)
: QObject(listbox), KListViewItem(listbox, text),
m_list(l)
m_list(l), m_text(text)
{
setPixmap(0, pix);
listbox->addName(text);
......@@ -429,13 +434,6 @@ PlaylistBox::Item::Item(PlaylistBox *listbox, const QPixmap &pix, const QString
connect(l, SIGNAL(signalNameChanged(const QString &)), this, SLOT(slotSetName(const QString &)));
}
PlaylistBox::Item::Item(PlaylistBox *listbox, const QString &text, Playlist *l)
: KListViewItem(listbox, text),
m_list(l)
{
setPixmap(0, SmallIcon("midi", 32));
}
PlaylistBox::Item::~Item()
{
......@@ -451,4 +449,43 @@ int PlaylistBox::Item::compare(QListViewItem *i, int col, bool) const
return text(col).lower().localeAwareCompare(i->text(col).lower());
}
void PlaylistBox::Item::paintCell(QPainter *painter, const QColorGroup &colorGroup, int column, int width, int align)
{
if(width > pixmap(column)->width()) {
QFontMetrics fm = painter->fontMetrics();
QStringList lines;
QString line = m_text;
while(!line.isEmpty()) {
int textLength = line.length();
while(textLength > 0 &&
fm.width(line.mid(0, textLength).stripWhiteSpace()) +
pixmap(column)->width() +
listView()->itemMargin() * 4 > width)
{
int i = line.findRev(QRegExp( "\\W"), textLength - 1);
if(i > 0)
textLength = i;
else
textLength--;
}
lines.append(line.mid(0, textLength).stripWhiteSpace());
line = line.mid(textLength);
}
setMultiLinesEnabled(lines.count() > 1);
KListViewItem::setText(column, lines.join("\n"));
}
KListViewItem::paintCell(painter, colorGroup, column, width, align);
}
void PlaylistBox::Item::setText(int column, const QString &text)
{
m_text = text;
KListViewItem::setText(column, text);
}
#include "playlistbox.moc"
......@@ -132,20 +132,22 @@ class PlaylistBox::Item : public QObject, public KListViewItem
public:
virtual ~Item();
public slots:
void slotSetName(const QString &name);
protected:
Item(PlaylistBox *listbox, const QPixmap &pix, const QString &text, Playlist *l = 0);
Item(PlaylistBox *listbox, const QString &text, Playlist *l = 0);
Playlist *playlist() const { return m_list; }
PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
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 setText(int column, const QString &text);
public slots:
void slotSetName(const QString &name);
private:
Playlist *m_list;
QString m_text;
};
#endif
......@@ -383,6 +383,8 @@ void PlaylistSplitter::slotRenameFile()
void PlaylistSplitter::setupLayout()
{
setOpaqueResize(true);
m_playlistBox = new PlaylistBox(this, "playlistBox");
// Create a splitter to go between the playlists and the editor.
......
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