File indexing completed on 2021-12-21 13:27:55

0001 /**
0002  * Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
0003  *
0004  * This program is free software; you can redistribute it and/or modify it under
0005  * the terms of the GNU General Public License as published by the Free Software
0006  * Foundation; either version 2 of the License, or (at your option) any later
0007  * version.
0008  *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0012  *
0013  * You should have received a copy of the GNU General Public License along with
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.
0015  */
0016 
0017 #ifndef NOWPLAYING_H
0018 #define NOWPLAYING_H
0019 
0020 #include <QWidget>
0021 #include <QLabel>
0022 #include <QPointer>
0023 #include <QList>
0024 
0025 #include "filehandle.h"
0026 #include "playlistinterface.h"
0027 
0028 class QTimer;
0029 class QPoint;
0030 
0031 class NowPlayingItem;
0032 class PlaylistCollection;
0033 class Playlist;
0034 
0035 /**
0036  * This is the widget that holds all of the other items and handles updating them
0037  * when the playing item changes.
0038  */
0039 
0040 class NowPlaying : public QWidget
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     NowPlaying(QWidget *parent, PlaylistCollection *collection);
0046     void addItem(NowPlayingItem *item);
0047     PlaylistCollection *collection() const;
0048 
0049 public slots:
0050     void slotUpdate(const FileHandle &file);
0051     void slotReloadCurrentItem();
0052 
0053 signals:
0054     void nowPlayingHidden();
0055 
0056 private:
0057     struct Observer final
0058     {
0059         Observer(NowPlaying *parent, PlaylistInterface *playlist)
0060         {
0061             connect(&playlist->signaller, &PlaylistInterfaceSignaller::playingItemDataChanged, parent, &NowPlaying::slotReloadCurrentItem);
0062         }
0063     };
0064 
0065     Observer m_observer;
0066     Observer m_collectionListObserver;
0067     PlaylistCollection *m_collection;
0068     QList<NowPlayingItem *> m_items;
0069     FileHandle m_file;
0070 };
0071 
0072 /**
0073  * Abstract base for the other NowPlaying items.
0074  */
0075 
0076 class NowPlayingItem
0077 {
0078 public:
0079     virtual ~NowPlayingItem() {}
0080     virtual void update(const FileHandle &file) = 0;
0081     NowPlaying *parentManager() const { return m_parent; }
0082 protected:
0083     NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); }
0084 private:
0085     NowPlaying *m_parent;
0086 };
0087 
0088 /**
0089  * Displays the cover of the currently playing file if available, or hides
0090  * itself if not.
0091  */
0092 
0093 class CoverItem : public QLabel, public NowPlayingItem
0094 {
0095 public:
0096     explicit CoverItem(NowPlaying *parent);
0097     virtual void update(const FileHandle &file) override;
0098     virtual void mouseReleaseEvent(QMouseEvent *event) override;
0099 
0100 protected:
0101     virtual void dragEnterEvent(QDragEnterEvent *e) override;
0102     virtual void dropEvent(QDropEvent *e) override;
0103 
0104     virtual void mousePressEvent(QMouseEvent *e) override;
0105     virtual void mouseMoveEvent(QMouseEvent *e) override;
0106 
0107 private:
0108     FileHandle m_file;
0109     bool m_dragging;
0110     QPoint m_dragStart;
0111 };
0112 
0113 /**
0114  * Show the text information on the current track and provides links to the
0115  * album and artist of the currently playing item.
0116  */
0117 
0118 class TrackItem : public QWidget, public NowPlayingItem
0119 {
0120     Q_OBJECT
0121 
0122 public:
0123     explicit TrackItem(NowPlaying *parent);
0124     virtual void update(const FileHandle &file) override;
0125 
0126 private slots:
0127     void slotOpenLink(const QString &link);
0128     void slotUpdate();
0129     void slotClearShowMore();
0130 
0131 private:
0132     FileHandle m_file;
0133     QLabel *m_label;
0134 };
0135 
0136 #endif
0137 
0138 // vim: set et sw=4 tw=0 sta: