viewmode.h 4.63 KB
Newer Older
1 2
/***************************************************************************
    begin                : Sat Jun 7 2003
3
    copyright            : (C) 2003 - 2004 by Scott Wheeler,
4
    email                : wheeler@kde.org
5 6
    copyright            : (c) 2007 Michael Pyne
    email                : michael.pyne@kdemail.net
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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

21 22 23
#include <QObject>
#include <QStringList>
#include <QMap>
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;
41 42
    virtual void setShown(bool shown);

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

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

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

53
    virtual void setupDynamicPlaylists() {}
54

55 56 57 58 59 60 61 62 63 64 65 66
    /**
     * 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)
    {
67 68
        Q_UNUSED(items);
        Q_UNUSED(column);
69 70 71 72 73 74 75 76
    }

    /**
     * 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)
    {
77 78
        Q_UNUSED(item);
        Q_UNUSED(column);
79 80
    }

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

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

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

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

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

107
    virtual QString name() const;
108 109
    virtual void setShown(bool shown);

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

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

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

122 123
class TreeViewItemPlaylist;

124 125
class TreeViewMode : public CompactViewMode
{
126 127
    Q_OBJECT

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

132
    virtual QString name() const;
133
    virtual void setShown(bool shown);
134 135
    virtual void setupDynamicPlaylists();
    virtual void setDynamicListsFrozen(bool frozen);
136

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

140 141 142
signals:
    void signalPlaylistDestroyed(Playlist*);

143
private:
144 145
    QMap<QString, PlaylistBox::Item*> m_searchCategories;
    QMap<QString, TreeViewItemPlaylist*> m_treeViewItems;
146
    QStringList m_pendingItemsToRemove;
147 148 149 150
    bool m_dynamicListsFrozen;
    bool m_setup;
};

151
#endif
152 153

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