Add new now playing widget mode

In an attempt to satisfy many users, I have added another mode to the
now playing widget. This shows the large cover art however it draws the song details
below the artwork, without the gradient that everyone seems to have a problem with.
This is just an option and all the original functionality is unchanged.
This commit is contained in:
Mark Furneaux 2014-05-14 19:07:53 -04:00
parent 542dbe8d12
commit eb0b53aa96
2 changed files with 61 additions and 5 deletions

View File

@ -93,6 +93,9 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
mode_mapper);
CreateModeAction(LargeSongDetails, tr("Large album cover"), mode_group,
mode_mapper);
CreateModeAction(LargeSongDetailsBelow,
tr("Large album cover (details below)"), mode_group,
mode_mapper);
menu_->addActions(mode_group->actions());
menu_->addSeparator();
@ -189,6 +192,12 @@ void NowPlayingWidget::UpdateHeight() {
total_height_ =
kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
break;
case LargeSongDetailsBelow:
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
total_height_ = kTopBorder + cover_loader_options_.desired_height_ +
kBottomOffset + details_->size().height();
break;
}
// Update the animation settings and resize the widget now if we're visible
@ -226,6 +235,16 @@ void NowPlayingWidget::UpdateDetailsText() {
"}");
html += "<p align=center>";
break;
case LargeSongDetailsBelow:
details_->setTextWidth(cover_loader_options_.desired_height_);
details_->setDefaultStyleSheet(
"p {"
" font-size: small;"
" color: white;"
"}");
html += "<p align=center>";
break;
}
// TODO: Make this configurable
@ -333,7 +352,7 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
p->translate(-small_ideal_height_ - kPadding, 0);
break;
case LargeSongDetails:
case LargeSongDetails: {
const int total_size = qMin(kMaxCoverSize, width());
const int x_offset =
(width() - cover_loader_options_.desired_height_) / 2;
@ -372,6 +391,37 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
details_->drawContents(p);
p->translate(-x_offset, -height() + text_height);
break;
}
case LargeSongDetailsBelow:
// 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 x_offset =
(width() - cover_loader_options_.desired_height_) / 2;
// Draw the black background
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
Qt::black);
// Draw the cover
if (hypnotoad_) {
p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size,
hypnotoad_->currentPixmap());
} else {
p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size, cover_);
if (downloading_covers_) {
p->drawPixmap(x_offset + 45, 35, 16, 16,
spinner_animation_->currentPixmap());
}
}
// Draw the text below
p->translate(x_offset, height() - text_height);
details_->drawContents(p);
p->translate(-x_offset, -height() + text_height);
break;
}
}
@ -396,9 +446,11 @@ void NowPlayingWidget::SetMode(int mode) {
}
void NowPlayingWidget::resizeEvent(QResizeEvent* e) {
if (visible_ && mode_ == LargeSongDetails && e->oldSize() != e->size()) {
UpdateHeight();
UpdateDetailsText();
if (visible_ && e->oldSize() != e->size()) {
if (mode_ == LargeSongDetails || mode_ == LargeSongDetailsBelow) {
UpdateHeight();
UpdateDetailsText();
}
}
}

View File

@ -54,7 +54,11 @@ class NowPlayingWidget : public QWidget {
static const int kTopBorder;
// Values are saved in QSettings
enum Mode { SmallSongDetails = 0, LargeSongDetails = 1, };
enum Mode {
SmallSongDetails = 0,
LargeSongDetails = 1,
LargeSongDetailsBelow = 2,
};
void SetApplication(Application* app);