viewmode.h 4.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org>
 * Copyright (C) 2007 Michael Pyne <mpyne@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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17

18 19
#ifndef JUK_VIEWMODE_H
#define JUK_VIEWMODE_H
20

21 22 23
#include <QObject>
#include <QStringList>
#include <QMap>
24

25 26
#include "playlistbox.h"

27 28 29
class QPainter;
class QColorGroup;

30 31

class ViewMode : public QObject
32
{
33 34
    Q_OBJECT

35
public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
36
    explicit ViewMode(PlaylistBox *b);
37 38
    virtual ~ViewMode();

39
    virtual QString name() const;
40 41
    virtual void setShown(bool shown);

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

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

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

52
    virtual void setupDynamicPlaylists() {}
53

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

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

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

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

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

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

class CompactViewMode : public ViewMode
{
102 103
    Q_OBJECT

104
public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
105
    explicit CompactViewMode(PlaylistBox *b);
106
    virtual ~CompactViewMode();
107

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

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

116 117 118 119
    virtual void setupItem(PlaylistBox::Item *item) const override
    {
        item->setup();
    }
120
protected:
121
    virtual void updateHeights() override;
122 123 124 125
};

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

126 127
class TreeViewItemPlaylist;

128
class TreeViewMode final : public CompactViewMode
129
{
130 131
    Q_OBJECT

132
public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
133
    explicit TreeViewMode(PlaylistBox *l);
134 135
    virtual ~TreeViewMode();

136 137 138 139
    virtual QString name() const override;
    virtual void setShown(bool shown) override;
    virtual void setupDynamicPlaylists() override;
    virtual void setDynamicListsFrozen(bool frozen) override;
140

141 142
    virtual void removeItem(const QString &item, unsigned column) override;
    virtual void addItems(const QStringList &items, unsigned column) override;
143

144 145 146
signals:
    void signalPlaylistDestroyed(Playlist*);

147
private:
148 149
    QMap<QString, PlaylistBox::Item*> m_searchCategories;
    QMap<QString, TreeViewItemPlaylist*> m_treeViewItems;
150
    QStringList m_pendingItemsToRemove;
151 152 153 154
    bool m_dynamicListsFrozen;
    bool m_setup;
};

155
#endif
156 157

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