File indexing completed on 2023-05-30 11:30:48
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 <QLabel> 0021 #include <QList> 0022 #include <QWidget> 0023 0024 #include "filehandle.h" 0025 #include "playlistinterface.h" 0026 0027 class QTimer; 0028 class QPoint; 0029 0030 class NowPlayingItem; 0031 class PlaylistCollection; 0032 class Playlist; 0033 0034 /** 0035 * This is the widget that holds all of the other items and handles updating them 0036 * when the playing item changes. 0037 */ 0038 0039 class NowPlaying : public QWidget 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 NowPlaying(QWidget *parent, PlaylistCollection *collection); 0045 void addItem(NowPlayingItem *item); 0046 PlaylistCollection *collection() const; 0047 0048 public slots: 0049 void slotUpdate(const FileHandle &file); 0050 void slotReloadCurrentItem(); 0051 0052 signals: 0053 void nowPlayingHidden(); 0054 0055 private: 0056 struct Observer final 0057 { 0058 Observer(NowPlaying *parent, PlaylistInterface *playlist) 0059 { 0060 connect(&playlist->signaller, &PlaylistInterfaceSignaller::playingItemDataChanged, parent, &NowPlaying::slotReloadCurrentItem); 0061 } 0062 }; 0063 0064 Observer m_observer; 0065 Observer m_collectionListObserver; 0066 PlaylistCollection *m_collection; 0067 QList<NowPlayingItem *> m_items; 0068 FileHandle m_file; 0069 }; 0070 0071 /** 0072 * Abstract base for the other NowPlaying items. 0073 */ 0074 0075 class NowPlayingItem 0076 { 0077 public: 0078 virtual ~NowPlayingItem() {} 0079 virtual void update(const FileHandle &file) = 0; 0080 NowPlaying *parentManager() const { return m_parent; } 0081 protected: 0082 NowPlayingItem(NowPlaying *parent) : m_parent(parent) { parent->addItem(this); } 0083 private: 0084 NowPlaying *m_parent; 0085 }; 0086 0087 /** 0088 * Displays the cover of the currently playing file if available, or hides 0089 * itself if not. 0090 */ 0091 0092 class CoverItem : public QLabel, public NowPlayingItem 0093 { 0094 public: 0095 explicit CoverItem(NowPlaying *parent); 0096 virtual void update(const FileHandle &file) override; 0097 virtual void mouseReleaseEvent(QMouseEvent *event) override; 0098 0099 protected: 0100 virtual void dragEnterEvent(QDragEnterEvent *e) override; 0101 virtual void dropEvent(QDropEvent *e) override; 0102 0103 virtual void mousePressEvent(QMouseEvent *e) override; 0104 virtual void mouseMoveEvent(QMouseEvent *e) override; 0105 0106 private: 0107 FileHandle m_file; 0108 bool m_dragging; 0109 QPoint m_dragStart; 0110 }; 0111 0112 /** 0113 * Show the text information on the current track and provides links to the 0114 * album and artist of the currently playing item. 0115 */ 0116 0117 class TrackItem : public QWidget, public NowPlayingItem 0118 { 0119 Q_OBJECT 0120 0121 public: 0122 explicit TrackItem(NowPlaying *parent); 0123 virtual void update(const FileHandle &file) override; 0124 0125 private slots: 0126 void slotOpenLink(const QString &link); 0127 void slotUpdate(); 0128 void slotClearShowMore(); 0129 0130 private: 0131 FileHandle m_file; 0132 QLabel *m_label; 0133 }; 0134 0135 #endif 0136 0137 // vim: set et sw=4 tw=0 sta: