Commit 5d417225 authored by Scott Wheeler's avatar Scott Wheeler

Started cleaning up the ugly "view modes" situaion in PlaylistBox. It's

now been moved out to another group of classes, each of which encapsulates
a view mode.

At the present the tree view's code has been ripped out of the old structure
and not replaced in the new one.  This hopefully will follow tomorrow.

svn path=/trunk/kdemultimedia/juk/; revision=230058
parent 293407ec
......@@ -11,7 +11,7 @@ juk_SOURCES = directorylistbase.ui genrelisteditorbase.ui \
slideraction.cpp keydialog.cpp juk.cpp main.cpp tagguesser.cpp \
tagguesserconfigdlgwidget.ui tagguesserconfigdlg.cpp jukIface.skel \
playlistsearch.cpp searchwidget.cpp filerenamer.cpp dynamicplaylist.cpp \
searchplaylist.cpp musicbrainzquery.cpp mediafiles.cpp
searchplaylist.cpp musicbrainzquery.cpp mediafiles.cpp viewmode.cpp
tagguessertest_SOURCES = tagguessertest.cpp tagguesser.cpp
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
#include <qmap.h>
#include "playlist.h"
#include "viewmode.h"
class PlaylistItem;
class PlaylistSplitter;
......@@ -42,8 +43,6 @@ class PlaylistBox : public KListView
Q_OBJECT
public:
enum ViewMode { Default = 0, Compact = 1, Tree = 2 };
PlaylistBox(PlaylistSplitter *parent = 0, const char *name = 0);
virtual ~PlaylistBox();
......@@ -60,10 +59,10 @@ public:
void duplicate();
void deleteItem();
bool hasSelection() const { return m_hasSelection; }
bool hasSelection() const { return m_hasSelection; }
void initViewMode();
ViewMode viewMode() const { return m_viewMode; }
ViewMode *viewMode() { return m_viewModes.at(m_viewModeIndex); }
int viewModeIndex() const { return m_viewModeIndex; }
class Item;
friend class Item;
......@@ -109,7 +108,7 @@ private slots:
void slotPlaylistChanged();
void slotDoubleClicked(QListViewItem *);
void slotShowContextMenu(QListViewItem *, const QPoint &point, int);
void slotSetViewMode(int viewMode);
void slotSetViewMode(int index);
private:
PlaylistSplitter *m_splitter;
......@@ -117,7 +116,8 @@ private:
KPopupMenu *m_contextMenu;
bool m_updatePlaylistStack;
QPtrDict<Item> m_playlistDict;
ViewMode m_viewMode;
int m_viewModeIndex;
QPtrList<ViewMode> m_viewModes;
KSelectAction *m_viewModeAction;
bool m_hasSelection;
};
......@@ -127,6 +127,8 @@ private:
class PlaylistBox::Item : public QObject, public KListViewItem
{
friend class PlaylistBox;
friend class ViewMode;
friend class CompactViewMode;
Q_OBJECT
......@@ -139,31 +141,25 @@ public:
protected:
Item(PlaylistBox *listBox, const char *icon, const QString &text, Playlist *l = 0);
Item(Item *parent, const char *icon, const QString &text, int category, Playlist *l = 0);
Playlist *playlist() const { return m_list; }
PlaylistBox *listView() const { return static_cast<PlaylistBox *>(KListViewItem::listView()); }
const char *iconName() const { return m_iconName; }
QString text() const { return m_text; }
int category() const { return m_category; }
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);
virtual Item *rootItem();
virtual QString text(int column) const { return KListViewItem::text(column); }
protected slots:
void slotSetName(const QString &name);
void slotTriggerSetData();
void slotSetData();
private:
Playlist *m_list;
QString m_text;
const char *m_iconName;
int m_category;
};
#endif
......@@ -54,7 +54,6 @@ PlaylistSplitter::PlaylistSplitter(QWidget *parent, bool restore, const char *na
readConfig();
m_editor->slotUpdateCollection();
m_playlistBox->initViewMode();
}
PlaylistSplitter::~PlaylistSplitter()
......@@ -675,7 +674,6 @@ void PlaylistSplitter::slotCreatePlaylist(const PlaylistItemList &items)
return;
playlist->createItems(items);
m_playlistBox->initViewMode();
}
void PlaylistSplitter::slotShowSearchResults()
......
/***************************************************************************
viewmode.cpp
-------------------
begin : Sat Jun 7 2003
copyright : (C) 2003 by Scott Wheeler,
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kiconloader.h>
#include <qpixmap.h>
#include <qpainter.h>
#include "viewmode.h"
#include "playlistbox.h"
////////////////////////////////////////////////////////////////////////////////
// ViewMode
////////////////////////////////////////////////////////////////////////////////
ViewMode::ViewMode(PlaylistBox *b) :
m_playlistBox(b),
m_visible(false)
{
}
ViewMode::~ViewMode()
{
}
void ViewMode::paintCell(QListViewItem *i,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align)
{
Q_UNUSED(align);
if(width < i->pixmap(column)->width())
return;
PlaylistBox::Item *item = static_cast<PlaylistBox::Item *>(i);
QFontMetrics fm = painter->fontMetrics();
QString line = item->text();
QStringList lines;
while(!line.isEmpty()) {
int textLength = line.length();
while(textLength > 0 &&
fm.width(line.mid(0, textLength).stripWhiteSpace()) + item->listView()->itemMargin() * 2 > 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);
}
int y = item->listView()->itemMargin();
const QPixmap *pm = item->pixmap(column);
int height = 3 * item->listView()->itemMargin() + pm->height() +
(fm.height() - fm.descent()) * lines.count();
if(item->isSelected()) {
painter->fillRect(0, 0, width, height, colorGroup.brush(QColorGroup::Highlight));
painter->setPen(colorGroup.highlightedText());
}
else
painter->eraseRect(0, 0, width, height);
if (!pm->isNull()) {
int x = (width - pm->width()) / 2;
x = QMAX(x, item->listView()->itemMargin());
painter->drawPixmap(x, y, *pm);
}
y += pm->height() + fm.height() - fm.descent();
for(QStringList::Iterator it = lines.begin(); it != lines.end(); ++it) {
int x = (width - fm.width(*it)) / 2;
x = QMAX(x, item->listView()->itemMargin());
painter->drawText(x, y, *it);
y += fm.height() - fm.descent();
}
item->setHeight(height);
}
void ViewMode::setShown(bool shown)
{
m_visible = shown;
if(shown)
updateIcons(32);
}
void ViewMode::updateIcons(int size)
{
for(QListViewItemIterator it(m_playlistBox); it.current(); ++it) {
PlaylistBox::Item *i = static_cast<PlaylistBox::Item *>(*it);
i->setPixmap(0, SmallIcon(i->iconName(), size));
}
}
///////////////////////////////////////////////////////////////////////////////
// CompactViewMode
////////////////////////////////////////////////////////////////////////////////
CompactViewMode::CompactViewMode(PlaylistBox *b) : ViewMode(b)
{
}
CompactViewMode::~CompactViewMode()
{
}
void CompactViewMode::paintCell(QListViewItem *i,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align)
{
if(width < i->pixmap(column)->width())
return;
PlaylistBox::Item *item = static_cast<PlaylistBox::Item *>(i);
QFontMetrics fm = painter->fontMetrics();
QString line = item->text();
int baseWidth = item->pixmap(column)->width() + item->listView()->itemMargin() * 4;
if(baseWidth + fm.width(line) > width) {
int ellipsisLength = fm.width("...");
if(width > baseWidth + ellipsisLength) {
while(baseWidth + fm.width(line) + ellipsisLength > width)
line.truncate(line.length() - 1);
line = line.append("...");
}
else
line = "...";
}
item->KListViewItem::setText(column, line);
item->KListViewItem::paintCell(painter, colorGroup, column, width, align);
}
void CompactViewMode::setShown(bool shown)
{
// m_visible = shown;
if(shown)
updateIcons(16);
}
////////////////////////////////////////////////////////////////////////////////
// TreeViewMode
////////////////////////////////////////////////////////////////////////////////
TreeViewMode::TreeViewMode(PlaylistBox *b) : CompactViewMode(b)
{
}
TreeViewMode::~TreeViewMode()
{
}
void TreeViewMode::setShown(bool show)
{
CompactViewMode::setShown(show);
}
/***************************************************************************
viewmode.h
-------------------
begin : Sat Jun 7 2003
copyright : (C) 2003 by Scott Wheeler,
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef VIEWMODE_H
#define VIEWMODE_H
#include <klocale.h>
#include <qstring.h>
class QPainter;
class QColorGroup;
class QListViewItem;
class PlaylistBox;
class ViewMode
{
public:
ViewMode(PlaylistBox *b);
virtual ~ViewMode();
virtual QString name() const { return i18n("Default"); }
virtual void setShown(bool shown);
virtual void paintCell(QListViewItem *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
protected:
PlaylistBox *playlistBox() const { return m_playlistBox; }
bool visible() const { return m_visible; }
void updateIcons(int size);
private:
PlaylistBox *m_playlistBox;
bool m_visible;
};
////////////////////////////////////////////////////////////////////////////////
class CompactViewMode : public ViewMode
{
public:
CompactViewMode(PlaylistBox *b);
virtual ~CompactViewMode();
virtual QString name() const { return i18n("Compact"); }
virtual void setShown(bool shown);
virtual void paintCell(QListViewItem *item,
QPainter *painter,
const QColorGroup &colorGroup,
int column, int width, int align);
};
////////////////////////////////////////////////////////////////////////////////
class TreeViewMode : public CompactViewMode
{
public:
TreeViewMode(PlaylistBox *l);
virtual ~TreeViewMode();
virtual QString name() const { return i18n("Tree"); }
virtual void setShown(bool shown);
};
#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