Commit 0dd849ec authored by Michael Pyne's avatar Michael Pyne

Bring back a visual indication of the playing item.

Turned out to be surprisingly more difficult than I thought, so
hopefully no additional bugs.

In particular some Phonon backends seem to insert a trip to a
StoppedState when changing the MediaObject's current source, so I had to
find a way around that to be able to call Playlist::stop() from
PlaylistCollection (which is what actually clears the visual indication
when playback stops).
parent 86f84e96
/** /**
* Copyright (C) 2004 Scott Wheeler <wheeler@kde.org> * Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
* Copyright (C) 2007 Matthias Kretz <kretz@kde.org> * Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
* Copyright (C) 2008, 2009 Michael Pyne <mpyne@kde.org> * Copyright (C) 2008, 2009, 2018 Michael Pyne <mpyne@kde.org>
* *
* This program is free software; you can redistribute it and/or modify it under * This program 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 * the terms of the GNU General Public License as published by the Free Software
...@@ -281,12 +281,12 @@ void PlayerManager::stop() ...@@ -281,12 +281,12 @@ void PlayerManager::stop()
action("forward")->setEnabled(false); action("forward")->setEnabled(false);
action("forwardAlbum")->setEnabled(false); action("forwardAlbum")->setEnabled(false);
m_media->stop();
if(!m_file.isNull()) { if(!m_file.isNull()) {
m_file = FileHandle(); m_file = FileHandle();
emit signalItemChanged(m_file); emit signalItemChanged(m_file);
} }
m_media->stop();
} }
void PlayerManager::setVolume(float volume) void PlayerManager::setVolume(float volume)
...@@ -446,7 +446,7 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State) ...@@ -446,7 +446,7 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State)
} }
// "normal" path // "normal" path
if(newstate == Phonon::StoppedState) { if(newstate == Phonon::StoppedState && m_file.isNull()) {
JuK::JuKInstance()->setWindowTitle(i18n("JuK")); JuK::JuKInstance()->setWindowTitle(i18n("JuK"));
emit signalStop(); emit signalStop();
} }
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include <QPixmap> #include <QPixmap>
#include <QStackedWidget> #include <QStackedWidget>
#include <QScrollBar> #include <QScrollBar>
#include <QPainter>
#include <id3v1genres.h> #include <id3v1genres.h>
...@@ -287,7 +288,7 @@ void Playlist::playNext() ...@@ -287,7 +288,7 @@ void Playlist::playNext()
void Playlist::stop() void Playlist::stop()
{ {
m_history.clear(); m_history.clear();
setPlaying(0); setPlaying(nullptr);
} }
void Playlist::playPrevious() void Playlist::playPrevious()
...@@ -467,6 +468,9 @@ void Playlist::setSearchEnabled(bool enabled) ...@@ -467,6 +468,9 @@ void Playlist::setSearchEnabled(bool enabled)
setItemsVisible(items(), true); setItemsVisible(items(), true);
} }
// Mostly seems to be for DynamicPlaylist
// TODO: See if this can't all be eliminated by making 'is-playing' a predicate
// of the playlist item itself
void Playlist::synchronizePlayingItems(const PlaylistList &sources, bool setMaster) void Playlist::synchronizePlayingItems(const PlaylistList &sources, bool setMaster)
{ {
foreach(const Playlist *p, sources) { foreach(const Playlist *p, sources) {
...@@ -1070,6 +1074,25 @@ void Playlist::resizeEvent(QResizeEvent *re) ...@@ -1070,6 +1074,25 @@ void Playlist::resizeEvent(QResizeEvent *re)
QTreeWidget::resizeEvent(re); QTreeWidget::resizeEvent(re);
} }
// Reimplemented to show a visual indication of which of the view's playlist
// items is actually playing.
void Playlist::drawRow(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
PlaylistItem *item = static_cast<PlaylistItem *>(itemFromIndex(index));
if(Q_LIKELY(!PlaylistItem::playingItems().contains(item))) {
return QTreeWidget::drawRow(p, option, index);
}
// Seems that the view draws the background now so we have to do this
// manually
p->fillRect(option.rect, QPalette{}.midlight());
QStyleOptionViewItem newOption {option};
newOption.font.setBold(true);
QTreeWidget::drawRow(p, newOption, index);
}
void Playlist::insertItem(QTreeWidgetItem *item) void Playlist::insertItem(QTreeWidgetItem *item)
{ {
// Because we're called from the PlaylistItem ctor, item may not be a // Because we're called from the PlaylistItem ctor, item may not be a
......
...@@ -436,6 +436,8 @@ protected: ...@@ -436,6 +436,8 @@ protected:
virtual void paintEvent(QPaintEvent *pe); virtual void paintEvent(QPaintEvent *pe);
virtual void resizeEvent(QResizeEvent *re); virtual void resizeEvent(QResizeEvent *re);
virtual void drawRow(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void insertItem(QTreeWidgetItem *item); virtual void insertItem(QTreeWidgetItem *item);
virtual void takeItem(QTreeWidgetItem *item); virtual void takeItem(QTreeWidgetItem *item);
......
...@@ -909,11 +909,11 @@ void PlaylistCollection::saveConfig() ...@@ -909,11 +909,11 @@ void PlaylistCollection::saveConfig()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ActionHanlder implementation // ActionHandler implementation
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection) : PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection) :
QObject(0), QObject(nullptr),
m_collection(collection) m_collection(collection)
{ {
setObjectName( QLatin1String("ActionHandler" )); setObjectName( QLatin1String("ActionHandler" ));
...@@ -989,6 +989,9 @@ PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection) ...@@ -989,6 +989,9 @@ PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection)
connect(upcomingAction, SIGNAL(triggered(bool)), connect(upcomingAction, SIGNAL(triggered(bool)),
this, SLOT(slotSetUpcomingPlaylistEnabled(bool))); this, SLOT(slotSetUpcomingPlaylistEnabled(bool)));
connect(m_collection->m_playerManager, &PlayerManager::signalStop,
this, [this]() { m_collection->stop(); });
} }
QAction *PlaylistCollection::ActionHandler::createAction(const QString &text, QAction *PlaylistCollection::ActionHandler::createAction(const QString &text,
......
...@@ -180,6 +180,7 @@ public: ...@@ -180,6 +180,7 @@ public:
void lowerDistraction(); void lowerDistraction();
class ActionHandler; class ActionHandler;
friend PlaylistCollection::ActionHandler;
protected: protected:
virtual QStackedWidget *playlistStack() const; virtual QStackedWidget *playlistStack() const;
...@@ -247,6 +248,7 @@ private: ...@@ -247,6 +248,7 @@ private:
const QString &icon = QString(), const QString &icon = QString(),
const QKeySequence &shortcut = QKeySequence()); const QKeySequence &shortcut = QKeySequence());
private slots: private slots:
void slotStop() { m_collection->stop(); }
void slotPlayFirst() { m_collection->playFirst(); } void slotPlayFirst() { m_collection->playFirst(); }
void slotPlayNextAlbum() { m_collection->playNextAlbum(); } void slotPlayNextAlbum() { m_collection->playNextAlbum(); }
......
...@@ -281,27 +281,6 @@ PlaylistItem::PlaylistItem(CollectionList *parent) : ...@@ -281,27 +281,6 @@ PlaylistItem::PlaylistItem(CollectionList *parent) :
setFlags(flags() | Qt::ItemIsDragEnabled); setFlags(flags() | Qt::ItemIsDragEnabled);
} }
// FIXME paintCell
/*void PlaylistItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align)
{
if(!m_playingItems.contains(this))
return QTreeWidgetItem::paintCell(p, cg, column, width, align);
QPalette colorGroup = cg;
QColor base = colorGroup.color( QPalette::Base );
QColor selection = colorGroup.color( QPalette::Highlight );
int r = (base.red() + selection.red()) / 2;
int b = (base.blue() + selection.blue()) / 2;
int g = (base.green() + selection.green()) / 2;
QColor c(r, g, b);
colorGroup.setColor(QPalette::Base, c);
QTreeWidgetItem::paintCell(p, colorGroup, column, width, align);
}*/
int PlaylistItem::compare(const QTreeWidgetItem *item, int column, bool ascending) const int PlaylistItem::compare(const QTreeWidgetItem *item, int column, bool ascending) const
{ {
// reimplemented from QListViewItem // reimplemented from QListViewItem
......
...@@ -176,9 +176,6 @@ protected: ...@@ -176,9 +176,6 @@ protected:
*/ */
virtual ~PlaylistItem(); virtual ~PlaylistItem();
//virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
//virtual void paintFocus(QPainter *, const QColorGroup &, const QRect &) {}
virtual int compare(const QTreeWidgetItem *item, int column, bool ascending) const; virtual int compare(const QTreeWidgetItem *item, int column, bool ascending) const;
int compare(const PlaylistItem *firstItem, const PlaylistItem *secondItem, int column, bool ascending) const; int compare(const PlaylistItem *firstItem, const PlaylistItem *secondItem, int column, bool ascending) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment