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 3.63 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

21 22
#include <qhbox.h>
#include <qlabel.h>
23
#include <qguardedptr.h>
24

25
#include "filehandle.h"
26
#include "playlist.h"
27 28

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

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

class NowPlaying : public QHBox
38 39 40 41
{
    Q_OBJECT

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

private slots:
48
    void slotUpdate();
49 50

private:
51
    PlaylistCollection *m_collection;
52 53
    QValueList<NowPlayingItem *> m_items;
};
54

55 56 57
/**
 * Abstract base for the other NowPlaying items.
 */
58

59 60 61 62
class NowPlayingItem
{
public:
    virtual void update(const FileHandle &file) = 0;
63
    NowPlaying *parent() const { return m_parent; }
64
protected:
65 66 67
    NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
private:
    NowPlaying *m_parent;
68 69 70 71 72 73 74 75 76 77 78 79
};

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

82 83 84 85
protected:
    virtual void dragEnterEvent(QDragEnterEvent *e);
    virtual void dropEvent(QDropEvent *e);

86 87
private:
    FileHandle m_file;
88 89
};

90 91 92 93 94 95 96 97 98 99 100
/**
 * A link label that doesn't automatically open Konqueror.
 */

class LinkLabel : public KActiveLabel
{
public:
    LinkLabel(QWidget *parent, const char *name = 0) : KActiveLabel(parent, name) {}
    virtual void openLink(const QString &) {}
};

101 102 103 104 105 106 107
/**
 * 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
{
108 109
    Q_OBJECT

110 111 112 113
public:
    TrackItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);

114 115 116
private slots:
    void slotOpenLink(const QString &link);

117
private:
118
    FileHandle m_file;
119
    LinkLabel *m_label;
120 121 122 123 124 125
};

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

126
class HistoryItem : public LinkLabel, public NowPlayingItem
127 128 129 130
{
public:
    HistoryItem(NowPlaying *parent);
    virtual void update(const FileHandle &file);
131
    virtual void openLink(const QString &link);
132 133

private:
134 135 136 137 138 139 140 141 142 143 144 145
    struct Item
    {
        Item() {}
        Item(const QString &a, const FileHandle &f, Playlist *p)
            : anchor(a), file(f), playlist(p) {}

        QString anchor;
        FileHandle file;
        QGuardedPtr<Playlist> playlist;
    };

    QValueList<Item> m_history;
146
    LinkLabel *m_label;
147 148 149
};

#endif