viewmode.h 4.87 KB
Newer Older
1 2
/***************************************************************************
    begin                : Sat Jun 7 2003
3
    copyright            : (C) 2003 - 2004 by Scott Wheeler,
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    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


Laurent Montel's avatar
Laurent Montel committed
20 21 22
#include <q3dict.h>
//Added by qt3to4:
#include <QEvent>
23

24 25
#include "playlistbox.h"

26 27 28
class QPainter;
class QColorGroup;

29 30 31
class SearchPlaylist;

class ViewMode : public QObject
32
{
33 34
    Q_OBJECT

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

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

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

47
    virtual bool eventFilter(QObject *watched, QEvent *e);
48 49
    void queueRefresh() { m_needsRefresh = true; }

50 51
    virtual void setupItem(PlaylistBox::Item *item) const;

52 53 54 55 56 57 58 59 60 61 62 63 64
    virtual void setupDynamicPlaylists() {}
    /**
     * If the view mode has dynamic lists, this function is used to temporarily
     * freeze them to prevent them from deleting dynamic elements.
     */
    virtual void setDynamicListsFrozen(bool /* frozen */) {}

    /**
     * Used for dynamic view modes.  This function will be called when \p items
     * are added to \p column (even if the view mode hasn't been shown yet).
     */
    virtual void addItems(const QStringList &items, unsigned column)
    {
65 66
        (void) items;
        (void) column;
67 68 69 70 71 72 73 74
    }

    /**
     * Used for dynamic view modes.  This function will be called when \p item
     * is removed from \p column (even if the view mode hasn't been shown yet).
     */
    virtual void removeItem(const QString &item, unsigned column)
    {
75 76
        (void) item;
        (void) column;
77 78
    }

79 80
protected:
    PlaylistBox *playlistBox() const { return m_playlistBox; }
81
    bool visible() const { return m_visible; }
82
    void setVisible(bool v) { m_visible = v; }
83
    void updateIcons(int size);
84
    virtual void updateHeights();
85
    static void paintDropIndicator(QPainter *painter, int width, int height);
86

87
private:
88
    static QStringList lines(const PlaylistBox::Item *item, const QFontMetrics &fm, int width);
89

90 91
    PlaylistBox *m_playlistBox;
    bool m_visible;
92
    bool m_needsRefresh;
93
    QMap<PlaylistBox::Item *, QStringList> m_lines;
94
    static const int border = 4;
95 96 97 98 99 100 101 102 103
};

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

class CompactViewMode : public ViewMode
{
public:
    CompactViewMode(PlaylistBox *b);
    virtual ~CompactViewMode();
104

105 106 107
    virtual QString name() const { return i18n("Compact"); }
    virtual void setShown(bool shown);

108
    virtual void paintCell(PlaylistBox::Item *item,
109 110 111
                           QPainter *painter,
                           const QColorGroup &colorGroup,
                           int column, int width, int align);
112

Laurent Montel's avatar
Laurent Montel committed
113
    virtual void setupItem(PlaylistBox::Item *item) const { item->K3ListViewItem::setup(); }
114
protected:
115
    virtual void updateHeights();
116 117 118 119
};

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

120 121
class TreeViewItemPlaylist;

122 123
class TreeViewMode : public CompactViewMode
{
124 125
    Q_OBJECT

126 127 128 129 130 131
public:
    TreeViewMode(PlaylistBox *l);
    virtual ~TreeViewMode();

    virtual QString name() const { return i18n("Tree"); }
    virtual void setShown(bool shown);
132 133
    virtual void setupDynamicPlaylists();
    virtual void setDynamicListsFrozen(bool frozen);
134

135 136
    virtual void removeItem(const QString &item, unsigned column);
    virtual void addItems(const QStringList &items, unsigned column);
137

138 139 140
signals:
    void signalPlaylistDestroyed(Playlist*);

141
private:
142
    Q3Dict<PlaylistBox::Item> m_searchCategories;
Laurent Montel's avatar
Laurent Montel committed
143
    Q3Dict<TreeViewItemPlaylist> m_treeViewItems;
144
    QStringList m_pendingItemsToRemove;
145 146 147 148 149 150 151 152 153 154 155 156 157 158
    bool m_dynamicListsFrozen;
    bool m_setup;
};

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

class CoverManagerMode : public ViewMode
{
    Q_OBJECT

public:
    CoverManagerMode(PlaylistBox *b);
    virtual QString name() const { return i18n("Cover Manager"); }
    //virtual void setShown(bool shown);
159 160 161
};

#endif
162 163

// vim: set et sw=4 tw=0 sta: