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.38 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

Laurent Montel's avatar
Laurent Montel committed
20
#include <q3hbox.h>
21
#include <QLabel>
Laurent Montel's avatar
Laurent Montel committed
22 23 24 25 26
#include <qpointer.h>
#include <QMouseEvent>
#include <QDragEnterEvent>
#include <Q3ValueList>
#include <QDropEvent>
27

28
#include "filehandle.h"
29
#include "playlist.h"
30

31
class QTimer;
32
class QPoint;
33

34
class NowPlayingItem;
35
class PlaylistCollection;
36
class Playlist;
37 38 39 40 41 42

/**
 * 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
43
class NowPlaying : public Q3HBox
44 45 46 47
{
    Q_OBJECT

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

private slots:
54
    void slotUpdate();
55 56

private:
57 58 59 60 61 62 63 64 65
    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;
    };
66
    friend struct Observer;
67 68

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

73 74 75
/**
 * Abstract base for the other NowPlaying items.
 */
76

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

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

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

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

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

114 115 116 117
/**
 * A link label that doesn't automatically open Konqueror.
 */

Tim Beaulen's avatar
Tim Beaulen committed
118
class LinkLabel : public QLabel
119 120
{
public:
Tim Beaulen's avatar
Tim Beaulen committed
121
    LinkLabel(QWidget *parent) : QLabel(parent) {}
122 123 124
    virtual void openLink(const QString &) {}
};

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

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

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

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

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

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

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

160 161 162
private slots:
    void slotAddPlaying();

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

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

#endif
182 183

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