nowplaying.h 4.17 KB
Newer Older
1
/***************************************************************************
2 3 4
    begin                : Tue Nov 9 2004
    copyright            : (C) 2004 by Scott Wheeler
    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 NOWPLAYING_H
#define NOWPLAYING_H

19
#include <QWidget>
20
#include <QLabel>
21 22
#include <QPointer>
#include <QList>
23

24
#include "filehandle.h"
25
#include "playlistinterface.h"
26

27
class QTimer;
28
class QPoint;
29

30
class NowPlayingItem;
31
class PlaylistCollection;
32
class Playlist;
33 34 35 36 37 38

/**
 * This is the widget that holds all of the other items and handles updating them
 * when the playing item changes.
 */

39
class NowPlaying : public QWidget
40 41 42 43
{
    Q_OBJECT

public:
44
    NowPlaying(QWidget *parent, PlaylistCollection *collection);
45
    void addItem(NowPlayingItem *item);
46
    PlaylistCollection *collection() const;
47

48 49 50
public slots:
    void slotUpdate(const FileHandle &file);
    void slotReloadCurrentItem();
51 52

private:
53 54 55 56 57 58
    struct Observer : public PlaylistObserver
    {
        Observer(NowPlaying *parent, PlaylistInterface *playlist) :
            PlaylistObserver(playlist),
            m_parent(parent) {}
        virtual void updateCurrent() {}
59
        virtual void updateData() { m_parent->slotReloadCurrentItem(); }
60 61
        NowPlaying *m_parent;
    };
62
    friend struct Observer;
63 64

    Observer m_observer;
65
    Observer m_collectionListObserver;
66
    PlaylistCollection *m_collection;
67
    QList<NowPlayingItem *> m_items;
68
    FileHandle m_file;
69
};
70

71 72 73
/**
 * Abstract base for the other NowPlaying items.
 */
74

75 76 77
class NowPlayingItem
{
public:
78
    virtual ~NowPlayingItem() {}
79
    virtual void update(const FileHandle &file) = 0;
80
    NowPlaying *parent() const { return m_parent; }
81
protected:
82 83 84
    NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
private:
    NowPlaying *m_parent;
85 86 87 88 89 90 91 92 93 94 95 96
};

/**
 * Displays the cover of the currently playing file if available, or hides
 * itself if not.
 */

class CoverItem : public QLabel, public NowPlayingItem
{
public:
    CoverItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
97
    virtual void mouseReleaseEvent(QMouseEvent *event);
98

99 100 101 102
protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);

103 104 105
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);

106 107
private:
    FileHandle m_file;
108 109
    bool m_dragging;
    QPoint m_dragStart;
110 111 112 113 114 115 116 117 118
};

/**
 * Show the text information on the current track and provides links to the
 * album and artist of the currently playing item.
 */

class TrackItem : public QWidget, public NowPlayingItem
{
119 120
    Q_OBJECT

121 122 123 124
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

125 126
private slots:
    void slotOpenLink(const QString &link);
127
    void slotUpdate();
128

129
private:
130
    FileHandle m_file;
131
    QLabel *m_label;
132 133 134 135 136 137
};

/**
 * Shows up to 10 items of history and links to those items.
 */

138
class HistoryItem : public QLabel, public NowPlayingItem
139
{
140 141
    Q_OBJECT

142 143 144
public:
    HistoryItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
145
    virtual void openLink(const QString &link);
146

147 148 149
private slots:
    void slotAddPlaying();

150
private:
151 152 153 154 155 156 157 158
    struct Item
    {
        Item() {}
        Item(const QString &a, const FileHandle &f, Playlist *p)
            : anchor(a), file(f), playlist(p) {}

        QString anchor;
        FileHandle file;
Laurent Montel's avatar
Laurent Montel committed
159
        QPointer<Playlist> playlist;
160 161
    };

162
    QList<Item> m_history;
163
    QLabel *m_label;
164 165
    QTimer *m_timer;
    FileHandle m_file;
166 167 168
};

#endif
169 170

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