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),
|
||||
menu_(new QMenu(this)),
|
||||
above_statusbar_action_(nullptr),
|
||||
fit_cover_width_action_(nullptr),
|
||||
visible_(false),
|
||||
small_ideal_height_(0),
|
||||
fit_width_(false),
|
||||
show_hide_animation_(new QTimeLine(500, this)),
|
||||
fade_animation_(new QTimeLine(1000, this)),
|
||||
details_(new QTextDocument(this)),
|
||||
|
@ -81,6 +83,7 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||
mode_ = Mode(s.value("mode", SmallSongDetails).toInt());
|
||||
album_cover_choice_controller_->search_cover_auto_action()->setChecked(
|
||||
s.value("search_for_cover_auto", false).toBool());
|
||||
fit_width_ = s.value("fit_cover_width", false).toBool();
|
||||
|
||||
// Accept drops for setting album art
|
||||
setAcceptDrops(true);
|
||||
|
@ -98,6 +101,15 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||
mode_mapper);
|
||||
|
||||
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();
|
||||
|
||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||
|
@ -147,10 +159,10 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
|
|||
// add placeholder text to get the correct height
|
||||
if (mode_ == LargeSongDetailsBelow) {
|
||||
details_->setDefaultStyleSheet(
|
||||
"p {"
|
||||
" font-size: small;"
|
||||
" color: white;"
|
||||
"}");
|
||||
"p {"
|
||||
" font-size: small;"
|
||||
" color: white;"
|
||||
"}");
|
||||
details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
|
||||
}
|
||||
|
||||
|
@ -198,13 +210,21 @@ void NowPlayingWidget::UpdateHeight() {
|
|||
break;
|
||||
|
||||
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_ =
|
||||
kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
|
||||
break;
|
||||
|
||||
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_ +
|
||||
kBottomOffset + details_->size().height();
|
||||
break;
|
||||
|
@ -248,11 +268,18 @@ void NowPlayingWidget::UpdateDetailsText() {
|
|||
|
||||
case LargeSongDetailsBelow:
|
||||
details_->setTextWidth(cover_loader_options_.desired_height_);
|
||||
details_->setDefaultStyleSheet(
|
||||
"p {"
|
||||
" font-size: small;"
|
||||
" color: white;"
|
||||
"}");
|
||||
if (fit_width_) {
|
||||
details_->setDefaultStyleSheet(
|
||||
"p {"
|
||||
" font-size: small;"
|
||||
"}");
|
||||
} else {
|
||||
details_->setDefaultStyleSheet(
|
||||
"p {"
|
||||
" font-size: small;"
|
||||
" color: white;"
|
||||
"}");
|
||||
}
|
||||
html += "<p align=center>";
|
||||
break;
|
||||
}
|
||||
|
@ -368,7 +395,8 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
|
|||
break;
|
||||
|
||||
case LargeSongDetails: {
|
||||
const int total_size = qMin(kMaxCoverSize, width());
|
||||
const int total_size =
|
||||
fit_width_ ? width() : qMin(kMaxCoverSize, width());
|
||||
const int x_offset =
|
||||
(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
|
||||
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 =
|
||||
(width() - cover_loader_options_.desired_height_) / 2;
|
||||
|
||||
// Draw the black background
|
||||
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
|
||||
Qt::black);
|
||||
if (!fit_width_) {
|
||||
// Draw the black background
|
||||
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
|
||||
Qt::black);
|
||||
}
|
||||
|
||||
// Draw the cover
|
||||
if (hypnotoad_) {
|
||||
|
@ -451,6 +482,13 @@ void NowPlayingWidget::FadePreviousTrack(qreal value) {
|
|||
|
||||
void NowPlayingWidget::SetMode(int mode) {
|
||||
mode_ = Mode(mode);
|
||||
|
||||
if (mode_ == SmallSongDetails) {
|
||||
fit_cover_width_action_->setEnabled(false);
|
||||
} else {
|
||||
fit_cover_width_action_->setEnabled(true);
|
||||
}
|
||||
|
||||
UpdateHeight();
|
||||
UpdateDetailsText();
|
||||
update();
|
||||
|
@ -508,6 +546,16 @@ bool NowPlayingWidget::show_above_status_bar() const {
|
|||
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) {
|
||||
if (hypnotoad) {
|
||||
hypnotoad_.reset(new QMovie(kHypnotoadPath, QByteArray(), this));
|
||||
|
|
|
@ -85,6 +85,7 @@ signals:
|
|||
private slots:
|
||||
void SetMode(int mode);
|
||||
void ShowAboveStatusBar(bool above);
|
||||
void FitCoverWidth(bool fit);
|
||||
|
||||
void AlbumArtLoaded(const Song& metadata, const QString& uri,
|
||||
const QImage& image);
|
||||
|
@ -126,11 +127,13 @@ signals:
|
|||
QMenu* menu_;
|
||||
|
||||
QAction* above_statusbar_action_;
|
||||
QAction* fit_cover_width_action_;
|
||||
|
||||
bool visible_;
|
||||
int small_ideal_height_;
|
||||
AlbumCoverLoaderOptions cover_loader_options_;
|
||||
int total_height_;
|
||||
bool fit_width_;
|
||||
QTimeLine* show_hide_animation_;
|
||||
QTimeLine* fade_animation_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue