Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

nowplaying.h 4.3 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 <Q3HBox>
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.
 */

Laurent Montel's avatar
Laurent Montel committed
39
class NowPlaying : public Q3HBox
40 41 42 43
{
    Q_OBJECT

public:
44 45
    NowPlaying(QWidget *parent, PlaylistCollection *collection,
               const char *name = 0);
46
    void addItem(NowPlayingItem *item);
47
    PlaylistCollection *collection() const;
48 49

private slots:
50
    void slotUpdate();
51 52

private:
53 54 55 56 57 58 59 60 61
    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;
    };
62
    friend struct Observer;
63 64

    Observer m_observer;
65
    PlaylistCollection *m_collection;
66
    QList<NowPlayingItem *> m_items;
67
};
68

69 70 71
/**
 * Abstract base for the other NowPlaying items.
 */
72

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

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

97 98 99 100
protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);

101 102 103
    virtual void mousePressEvent(QMouseEvent *e);
    virtual void mouseMoveEvent(QMouseEvent *e);

104 105
private:
    FileHandle m_file;
106 107
    bool m_dragging;
    QPoint m_dragStart;
108 109
};

110 111 112 113
/**
 * A link label that doesn't automatically open Konqueror.
 */

Tim Beaulen's avatar
Tim Beaulen committed
114
class LinkLabel : public QLabel
115 116
{
public:
Tim Beaulen's avatar
Tim Beaulen committed
117
    LinkLabel(QWidget *parent) : QLabel(parent) {}
118 119 120
    virtual void openLink(const QString &) {}
};

121 122 123 124 125 126 127
/**
 * 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
{
128 129
    Q_OBJECT

130 131 132 133
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

134 135
private slots:
    void slotOpenLink(const QString &link);
136
    void slotUpdate();
137

138
private:
139
    FileHandle m_file;
140
    LinkLabel *m_label;
141 142 143 144 145 146
};

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

147
class HistoryItem : public LinkLabel, public NowPlayingItem
148
{
149 150
    Q_OBJECT

151 152 153
public:
    HistoryItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
154
    virtual void openLink(const QString &link);
155

156 157 158
private slots:
    void slotAddPlaying();

159
private:
160 161 162 163 164 165 166 167
    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
168
        QPointer<Playlist> playlist;
169 170
    };

171
    QList<Item> m_history;
172
    LinkLabel *m_label;
173 174
    QTimer *m_timer;
    FileHandle m_file;
175 176 177
};

#endif
178 179

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