viewmode.h 3.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/***************************************************************************
                          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>

23
#include <qdict.h>
24

25 26
#include "playlistbox.h"

27 28 29
class QPainter;
class QColorGroup;

30 31 32
class SearchPlaylist;

class ViewMode : public QObject
33
{
34 35
    Q_OBJECT

36 37 38 39
public:
    ViewMode(PlaylistBox *b);
    virtual ~ViewMode();

40
    virtual QString name() const { return i18n("Default"); }
41 42
    virtual void setShown(bool shown);

43
    virtual void paintCell(PlaylistBox::Item *item,
44 45 46
                           QPainter *painter, 
                           const QColorGroup &colorGroup,
                           int column, int width, int align);
47 48 49 50

    virtual PlaylistBox::Item *createSearchItem(PlaylistBox *box,
                                                SearchPlaylist *playlist,
                                                const QString &searchCategory);
51 52

    virtual bool eventFilter(QObject *watched, QEvent *e);
53
    
54 55 56

    void queueRefresh() { m_needsRefresh = true; }

57 58
protected:
    PlaylistBox *playlistBox() const { return m_playlistBox; }
59
    bool visible() const { return m_visible; }
60
    void setVisible(bool v) { m_visible = v; }
61
    void updateIcons(int size);
62
    virtual void updateHeights();
63
    static void paintDropIndicator(QPainter *painter, int width, int height);
64

65
private:
66 67
    QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width) const;

68 69
    PlaylistBox *m_playlistBox;
    bool m_visible;
70
    bool m_needsRefresh;
71
    QMap<PlaylistBox::Item *, QStringList> m_lines;
72
    static const int border = 4;
73 74 75 76 77 78 79 80 81 82 83 84 85
};

////////////////////////////////////////////////////////////////////////////////

class CompactViewMode : public ViewMode
{
public:
    CompactViewMode(PlaylistBox *b);
    virtual ~CompactViewMode();
    
    virtual QString name() const { return i18n("Compact"); }
    virtual void setShown(bool shown);

86
    virtual void paintCell(PlaylistBox::Item *item,
87 88 89
                           QPainter *painter,
                           const QColorGroup &colorGroup,
                           int column, int width, int align);
90 91 92 93
protected:
    /**
     * Override the implementation from the base class.  This isn't needed here.
     */
94
    virtual void updateHeights();
95 96 97 98 99 100
};

////////////////////////////////////////////////////////////////////////////////

class TreeViewMode : public CompactViewMode
{
101 102
    Q_OBJECT

103 104 105 106 107 108
public:
    TreeViewMode(PlaylistBox *l);
    virtual ~TreeViewMode();

    virtual QString name() const { return i18n("Tree"); }
    virtual void setShown(bool shown);
109

110 111 112 113
    virtual PlaylistBox::Item *createSearchItem(PlaylistBox *box,
                                                SearchPlaylist *playlist,
                                                const QString &searchCategory);

114
private:
115 116
    void setupCategory(const QString &searchCategory, const QStringList &members,
		       int column, bool exact = true);
117

118 119 120 121 122 123
private slots:
    /**
     * Setup all of the categories.
     */
    void slotSetupCategories();

124
private:
125
    QDict<PlaylistBox::Item> m_searchCategories;    
126 127 128
};

#endif