mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-02 20:36:44 +01:00
Merge pull request #4350 from TheUbuntuGuy/master
Add ability to fit now playing cover to width
This commit is contained in:
commit
22a454e405
@ -64,8 +64,10 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||||||
mode_(SmallSongDetails),
|
mode_(SmallSongDetails),
|
||||||
menu_(new QMenu(this)),
|
menu_(new QMenu(this)),
|
||||||
above_statusbar_action_(nullptr),
|
above_statusbar_action_(nullptr),
|
||||||
|
fit_cover_width_action_(nullptr),
|
||||||
visible_(false),
|
visible_(false),
|
||||||
small_ideal_height_(0),
|
small_ideal_height_(0),
|
||||||
|
fit_width_(false),
|
||||||
show_hide_animation_(new QTimeLine(500, this)),
|
show_hide_animation_(new QTimeLine(500, this)),
|
||||||
fade_animation_(new QTimeLine(1000, this)),
|
fade_animation_(new QTimeLine(1000, this)),
|
||||||
details_(new QTextDocument(this)),
|
details_(new QTextDocument(this)),
|
||||||
@ -81,6 +83,7 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||||||
mode_ = Mode(s.value("mode", SmallSongDetails).toInt());
|
mode_ = Mode(s.value("mode", SmallSongDetails).toInt());
|
||||||
album_cover_choice_controller_->search_cover_auto_action()->setChecked(
|
album_cover_choice_controller_->search_cover_auto_action()->setChecked(
|
||||||
s.value("search_for_cover_auto", false).toBool());
|
s.value("search_for_cover_auto", false).toBool());
|
||||||
|
fit_width_ = s.value("fit_cover_width", false).toBool();
|
||||||
|
|
||||||
// Accept drops for setting album art
|
// Accept drops for setting album art
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
@ -98,6 +101,15 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||||||
mode_mapper);
|
mode_mapper);
|
||||||
|
|
||||||
menu_->addActions(mode_group->actions());
|
menu_->addActions(mode_group->actions());
|
||||||
|
|
||||||
|
fit_cover_width_action_ = menu_->addAction(tr("Fit cover to width"));
|
||||||
|
|
||||||
|
fit_cover_width_action_->setCheckable(true);
|
||||||
|
fit_cover_width_action_->setEnabled((mode_ != SmallSongDetails) ? true
|
||||||
|
: false);
|
||||||
|
connect(fit_cover_width_action_, SIGNAL(toggled(bool)),
|
||||||
|
SLOT(FitCoverWidth(bool)));
|
||||||
|
fit_cover_width_action_->setChecked(fit_width_);
|
||||||
menu_->addSeparator();
|
menu_->addSeparator();
|
||||||
|
|
||||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||||
@ -147,10 +159,10 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||||||
// add placeholder text to get the correct height
|
// add placeholder text to get the correct height
|
||||||
if (mode_ == LargeSongDetailsBelow) {
|
if (mode_ == LargeSongDetailsBelow) {
|
||||||
details_->setDefaultStyleSheet(
|
details_->setDefaultStyleSheet(
|
||||||
"p {"
|
"p {"
|
||||||
" font-size: small;"
|
" font-size: small;"
|
||||||
" color: white;"
|
" color: white;"
|
||||||
"}");
|
"}");
|
||||||
details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
|
details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,13 +210,21 @@ void NowPlayingWidget::UpdateHeight() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LargeSongDetails:
|
case LargeSongDetails:
|
||||||
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
|
if (fit_width_) {
|
||||||
|
cover_loader_options_.desired_height_ = width();
|
||||||
|
} else {
|
||||||
|
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
|
||||||
|
}
|
||||||
total_height_ =
|
total_height_ =
|
||||||
kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
|
kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LargeSongDetailsBelow:
|
case LargeSongDetailsBelow:
|
||||||
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
|
if (fit_width_) {
|
||||||
|
cover_loader_options_.desired_height_ = width();
|
||||||
|
} else {
|
||||||
|
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
|
||||||
|
}
|
||||||
total_height_ = kTopBorder + cover_loader_options_.desired_height_ +
|
total_height_ = kTopBorder + cover_loader_options_.desired_height_ +
|
||||||
kBottomOffset + details_->size().height();
|
kBottomOffset + details_->size().height();
|
||||||
break;
|
break;
|
||||||
@ -248,11 +268,18 @@ void NowPlayingWidget::UpdateDetailsText() {
|
|||||||
|
|
||||||
case LargeSongDetailsBelow:
|
case LargeSongDetailsBelow:
|
||||||
details_->setTextWidth(cover_loader_options_.desired_height_);
|
details_->setTextWidth(cover_loader_options_.desired_height_);
|
||||||
details_->setDefaultStyleSheet(
|
if (fit_width_) {
|
||||||
"p {"
|
details_->setDefaultStyleSheet(
|
||||||
" font-size: small;"
|
"p {"
|
||||||
" color: white;"
|
" font-size: small;"
|
||||||
"}");
|
"}");
|
||||||
|
} else {
|
||||||
|
details_->setDefaultStyleSheet(
|
||||||
|
"p {"
|
||||||
|
" font-size: small;"
|
||||||
|
" color: white;"
|
||||||
|
"}");
|
||||||
|
}
|
||||||
html += "<p align=center>";
|
html += "<p align=center>";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -368,7 +395,8 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LargeSongDetails: {
|
case LargeSongDetails: {
|
||||||
const int total_size = qMin(kMaxCoverSize, width());
|
const int total_size =
|
||||||
|
fit_width_ ? width() : qMin(kMaxCoverSize, width());
|
||||||
const int x_offset =
|
const int x_offset =
|
||||||
(width() - cover_loader_options_.desired_height_) / 2;
|
(width() - cover_loader_options_.desired_height_) / 2;
|
||||||
|
|
||||||
@ -412,13 +440,16 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
|
|||||||
// Work out how high the text is going to be
|
// Work out how high the text is going to be
|
||||||
const int text_height = details_->size().height();
|
const int text_height = details_->size().height();
|
||||||
|
|
||||||
const int cover_size = qMin(kMaxCoverSize, width());
|
const int cover_size =
|
||||||
|
fit_width_ ? width() : qMin(kMaxCoverSize, width());
|
||||||
const int x_offset =
|
const int x_offset =
|
||||||
(width() - cover_loader_options_.desired_height_) / 2;
|
(width() - cover_loader_options_.desired_height_) / 2;
|
||||||
|
|
||||||
// Draw the black background
|
if (!fit_width_) {
|
||||||
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
|
// Draw the black background
|
||||||
Qt::black);
|
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
|
||||||
|
Qt::black);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw the cover
|
// Draw the cover
|
||||||
if (hypnotoad_) {
|
if (hypnotoad_) {
|
||||||
@ -451,6 +482,13 @@ void NowPlayingWidget::FadePreviousTrack(qreal value) {
|
|||||||
|
|
||||||
void NowPlayingWidget::SetMode(int mode) {
|
void NowPlayingWidget::SetMode(int mode) {
|
||||||
mode_ = Mode(mode);
|
mode_ = Mode(mode);
|
||||||
|
|
||||||
|
if (mode_ == SmallSongDetails) {
|
||||||
|
fit_cover_width_action_->setEnabled(false);
|
||||||
|
} else {
|
||||||
|
fit_cover_width_action_->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
UpdateHeight();
|
UpdateHeight();
|
||||||
UpdateDetailsText();
|
UpdateDetailsText();
|
||||||
update();
|
update();
|
||||||
@ -508,6 +546,16 @@ bool NowPlayingWidget::show_above_status_bar() const {
|
|||||||
return above_statusbar_action_->isChecked();
|
return above_statusbar_action_->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NowPlayingWidget::FitCoverWidth(bool fit) {
|
||||||
|
fit_width_ = fit;
|
||||||
|
UpdateHeight();
|
||||||
|
update();
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
|
s.beginGroup(kSettingsGroup);
|
||||||
|
s.setValue("fit_cover_width", fit_width_);
|
||||||
|
}
|
||||||
|
|
||||||
void NowPlayingWidget::AllHail(bool hypnotoad) {
|
void NowPlayingWidget::AllHail(bool hypnotoad) {
|
||||||
if (hypnotoad) {
|
if (hypnotoad) {
|
||||||
hypnotoad_.reset(new QMovie(kHypnotoadPath, QByteArray(), this));
|
hypnotoad_.reset(new QMovie(kHypnotoadPath, QByteArray(), this));
|
||||||
|
@ -85,6 +85,7 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void SetMode(int mode);
|
void SetMode(int mode);
|
||||||
void ShowAboveStatusBar(bool above);
|
void ShowAboveStatusBar(bool above);
|
||||||
|
void FitCoverWidth(bool fit);
|
||||||
|
|
||||||
void AlbumArtLoaded(const Song& metadata, const QString& uri,
|
void AlbumArtLoaded(const Song& metadata, const QString& uri,
|
||||||
const QImage& image);
|
const QImage& image);
|
||||||
@ -126,11 +127,13 @@ signals:
|
|||||||
QMenu* menu_;
|
QMenu* menu_;
|
||||||
|
|
||||||
QAction* above_statusbar_action_;
|
QAction* above_statusbar_action_;
|
||||||
|
QAction* fit_cover_width_action_;
|
||||||
|
|
||||||
bool visible_;
|
bool visible_;
|
||||||
int small_ideal_height_;
|
int small_ideal_height_;
|
||||||
AlbumCoverLoaderOptions cover_loader_options_;
|
AlbumCoverLoaderOptions cover_loader_options_;
|
||||||
int total_height_;
|
int total_height_;
|
||||||
|
bool fit_width_;
|
||||||
QTimeLine* show_hide_animation_;
|
QTimeLine* show_hide_animation_;
|
||||||
QTimeLine* fade_animation_;
|
QTimeLine* fade_animation_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user