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) 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
* the terms of the GNU General Public License as published by the Free Software
......@@ -281,12 +281,12 @@ void PlayerManager::stop()
action("forward")->setEnabled(false);
action("forwardAlbum")->setEnabled(false);
m_media->stop();
if(!m_file.isNull()) {
m_file = FileHandle();
emit signalItemChanged(m_file);
}
m_media->stop();
}
void PlayerManager::setVolume(float volume)
......@@ -446,7 +446,7 @@ void PlayerManager::slotStateChanged(Phonon::State newstate, Phonon::State)
}
// "normal" path
if(newstate == Phonon::StoppedState) {
if(newstate == Phonon::StoppedState && m_file.isNull()) {
JuK::JuKInstance()->setWindowTitle(i18n("JuK"));
emit signalStop();
}
......
......@@ -52,6 +52,7 @@
#include <QPixmap>
#include <QStackedWidget>
#include <QScrollBar>
#include <QPainter>
#include <id3v1genres.h>
......@@ -287,7 +288,7 @@ void Playlist::playNext()
void Playlist::stop()
{
m_history.clear();
setPlaying(0);
setPlaying(nullptr);
}
void Playlist::playPrevious()
......@@ -467,6 +468,9 @@ void Playlist::setSearchEnabled(bool enabled)
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)
{
foreach(const Playlist *p, sources) {
......@@ -1070,6 +1074,25 @@ void Playlist::resizeEvent(QResizeEvent *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)
{
// Because we're called from the PlaylistItem ctor, item may not be a
......
......@@ -436,6 +436,8 @@ protected:
virtual void paintEvent(QPaintEvent *pe);
virtual void resizeEvent(QResizeEvent *re);
virtual void drawRow(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void insertItem(QTreeWidgetItem *item);
virtual void takeItem(QTreeWidgetItem *item);
......
......@@ -909,11 +909,11 @@ void PlaylistCollection::saveConfig()
}
////////////////////////////////////////////////////////////////////////////////
// ActionHanlder implementation
// ActionHandler implementation
////////////////////////////////////////////////////////////////////////////////
PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection) :
QObject(0),
QObject(nullptr),
m_collection(collection)
{
setObjectName( QLatin1String("ActionHandler" ));
......@@ -989,6 +989,9 @@ PlaylistCollection::ActionHandler::ActionHandler(PlaylistCollection *collection)
connect(upcomingAction, SIGNAL(triggered(bool)),
this, SLOT(slotSetUpcomingPlaylistEnabled(bool)));
connect(m_collection->m_playerManager, &PlayerManager::signalStop,
this, [this]() { m_collection->stop(); });
}
QAction *PlaylistCollection::ActionHandler::createAction(const QString &text,
......
......@@ -180,6 +180,7 @@ public:
void lowerDistraction();
class ActionHandler;
friend PlaylistCollection::ActionHandler;
protected:
virtual QStackedWidget *playlistStack() const;
......@@ -247,6 +248,7 @@ private:
const QString &icon = QString(),
const QKeySequence &shortcut = QKeySequence());
private slots:
void slotStop() { m_collection->stop(); }
void slotPlayFirst() { m_collection->playFirst(); }
void slotPlayNextAlbum() { m_collection->playNextAlbum(); }
......
......@@ -281,27 +281,6 @@ PlaylistItem::PlaylistItem(CollectionList *parent) :
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
{
// reimplemented from QListViewItem
......
......@@ -176,9 +176,6 @@ protected:
*/
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;
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