1 /* This file is part of Clementine. 2 Copyright 2010, David Sansome <me@davidsansome.com> 3 4 Clementine is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 Clementine is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef NOWPLAYINGWIDGET_H 19 #define NOWPLAYINGWIDGET_H 20 21 #include <memory> 22 23 #include <QWidget> 24 25 #include "core/song.h" 26 #include "covers/albumcoverloaderoptions.h" 27 28 class AlbumCoverChoiceController; 29 class Application; 30 class FullscreenHypnotoad; 31 class KittenLoader; 32 33 class QAction; 34 class QActionGroup; 35 class QMenu; 36 class QMovie; 37 class QTextDocument; 38 class QTimeLine; 39 40 class NowPlayingWidget : public QWidget { 41 Q_OBJECT 42 43 public: 44 NowPlayingWidget(QWidget* parent = nullptr); 45 ~NowPlayingWidget(); 46 47 static const char* kSettingsGroup; 48 static const int kPadding; 49 static const int kGradientHead; 50 static const int kGradientTail; 51 static const int kMaxCoverSize; 52 static const int kBottomOffset; 53 static const int kTopBorder; 54 55 // Values are saved in QSettings 56 enum Mode { 57 SmallSongDetails = 0, 58 LargeSongDetails = 1, 59 LargeSongDetailsBelow = 2, 60 LargeNoSongDetails = 3, 61 }; 62 63 void SetApplication(Application* app); 64 65 void set_ideal_height(int height); 66 bool show_above_status_bar() const; 67 68 QSize sizeHint() const; 69 70 signals: 71 void ShowAboveStatusBarChanged(bool above); 72 73 public slots: 74 void Stopped(); 75 void AllHail(bool hypnotoad); 76 void EnableKittens(bool aww); 77 78 protected: 79 void paintEvent(QPaintEvent* e); 80 void resizeEvent(QResizeEvent*); 81 void contextMenuEvent(QContextMenuEvent* e); 82 void mouseReleaseEvent(QMouseEvent*); 83 void dragEnterEvent(QDragEnterEvent* e); 84 void dropEvent(QDropEvent* e); 85 86 private slots: 87 void SetMode(int mode); 88 void ShowAboveStatusBar(bool above); 89 void FitCoverWidth(bool fit); 90 91 void AlbumArtLoaded(const Song& metadata, const QString& uri, 92 const QImage& image); 93 void KittenLoaded(quint64 id, const QImage& image); 94 95 void SetVisible(bool visible); 96 void SetHeight(int height); 97 98 void FadePreviousTrack(qreal value); 99 100 void LoadCoverFromFile(); 101 void SaveCoverToFile(); 102 void LoadCoverFromURL(); 103 void SearchForCover(); 104 void UnsetCover(); 105 void ShowCover(); 106 void SearchCoverAutomatically(); 107 108 void Bask(); 109 110 void AutomaticCoverSearchDone(); 111 112 private: 113 void CreateModeAction(Mode mode, const QString& text, QActionGroup* group); 114 void UpdateDetailsText(); 115 void UpdateHeight(); 116 void DrawContents(QPainter* p); 117 void SetImage(const QImage& image); 118 void ScaleCover(); 119 bool GetCoverAutomatically(); 120 121 private: 122 Application* app_; 123 AlbumCoverChoiceController* album_cover_choice_controller_; 124 125 Mode mode_; 126 127 QMenu* menu_; 128 129 QAction* above_statusbar_action_; 130 QAction* fit_cover_width_action_; 131 132 bool visible_; 133 int small_ideal_height_; 134 AlbumCoverLoaderOptions cover_loader_options_; 135 int total_height_; 136 bool fit_width_; 137 QTimeLine* show_hide_animation_; 138 QTimeLine* fade_animation_; 139 140 // Information about the current track 141 Song metadata_; 142 QPixmap cover_; 143 // A copy of the original, unscaled album cover. 144 QImage original_; 145 QTextDocument* details_; 146 147 // Holds the last track while we're fading to the new track 148 QPixmap previous_track_; 149 qreal previous_track_opacity_; 150 151 static const char* kHypnotoadPath; 152 QAction* bask_in_his_glory_action_; 153 std::unique_ptr<QMovie> hypnotoad_; 154 std::unique_ptr<FullscreenHypnotoad> big_hypnotoad_; 155 156 std::unique_ptr<QMovie> spinner_animation_; 157 bool downloading_covers_; 158 159 bool aww_; 160 KittenLoader* kittens_; 161 quint64 pending_kitten_; 162 }; 163 164 #endif // NOWPLAYINGWIDGET_H 165