nowplaying.h 3.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 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 NOWPLAYING_H
#define NOWPLAYING_H

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

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

28
class QTimer;
29
class QPoint;
30

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

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

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

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

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

53 54 55
signals:
    void nowPlayingHidden();

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

    Observer m_observer;
69
    Observer m_collectionListObserver;
70
    PlaylistCollection *m_collection;
71
    QList<NowPlayingItem *> m_items;
72
    FileHandle m_file;
73
};
74

75 76 77
/**
 * Abstract base for the other NowPlaying items.
 */
78

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

/**
 * 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);
101
    virtual void mouseReleaseEvent(QMouseEvent *event);
102

103 104 105 106
protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);

107 108 109
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);

110 111
private:
    FileHandle m_file;
112 113
    bool m_dragging;
    QPoint m_dragStart;
114 115 116 117 118 119 120 121 122
};

/**
 * 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
{
123 124
    Q_OBJECT

125 126 127 128
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

129 130
private slots:
    void slotOpenLink(const QString &link);
131
    void slotUpdate();
132
    void slotClearShowMore();
133

134
private:
135
    FileHandle m_file;
136
    QLabel *m_label;
137 138
};

139
#endif
140 141

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