playlistbox.h 5.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2002-2004 Scott Wheeler <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.
 *
 * 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/>.
 */
16 17 18 19

#ifndef PLAYLISTBOX_H
#define PLAYLISTBOX_H

20 21
#include "playlistcollection.h"

22
#include <QHash>
23
#include <QTreeWidget>
24

25
class Playlist;
26
class PlaylistItem;
27
class ViewMode;
28

Michael Pyne's avatar
Michael Pyne committed
29
class QMenu;
Nadeem Hasan's avatar
Nadeem Hasan committed
30

31
template<class T>
32
class QVector;
33

34
typedef QVector<Playlist *> PlaylistList;
35

36
/**
37
 * This is the play list selection box that is by default on the left side of
38
 * JuK's main widget (PlaylistSplitter).
39
 */
40

41
class PlaylistBox final : public QTreeWidget, public PlaylistCollection
42 43
{
    Q_OBJECT
44

45
public:
46
    class Item;
47
    typedef QList<Item *> ItemList;
48

49 50
    friend class Item;

51
    PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget *playlistStack);
52
    virtual ~PlaylistBox();
53

54 55 56
    virtual void raise(Playlist *playlist) override;
    virtual void duplicate() override;
    virtual void remove() override;
57

58 59
    // Called after files loaded to pickup any new files that might be present
    // in managed directories.
60
    virtual void scanFolders() override;
61

62 63 64 65
    /**
     * For view modes that have dynamic playlists, this freezes them from
     * removing playlists.
     */
66
    virtual void setDynamicListsFrozen(bool frozen) override;
67

68 69
    Item *dropItem() const { return m_dropItem; }

70
    void setupPlaylist(Playlist *playlist, const QString &iconName, Item *parentItem = nullptr);
71

72
public slots:
73
    void paste();
74 75
    void clear() {}

76 77
    void slotFreezePlaylists();
    void slotUnfreezePlaylists();
78
    void slotPlaylistDataChanged();
79
    void slotSetHistoryPlaylistEnabled(bool enable);
80

81
protected:
82 83
    virtual void setupPlaylist(Playlist *playlist, const QString &iconName) override;
    virtual void removePlaylist(Playlist *playlist) override;
84

85 86
signals:
    void signalPlaylistDestroyed(Playlist *);
87
    void signalMoveFocusAway(); // Handles keyboard scrolling up out of playlist
Michael Pyne's avatar
Michael Pyne committed
88
    void startupComplete(); ///< Emitted after playlists are loaded.
89
    void startFilePlayback(const FileHandle &file);
90

91
private:
92 93 94
    void readConfig();
    void saveConfig();

95 96 97 98
    virtual void mousePressEvent(QMouseEvent *e) override;
    virtual void mouseReleaseEvent(QMouseEvent *e) override;
    virtual void keyPressEvent(QKeyEvent *e) override;
    virtual void keyReleaseEvent(QKeyEvent *e) override;
99

100 101 102
    // selectedItems already used for something different

    ItemList selectedBoxItems() const;
103
    void setSingleItem(QTreeWidgetItem *item);
104

105
    void setupItem(Item *item);
106
    void setupUpcomingPlaylist();
107 108
    int viewModeIndex() const { return m_viewModeIndex; }
    ViewMode *viewMode() const { return m_viewModes[m_viewModeIndex]; }
109

110
private slots:
111
    /**
112
     * Catches QListBox::currentChanged(QListBoxItem *), does a cast and then re-emits
113
     * the signal as currentChanged(Item *).
114
     */
115
    void slotPlaylistChanged();
116
    void slotDoubleClicked(QTreeWidgetItem *);
117
    void slotShowContextMenu(const QPoint &point);
118
    void slotSetViewMode(int index);
119
    void slotSavePlaylists();
120 121 122
    void slotShowDropTarget();

    void slotPlaylistItemsDropped(Playlist *p);
123

124 125 126
    void slotAddItem(const QString &tag, unsigned column);
    void slotRemoveItem(const QString &tag, unsigned column);

Michael Pyne's avatar
Michael Pyne committed
127 128 129
    // Used to load the playlists after GUI setup.
    void slotLoadCachedPlaylists();

130
private:
Michael Pyne's avatar
Michael Pyne committed
131
    QMenu *m_contextMenu;
132
    QHash<Playlist *, Item*> m_playlistDict;
133
    int m_viewModeIndex;
134
    QList<ViewMode *> m_viewModes;
135
    bool m_hasSelection;
136
    bool m_doingMultiSelect;
137
    Item *m_dropItem;
138
    QTimer *m_showTimer;
139
    QTimer *m_savePlaylistTimer;
140 141
};

142
class PlaylistBox::Item final : public QObject, public QTreeWidgetItem, public PlaylistObserver
143
{
144
    friend class PlaylistBox;
145
    friend class PlaylistSplitter;
146 147
    friend class ViewMode;
    friend class CompactViewMode;
148
    friend class TreeViewMode;
149

150 151
    Q_OBJECT

152 153 154 155
    // moc won't let me create private QObject subclasses and Qt won't let me
    // make the destructor protected, so here's the closest hack that will
    // compile.

156
public:
157
    virtual ~Item();
158

159
protected:
160 161
    using QTreeWidgetItem::text;

162
    Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l = 0);
163
    Item(Item *parent, const QString &icon, const QString &text, Playlist *l = 0);
164

165
    Playlist *playlist() const { return m_playlist; }
166
    PlaylistBox *listView() const { return static_cast<PlaylistBox *>(QTreeWidgetItem::treeWidget()); }
167
    QString iconName() const { return m_iconName; }
168
    QString text() const { return QTreeWidgetItem::text(0); }
169
    void setSortedFirst(bool first = true) { m_sortedFirst = first; }
170

171 172
    /*virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align);
    virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}*/
173

174 175
    virtual void setup();

176
    static Item *collectionItem() { return m_collectionItem; }
177
    static void setCollectionItem(Item *item) { m_collectionItem = item; }
178

179 180 181 182
    //
    // Reimplemented from PlaylistObserver
    //

183
    virtual void playingItemHasChanged() override;
184 185

    // Used to post a timer in PlaylistBox to save playlists.
186
    virtual void playlistItemDataHasChanged() override;
187

188

189 190 191
protected slots:
    void slotSetName(const QString &name);

192
private:
193 194
    // setup() was already taken.
    void init();
195
    QString sortTextFor(const QString &name) const;
196

197 198
    Playlist *m_playlist;
    QString m_iconName;
199
    bool m_sortedFirst;
200
    static Item *m_collectionItem;
201 202 203
};

#endif
204 205

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