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.44 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
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
/**
 * A link label that doesn't automatically open Konqueror.
 */

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

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

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

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

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

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

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

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

162 163 164
private slots:
    void slotAddPlaying();

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

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

#endif
184 185

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