nowplaying.h 3.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 * Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
16 17 18 19

#ifndef NOWPLAYING_H
#define NOWPLAYING_H

20
#include <QWidget>
21
#include <QLabel>
22 23
#include <QPointer>
#include <QList>
24

25
#include "filehandle.h"
26
#include "playlistinterface.h"
27

28
class QTimer;
29
class QPoint;
30

31
class NowPlayingItem;
32
class PlaylistCollection;
33
class Playlist;
34 35 36 37 38 39

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

40
class NowPlaying : public QWidget
41 42 43 44
{
    Q_OBJECT

public:
45
    NowPlaying(QWidget *parent, PlaylistCollection *collection);
46
    void addItem(NowPlayingItem *item);
47
    PlaylistCollection *collection() const;
48

49 50 51
public slots:
    void slotUpdate(const FileHandle &file);
    void slotReloadCurrentItem();
52

53 54 55
signals:
    void nowPlayingHidden();

56
private:
57
    struct Observer final
58
    {
59
        Observer(NowPlaying *parent, PlaylistInterface *playlist)
60
        {
61
            connect(&playlist->signaller, &PlaylistInterfaceSignaller::playingItemDataChanged, parent, &NowPlaying::slotReloadCurrentItem);
62
        }
63 64 65
    };

    Observer m_observer;
66
    Observer m_collectionListObserver;
67
    PlaylistCollection *m_collection;
68
    QList<NowPlayingItem *> m_items;
69
    FileHandle m_file;
70
};
71

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

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

/**
 * Displays the cover of the currently playing file if available, or hides
 * itself if not.
 */

class CoverItem : public QLabel, public NowPlayingItem
{
public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
96
    explicit CoverItem(NowPlaying *parent);
97 98
    virtual void update(const FileHandle &file) override;
    virtual void mouseReleaseEvent(QMouseEvent *event) override;
99

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

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

107 108
private:
    FileHandle m_file;
109 110
    bool m_dragging;
    QPoint m_dragStart;
111 112 113 114 115 116 117 118 119
};

/**
 * 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
{
120 121
    Q_OBJECT

122
public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
123
    explicit TrackItem(NowPlaying *parent);
124
    virtual void update(const FileHandle &file) override;
125

126 127
private slots:
    void slotOpenLink(const QString &link);
128
    void slotUpdate();
129
    void slotClearShowMore();
130

131
private:
132
    FileHandle m_file;
133
    QLabel *m_label;
134 135
};

136
#endif
137 138

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