diff --git a/data/style/strawberry.css b/data/style/strawberry.css index 68953158e..cda600d42 100644 --- a/data/style/strawberry.css +++ b/data/style/strawberry.css @@ -52,19 +52,14 @@ macos QMenu { font-size: 13pt; } -#scrollarea_play { +#context-layout-container { background-color: %palette-base; - font: 11pt; } -#scrollarea_stop { +#context-widget-scrollarea { background-color: %palette-base; - font: 11pt; } -#scrollAreaWidgetContents_stop { - background-color: %palette-base; -} -#scrollAreaWidgetContents_play { +#context-layout-scrollarea { background-color: %palette-base; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9dd0db50..112ddc0c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -154,6 +154,7 @@ set(SOURCES equalizer/equalizerslider.cpp context/contextview.cpp + context/contextalbum.cpp context/contextalbumsmodel.cpp context/contextalbumsview.cpp @@ -347,6 +348,7 @@ set(HEADERS equalizer/equalizerslider.h context/contextview.h + context/contextalbum.h context/contextalbumsmodel.h context/contextalbumsview.h @@ -500,8 +502,6 @@ set(UI core/mainwindow.ui - context/contextviewcontainer.ui - collection/groupbydialog.ui collection/collectionfilterwidget.ui collection/collectionviewcontainer.ui diff --git a/src/context/contextalbum.cpp b/src/context/contextalbum.cpp new file mode 100644 index 000000000..0bce1e1af --- /dev/null +++ b/src/context/contextalbum.cpp @@ -0,0 +1,177 @@ +/* + * Strawberry Music Player + * Copyright 2020, Jonas Kvinge + * + * 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 . + * + */ + +#include "config.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "covermanager/albumcoverchoicecontroller.h" +#include "covermanager/albumcoverloader.h" + +#include "contextalbum.h" + +const int ContextAlbum::kWidgetSpacing = 40; + +ContextAlbum::ContextAlbum(QWidget *parent) : + QWidget(parent), + album_cover_choice_controller_(nullptr), + downloading_covers_(false), + timeline_fade_(new QTimeLine(1000, this)), + image_strawberry_(":/pictures/strawberry.png"), + image_original_(image_strawberry_), + prev_width_(width()) { + + setObjectName("context-widget-album"); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + cover_loader_options_.desired_height_ = 600; + cover_loader_options_.pad_output_image_ = true; + cover_loader_options_.scale_output_image_ = true; + pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_strawberry_)); + + connect(timeline_fade_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousTrack(qreal))); + timeline_fade_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0 + +} + +void ContextAlbum::Init(AlbumCoverChoiceController *album_cover_choice_controller) { + + album_cover_choice_controller_ = album_cover_choice_controller; + connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); + +} + +void ContextAlbum::paintEvent(QPaintEvent*) { + + QPainter p(this); + + DrawImage(&p); + + // Draw the previous track's image if we're fading + if (!pixmap_previous_.isNull()) { + p.setOpacity(pixmap_previous_opacity_); + p.drawPixmap(0, 0, pixmap_previous_); + } + +} + +void ContextAlbum::DrawImage(QPainter *p) { + + if (width() != prev_width_) { + cover_loader_options_.desired_height_ = width() - kWidgetSpacing; + pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_original_)); + prev_width_ = width(); + } + + p->drawPixmap(0, 0, width() - kWidgetSpacing, width() - kWidgetSpacing, pixmap_current_); + if (downloading_covers_ && spinner_animation_) { + p->drawPixmap(50, 50, 16, 16, spinner_animation_->currentPixmap()); + } + +} + +void ContextAlbum::FadePreviousTrack(const qreal value) { + + pixmap_previous_opacity_ = value; + if (qFuzzyCompare(pixmap_previous_opacity_, qreal(0.0))) { + image_previous_ = QImage(); + pixmap_previous_ = QPixmap(); + } + update(); + + if (value == 0 && image_original_ == image_strawberry_) { + emit FadeStopFinished(); + } + +} + +void ContextAlbum::ScaleCover() { + + cover_loader_options_.desired_height_ = width() - kWidgetSpacing; + pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_original_)); + prev_width_ = width(); + update(); + +} + +void ContextAlbum::SetImage(QImage image) { + + if (image.isNull()) image = image_strawberry_; + + if (downloading_covers_) { + downloading_covers_ = false; + spinner_animation_.reset(); + } + + // Cache the current pixmap so we can fade between them + pixmap_previous_ = QPixmap(width() - kWidgetSpacing, width() - kWidgetSpacing); + pixmap_previous_.fill(palette().window().color()); + pixmap_previous_opacity_ = 1.0; + + QPainter p(&pixmap_previous_); + DrawImage(&p); + p.end(); + + image_previous_ = image_original_; + image_original_ = image; + + ScaleCover(); + + // Were we waiting for this cover to load before we started fading? + if (!pixmap_previous_.isNull() && timeline_fade_) { + timeline_fade_->stop(); + timeline_fade_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0 + timeline_fade_->start(); + } + +} + +void ContextAlbum::SearchCoverInProgress() { + + downloading_covers_ = true; + + // Show a spinner animation + spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); + connect(spinner_animation_.get(), SIGNAL(updated(const QRect&)), SLOT(update())); + spinner_animation_->start(); + update(); + +} + +void ContextAlbum::AutomaticCoverSearchDone() { + + downloading_covers_ = false; + spinner_animation_.reset(); + update(); + +} diff --git a/src/context/contextalbum.h b/src/context/contextalbum.h new file mode 100644 index 000000000..43c51e6df --- /dev/null +++ b/src/context/contextalbum.h @@ -0,0 +1,84 @@ +/* + * Strawberry Music Player + * Copyright 2020, Jonas Kvinge + * + * 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 . + * + */ + +#ifndef CONTEXTALBUM_H +#define CONTEXTALBUM_H + +#include "config.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "covermanager/albumcoverloaderoptions.h" + +class QTimeLine; +class QPainter; +class QPaintEvent; + +class AlbumCoverChoiceController; + +class ContextAlbum : public QWidget { + Q_OBJECT + + public: + ContextAlbum(QWidget *parent = nullptr); + + void Init(AlbumCoverChoiceController *album_cover_choice_controller); + void SetImage(QImage image = QImage()); + + protected: + void paintEvent(QPaintEvent*); + + private: + void DrawImage(QPainter *p); + void ScaleCover(); + void GetCoverAutomatically(); + + signals: + void FadeStopFinished(); + + private slots: + void SearchCoverInProgress(); + void AutomaticCoverSearchDone(); + void FadePreviousTrack(const qreal value); + + private: + static const int kWidgetSpacing; + AlbumCoverChoiceController *album_cover_choice_controller_; + AlbumCoverLoaderOptions cover_loader_options_; + bool downloading_covers_; + QTimeLine *timeline_fade_; + QImage image_strawberry_; + QImage image_original_; + QImage image_previous_; + QPixmap pixmap_current_; + QPixmap pixmap_previous_; + qreal pixmap_previous_opacity_; + std::unique_ptr spinner_animation_; + int prev_width_; +}; + +#endif // CONTEXTALBUM_H diff --git a/src/context/contextalbumsmodel.cpp b/src/context/contextalbumsmodel.cpp index 9c500068d..07bdb7a3b 100644 --- a/src/context/contextalbumsmodel.cpp +++ b/src/context/contextalbumsmodel.cpp @@ -2,7 +2,7 @@ * Strawberry Music Player * This code was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2013, Jonas Kvinge + * Copyright 2013-2020, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/context/contextalbumsview.cpp b/src/context/contextalbumsview.cpp index 26dec0d71..21480e4fc 100644 --- a/src/context/contextalbumsview.cpp +++ b/src/context/contextalbumsview.cpp @@ -2,7 +2,7 @@ * Strawberry Music Player * This code was part of Clementine. * Copyright 2010, David Sansome - * Copyright 2013, Jonas Kvinge + * Copyright 2013-2020, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index 9d2455eaf..dd78f1b60 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -1,6 +1,6 @@ /* * Strawberry Music Player - * Copyright 2013, Jonas Kvinge + * Copyright 2013-2020, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,30 +22,29 @@ #include #include #include -#include #include #include #include #include #include -#include #include -#include -#include -#include -#include #include +#include #include #include -#include -#include -#include -#include #include -#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include "core/application.h" #include "core/player.h" @@ -61,49 +60,209 @@ #include "collection/collectionquery.h" #include "collection/collectionview.h" #include "covermanager/albumcoverchoicecontroller.h" -#include "covermanager/albumcoverloader.h" #include "lyrics/lyricsfetcher.h" #include "settings/contextsettingspage.h" #include "contextview.h" +#include "contextalbum.h" #include "contextalbumsmodel.h" #include "contextalbumsview.h" -#include "ui_contextviewcontainer.h" - -using std::unique_ptr; ContextView::ContextView(QWidget *parent) : QWidget(parent), - ui_(new Ui_ContextViewContainer), app_(nullptr), collectionview_(nullptr), album_cover_choice_controller_(nullptr), lyrics_fetcher_(nullptr), menu_(new QMenu(this)), - timeline_fade_(new QTimeLine(1000, this)), - image_strawberry_(":/pictures/strawberry.png"), - active_(false), - downloading_covers_(false), - lyrics_id_(-1) + action_show_album_(nullptr), + action_show_data_(nullptr), + action_show_output_(nullptr), + action_show_albums_(nullptr), + action_show_lyrics_(nullptr), + layout_container_(new QVBoxLayout()), + widget_scrollarea_(new QWidget(this)), + layout_scrollarea_(new QVBoxLayout()), + scrollarea_(new QScrollArea(this)), + label_top_(new QLabel(this)), + widget_album_(new ContextAlbum(this)), + widget_stacked_(new QStackedWidget(this)), + widget_stop_(new QWidget(this)), + widget_play_(new QWidget(this)), + layout_stop_(new QVBoxLayout()), + layout_play_(new QVBoxLayout()), + label_stop_summary_(new QLabel(this)), + spacer_stop_bottom_(new QSpacerItem(0, 20, QSizePolicy::Expanding, QSizePolicy::Expanding)), + widget_play_data_(new QWidget(this)), + widget_play_engine_device_(new QWidget(this)), + layout_play_data_(new QGridLayout()), + layout_play_output_(new QGridLayout()), + label_play_albums_(new QLabel(this)), + label_play_lyrics_(new QLabel(this)), + widget_albums_(new ContextAlbumsView(this)), + //spacer_play_album_(new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed)), + spacer_play_output_(new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed)), + spacer_play_data_(new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed)), + spacer_play_albums_(new QSpacerItem(20, 20, QSizePolicy::Fixed, QSizePolicy::Fixed)), + spacer_play_bottom_(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding)), + label_filetype_title_(new QLabel(this)), + label_length_title_(new QLabel(this)), + label_samplerate_title_(new QLabel(this)), + label_bitdepth_title_(new QLabel(this)), + label_bitrate_title_(new QLabel(this)), + label_filetype_(new QLabel(this)), + label_length_(new QLabel(this)), + label_samplerate_(new QLabel(this)), + label_bitdepth_(new QLabel(this)), + label_bitrate_(new QLabel(this)), + label_device_title_(new QLabel(this)), + label_engine_title_(new QLabel(this)), + label_device_space_(new QLabel(this)), + label_engine_space_(new QLabel(this)), + label_device_(new QLabel(this)), + label_engine_(new QLabel(this)), + label_device_icon_(new QLabel(this)), + label_engine_icon_(new QLabel(this)), + spacer_bottom_(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding)), + lyrics_id_(-1), + prev_width_(0) { - ui_->setupUi(this); - ui_->widget_stacked->setCurrentWidget(ui_->widget_stop); - ui_->label_play_album->installEventFilter(this); + setLayout(layout_container_); + + layout_container_->setObjectName("context-layout-container"); + layout_container_->setContentsMargins(0, 0, 0, 0); + layout_container_->addWidget(scrollarea_); + + scrollarea_->setObjectName("context-scrollarea"); + scrollarea_->setWidgetResizable(true); + scrollarea_->setWidget(widget_scrollarea_); + scrollarea_->setContentsMargins(0, 0, 0, 0); + scrollarea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + widget_scrollarea_->setObjectName("context-widget-scrollarea"); + widget_scrollarea_->setLayout(layout_scrollarea_); + widget_scrollarea_->setContentsMargins(0, 0, 0, 0); + + label_top_->setWordWrap(true); + label_top_->setAlignment(Qt::AlignTop|Qt::AlignLeft); + label_top_->setMinimumHeight(50); + + layout_scrollarea_->setObjectName("context-layout-scrollarea"); + layout_scrollarea_->setContentsMargins(15, 15, 15, 15); + layout_scrollarea_->addWidget(label_top_); + layout_scrollarea_->addWidget(widget_album_); + layout_scrollarea_->addWidget(widget_stacked_); + layout_scrollarea_->addSpacerItem(spacer_bottom_); + + widget_stacked_->setContentsMargins(0, 0, 0, 0); + widget_stacked_->addWidget(widget_stop_); + widget_stacked_->addWidget(widget_play_); + widget_stacked_->setCurrentWidget(widget_stop_); + + widget_stop_->setLayout(layout_stop_); + widget_stop_->setContentsMargins(0, 0, 0, 0); + widget_play_->setLayout(layout_play_); + widget_play_->setContentsMargins(0, 0, 0, 0); + + layout_stop_->setContentsMargins(0, 0, 0, 0); + layout_play_->setContentsMargins(0, 0, 0, 0); + + // Stopped + + layout_stop_->setContentsMargins(5, 0, 40, 0); + layout_stop_->addWidget(label_stop_summary_); + layout_stop_->addSpacerItem(spacer_stop_bottom_); + + // Playing + + label_engine_title_->setText(tr("Engine")); + label_device_title_->setText(tr("Device")); + label_engine_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_device_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_engine_space_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_device_space_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_engine_space_->setMinimumWidth(24); + label_device_space_->setMinimumWidth(24); + label_engine_icon_->setMinimumSize(32, 32); + label_device_icon_->setMaximumSize(32, 32); + label_engine_icon_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_device_icon_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + label_engine_->setWordWrap(true); + label_device_->setWordWrap(true); + + layout_play_output_->setContentsMargins(0, 0, 0, 0); + + layout_play_output_->addWidget(label_engine_title_, 0, 0); + layout_play_output_->addWidget(label_engine_space_, 0, 1); + layout_play_output_->addWidget(label_engine_icon_, 0, 2); + layout_play_output_->addWidget(label_engine_, 0, 3); + + layout_play_output_->addWidget(label_device_title_, 1, 0); + layout_play_output_->addWidget(label_device_space_, 1, 1); + layout_play_output_->addWidget(label_device_icon_, 1, 2); + layout_play_output_->addWidget(label_device_, 1, 3); + + widget_play_engine_device_->setLayout(layout_play_output_); + + label_filetype_title_->setText(tr("Filetype")); + label_length_title_->setText(tr("Length")); + label_samplerate_title_->setText(tr("Samplerate")); + label_bitdepth_title_->setText(tr("Bit depth")); + label_bitrate_title_->setText(tr("Bitrate")); + + label_filetype_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_length_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_samplerate_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_bitdepth_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + label_bitrate_title_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + + label_filetype_->setWordWrap(true); + label_length_->setWordWrap(true); + label_samplerate_->setWordWrap(true); + label_bitdepth_->setWordWrap(true); + label_bitrate_->setWordWrap(true); + + layout_play_data_->setContentsMargins(0, 0, 0, 0); + layout_play_data_->addWidget(label_filetype_title_, 0, 0); + layout_play_data_->addWidget(label_filetype_, 0, 1); + layout_play_data_->addWidget(label_length_title_, 1, 0); + layout_play_data_->addWidget(label_length_, 1, 1); + layout_play_data_->addWidget(label_samplerate_title_, 2, 0); + layout_play_data_->addWidget(label_samplerate_, 2, 1); + layout_play_data_->addWidget(label_bitdepth_title_, 3, 0); + layout_play_data_->addWidget(label_bitdepth_, 3, 1); + layout_play_data_->addWidget(label_bitrate_title_, 4, 0); + layout_play_data_->addWidget(label_bitrate_, 4, 1); + + widget_play_data_->setLayout(layout_play_data_); + + label_play_lyrics_->setWordWrap(true); + label_play_lyrics_->setTextInteractionFlags(Qt::TextSelectableByMouse); + + layout_play_->setContentsMargins(5, 0, 40, 0); + layout_play_->addWidget(widget_play_engine_device_); + layout_play_->addSpacerItem(spacer_play_output_); + layout_play_->addWidget(widget_play_data_); + layout_play_->addSpacerItem(spacer_play_data_); + layout_play_->addWidget(label_play_albums_); + layout_play_->addWidget(widget_albums_); + layout_play_->addSpacerItem(spacer_play_albums_); + layout_play_->addWidget(label_play_lyrics_); + layout_play_->addSpacerItem(spacer_play_bottom_); QFontDatabase::addApplicationFont(":/fonts/HumongousofEternitySt.ttf"); - connect(timeline_fade_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousTrack(qreal))); - timeline_fade_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0 - - cover_loader_options_.desired_height_ = 300; - cover_loader_options_.pad_output_image_ = true; - cover_loader_options_.scale_output_image_ = true; - pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_strawberry_)); + connect(widget_album_, SIGNAL(FadeStopFinished()), SLOT(FadeStopFinished())); } -ContextView::~ContextView() { delete ui_; } +void ContextView::resizeEvent(QResizeEvent*) { + + widget_album_->setFixedSize(width() - 15, width()); + +} void ContextView::Init(Application *app, CollectionView *collectionview, AlbumCoverChoiceController *album_cover_choice_controller) { @@ -111,14 +270,14 @@ void ContextView::Init(Application *app, CollectionView *collectionview, AlbumCo collectionview_ = collectionview; album_cover_choice_controller_ = album_cover_choice_controller; - ui_->widget_play_albums->Init(app_); + widget_album_->Init(album_cover_choice_controller_); + widget_albums_->Init(app_); lyrics_fetcher_ = new LyricsFetcher(app_->lyrics_providers(), this); connect(collectionview_, SIGNAL(TotalSongCountUpdated_()), this, SLOT(UpdateNoSong())); connect(collectionview_, SIGNAL(TotalArtistCountUpdated_()), this, SLOT(UpdateNoSong())); connect(collectionview_, SIGNAL(TotalAlbumCountUpdated_()), this, SLOT(UpdateNoSong())); connect(lyrics_fetcher_, SIGNAL(LyricsFetched(const quint64, const QString&, const QString&)), this, SLOT(UpdateLyrics(const quint64, const QString&, const QString&))); - connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); AddActions(); @@ -126,6 +285,10 @@ void ContextView::Init(Application *app, CollectionView *collectionview, AlbumCo void ContextView::AddActions() { + action_show_album_ = new QAction(tr("Show album cover"), this); + action_show_album_->setCheckable(true); + action_show_album_->setChecked(true); + action_show_data_ = new QAction(tr("Show song technical data"), this); action_show_data_->setCheckable(true); action_show_data_->setChecked(true); @@ -142,6 +305,7 @@ void ContextView::AddActions() { action_show_lyrics_->setCheckable(true); action_show_lyrics_->setChecked(false); + menu_->addAction(action_show_album_); menu_->addAction(action_show_data_); menu_->addAction(action_show_output_); menu_->addAction(action_show_albums_); @@ -155,6 +319,7 @@ void ContextView::AddActions() { ReloadSettings(); + connect(action_show_album_, SIGNAL(triggered()), this, SLOT(ActionShowAlbums())); connect(action_show_data_, SIGNAL(triggered()), this, SLOT(ActionShowData())); connect(action_show_output_, SIGNAL(triggered()), this, SLOT(ActionShowOutput())); connect(action_show_albums_, SIGNAL(triggered()), this, SLOT(ActionShowAlbums())); @@ -162,90 +327,86 @@ void ContextView::AddActions() { } -void ContextView::Playing() {} - -void ContextView::Stopped() { - - active_ = false; - song_playing_ = Song(); - song_ = Song(); - downloading_covers_ = false; - song_prev_ = Song(); - lyrics_ = QString(); - SetImage(image_strawberry_); - -} - -void ContextView::Error() {} - -void ContextView::UpdateNoSong() { - NoSong(); -} - -void ContextView::SongChanged(const Song &song) { - - if (song_playing_.is_valid() && song == song_playing_) { - UpdateSong(song); - } - else { - song_prev_ = song_playing_; - lyrics_ = song.lyrics(); - lyrics_id_ = -1; - song_playing_ = song; - song_ = song; - SetSong(song); - if (lyrics_.isEmpty() && action_show_lyrics_->isChecked() && !song.artist().isEmpty() && !song.title().isEmpty()) { - lyrics_fetcher_->Clear(); - lyrics_id_ = lyrics_fetcher_->Search(song.effective_albumartist(), song.album(), song.title()); - } - } - -} - void ContextView::ReloadSettings() { QSettings s; s.beginGroup(ContextSettingsPage::kSettingsGroup); title_fmt_ = s.value(ContextSettingsPage::kSettingsTitleFmt, "%title% - %artist%").toString(); summary_fmt_ = s.value(ContextSettingsPage::kSettingsSummaryFmt, "%album%").toString(); + action_show_album_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUM], true).toBool()); action_show_data_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::TECHNICAL_DATA], true).toBool()); action_show_output_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ENGINE_AND_DEVICE], true).toBool()); action_show_albums_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUMS_BY_ARTIST], false).toBool()); action_show_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS], true).toBool()); s.endGroup(); - if (song_.is_valid()) { - SetSong(song_); + if (widget_stacked_->currentWidget() == widget_stop_) { + NoSong(); } else { - UpdateNoSong(); + SetSong(); } + } -void ContextView::SetLabelEnabled(QLabel *label) { - label->setEnabled(true); - label->setVisible(true); - label->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); +void ContextView::Playing() {} + +void ContextView::Stopped() { + + song_playing_ = Song(); + song_prev_ = Song(); + lyrics_ = QString(); + image_original_ = QImage(); + widget_album_->SetImage(); + +} + +void ContextView::Error() {} + +void ContextView::SongChanged(const Song &song) { + + if (widget_stacked_->currentWidget() == widget_play_ && song_playing_.is_valid() && song == song_playing_) { + UpdateSong(song); + } + else { + song_prev_ = song_playing_; + lyrics_ = song.lyrics(); + lyrics_id_ = -1; + song_playing_ = song; + SetSong(); + if (lyrics_.isEmpty() && action_show_lyrics_->isChecked() && !song.artist().isEmpty() && !song.title().isEmpty()) { + lyrics_fetcher_->Clear(); + lyrics_id_ = lyrics_fetcher_->Search(song.effective_albumartist(), song.album(), song.title()); + } + } + +} + +void ContextView::FadeStopFinished() { + + widget_stacked_->setCurrentWidget(widget_stop_); + NoSong(); + ResetSong(); + } void ContextView::SetLabelText(QLabel *label, int value, const QString &suffix, const QString &def) { label->setText(value <= 0 ? def : (QString::number(value) + " " + suffix)); } -void ContextView::SetLabelDisabled(QLabel *label) { - label->setEnabled(false); - label->setVisible(false); - label->setMaximumSize(0, 0); +void ContextView::UpdateNoSong() { + if (widget_stacked_->currentWidget() == widget_stop_) NoSong(); } void ContextView::NoSong() { - ui_->label_stop_top->setStyleSheet( - "font: 20pt \"Humongous of Eternity St\";" - "font-weight: Regular;" - ); + if (!widget_album_->isVisible()) { + widget_album_->show(); + } - ui_->label_stop_top->setText(tr("No song playing")); + label_top_->setStyleSheet("font: 20pt \"Humongous of Eternity St\"; font-weight: Regular;"); + + label_top_->setText(tr("No song playing")); QString html; if (collectionview_->TotalSongs() == 1) html += tr("%1 song").arg(collectionview_->TotalSongs()); @@ -260,103 +421,84 @@ void ContextView::NoSong() { else html += tr("%1 albums").arg(collectionview_->TotalAlbums()); html += "
"; - ui_->label_stop_summary->setStyleSheet( - "font: 12pt;" - "font-weight: regular;" - ); - ui_->label_stop_summary->setText(html); + label_stop_summary_->setStyleSheet("font: 12pt; font-weight: regular;"); + label_stop_summary_->setText(html); } -void ContextView::SetSong(const Song &song) { +void ContextView::SetSong() { - QList labels_play_data; + label_top_->setStyleSheet("font: 11pt; font-weight: regular;"); + label_top_->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song_playing_, "
"), Utilities::ReplaceMessage(summary_fmt_, song_playing_, "
"))); - labels_play_data << ui_->label_filetype - << ui_->filetype - << ui_->label_length - << ui_->length - << ui_->label_samplerate - << ui_->samplerate - << ui_->label_bitdepth - << ui_->bitdepth - << ui_->label_bitrate - << ui_->bitrate; + label_stop_summary_->clear(); - ui_->label_play_top->setStyleSheet( - "font: 11pt;" - "font-weight: regular;" - ); - ui_->label_play_top->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "
"), Utilities::ReplaceMessage(summary_fmt_, song, "
"))); + bool widget_album_changed = !song_prev_.is_valid(); + if (action_show_album_->isChecked() && !widget_album_->isVisible()) { + widget_album_->show(); + widget_album_changed = true; + } + else if (!action_show_album_->isChecked() && widget_album_->isVisible()) { + widget_album_->hide(); + widget_album_changed = true; + } + if (widget_album_changed) emit AlbumEnabledChanged(); if (action_show_data_->isChecked()) { - ui_->layout_play_data->setEnabled(true); - SetLabelEnabled(ui_->label_filetype); - SetLabelEnabled(ui_->filetype); - SetLabelEnabled(ui_->label_length); - SetLabelEnabled(ui_->length); - ui_->filetype->setText(song.TextForFiletype()); - ui_->length->setText(Utilities::PrettyTimeNanosec(song.length_nanosec())); - if (song.samplerate() <= 0) { - SetLabelDisabled(ui_->label_samplerate); - SetLabelDisabled(ui_->samplerate); - ui_->samplerate->clear(); + widget_play_data_->show(); + label_filetype_->setText(song_playing_.TextForFiletype()); + label_length_->setText(Utilities::PrettyTimeNanosec(song_playing_.length_nanosec())); + if (song_playing_.samplerate() <= 0) { + label_samplerate_title_->hide(); + label_samplerate_->hide(); + label_samplerate_->clear(); } else { - SetLabelEnabled(ui_->label_samplerate); - SetLabelEnabled(ui_->samplerate); - SetLabelText(ui_->samplerate, song.samplerate(), "Hz"); + label_samplerate_title_->show(); + label_samplerate_->show(); + SetLabelText(label_samplerate_, song_playing_.samplerate(), "Hz"); } - if (song.bitdepth() <= 0) { - SetLabelDisabled(ui_->label_bitdepth); - SetLabelDisabled(ui_->bitdepth); - ui_->bitdepth->clear(); + if (song_playing_.bitdepth() <= 0) { + label_bitdepth_title_->hide(); + label_bitdepth_->hide(); + label_bitdepth_->clear(); } else { - SetLabelEnabled(ui_->label_bitdepth); - SetLabelEnabled(ui_->bitdepth); - SetLabelText(ui_->bitdepth, song.bitdepth(), "Bit"); + label_bitdepth_title_->show(); + label_bitdepth_->show(); + SetLabelText(label_bitdepth_, song_playing_.bitdepth(), "Bit"); } - if (song.bitrate() <= 0) { - SetLabelDisabled(ui_->label_bitrate); - SetLabelDisabled(ui_->bitrate); - ui_->bitrate->clear(); + if (song_playing_.bitrate() <= 0) { + label_bitrate_title_->hide(); + label_bitrate_->hide(); + label_bitrate_->clear(); } else { - SetLabelEnabled(ui_->label_bitrate); - SetLabelEnabled(ui_->bitrate); - SetLabelText(ui_->bitrate, song.bitrate(), tr("kbps")); + label_bitrate_title_->show(); + label_bitrate_->show(); + SetLabelText(label_bitrate_, song_playing_.bitrate(), tr("kbps")); } - ui_->spacer_play_data->changeSize(20, 20, QSizePolicy::Fixed); + spacer_play_data_->changeSize(20, 20, QSizePolicy::Fixed); } else { - ui_->filetype->clear(); - ui_->length->clear(); - ui_->samplerate->clear(); - ui_->bitdepth->clear(); - ui_->bitrate->clear(); - for (QLabel *l : labels_play_data) { - SetLabelDisabled(l); - } - ui_->layout_play_data->setEnabled(false); - ui_->spacer_play_data->changeSize(0, 0, QSizePolicy::Fixed); + widget_play_data_->hide(); + label_filetype_->clear(); + label_length_->clear(); + label_samplerate_->clear(); + label_bitdepth_->clear(); + label_bitrate_->clear(); + spacer_play_data_->changeSize(0, 0, QSizePolicy::Fixed); } if (action_show_output_->isChecked()) { + widget_play_engine_device_->show(); Engine::EngineType enginetype(Engine::None); if (app_->player()->engine()) enginetype = app_->player()->engine()->type(); QIcon icon_engine = IconLoader::Load(EngineName(enginetype), 32); - ui_->label_engine->setVisible(true); - ui_->label_engine->setMaximumSize(60, QWIDGETSIZE_MAX); - ui_->label_engine_icon->setVisible(true); - ui_->label_engine_icon->setPixmap(icon_engine.pixmap(icon_engine.availableSizes().last())); - ui_->label_engine_icon->setMinimumSize(32, 32); - ui_->label_engine_icon->setMaximumSize(32, 32); - ui_->engine->setVisible(true); - ui_->engine->setText(EngineDescription(enginetype)); - ui_->engine->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); - ui_->spacer_play_output->changeSize(20, 20, QSizePolicy::Fixed); + label_engine_icon_->setPixmap(icon_engine.pixmap(icon_engine.availableSizes().last())); + label_engine_->setText(EngineDescription(enginetype)); + spacer_play_output_->changeSize(20, 20, QSizePolicy::Fixed); DeviceFinder::Device device; for (DeviceFinder *f : app_->device_finders()->ListFinders()) { @@ -367,148 +509,142 @@ void ContextView::SetSong(const Song &song) { } } if (device.value.isValid()) { - ui_->label_device->setVisible(true); - ui_->label_device->setMaximumSize(60, QWIDGETSIZE_MAX); - ui_->label_device_icon->setVisible(true); - ui_->label_device_icon->setMinimumSize(32, 32); - ui_->label_device_icon->setMaximumSize(32, 32); - ui_->device->setVisible(true); - ui_->device->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + label_device_title_->show(); + label_device_icon_->show(); + label_device_->show(); QIcon icon_device = IconLoader::Load(device.iconname, 32); - ui_->label_device_icon->setPixmap(icon_device.pixmap(icon_device.availableSizes().last())); - ui_->device->setText(device.description); + label_device_icon_->setPixmap(icon_device.pixmap(icon_device.availableSizes().last())); + label_device_->setText(device.description); } else { - ui_->label_device->setVisible(false); - ui_->label_device->setMaximumSize(0, 0); - ui_->label_device_icon->setVisible(false); - ui_->label_device_icon->setMinimumSize(0, 0); - ui_->label_device_icon->setMaximumSize(0, 0); - ui_->label_device_icon->clear(); - ui_->device->clear(); - ui_->device->setVisible(false); - ui_->device->setMaximumSize(0, 0); + label_device_title_->hide(); + label_device_icon_->hide(); + label_device_->hide(); + label_device_icon_->clear(); + label_device_->clear(); } } else { - ui_->label_engine->setVisible(false); - ui_->label_engine->setMaximumSize(0, 0); - ui_->label_engine_icon->clear(); - ui_->label_engine_icon->setVisible(false); - ui_->label_engine_icon->setMinimumSize(0, 0); - ui_->label_engine_icon->setMaximumSize(0, 0); - ui_->engine->clear(); - ui_->engine->setVisible(false); - ui_->engine->setMaximumSize(0, 0); - ui_->spacer_play_output->changeSize(0, 0, QSizePolicy::Fixed); - ui_->label_device->setVisible(false); - ui_->label_device->setMaximumSize(0, 0); - ui_->label_device_icon->setVisible(false); - ui_->label_device_icon->setMinimumSize(0, 0); - ui_->label_device_icon->setMaximumSize(0, 0); - ui_->label_device_icon->clear(); - ui_->device->clear(); - ui_->device->setVisible(false); - ui_->device->setMaximumSize(0, 0); + widget_play_engine_device_->hide(); + label_engine_icon_->clear(); + label_engine_->clear(); + label_device_icon_->clear(); + label_device_->clear(); + spacer_play_output_->changeSize(0, 0, QSizePolicy::Fixed); } - if (action_show_albums_->isChecked() && song_prev_.artist() != song.artist()) { + if (action_show_albums_->isChecked() && song_prev_.artist() != song_playing_.artist()) { const QueryOptions opt; CollectionBackend::AlbumList albumlist; - ui_->widget_play_albums->albums_model()->Reset(); - albumlist = app_->collection_backend()->GetAlbumsByArtist(song.artist(), opt); + widget_albums_->albums_model()->Reset(); + albumlist = app_->collection_backend()->GetAlbumsByArtist(song_playing_.artist(), opt); if (albumlist.count() > 1) { - ui_->label_play_albums->setVisible(true); - ui_->label_play_albums->setMinimumSize(0, 20); - ui_->label_play_albums->setText("" + tr("Albums by %1").arg( song.artist().toHtmlEscaped()) + ""); - ui_->label_play_albums->setStyleSheet("background-color: #3DADE8; color: rgb(255, 255, 255); font: 11pt;"); + label_play_albums_->show(); + widget_albums_->show(); + label_play_albums_->setText("" + tr("Albums by %1").arg( song_playing_.artist().toHtmlEscaped()) + ""); + label_play_albums_->setStyleSheet("background-color: #3DADE8; color: rgb(255, 255, 255); font: 11pt;"); for (CollectionBackend::Album album : albumlist) { - SongList songs = app_->collection_backend()->GetSongs(song.artist(), album.album_name, opt); - ui_->widget_play_albums->albums_model()->AddSongs(songs); + SongList songs = app_->collection_backend()->GetSongs(song_playing_.artist(), album.album_name, opt); + widget_albums_->albums_model()->AddSongs(songs); } - ui_->widget_play_albums->setEnabled(true); - ui_->widget_play_albums->setVisible(true); - ui_->spacer_play_albums1->changeSize(20, 10, QSizePolicy::Fixed); - ui_->spacer_play_albums2->changeSize(20, 20, QSizePolicy::Fixed); + spacer_play_albums_->changeSize(20, 10, QSizePolicy::Fixed); } else { - ui_->label_play_albums->clear(); - ui_->label_play_albums->setVisible(false); - ui_->label_play_albums->setMinimumSize(0, 0); - ui_->widget_play_albums->setEnabled(false); - ui_->widget_play_albums->setVisible(false); - ui_->spacer_play_albums1->changeSize(0, 0, QSizePolicy::Fixed); - ui_->spacer_play_albums2->changeSize(0, 0, QSizePolicy::Fixed); + label_play_albums_->hide(); + widget_albums_->hide(); + label_play_albums_->clear(); + spacer_play_albums_->changeSize(0, 0, QSizePolicy::Fixed); } } else if (!action_show_albums_->isChecked()) { - ui_->label_play_albums->clear(); - ui_->label_play_albums->setVisible(false); - ui_->label_play_albums->setMinimumSize(0, 0); - ui_->widget_play_albums->albums_model()->Reset(); - ui_->widget_play_albums->setEnabled(false); - ui_->widget_play_albums->setVisible(false); - ui_->spacer_play_albums1->changeSize(0, 0, QSizePolicy::Fixed); - ui_->spacer_play_albums2->changeSize(0, 0, QSizePolicy::Fixed); + label_play_albums_->hide(); + widget_albums_->hide(); + label_play_albums_->clear(); + widget_albums_->albums_model()->Reset(); + spacer_play_albums_->changeSize(0, 0, QSizePolicy::Fixed); } if (action_show_lyrics_->isChecked()) { - ui_->label_play_lyrics->setText(lyrics_); + label_play_lyrics_->show(); + label_play_lyrics_->setText(lyrics_); } else { - ui_->label_play_lyrics->clear(); + label_play_lyrics_->hide(); + label_play_lyrics_->clear(); } - ui_->widget_stacked->setCurrentWidget(ui_->widget_play); + widget_stacked_->setCurrentWidget(widget_play_); } void ContextView::UpdateSong(const Song &song) { - ui_->label_play_top->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "
"), Utilities::ReplaceMessage(summary_fmt_, song, "
"))); + label_top_->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "
"), Utilities::ReplaceMessage(summary_fmt_, song, "
"))); if (action_show_data_->isChecked()) { - if (song.filetype() != song_playing_.filetype()) ui_->filetype->setText(song.TextForFiletype()); - if (song.length_nanosec() != song_playing_.length_nanosec()) ui_->label_length->setText(Utilities::PrettyTimeNanosec(song.length_nanosec())); + if (song.filetype() != song_playing_.filetype()) label_filetype_->setText(song.TextForFiletype()); + if (song.length_nanosec() != song_playing_.length_nanosec()) label_length_->setText(Utilities::PrettyTimeNanosec(song.length_nanosec())); if (song.samplerate() != song_playing_.samplerate()) { if (song.samplerate() <= 0) { - SetLabelDisabled(ui_->label_samplerate); - SetLabelDisabled(ui_->samplerate); - ui_->samplerate->clear(); + label_samplerate_title_->hide(); + label_samplerate_->hide(); + label_samplerate_->clear(); } else { - SetLabelEnabled(ui_->label_samplerate); - SetLabelEnabled(ui_->samplerate); - SetLabelText(ui_->samplerate, song.samplerate(), "Hz"); + label_samplerate_title_->show(); + label_samplerate_->show(); + SetLabelText(label_samplerate_, song.samplerate(), "Hz"); } } if (song.bitdepth() != song_playing_.bitdepth()) { if (song.bitdepth() <= 0) { - SetLabelDisabled(ui_->label_bitdepth); - SetLabelDisabled(ui_->bitdepth); - ui_->bitdepth->clear(); + label_bitdepth_title_->hide(); + label_bitdepth_->hide(); + label_bitdepth_->clear(); } else { - SetLabelEnabled(ui_->label_bitdepth); - SetLabelEnabled(ui_->bitdepth); - SetLabelText(ui_->bitdepth, song.bitdepth(), "Bit"); + label_bitdepth_title_->show(); + label_bitdepth_->show(); + SetLabelText(label_bitdepth_, song.bitdepth(), "Bit"); } } if (song.bitrate() != song_playing_.bitrate()) { if (song.bitrate() <= 0) { - SetLabelDisabled(ui_->label_bitrate); - SetLabelDisabled(ui_->bitrate); - ui_->bitrate->clear(); + label_bitrate_title_->hide(); + label_bitrate_->hide(); + label_bitrate_->clear(); } else { - SetLabelEnabled(ui_->label_bitrate); - SetLabelEnabled(ui_->bitrate); - SetLabelText(ui_->bitrate, song.bitrate(), tr("kbps")); + label_bitrate_title_->show(); + label_bitrate_->show(); + SetLabelText(label_bitrate_, song.bitrate(), tr("kbps")); } } } + song_playing_ = song; - song_ = song; + +} + +void ContextView::ResetSong() { + + QList labels_play_data; + + labels_play_data << label_engine_icon_ + << label_engine_ + << label_device_ + << label_device_icon_ + << label_filetype_ + << label_length_ + << label_samplerate_ + << label_bitdepth_ + << label_bitrate_ + << label_play_albums_ + << label_play_lyrics_; + + for (QLabel *l: labels_play_data) { + l->clear(); + } } @@ -518,98 +654,33 @@ void ContextView::UpdateLyrics(const quint64 id, const QString &provider, const lyrics_ = lyrics + "\n\n(Lyrics from " + provider + ")\n"; lyrics_id_ = -1; if (action_show_lyrics_->isChecked()) { - ui_->label_play_lyrics->setText(lyrics_); - } - else ui_->label_play_lyrics->clear(); - -} - -bool ContextView::eventFilter(QObject *object, QEvent *event) { - - switch(event->type()) { - case QEvent::Paint:{ - handlePaintEvent(object, event); - } - // fallthrough - default:{ - return QObject::eventFilter(object, event); - } - } - - return(true); - -} - -void ContextView::handlePaintEvent(QObject *object, QEvent *event) { - - if (object == ui_->label_play_album) { - PaintEventAlbum(event); - } - - return; - -} - -void ContextView::PaintEventAlbum(QEvent *event) { - - Q_UNUSED(event); - - QPainter p(ui_->label_play_album); - - DrawImage(&p); - - // Draw the previous track's image if we're fading - if (!pixmap_previous_.isNull()) { - p.setOpacity(pixmap_previous_opacity_); - p.drawPixmap(0, 0, pixmap_previous_); - } - -} - -void ContextView::DrawImage(QPainter *p) { - - p->drawPixmap(0, 0, 300, 300, pixmap_current_); - if ((downloading_covers_) && (spinner_animation_)) { - p->drawPixmap(50, 50, 16, 16, spinner_animation_->currentPixmap()); - } - -} - -void ContextView::FadePreviousTrack(qreal value) { - - pixmap_previous_opacity_ = value; - if (qFuzzyCompare(pixmap_previous_opacity_, qreal(0.0))) { - image_previous_ = QImage(); - pixmap_previous_ = QPixmap(); - } - update(); - - if (value == 0 && !active_) { - ui_->widget_stacked->setCurrentWidget(ui_->widget_stop); - NoSong(); + label_play_lyrics_->setText(lyrics_); } + else label_play_lyrics_->clear(); } void ContextView::contextMenuEvent(QContextMenuEvent *e) { - if (menu_ && ui_->widget_stacked->currentWidget() == ui_->widget_play) menu_->popup(mapToGlobal(e->pos())); -} - -void ContextView::mouseReleaseEvent(QMouseEvent *) { + if (menu_ && widget_stacked_->currentWidget() == widget_play_) menu_->popup(mapToGlobal(e->pos())); } void ContextView::dragEnterEvent(QDragEnterEvent *e) { + + if (song_playing_.is_valid() && AlbumCoverChoiceController::CanAcceptDrag(e)) { + e->acceptProposedAction(); + } + QWidget::dragEnterEvent(e); + } void ContextView::dropEvent(QDropEvent *e) { + + if (song_playing_.is_valid()) { + album_cover_choice_controller_->SaveCover(&song_playing_, e); + } + QWidget::dropEvent(e); -} - -void ContextView::ScaleCover() { - - pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_original_)); - update(); } @@ -619,91 +690,63 @@ void ContextView::AlbumCoverLoaded(const Song &song, const QUrl &cover_url, cons if (song != song_playing_ || image == image_original_) return; - active_ = true; - downloading_covers_ = false; - song_ = song; - SetImage(image); - -} - -void ContextView::SetImage(const QImage &image) { - - // Cache the current pixmap so we can fade between them - pixmap_previous_ = QPixmap(size()); - pixmap_previous_.fill(palette().window().color()); - pixmap_previous_opacity_ = 1.0; - - QPainter p(&pixmap_previous_); - DrawImage(&p); - p.end(); - - image_previous_ = image_original_; + widget_album_->SetImage(image); image_original_ = image; - ScaleCover(); - - // Were we waiting for this cover to load before we started fading? - if (!pixmap_previous_.isNull() && timeline_fade_) { - timeline_fade_->stop(); - timeline_fade_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0 - timeline_fade_->start(); - } - } -void ContextView::SearchCoverInProgress() { +void ContextView::ActionShowAlbum() { - downloading_covers_ = true; - - // Show a spinner animation - spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); - connect(spinner_animation_.get(), SIGNAL(updated(const QRect&)), SLOT(update())); - spinner_animation_->start(); - update(); - -} - -void ContextView::AutomaticCoverSearchDone() { - - downloading_covers_ = false; - spinner_animation_.reset(); - update(); + QSettings s; + s.beginGroup(ContextSettingsPage::kSettingsGroup); + s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUM], action_show_album_->isChecked()); + s.endGroup(); + if (song_playing_.is_valid()) SetSong(); } void ContextView::ActionShowData() { + QSettings s; s.beginGroup(ContextSettingsPage::kSettingsGroup); s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::TECHNICAL_DATA], action_show_data_->isChecked()); s.endGroup(); - SetSong(song_); + if (song_playing_.is_valid()) SetSong(); + } void ContextView::ActionShowOutput() { + QSettings s; s.beginGroup(ContextSettingsPage::kSettingsGroup); s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ENGINE_AND_DEVICE], action_show_output_->isChecked()); s.endGroup(); - SetSong(song_); + if (song_playing_.is_valid()) SetSong(); + } void ContextView::ActionShowAlbums() { + QSettings s; s.beginGroup(ContextSettingsPage::kSettingsGroup); s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUMS_BY_ARTIST], action_show_albums_->isChecked()); s.endGroup(); song_prev_ = Song(); - SetSong(song_); + if (song_playing_.is_valid()) SetSong(); + } void ContextView::ActionShowLyrics() { + QSettings s; s.beginGroup(ContextSettingsPage::kSettingsGroup); s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS], action_show_lyrics_->isChecked()); s.endGroup(); - SetSong(song_); - if (lyrics_.isEmpty() && action_show_lyrics_->isChecked() && !song_.artist().isEmpty() && !song_.title().isEmpty()) { + if (song_playing_.is_valid()) SetSong(); + + if (lyrics_.isEmpty() && action_show_lyrics_->isChecked() && !song_playing_.artist().isEmpty() && !song_playing_.title().isEmpty()) { lyrics_fetcher_->Clear(); - lyrics_id_ = lyrics_fetcher_->Search(song_.artist(), song_.album(), song_.title()); + lyrics_id_ = lyrics_fetcher_->Search(song_playing_.artist(), song_playing_.album(), song_playing_.title()); } + } diff --git a/src/context/contextview.h b/src/context/contextview.h index 1578ada3c..9718682e0 100644 --- a/src/context/contextview.h +++ b/src/context/contextview.h @@ -1,6 +1,6 @@ /* * Strawberry Music Player - * Copyright 2013, Jonas Kvinge + * Copyright 2013-2020, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,39 +22,31 @@ #include "config.h" -#include - #include #include #include #include #include -#include -#include #include "core/song.h" -#include "covermanager/albumcoverloaderoptions.h" +#include "contextalbum.h" -#include "ui_contextviewcontainer.h" - -using std::unique_ptr; - -class QTimeLine; -class QPainter; class QMenu; class QAction; class QLabel; -class QEvent; +class QStackedWidget; +class QVBoxLayout; +class QGridLayout; +class QScrollArea; +class QSpacerItem; +class QResizeEvent; class QContextMenuEvent; -class QMouseEvent; class QDragEnterEvent; class QDropEvent; class Application; class CollectionView; -class CollectionModel; class AlbumCoverChoiceController; -class Ui_ContextViewContainer; class ContextAlbumsView; class LyricsFetcher; @@ -63,86 +55,123 @@ class ContextView : public QWidget { public: ContextView(QWidget *parent = nullptr); - ~ContextView(); void Init(Application *app, CollectionView *collectionview, AlbumCoverChoiceController *album_cover_choice_controller); - ContextAlbumsView *albums() { return ui_->widget_play_albums; } + ContextAlbum *album_widget() const { return widget_album_; } + ContextAlbumsView *albums_widget() const { return widget_albums_; } + bool album_enabled() const { return widget_album_->isVisible(); } - public slots: + protected: + void resizeEvent(QResizeEvent*); + void contextMenuEvent(QContextMenuEvent*); + void dragEnterEvent(QDragEnterEvent*); + void dropEvent(QDropEvent*); + + private: + void AddActions(); + void SetLabelText(QLabel *label, int value, const QString &suffix, const QString &def = QString()); + void NoSong(); + void SetSong(); + void UpdateSong(const Song &song); + void ResetSong(); + void GetCoverAutomatically(); + + signals: + void AlbumEnabledChanged(); + + private slots: + void ActionShowAlbum(); + void ActionShowData(); + void ActionShowOutput(); + void ActionShowAlbums(); + void ActionShowLyrics(); void UpdateNoSong(); void Playing(); void Stopped(); void Error(); void SongChanged(const Song &song); + void AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage &image); + void FadeStopFinished(); + void UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics); + + public slots: void ReloadSettings(); private: - - Ui_ContextViewContainer *ui_; Application *app_; CollectionView *collectionview_; AlbumCoverChoiceController *album_cover_choice_controller_; LyricsFetcher *lyrics_fetcher_; QMenu *menu_; - QTimeLine *timeline_fade_; - QImage image_strawberry_; - bool active_; - bool downloading_covers_; - + QAction *action_show_album_; QAction *action_show_data_; QAction *action_show_output_; QAction *action_show_albums_; QAction *action_show_lyrics_; - AlbumCoverLoaderOptions cover_loader_options_; - Song song_; + + QVBoxLayout *layout_container_; + QWidget *widget_scrollarea_; + QVBoxLayout *layout_scrollarea_; + QScrollArea *scrollarea_; + QLabel *label_top_; + ContextAlbum *widget_album_; + QStackedWidget *widget_stacked_; + QWidget *widget_stop_; + QWidget *widget_play_; + QVBoxLayout *layout_stop_; + QVBoxLayout *layout_play_; + + QLabel *label_stop_summary_; + QSpacerItem *spacer_stop_bottom_; + + QWidget *widget_play_data_; + QWidget *widget_play_engine_device_; + QGridLayout *layout_play_data_; + QGridLayout *layout_play_output_; + QLabel *label_play_albums_; + QLabel *label_play_lyrics_; + ContextAlbumsView *widget_albums_; + + //QSpacerItem *spacer_play_album_; + QSpacerItem *spacer_play_output_; + QSpacerItem *spacer_play_data_; + QSpacerItem *spacer_play_albums_; + QSpacerItem *spacer_play_bottom_; + + QLabel *label_filetype_title_; + QLabel *label_length_title_; + QLabel *label_samplerate_title_; + QLabel *label_bitdepth_title_; + QLabel *label_bitrate_title_; + + QLabel *label_filetype_; + QLabel *label_length_; + QLabel *label_samplerate_; + QLabel *label_bitdepth_; + QLabel *label_bitrate_; + + QLabel *label_device_title_; + QLabel *label_engine_title_; + QLabel *label_device_space_; + QLabel *label_engine_space_; + QLabel *label_device_; + QLabel *label_engine_; + QLabel *label_device_icon_; + QLabel *label_engine_icon_; + + QSpacerItem *spacer_bottom_; + Song song_playing_; Song song_prev_; QImage image_original_; - QImage image_previous_; - QPixmap pixmap_current_; - QPixmap pixmap_previous_; - qreal pixmap_previous_opacity_; - std::unique_ptr spinner_animation_; qint64 lyrics_id_; QString lyrics_; QString title_fmt_; QString summary_fmt_; - - void AddActions(); - void SetLabelEnabled(QLabel *label); - void SetLabelDisabled(QLabel *label); - void SetLabelText(QLabel *label, int value, const QString &suffix, const QString &def = QString()); - void NoSong(); - void SetSong(const Song &song); - void UpdateSong(const Song &song); - void SetImage(const QImage &image); - void DrawImage(QPainter *p); - void ScaleCover(); - void GetCoverAutomatically(); - - protected: - bool eventFilter(QObject *, QEvent *); - void handlePaintEvent(QObject *object, QEvent *event); - void PaintEventAlbum(QEvent *event); - void contextMenuEvent(QContextMenuEvent *e); - void mouseReleaseEvent(QMouseEvent *); - void dragEnterEvent(QDragEnterEvent *e); - void dropEvent(QDropEvent *e); - - private slots: - void ActionShowData(); - void ActionShowOutput(); - void ActionShowAlbums(); - void ActionShowLyrics(); - void UpdateLyrics(const quint64 id, const QString &provider, const QString &lyrics); - void SearchCoverInProgress(); - void AutomaticCoverSearchDone(); - void AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage &image); - void FadePreviousTrack(qreal value); + int prev_width_; }; #endif // CONTEXTVIEW_H - diff --git a/src/context/contextviewcontainer.ui b/src/context/contextviewcontainer.ui deleted file mode 100644 index 614373b44..000000000 --- a/src/context/contextviewcontainer.ui +++ /dev/null @@ -1,574 +0,0 @@ - - - ContextViewContainer - - - - 0 - 0 - 400 - 900 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - true - - - - - 0 - 0 - 394 - 894 - - - - - - - - 0 - 70 - - - - - 16777215 - 70 - - - - No song playing - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - 300 - 300 - - - - - 300 - 300 - - - - - - - :/pictures/strawberry.png - - - true - - - - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - Qt::Vertical - - - - 0 - 53 - - - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - true - - - - - 0 - 0 - 394 - 894 - - - - - - - - 0 - 70 - - - - - 16777215 - 700 - - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - - - - 300 - 300 - - - - - 300 - 300 - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - - - 0 - 0 - - - - Bit depth - - - - - - - - - - - - - - - - - - - - - - 0 - 0 - - - - Length - - - - - - - - - - - - - - - 0 - 0 - - - - Samplerate - - - - - - - - - - - - - - - 0 - 0 - - - - Filetype - - - - - - - - 0 - 0 - - - - Bitrate - - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - - - 32 - 32 - - - - - - - - - - - - 100 - 0 - - - - - - - - - - - - 100 - 0 - - - - - - - - - - - - 32 - 32 - - - - - - - - - - - - 60 - 16777215 - - - - Engine - - - - - - - - 60 - 16777215 - - - - Device - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 20 - - - - - 300 - 16777215 - - - - - - - true - - - 6 - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 0 - 20 - - - - - - - - - - - true - - - true - - - Qt::TextSelectableByMouse - - - - - - - Qt::Vertical - - - - 0 - 20 - - - - - - - - - - - - - - - - - - - ContextAlbumsView - QWidget -
context/contextalbumsview.h
-
-
- - - - - -
diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 8963b5646..d3be1a607 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -683,8 +683,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co connect(app_->player(), SIGNAL(Stopped()), context_view_, SLOT(Stopped())); connect(app_->player(), SIGNAL(Error()), context_view_, SLOT(Error())); connect(this, SIGNAL(AlbumCoverReady(Song, QUrl, QImage)), context_view_, SLOT(AlbumCoverLoaded(Song, QUrl, QImage))); - connect(this, SIGNAL(SearchCoverInProgress()), context_view_, SLOT(SearchCoverInProgress())); - connect(context_view_->albums(), SIGNAL(AddToPlaylistSignal(QMimeData*)), SLOT(AddToPlaylist(QMimeData*))); + connect(this, SIGNAL(SearchCoverInProgress()), context_view_->album_widget(), SLOT(SearchCoverInProgress())); + connect(context_view_, SIGNAL(AlbumEnabledChanged()), SLOT(TabSwitched())); + connect(context_view_->albums_widget(), SIGNAL(AddToPlaylistSignal(QMimeData*)), SLOT(AddToPlaylist(QMimeData*))); // Analyzer connect(ui_->analyzer, SIGNAL(WheelEvent(int)), SLOT(VolumeWheelEvent(int))); @@ -1105,7 +1106,7 @@ void MainWindow::TrackSkipped(PlaylistItemPtr item) { void MainWindow::TabSwitched() { - if (playing_widget_ && ui_->tabs->tabBar()->tabData(ui_->tabs->currentIndex()).toString().toLower() != "context") { + if (playing_widget_ && (ui_->tabs->tabBar()->tabData(ui_->tabs->currentIndex()).toString().toLower() != "context" || !context_view_->album_enabled())) { ui_->widget_playing->SetEnabled(); } else { diff --git a/src/settings/contextsettingspage.cpp b/src/settings/contextsettingspage.cpp index 8b747641e..4b9882138 100644 --- a/src/settings/contextsettingspage.cpp +++ b/src/settings/contextsettingspage.cpp @@ -46,30 +46,33 @@ const char *ContextSettingsPage::kSettingsGroupLabels[ContextSettingsOrder::NELE "Engine and Device", "Albums by Artist", "Song Lyrics", + "Album", }; const char *ContextSettingsPage::kSettingsGroupEnable[ContextSettingsOrder::NELEMS] = { "TechnicalDataEnable", "EngineAndDeviceEnable", "AlbumsByArtistEnable", "SongLyricsEnable", + "AlbumEnable", }; -ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) - : SettingsPage(dialog), ui_(new Ui_ContextSettingsPage) { +ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) : SettingsPage(dialog), ui_(new Ui_ContextSettingsPage) { + ui_->setupUi(this); setWindowIcon(IconLoader::Load("view-choose")); - checkboxes[ContextSettingsOrder::TECHNICAL_DATA] = ui_->context_item1_enable; - checkboxes[ContextSettingsOrder::ENGINE_AND_DEVICE] = ui_->context_item2_enable; - checkboxes[ContextSettingsOrder::ALBUMS_BY_ARTIST] = ui_->context_item3_enable; - checkboxes[ContextSettingsOrder::SONG_LYRICS] = ui_->context_item4_enable; + checkboxes[ContextSettingsOrder::ALBUM] = ui_->context_item1_enable; + checkboxes[ContextSettingsOrder::TECHNICAL_DATA] = ui_->context_item2_enable; + checkboxes[ContextSettingsOrder::ENGINE_AND_DEVICE] = ui_->context_item3_enable; + checkboxes[ContextSettingsOrder::ALBUMS_BY_ARTIST] = ui_->context_item4_enable; + checkboxes[ContextSettingsOrder::SONG_LYRICS] = ui_->context_item5_enable; // Create and populate the helper menus QMenu *menu = new QMenu(this); + menu->addAction(ui_->action_albumartist); menu->addAction(ui_->action_artist); menu->addAction(ui_->action_album); menu->addAction(ui_->action_title); - menu->addAction(ui_->action_albumartist); menu->addAction(ui_->action_year); menu->addAction(ui_->action_composer); menu->addAction(ui_->action_performer); @@ -81,8 +84,6 @@ ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) menu->addAction(ui_->action_playcount); menu->addAction(ui_->action_skipcount); menu->addAction(ui_->action_filename); - menu->addAction(ui_->action_rating); - menu->addAction(ui_->action_score); menu->addSeparator(); menu->addAction(ui_->action_newline); ui_->context_exp_chooser1->setMenu(menu); @@ -101,10 +102,7 @@ ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) } -ContextSettingsPage::~ContextSettingsPage() -{ - delete ui_; -} +ContextSettingsPage::~ContextSettingsPage() { delete ui_; } void ContextSettingsPage::Load() { @@ -113,7 +111,7 @@ void ContextSettingsPage::Load() { s.beginGroup(ContextSettingsPage::kSettingsGroup); ui_->context_custom_text1->setText(s.value(kSettingsTitleFmt, "%title% - %artist%").toString()); ui_->context_custom_text2->setText(s.value(kSettingsSummaryFmt, "%album%").toString()); - for (int i = 0; i < ContextSettingsOrder::NELEMS; ++i) { + for (int i = 0 ; i < ContextSettingsOrder::NELEMS ; ++i) { checkboxes[i]->setChecked(s.value(kSettingsGroupEnable[i], i != ContextSettingsOrder::ALBUMS_BY_ARTIST).toBool()); } s.endGroup(); diff --git a/src/settings/contextsettingspage.h b/src/settings/contextsettingspage.h index fe6ab8518..49444db70 100644 --- a/src/settings/contextsettingspage.h +++ b/src/settings/contextsettingspage.h @@ -35,8 +35,7 @@ class QCheckBox; class SettingsDialog; class Ui_ContextSettingsPage; -class ContextSettingsPage : public SettingsPage -{ +class ContextSettingsPage : public SettingsPage { Q_OBJECT public: @@ -48,7 +47,8 @@ public: ENGINE_AND_DEVICE, ALBUMS_BY_ARTIST, SONG_LYRICS, - NELEMS, + ALBUM, + NELEMS }; static const char *kSettingsGroup; diff --git a/src/settings/contextsettingspage.ui b/src/settings/contextsettingspage.ui index 8e724fe79..f7f1a2f75 100644 --- a/src/settings/contextsettingspage.ui +++ b/src/settings/contextsettingspage.ui @@ -6,8 +6,8 @@ 0 0 - 526 - 733 + 500 + 600 @@ -147,64 +147,53 @@ - - - QFrame::NoFrame + + + Album - - QFrame::Plain + + true - - 0 + + + + + + Technical Data + + + true + + + + + + + Engine and Device + + + true + + + + + + + Albums by Artist + + + false + + + + + + + Song Lyrics + + + true - - - 0 - - - 0 - - - - - Technical Data - - - true - - - - - - - Engine and Device - - - true - - - - - - - Albums by Artist - - - true - - - - - - - Song Lyrics - - - true - - - - @@ -336,22 +325,6 @@ Add song skip count - - - %rating% - - - Add song rating - - - - - %score% - - - Add song auto score - - %newline%