nowplaying.h 4.41 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 <kactivelabel.h>
20

Laurent Montel's avatar
Laurent Montel committed
21
#include <q3hbox.h>
22
#include <qlabel.h>
Laurent Montel's avatar
Laurent Montel committed
23 24 25 26 27 28
#include <qpointer.h>
//Added by qt3to4:
#include <QMouseEvent>
#include <QDragEnterEvent>
#include <Q3ValueList>
#include <QDropEvent>
29

30
#include "filehandle.h"
31
#include "playlist.h"
32

33
class QTimer;
34
class QPoint;
35

36
class NowPlayingItem;
37
class PlaylistCollection;
38
class Playlist;
39 40 41 42 43 44

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

Laurent Montel's avatar
Laurent Montel committed
45
class NowPlaying : public Q3HBox
46 47 48 49
{
    Q_OBJECT

public:
50 51
    NowPlaying(QWidget *parent, PlaylistCollection *collection,
               const char *name = 0);
52
    void addItem(NowPlayingItem *item);
53
    PlaylistCollection *collection() const;
54 55

private slots:
56
    void slotUpdate();
57 58

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

    Observer m_observer;
71
    PlaylistCollection *m_collection;
Laurent Montel's avatar
Laurent Montel committed
72
    Q3ValueList<NowPlayingItem *> m_items;
73
};
74

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

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

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

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

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

109 110
private:
    FileHandle m_file;
111 112
    bool m_dragging;
    QPoint m_dragStart;
113 114
};

115 116 117 118 119 120 121
/**
 * A link label that doesn't automatically open Konqueror.
 */

class LinkLabel : public KActiveLabel
{
public:
122
    LinkLabel(QWidget *parent) : KActiveLabel(parent) {}
123 124 125
    virtual void openLink(const QString &) {}
};

126 127 128 129 130 131 132
/**
 * 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
{
133 134
    Q_OBJECT

135 136 137 138
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

139 140
private slots:
    void slotOpenLink(const QString &link);
141
    void slotUpdate();
142

143
private:
144
    FileHandle m_file;
145
    LinkLabel *m_label;
146 147 148 149 150 151
};

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

152
class HistoryItem : public LinkLabel, public NowPlayingItem
153
{
154 155
    Q_OBJECT

156 157 158
public:
    HistoryItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
159
    virtual void openLink(const QString &link);
160

161 162 163
private slots:
    void slotAddPlaying();

164
private:
165 166 167 168 169 170 171 172
    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
173
        QPointer<Playlist> playlist;
174 175
    };

Laurent Montel's avatar
Laurent Montel committed
176
    Q3ValueList<Item> m_history;
177
    LinkLabel *m_label;
178 179
    QTimer *m_timer;
    FileHandle m_file;
180 181 182
};

#endif
183 184

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