Add a Now Playing widget
This commit is contained in:
parent
0d7eabcfb0
commit
afa4d0a4e2
@ -125,6 +125,7 @@ set(SOURCES
|
||||
widgets/fileviewlist.cpp
|
||||
widgets/lineedit.cpp
|
||||
widgets/multiloadingindicator.cpp
|
||||
widgets/nowplayingwidget.cpp
|
||||
widgets/osd.cpp
|
||||
widgets/osdpretty.cpp
|
||||
widgets/progressitemdelegate.cpp
|
||||
@ -225,6 +226,7 @@ set(HEADERS
|
||||
widgets/fileviewlist.h
|
||||
widgets/lineedit.h
|
||||
widgets/multiloadingindicator.h
|
||||
widgets/nowplayingwidget.h
|
||||
widgets/osd.h
|
||||
widgets/osdpretty.h
|
||||
widgets/progressitemdelegate.h
|
||||
|
@ -456,6 +456,15 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
|
||||
ui_->status_bar_stack->setCurrentWidget(ui_->playlist_summary_page);
|
||||
connect(ui_->multi_loading_indicator, SIGNAL(TaskCountChange(int)), SLOT(TaskCountChanged(int)));
|
||||
|
||||
// Now playing widget
|
||||
ui_->now_playing->set_network(network);
|
||||
ui_->now_playing->set_ideal_height(ui_->status_bar->sizeHint().height() +
|
||||
ui_->status_bar_line->sizeHint().height() +
|
||||
ui_->player_controls->sizeHint().height() +
|
||||
1); // Don't question the 1
|
||||
connect(playlists_, SIGNAL(CurrentSongChanged(Song)), ui_->now_playing, SLOT(NowPlaying(Song)));
|
||||
connect(player_, SIGNAL(Stopped()), ui_->now_playing, SLOT(Stopped()));
|
||||
|
||||
// Load theme
|
||||
StyleSheetLoader* css_loader = new StyleSheetLoader(this);
|
||||
css_loader->SetStyleSheet(this, ":mainwindow.css");
|
||||
|
@ -18,7 +18,7 @@
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
@ -30,100 +30,112 @@
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTabWidget" name="tabs">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="usesScrollButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="library_tab">
|
||||
<attribute name="title">
|
||||
<string>Library</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="LibraryFilterWidget" name="library_filter" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LibraryView" name="library_view">
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="file_tab">
|
||||
<attribute name="title">
|
||||
<string>Files</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="FileView" name="file_view" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="radio_tab">
|
||||
<attribute name="title">
|
||||
<string>Internet</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="RadioViewContainer" name="radio_view" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabs">
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::North</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="usesScrollButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="documentMode">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="movable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="library_tab">
|
||||
<attribute name="title">
|
||||
<string>Library</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="LibraryFilterWidget" name="library_filter" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LibraryView" name="library_view">
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="file_tab">
|
||||
<attribute name="title">
|
||||
<string>Files</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="FileView" name="file_view" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="radio_tab">
|
||||
<attribute name="title">
|
||||
<string>Internet</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="RadioViewContainer" name="radio_view" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="NowPlayingWidget" name="now_playing" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
@ -339,11 +351,11 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="Line" name="status_bar_line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="status_bar" native="true">
|
||||
@ -417,7 +429,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>804</width>
|
||||
<height>25</height>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuMusic">
|
||||
@ -755,6 +767,12 @@
|
||||
<header>widgets/multiloadingindicator.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>NowPlayingWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgets/nowplayingwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../data/data.qrc"/>
|
||||
|
157
src/widgets/nowplayingwidget.cpp
Normal file
157
src/widgets/nowplayingwidget.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine 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.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nowplayingwidget.h"
|
||||
#include "core/albumcoverloader.h"
|
||||
#include "core/networkaccessmanager.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QTextDocument>
|
||||
#include <QTimeLine>
|
||||
#include <QtDebug>
|
||||
|
||||
// Space between the cover and the details
|
||||
const int NowPlayingWidget::kPadding = 4;
|
||||
|
||||
NowPlayingWidget::NowPlayingWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
cover_loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this)),
|
||||
network_(NULL),
|
||||
visible_(false),
|
||||
ideal_height_(0),
|
||||
show_hide_animation_(new QTimeLine(500, this)),
|
||||
fade_animation_(new QTimeLine(1000, this)),
|
||||
no_cover_(":nocover.png"),
|
||||
load_cover_id_(0),
|
||||
details_(new QTextDocument(this)),
|
||||
previous_track_opacity_(0.0)
|
||||
{
|
||||
connect(show_hide_animation_, SIGNAL(frameChanged(int)), SLOT(SetHeight(int)));
|
||||
setMaximumHeight(0);
|
||||
|
||||
connect(fade_animation_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousTrack(qreal)));
|
||||
fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
|
||||
|
||||
cover_loader_->Start();
|
||||
connect(cover_loader_, SIGNAL(Initialised()), SLOT(CoverLoaderInitialised()));
|
||||
}
|
||||
|
||||
void NowPlayingWidget::set_ideal_height(int height) {
|
||||
ideal_height_= height;
|
||||
show_hide_animation_->setFrameRange(0, ideal_height_);
|
||||
}
|
||||
|
||||
QSize NowPlayingWidget::sizeHint() const {
|
||||
return QSize(ideal_height_, ideal_height_);
|
||||
}
|
||||
|
||||
void NowPlayingWidget::CoverLoaderInitialised() {
|
||||
cover_loader_->Worker()->SetNetwork(network_);
|
||||
cover_loader_->Worker()->SetDesiredHeight(ideal_height_);
|
||||
cover_loader_->Worker()->SetPadOutputImage(true);
|
||||
cover_loader_->Worker()->SetDefaultOutputImage(QImage(":nocover.png"));
|
||||
connect(cover_loader_->Worker().get(), SIGNAL(ImageLoaded(quint64,QImage)),
|
||||
SLOT(AlbumArtLoaded(quint64,QImage)));
|
||||
}
|
||||
|
||||
void NowPlayingWidget::NowPlaying(const Song& metadata) {
|
||||
if (visible_) {
|
||||
// Cache the current pixmap so we can fade between them
|
||||
previous_track_ = QPixmap(size());
|
||||
previous_track_.fill(palette().background().color());
|
||||
previous_track_opacity_ = 1.0;
|
||||
QPainter p(&previous_track_);
|
||||
DrawContents(&p);
|
||||
p.end();
|
||||
}
|
||||
|
||||
metadata_ = metadata;
|
||||
|
||||
// Load the cover
|
||||
cover_ = QPixmap();
|
||||
load_cover_id_ = cover_loader_->Worker()->LoadImageAsync(
|
||||
metadata.art_automatic(), metadata.art_manual());
|
||||
|
||||
// TODO: Make this configurable
|
||||
details_->setHtml(QString("<i>%1</i><br/>%2<br/>%3").arg(
|
||||
Qt::escape(metadata.title()), Qt::escape(metadata.artist()),
|
||||
Qt::escape(metadata.album())));
|
||||
|
||||
SetVisible(true);
|
||||
update();
|
||||
}
|
||||
|
||||
void NowPlayingWidget::Stopped() {
|
||||
SetVisible(false);
|
||||
}
|
||||
|
||||
void NowPlayingWidget::AlbumArtLoaded(quint64 id, const QImage& image) {
|
||||
if (id != load_cover_id_)
|
||||
return;
|
||||
|
||||
cover_ = QPixmap::fromImage(image);
|
||||
update();
|
||||
|
||||
// Were we waiting for this cover to load before we started fading?
|
||||
if (!previous_track_.isNull()) {
|
||||
fade_animation_->start();
|
||||
}
|
||||
}
|
||||
|
||||
void NowPlayingWidget::SetHeight(int height) {
|
||||
setMaximumHeight(height);
|
||||
}
|
||||
|
||||
void NowPlayingWidget::SetVisible(bool visible) {
|
||||
if (visible == visible_)
|
||||
return;
|
||||
visible_ = visible;
|
||||
|
||||
show_hide_animation_->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward);
|
||||
show_hide_animation_->start();
|
||||
}
|
||||
|
||||
void NowPlayingWidget::paintEvent(QPaintEvent *e) {
|
||||
QPainter p(this);
|
||||
|
||||
DrawContents(&p);
|
||||
|
||||
// Draw the previous track's image if we're fading
|
||||
if (!previous_track_.isNull()) {
|
||||
p.setOpacity(previous_track_opacity_);
|
||||
p.drawPixmap(0, 0, previous_track_);
|
||||
}
|
||||
}
|
||||
|
||||
void NowPlayingWidget::DrawContents(QPainter *p) {
|
||||
// Draw the cover
|
||||
p->drawPixmap(0, 0, ideal_height_, ideal_height_, cover_);
|
||||
|
||||
// Draw the details
|
||||
p->translate(ideal_height_ + kPadding, 0);
|
||||
details_->drawContents(p);
|
||||
p->translate(-ideal_height_ - kPadding, 0);
|
||||
}
|
||||
|
||||
void NowPlayingWidget::FadePreviousTrack(qreal value) {
|
||||
previous_track_opacity_ = value;
|
||||
if (qFuzzyCompare(previous_track_opacity_, 0.0)) {
|
||||
previous_track_ = QPixmap();
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
83
src/widgets/nowplayingwidget.h
Normal file
83
src/widgets/nowplayingwidget.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* This file is part of Clementine.
|
||||
|
||||
Clementine 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.
|
||||
|
||||
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NOWPLAYINGWIDGET_H
|
||||
#define NOWPLAYINGWIDGET_H
|
||||
|
||||
#include "core/backgroundthread.h"
|
||||
#include "core/song.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class AlbumCoverLoader;
|
||||
class NetworkAccessManager;
|
||||
|
||||
class QTextDocument;
|
||||
class QTimeLine;
|
||||
|
||||
class NowPlayingWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NowPlayingWidget(QWidget* parent = 0);
|
||||
|
||||
static const int kPadding;
|
||||
|
||||
void set_network(NetworkAccessManager* network) { network_ = network; }
|
||||
void set_ideal_height(int height);
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
public slots:
|
||||
void NowPlaying(const Song& metadata);
|
||||
void Stopped();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* e);
|
||||
|
||||
private slots:
|
||||
void CoverLoaderInitialised();
|
||||
void AlbumArtLoaded(quint64 id, const QImage& image);
|
||||
|
||||
void SetVisible(bool visible);
|
||||
void SetHeight(int height);
|
||||
|
||||
void FadePreviousTrack(qreal value);
|
||||
|
||||
private:
|
||||
void DrawContents(QPainter* p);
|
||||
|
||||
private:
|
||||
BackgroundThread<AlbumCoverLoader>* cover_loader_;
|
||||
NetworkAccessManager* network_;
|
||||
|
||||
bool visible_;
|
||||
int ideal_height_;
|
||||
QTimeLine* show_hide_animation_;
|
||||
QTimeLine* fade_animation_;
|
||||
|
||||
QPixmap no_cover_;
|
||||
|
||||
Song metadata_;
|
||||
quint64 load_cover_id_;
|
||||
QPixmap cover_;
|
||||
QTextDocument* details_;
|
||||
|
||||
QPixmap previous_track_;
|
||||
qreal previous_track_opacity_;
|
||||
};
|
||||
|
||||
#endif // NOWPLAYINGWIDGET_H
|
Loading…
x
Reference in New Issue
Block a user