mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
Make clicking back to current track work on dashboard, charts, and artist/album pages
This commit is contained in:
parent
115c618fc2
commit
96d8d8b2b2
@ -238,6 +238,7 @@ set( libGuiHeaders
|
||||
widgets/playlisttypeselectordlg.h
|
||||
widgets/welcomewidget.h
|
||||
widgets/whatshotwidget.h
|
||||
widgets/whatshotwidget_p.h
|
||||
widgets/RecentlyPlayedPlaylistsModel.h
|
||||
widgets/RecentPlaylistsModel.h
|
||||
widgets/OverlayButton.h
|
||||
|
@ -369,6 +369,9 @@ ArtistView::onMenuTriggered( int action )
|
||||
bool
|
||||
ArtistView::jumpToCurrentTrack()
|
||||
{
|
||||
if ( !m_proxyModel )
|
||||
return false;
|
||||
|
||||
scrollTo( m_proxyModel->currentIndex(), QAbstractItemView::PositionAtCenter );
|
||||
return true;
|
||||
}
|
||||
|
@ -43,6 +43,15 @@ TreeProxyModel::TreeProxyModel( QObject* parent )
|
||||
setSourceTreeModel( 0 );
|
||||
}
|
||||
|
||||
QPersistentModelIndex
|
||||
TreeProxyModel::currentIndex() const
|
||||
{
|
||||
if ( !m_model )
|
||||
return QPersistentModelIndex();
|
||||
|
||||
return mapFromSource( m_model->currentItem() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeProxyModel::setSourceModel( QAbstractItemModel* sourceModel )
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
virtual void setSourceTreeModel( TreeModel* sourceModel );
|
||||
virtual void setSourceModel( QAbstractItemModel* sourceModel );
|
||||
|
||||
virtual QPersistentModelIndex currentIndex() const { return mapFromSource( m_model->currentItem() ); }
|
||||
virtual QPersistentModelIndex currentIndex() const;
|
||||
virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }
|
||||
|
||||
virtual QList<Tomahawk::query_ptr> tracks() { Q_ASSERT( FALSE ); QList<Tomahawk::query_ptr> queries; return queries; }
|
||||
|
@ -67,6 +67,10 @@ public:
|
||||
|
||||
virtual void reset() {}
|
||||
|
||||
// Some playlist interfaces can wrap other interfaces. When checking for top-level
|
||||
// equality (say, to compare the currently playing interface) this might be needed
|
||||
virtual bool hasChildInterface( PlaylistInterface* ) { return false; }
|
||||
|
||||
QObject* object() const { return m_object; }
|
||||
|
||||
static void dontDelete( Tomahawk::PlaylistInterface* obj )
|
||||
|
@ -818,6 +818,8 @@ ViewManager::pageForInterface( Tomahawk::PlaylistInterface* interface ) const
|
||||
ViewPage* page = m_pageHistory.at( i );
|
||||
if ( page->playlistInterface() == interface )
|
||||
return page;
|
||||
if ( page->playlistInterface() && page->playlistInterface()->hasChildInterface( interface ) )
|
||||
return page;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -64,6 +64,12 @@ public:
|
||||
virtual QList< Tomahawk::query_ptr > tracks() { return QList< Tomahawk::query_ptr >(); }
|
||||
virtual int unfilteredTrackCount() const { return 0; }
|
||||
|
||||
virtual bool hasChildInterface( PlaylistInterface* other )
|
||||
{
|
||||
return ( m_w->ui->albums->playlistInterface() == other ) ||
|
||||
( m_w->ui->relatedArtists->playlistInterface() == other ) ||
|
||||
( m_w->ui->topHits->playlistInterface() == other );
|
||||
}
|
||||
public slots:
|
||||
virtual void setRepeatMode( RepeatMode mode )
|
||||
{
|
||||
|
@ -99,6 +99,19 @@ WelcomeWidget::~WelcomeWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
PlaylistInterface*
|
||||
WelcomeWidget::playlistInterface() const
|
||||
{
|
||||
return ui->tracksView->playlistInterface();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
WelcomeWidget::jumpToCurrentTrack()
|
||||
{
|
||||
return ui->tracksView->jumpToCurrentTrack();
|
||||
}
|
||||
|
||||
bool
|
||||
WelcomeWidget::isBeingPlayed() const
|
||||
{
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
~WelcomeWidget();
|
||||
|
||||
virtual QWidget* widget() { return this; }
|
||||
virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; }
|
||||
virtual Tomahawk::PlaylistInterface* playlistInterface() const;
|
||||
|
||||
virtual QString title() const { return tr( "Welcome to Tomahawk" ); }
|
||||
virtual QString description() const { return QString(); }
|
||||
@ -92,7 +92,7 @@ public:
|
||||
virtual bool showStatsBar() const { return false; }
|
||||
virtual bool showInfoBar() const { return false; }
|
||||
|
||||
virtual bool jumpToCurrentTrack() { return false; }
|
||||
virtual bool jumpToCurrentTrack();
|
||||
virtual bool isBeingPlayed() const;
|
||||
|
||||
protected:
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "whatshotwidget.h"
|
||||
#include "whatshotwidget_p.h"
|
||||
#include "ui_whatshotwidget.h"
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
@ -50,6 +51,7 @@ static QString s_whatsHotIdentifier = QString( "WhatsHotWidget" );
|
||||
WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, ui( new Ui::WhatsHotWidget )
|
||||
, m_playlistInterface( 0 )
|
||||
, m_sortedProxy( 0 )
|
||||
{
|
||||
ui->setupUi( this );
|
||||
@ -90,6 +92,8 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||
ui->artistsViewLeft->header()->setVisible( false );
|
||||
|
||||
m_playlistInterface = new ChartsPlaylistInterface( this );
|
||||
|
||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) );
|
||||
@ -102,9 +106,16 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
|
||||
WhatsHotWidget::~WhatsHotWidget()
|
||||
{
|
||||
delete m_playlistInterface;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
PlaylistInterface*
|
||||
WhatsHotWidget::playlistInterface() const
|
||||
{
|
||||
return m_playlistInterface;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
WhatsHotWidget::isBeingPlayed() const
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
class ChartsPlaylistInterface;
|
||||
class QSortFilterProxyModel;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
@ -58,7 +59,7 @@ public:
|
||||
~WhatsHotWidget();
|
||||
|
||||
virtual QWidget* widget() { return this; }
|
||||
virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; }
|
||||
virtual Tomahawk::PlaylistInterface* playlistInterface() const;
|
||||
|
||||
virtual QString title() const { return tr( "Charts" ); }
|
||||
virtual QString description() const { return QString(); }
|
||||
@ -90,6 +91,7 @@ private:
|
||||
|
||||
QStandardItem* parseNode( QStandardItem* parentItem, const QString &label, const QVariant &data );
|
||||
Ui::WhatsHotWidget *ui;
|
||||
ChartsPlaylistInterface* m_playlistInterface;
|
||||
|
||||
QStandardItemModel* m_crumbModelLeft;
|
||||
QSortFilterProxyModel* m_sortedProxy;
|
||||
@ -101,6 +103,8 @@ private:
|
||||
QString m_queueItemToShow;
|
||||
QSet< QString > m_queuedFetches;
|
||||
QTimer* m_timer;
|
||||
|
||||
friend class ChartsPlaylistInterface;
|
||||
};
|
||||
|
||||
#endif // WHATSHOTWIDGET_H
|
||||
|
107
src/libtomahawk/widgets/whatshotwidget_p.h
Normal file
107
src/libtomahawk/widgets/whatshotwidget_p.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||
*
|
||||
* Tomahawk 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.
|
||||
*
|
||||
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WHATSHOTWIDGET_P_H
|
||||
#define WHATSHOTWIDGET_P_H
|
||||
|
||||
#include "whatshotwidget.h"
|
||||
#include "playlistinterface.h"
|
||||
#include "ui_whatshotwidget.h"
|
||||
#include "treeproxymodel.h"
|
||||
#include "playlistview.h"
|
||||
#include "result.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ChartsPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ChartsPlaylistInterface( WhatsHotWidget* w )
|
||||
: PlaylistInterface( this )
|
||||
, m_w( w )
|
||||
{
|
||||
connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
|
||||
SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
|
||||
connect( m_w->ui->artistsViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
|
||||
SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
|
||||
|
||||
connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ),
|
||||
SLOT( anyShuffleChanged( bool ) ) );
|
||||
connect( m_w->ui->artistsViewLeft->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ),
|
||||
SLOT( anyShuffleChanged( bool ) ) );
|
||||
}
|
||||
virtual ~ChartsPlaylistInterface() {}
|
||||
|
||||
|
||||
// Any one is fine, we keep them all synched
|
||||
virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->repeatMode(); }
|
||||
|
||||
virtual bool shuffled() const { return m_w->ui->tracksViewLeft->proxyModel()->shuffled(); }
|
||||
|
||||
// Do nothing
|
||||
virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); }
|
||||
virtual Tomahawk::result_ptr siblingItem( int ) { return Tomahawk::result_ptr(); }
|
||||
virtual int trackCount() const { return 0; }
|
||||
virtual QList< Tomahawk::query_ptr > tracks() { return QList< Tomahawk::query_ptr >(); }
|
||||
virtual int unfilteredTrackCount() const { return 0; }
|
||||
|
||||
virtual bool hasChildInterface( PlaylistInterface* other )
|
||||
{
|
||||
return m_w->ui->tracksViewLeft->playlistInterface() == other ||
|
||||
m_w->ui->artistsViewLeft->playlistInterface() == other;
|
||||
|
||||
}
|
||||
public slots:
|
||||
virtual void setRepeatMode( RepeatMode mode )
|
||||
{
|
||||
m_w->ui->tracksViewLeft->proxyModel()->setRepeatMode( mode );
|
||||
m_w->ui->artistsViewLeft->proxyModel()->setRepeatMode( mode );
|
||||
}
|
||||
|
||||
virtual void setShuffled( bool enabled )
|
||||
{
|
||||
m_w->ui->tracksViewLeft->proxyModel()->setShuffled( enabled );
|
||||
m_w->ui->artistsViewLeft->proxyModel()->setShuffled( enabled );
|
||||
}
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||
void shuffleModeChanged( bool enabled );
|
||||
|
||||
void trackCountChanged( unsigned int tracks );
|
||||
void sourceTrackCountChanged( unsigned int tracks );
|
||||
void nextTrackReady();
|
||||
|
||||
private slots:
|
||||
void anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode )
|
||||
{
|
||||
emit repeatModeChanged( mode );
|
||||
}
|
||||
|
||||
void anyShuffleChanged( bool enabled )
|
||||
{
|
||||
emit shuffleModeChanged( enabled );
|
||||
}
|
||||
|
||||
private:
|
||||
WhatsHotWidget* m_w;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user