mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Allow to set icon and text for externally added generic page items without instantiating them (aka fix lazy loading for vsxu widget)
This commit is contained in:
@@ -924,18 +924,18 @@ ViewManager::dynamicPageWidget( const QString& pageName ) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ViewManager::addDynamicPage(const QString& pageName, ViewPage* page )
|
ViewManager::addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function<Tomahawk::ViewPage*()> instanceLoader )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Trying to add " << pageName;
|
tLog() << Q_FUNC_INFO << "Trying to add " << pageName;
|
||||||
|
|
||||||
if( dynamicPageWidget( pageName ) )
|
if( m_dynamicPages.contains( pageName ) )
|
||||||
{
|
{
|
||||||
tLog() << "Not adding a second ViewPage with name " << pageName;
|
tLog() << "Not adding a second ViewPage with name " << pageName;
|
||||||
Q_ASSERT( false );
|
Q_ASSERT( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dynamicPages.insert( pageName, page );
|
m_dynamicPagesInstanceLoaders.insert( pageName, instanceLoader );
|
||||||
emit viewPageAdded( pageName );
|
emit viewPageAdded( pageName, text, icon );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -944,6 +944,18 @@ ViewManager::showDynamicPage( const QString& pageName )
|
|||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "pageName: " << pageName;
|
tLog() << Q_FUNC_INFO << "pageName: " << pageName;
|
||||||
|
|
||||||
|
if( !m_dynamicPages.contains( pageName ) )
|
||||||
|
{
|
||||||
|
if( !m_dynamicPagesInstanceLoaders.contains( pageName ) )
|
||||||
|
{
|
||||||
|
tLog() << "Trying to show a page that does not exist and does not have a registered loader";
|
||||||
|
Q_ASSERT(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
m_dynamicPages.insert( pageName, m_dynamicPagesInstanceLoaders.value( pageName )() );
|
||||||
|
m_dynamicPagesInstanceLoaders.remove( pageName );
|
||||||
|
}
|
||||||
|
|
||||||
return show( dynamicPageWidget( pageName ) );
|
return show( dynamicPageWidget( pageName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,16 +20,19 @@
|
|||||||
#ifndef VIEWMANAGER_H
|
#ifndef VIEWMANAGER_H
|
||||||
#define VIEWMANAGER_H
|
#define VIEWMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QHash>
|
|
||||||
#include <QStackedWidget>
|
|
||||||
|
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
#include "collection/Collection.h"
|
#include "collection/Collection.h"
|
||||||
#include "PlaylistInterface.h"
|
#include "PlaylistInterface.h"
|
||||||
#include "playlist/QueueView.h"
|
#include "playlist/QueueView.h"
|
||||||
#include "ViewPage.h"
|
#include "ViewPage.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QStackedWidget>
|
||||||
|
|
||||||
|
// best regards to you, mr. pimple aka xhochy :)
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class AnimatedSplitter;
|
class AnimatedSplitter;
|
||||||
@@ -137,7 +140,7 @@ signals:
|
|||||||
void historyBackAvailable( bool avail );
|
void historyBackAvailable( bool avail );
|
||||||
void historyForwardAvailable( bool avail );
|
void historyForwardAvailable( bool avail );
|
||||||
|
|
||||||
void viewPageAdded( const QString& pageName );
|
void viewPageAdded( const QString& pageName, const QString& text, const QIcon& icon );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
Tomahawk::ViewPage* showSuperCollection();
|
Tomahawk::ViewPage* showSuperCollection();
|
||||||
@@ -148,7 +151,7 @@ public slots:
|
|||||||
Tomahawk::ViewPage* showInboxPage();
|
Tomahawk::ViewPage* showInboxPage();
|
||||||
Tomahawk::ViewPage* showNetworkActivityPage();
|
Tomahawk::ViewPage* showNetworkActivityPage();
|
||||||
|
|
||||||
void addDynamicPage( const QString& pageName, Tomahawk::ViewPage* page );
|
void addDynamicPage( const QString& pageName, const QString& text, const QIcon& icon, boost::function< Tomahawk::ViewPage*() > instanceLoader );
|
||||||
Tomahawk::ViewPage* showDynamicPage( const QString& pageName );
|
Tomahawk::ViewPage* showDynamicPage( const QString& pageName );
|
||||||
|
|
||||||
void showCurrentTrack();
|
void showCurrentTrack();
|
||||||
@@ -207,6 +210,7 @@ private:
|
|||||||
NetworkActivityWidget* m_networkActivityWidget;
|
NetworkActivityWidget* m_networkActivityWidget;
|
||||||
|
|
||||||
QHash< QString, Tomahawk::ViewPage* > m_dynamicPages;
|
QHash< QString, Tomahawk::ViewPage* > m_dynamicPages;
|
||||||
|
QHash< QString, boost::function< Tomahawk::ViewPage*() > > m_dynamicPagesInstanceLoaders;
|
||||||
|
|
||||||
QList< Tomahawk::collection_ptr > m_superCollections;
|
QList< Tomahawk::collection_ptr > m_superCollections;
|
||||||
|
|
||||||
|
@@ -79,7 +79,7 @@ SourcesModel::SourcesModel( QObject* parent )
|
|||||||
this, SLOT( onScriptCollectionRemoved( Tomahawk::collection_ptr ) ) );
|
this, SLOT( onScriptCollectionRemoved( Tomahawk::collection_ptr ) ) );
|
||||||
|
|
||||||
|
|
||||||
connect( ViewManager::instance(), SIGNAL( viewPageAdded( QString ) ), SLOT( onViewPageAdded( QString ) ) );
|
connect( ViewManager::instance(), SIGNAL( viewPageAdded( QString, QString, QIcon ) ), SLOT( appendPageItem( QString, QString, QIcon ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -348,13 +348,13 @@ SourcesModel::appendGroups()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SourcesModel::appendPageItem( const QIcon& pageIcon, const QString& pageTitle, const QString& pageName )
|
SourcesModel::appendPageItem( const QString& name, const QString& text, const QIcon& icon )
|
||||||
{
|
{
|
||||||
QModelIndex parentIndex = indexFromItem( m_browse );
|
QModelIndex parentIndex = indexFromItem( m_browse );
|
||||||
beginInsertRows( parentIndex, rowCount( parentIndex ), rowCount( parentIndex ) );
|
beginInsertRows( parentIndex, rowCount( parentIndex ), rowCount( parentIndex ) );
|
||||||
GenericPageItem* pageItem = new GenericPageItem( this, m_browse, pageTitle, pageIcon,
|
GenericPageItem* pageItem = new GenericPageItem( this, m_browse, text, icon,
|
||||||
boost::bind( &ViewManager::showDynamicPage, ViewManager::instance(), pageName ),
|
boost::bind( &ViewManager::showDynamicPage, ViewManager::instance(), name ),
|
||||||
boost::bind( &ViewManager::dynamicPageWidget, ViewManager::instance(), pageName ) );
|
boost::bind( &ViewManager::dynamicPageWidget, ViewManager::instance(), name ) );
|
||||||
pageItem->setSortValue( rowCount( parentIndex ) );
|
pageItem->setSortValue( rowCount( parentIndex ) );
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
@@ -672,13 +672,6 @@ SourcesModel::onWidgetDestroyed( QWidget* w )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourcesModel::onViewPageAdded( const QString& name )
|
|
||||||
{
|
|
||||||
appendPageItem( ImageRegistry::instance()->icon( RESPATH "images/new-releases.svg" ), name, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourcesModel::removeSourceItemLink( SourceTreeItem* item )
|
SourcesModel::removeSourceItemLink( SourceTreeItem* item )
|
||||||
{
|
{
|
||||||
|
@@ -103,11 +103,6 @@ public:
|
|||||||
|
|
||||||
void appendGroups();
|
void appendGroups();
|
||||||
|
|
||||||
/*
|
|
||||||
* pageIcon and pageTitle are visible in the source tree, pageName is the internal name in the ViewManager
|
|
||||||
*/
|
|
||||||
void appendPageItem( const QIcon& pageIcon, const QString& pageTitle, const QString& pageName );
|
|
||||||
|
|
||||||
void appendItem( const Tomahawk::source_ptr& source );
|
void appendItem( const Tomahawk::source_ptr& source );
|
||||||
bool removeItem( const Tomahawk::source_ptr& source );
|
bool removeItem( const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
@@ -151,7 +146,10 @@ private slots:
|
|||||||
|
|
||||||
void onWidgetDestroyed( QWidget* w );
|
void onWidgetDestroyed( QWidget* w );
|
||||||
|
|
||||||
void onViewPageAdded( const QString& name );
|
/*
|
||||||
|
* pageIcon and pageTitle are visible in the source tree, pageName is the internal name in the ViewManager
|
||||||
|
*/
|
||||||
|
void appendPageItem( const QString& name, const QString& text, const QIcon& icon );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
|
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
|
||||||
|
Reference in New Issue
Block a user