playlistbox.h 5.74 KB
Newer Older
1 2
/***************************************************************************
    begin                : Thu Sep 12 2002
3
    copyright            : (C) 2002 - 2004 by Scott Wheeler
4
    email                : wheeler@kde.org
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 PLAYLISTBOX_H
#define PLAYLISTBOX_H

19 20
#include "playlistcollection.h"

Laurent Montel's avatar
Laurent Montel committed
21
#include <k3listview.h>
22

Laurent Montel's avatar
Laurent Montel committed
23
#include <q3ptrdict.h>
24

Laurent Montel's avatar
Laurent Montel committed
25 26 27 28 29 30
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QKeyEvent>
#include <QDropEvent>
#include <Q3ValueList>
#include <QMouseEvent>
31

32
class Playlist;
33
class PlaylistItem;
34
class ViewMode;
35 36
class PlaylistSearch;
class SearchPlaylist;
37

Laurent Montel's avatar
Laurent Montel committed
38
class KMenu;
39
class KSelectAction;
Nadeem Hasan's avatar
Nadeem Hasan committed
40

Laurent Montel's avatar
Laurent Montel committed
41
typedef Q3ValueList<Playlist *> PlaylistList;
42

43
/**
44
 * This is the play list selection box that is by default on the right side of
45
 * JuK's main widget (PlaylistSplitter).
46
 */
47

Laurent Montel's avatar
Laurent Montel committed
48
class PlaylistBox : public K3ListView, public PlaylistCollection
49 50
{
    Q_OBJECT
51

52
public:
53
    class Item;
Laurent Montel's avatar
Laurent Montel committed
54
    typedef Q3ValueList<Item *> ItemList;
55

56 57
    friend class Item;

58
    PlaylistBox(QWidget *parent, Q3WidgetStack *playlistStack);
59
    virtual ~PlaylistBox();
60

61 62 63
    virtual void raise(Playlist *playlist);
    virtual void duplicate();
    virtual void remove();
64

65 66 67 68 69
    /**
     * For view modes that have dynamic playlists, this freezes them from
     * removing playlists.
     */
    virtual void setDynamicListsFrozen(bool frozen);
70

71 72
    Item *dropItem() const { return m_dropItem; }

73 74
    void setupPlaylist(Playlist *playlist, const QString &iconName, Item *parentItem = 0);

75
public slots:
76
    void paste();
77 78
    void clear() {}

79 80 81
    void slotFreezePlaylists();
    void slotUnfreezePlaylists();

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

86 87 88
signals:
    void signalPlaylistDestroyed(Playlist *);

89
private:
90 91 92
    void readConfig();
    void saveConfig();

93
    virtual void decode(QMimeSource *s, Item *item);
94 95
    virtual void contentsDropEvent(QDropEvent *e);
    virtual void contentsDragMoveEvent(QDragMoveEvent *e);
96
    virtual void contentsDragLeaveEvent(QDragLeaveEvent *e);
97 98
    virtual void contentsMousePressEvent(QMouseEvent *e);
    virtual void contentsMouseReleaseEvent(QMouseEvent *e);
99 100
    virtual void keyPressEvent(QKeyEvent *e);
    virtual void keyReleaseEvent(QKeyEvent *e);
101

Laurent Montel's avatar
Laurent Montel committed
102 103
    Q3ValueList<Item *> selectedItems() const;
    void setSingleItem(Q3ListViewItem *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();
Laurent Montel's avatar
Laurent Montel committed
117
    void slotShowContextMenu(Q3ListViewItem *, const QPoint &point, int);
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);

127
private:
Laurent Montel's avatar
Laurent Montel committed
128
    KMenu *m_contextMenu;
Laurent Montel's avatar
Laurent Montel committed
129
    Q3PtrDict<Item> m_playlistDict;
130
    int m_viewModeIndex;
131
    QList<ViewMode *> m_viewModes;
132
    KAction *m_k3bAction;
133
    bool m_hasSelection;
134
    bool m_doingMultiSelect;
135
    Item *m_dropItem;
136
    QTimer *m_showTimer;
137 138
};

139 140


Laurent Montel's avatar
Laurent Montel committed
141
class PlaylistBox::Item : public QObject, public K3ListViewItem
142
{
143
    friend class PlaylistBox;
144 145
    friend class ViewMode;
    friend class CompactViewMode;
146
    friend class TreeViewMode;
147

148 149
    Q_OBJECT

150 151 152 153
    // 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.

154
public:
155
    virtual ~Item();
156

157
protected:
158
    Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l = 0);
159
    Item(Item *parent, const QString &icon, const QString &text, Playlist *l = 0);
160

161
    Playlist *playlist() const { return m_playlist; }
Laurent Montel's avatar
Laurent Montel committed
162
    PlaylistBox *listView() const { return static_cast<PlaylistBox *>(K3ListViewItem::listView()); }
163
    QString iconName() const { return m_iconName; }
164
    QString text() const { return m_text; }
165
    void setSortedFirst(bool first = true) { m_sortedFirst = first; }
166

Laurent Montel's avatar
Laurent Montel committed
167
    virtual int compare(Q3ListViewItem *i, int col, bool) const;
168
    virtual void paintCell(QPainter *p, const QColorGroup &colorGroup, int column, int width, int align);
169
    virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}
170
    virtual void setText(int column, const QString &text);
171

Laurent Montel's avatar
Laurent Montel committed
172
    virtual QString text(int column) const { return K3ListViewItem::text(column); }
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
protected slots:
    void slotSetName(const QString &name);

183
private:
184 185 186
    // setup() was already taken.
    void init();

187
    Playlist *m_playlist;
188
    QString m_text;
189
    QString m_iconName;
190
    bool m_sortedFirst;
191
    static Item *m_collectionItem;
192 193 194
};

#endif
195 196

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