strawberry-audio-player-win.../src/widgets/playingwidget.h

155 lines
4.0 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2013-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef PLAYINGWIDGET_H
#define PLAYINGWIDGET_H
#include <memory>
#include <QtGlobal>
#include <QObject>
2018-02-27 18:06:05 +01:00
#include <QWidget>
#include <QString>
#include <QImage>
#include <QPixmap>
#include <QSize>
2020-02-09 02:29:35 +01:00
#include <QAction>
#include <QMovie>
2018-02-27 18:06:05 +01:00
#include "core/song.h"
#include "covermanager/albumcoverloaderoptions.h"
class QTimeLine;
class QTextDocument;
class QPainter;
class QMenu;
class QActionGroup;
class QContextMenuEvent;
class QDragEnterEvent;
class QDropEvent;
class QMouseEvent;
class QPaintEvent;
class QResizeEvent;
2018-02-27 18:06:05 +01:00
class AlbumCoverChoiceController;
class Application;
class PlayingWidget : public QWidget {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit PlayingWidget(QWidget *parent = nullptr);
2018-02-27 18:06:05 +01:00
void Init(Application *app, AlbumCoverChoiceController *album_cover_choice_controller);
2019-03-09 17:20:07 +01:00
bool IsEnabled() { return enabled_; }
2021-01-26 16:48:04 +01:00
void SetEnabled(const bool enabled);
2018-02-27 18:06:05 +01:00
void SetEnabled();
void SetDisabled();
2021-01-26 16:48:04 +01:00
void set_ideal_height(const int height);
2020-06-15 21:55:05 +02:00
QSize sizeHint() const override;
bool show_above_status_bar() const { return above_statusbar_action_->isChecked(); }
2018-02-27 18:06:05 +01:00
signals:
2018-02-27 18:06:05 +01:00
void ShowAboveStatusBarChanged(bool above);
public slots:
void Playing();
2018-02-27 18:06:05 +01:00
void Stopped();
void Error();
void SongChanged(const Song &song);
void SearchCoverInProgress();
2021-01-26 16:48:04 +01:00
void AlbumCoverLoaded(const Song &song, const QImage &image);
2018-02-27 18:06:05 +01:00
protected:
2020-06-15 21:55:05 +02:00
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent*) override;
void contextMenuEvent(QContextMenuEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent*) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dropEvent(QDropEvent *e) override;
2018-02-27 18:06:05 +01:00
2023-02-18 14:09:27 +01:00
private:
enum class Mode {
SmallSongDetails = 0,
LargeSongDetails = 1
};
private slots:
2021-01-26 16:48:04 +01:00
void Update() { update(); }
2023-02-18 14:09:27 +01:00
void SetMode(const Mode mode);
2021-01-26 16:48:04 +01:00
void ShowAboveStatusBar(const bool above);
void FitCoverWidth(const bool fit);
2018-02-27 18:06:05 +01:00
void AutomaticCoverSearchDone();
2021-01-26 16:48:04 +01:00
void SetHeight(const int height);
void FadePreviousTrack(const qreal value);
2018-02-27 18:06:05 +01:00
private:
static const char *kSettingsGroup;
static const int kPadding;
static const int kGradientHead;
static const int kGradientTail;
static const int kMaxCoverSize;
static const int kBottomOffset;
static const int kTopBorder;
2018-02-27 18:06:05 +01:00
Application *app_;
AlbumCoverChoiceController *album_cover_choice_controller_;
Mode mode_;
QMenu *menu_;
2021-01-26 16:48:04 +01:00
QAction *above_statusbar_action_;
2018-02-27 18:06:05 +01:00
QAction *fit_cover_width_action_;
bool enabled_;
bool visible_;
bool playing_;
2018-02-27 18:06:05 +01:00
bool active_;
int small_ideal_height_;
AlbumCoverLoaderOptions cover_loader_options_;
int total_height_;
bool fit_width_;
QTimeLine *timeline_show_hide_;
QTimeLine *timeline_fade_;
2018-02-27 18:06:05 +01:00
QTextDocument *details_;
qreal pixmap_previous_track_opacity_;
bool downloading_covers_;
2018-02-27 18:06:05 +01:00
Song song_;
Song song_playing_;
QImage image_current_;
QImage image_original_;
QPixmap pixmap_cover_;
QPixmap pixmap_previous_track_;
2018-02-27 18:06:05 +01:00
std::unique_ptr<QMovie> spinner_animation_;
2021-01-26 16:48:04 +01:00
void SetVisible(const bool visible);
void CreateModeAction(const Mode mode, const QString &text, QActionGroup *group);
void UpdateDetailsText();
void UpdateHeight();
void SetImage(const QImage &image);
void DrawContents(QPainter *p);
void ScaleCover();
void GetCoverAutomatically();
2018-02-27 18:06:05 +01:00
};
#endif // PLAYINGWIDGET_H