mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
hook up the dynamic GUI a bit
This commit is contained in:
@@ -31,3 +31,37 @@ Tomahawk::GeneratorInterface::~GeneratorInterface()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList< Tomahawk::dyncontrol_ptr >
|
||||||
|
Tomahawk::GeneratorInterface::controls() const
|
||||||
|
{
|
||||||
|
if( m_controls.isEmpty() ) { // return a default control (so the user can add more)
|
||||||
|
return QList< Tomahawk::dyncontrol_ptr >() << createControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tomahawk::GeneratorInterface::addControl( const Tomahawk::dyncontrol_ptr& control )
|
||||||
|
{
|
||||||
|
m_controls << control;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tomahawk::GeneratorInterface::clearControls()
|
||||||
|
{
|
||||||
|
m_controls.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tomahawk::GeneratorInterface::setControls( const QList< Tomahawk::dyncontrol_ptr >& controls )
|
||||||
|
{
|
||||||
|
m_controls = controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::dyncontrol_ptr Tomahawk::GeneratorInterface::createControl(const QString& type) const
|
||||||
|
{
|
||||||
|
return dyncontrol_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include "dynamic/DynamicControl.h"
|
#include "tomahawk/typedefs.h"
|
||||||
#include <tomahawk/typedefs.h>
|
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public:
|
|||||||
|
|
||||||
// Can't make it pure otherwise we can't shove it in QVariants :-/
|
// Can't make it pure otherwise we can't shove it in QVariants :-/
|
||||||
// empty QString means use default
|
// empty QString means use default
|
||||||
virtual dyncontrol_ptr createControl( const QString& type = QString() ) const { return dyncontrol_ptr(); }
|
virtual dyncontrol_ptr createControl( const QString& type = QString() ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate tracks from the controls in this playlist. If the current mode is
|
* Generate tracks from the controls in this playlist. If the current mode is
|
||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
* Connect to the generated() signal for the results.
|
* Connect to the generated() signal for the results.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
virtual void generate( int number = -1 ) {};
|
virtual void generate( int number = -1 ) {}
|
||||||
|
|
||||||
/// The type of this generator
|
/// The type of this generator
|
||||||
QString type() const { return m_type; }
|
QString type() const { return m_type; }
|
||||||
@@ -66,10 +66,10 @@ public:
|
|||||||
void setMode( GeneratorMode mode ) { m_mode = mode; }
|
void setMode( GeneratorMode mode ) { m_mode = mode; }
|
||||||
|
|
||||||
// control functions
|
// control functions
|
||||||
QList< dyncontrol_ptr > controls() const { return m_controls; }
|
QList< dyncontrol_ptr > controls() const;
|
||||||
void addControl( const dyncontrol_ptr& control ) { m_controls << control; }
|
void addControl( const dyncontrol_ptr& control );
|
||||||
void clearControls() { m_controls.clear(); }
|
void clearControls();
|
||||||
void setControls( const QList< dyncontrol_ptr>& controls ) { m_controls = controls; }
|
void setControls( const QList< dyncontrol_ptr>& controls );
|
||||||
|
|
||||||
QStringList typeSelectors() const { return m_typeSelectors; }
|
QStringList typeSelectors() const { return m_typeSelectors; }
|
||||||
|
|
||||||
@@ -81,9 +81,6 @@ protected:
|
|||||||
GeneratorMode m_mode;
|
GeneratorMode m_mode;
|
||||||
QList< dyncontrol_ptr > m_controls;
|
QList< dyncontrol_ptr > m_controls;
|
||||||
QStringList m_typeSelectors;
|
QStringList m_typeSelectors;
|
||||||
|
|
||||||
private:
|
|
||||||
Q_DISABLE_COPY(GeneratorInterface)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;
|
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
Tomahawk::EchonestControl::EchonestControl( const QString& type, QObject* parent )
|
Tomahawk::EchonestControl::EchonestControl( const QString& type, QObject* parent )
|
||||||
: DynamicControl ( type, parent )
|
: DynamicControl ( type.isEmpty() ? "Artist" : type, parent )
|
||||||
{
|
{
|
||||||
updateWidgets();
|
updateWidgets();
|
||||||
}
|
}
|
||||||
|
@@ -18,11 +18,14 @@
|
|||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include "DynamicControlWidget.h"
|
#include "DynamicControlWidget.h"
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
DynamicControlList::DynamicControlList()
|
DynamicControlList::DynamicControlList()
|
||||||
: AnimatedWidget()
|
: AnimatedWidget()
|
||||||
|
, m_layout( new QVBoxLayout )
|
||||||
, m_summaryWidget( 0 )
|
, m_summaryWidget( 0 )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -30,6 +33,7 @@ DynamicControlList::DynamicControlList()
|
|||||||
|
|
||||||
DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
||||||
: AnimatedWidget( parent )
|
: AnimatedWidget( parent )
|
||||||
|
, m_layout( new QVBoxLayout )
|
||||||
, m_summaryWidget( 0 )
|
, m_summaryWidget( 0 )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -37,6 +41,7 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
|||||||
|
|
||||||
DynamicControlList::DynamicControlList( const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent)
|
DynamicControlList::DynamicControlList( const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent)
|
||||||
: AnimatedWidget(parent)
|
: AnimatedWidget(parent)
|
||||||
|
, m_layout( new QVBoxLayout )
|
||||||
, m_summaryWidget( 0 )
|
, m_summaryWidget( 0 )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -51,26 +56,32 @@ DynamicControlList::~DynamicControlList()
|
|||||||
void
|
void
|
||||||
DynamicControlList::init()
|
DynamicControlList::init()
|
||||||
{
|
{
|
||||||
setLayout( new QVBoxLayout );
|
setLayout( m_layout );
|
||||||
layout()->setMargin( 0 );
|
m_layout->setMargin( 0 );
|
||||||
layout()->setSpacing( 0 );
|
m_layout->setSpacing( 0 );
|
||||||
|
// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Ignored );
|
||||||
|
|
||||||
m_summaryWidget = new QWidget();
|
m_summaryWidget = new QWidget( this );
|
||||||
// TODO replace
|
// TODO replace
|
||||||
m_summaryWidget->setMaximumHeight( 24 );
|
// m_summaryWidget->setMinimumHeight( 24 );
|
||||||
|
// m_summaryWidget->setMaximumHeight( 24 );
|
||||||
m_summaryWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
m_summaryWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||||
m_summaryWidget->setLayout( new QVBoxLayout );
|
m_summaryWidget->setLayout( new QVBoxLayout );
|
||||||
m_summaryWidget->layout()->setMargin( 0 );
|
m_summaryWidget->layout()->setMargin( 0 );
|
||||||
m_summaryWidget->layout()->addWidget( new QLabel( "replace me plz", m_summaryWidget ) );
|
m_summaryWidget->layout()->addWidget( new QLabel( "replace me plz", m_summaryWidget ) );
|
||||||
|
|
||||||
setHiddenSize( m_summaryWidget->size() );
|
setHiddenSize( m_summaryWidget->size() );
|
||||||
|
|
||||||
|
emit showWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicControlList::setControls(const QList< dyncontrol_ptr >& controls)
|
DynamicControlList::setControls(const QList< dyncontrol_ptr >& controls)
|
||||||
{
|
{
|
||||||
foreach( const dyncontrol_ptr& control, controls )
|
foreach( const dyncontrol_ptr& control, controls ) {
|
||||||
m_controls << new DynamicControlWidget( control, false, this );
|
m_controls << new DynamicControlWidget( control, false, this );
|
||||||
|
}
|
||||||
|
onShown( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -82,9 +93,11 @@ DynamicControlList::onHidden( QWidget* w )
|
|||||||
AnimatedWidget::onHidden( w );
|
AnimatedWidget::onHidden( w );
|
||||||
|
|
||||||
foreach( DynamicControlWidget* control, m_controls ) {
|
foreach( DynamicControlWidget* control, m_controls ) {
|
||||||
layout()->removeWidget( control );
|
m_layout->removeWidget( control );
|
||||||
|
control->hide();
|
||||||
}
|
}
|
||||||
layout()->addWidget( m_summaryWidget );
|
m_layout->addWidget( m_summaryWidget );
|
||||||
|
m_summaryWidget->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -95,10 +108,15 @@ DynamicControlList::onShown( QWidget* w )
|
|||||||
|
|
||||||
AnimatedWidget::onShown( w );
|
AnimatedWidget::onShown( w );
|
||||||
|
|
||||||
layout()->removeWidget( m_summaryWidget );
|
m_layout->removeWidget( m_summaryWidget );
|
||||||
|
m_summaryWidget->hide();
|
||||||
foreach( DynamicControlWidget* control, m_controls ) {
|
foreach( DynamicControlWidget* control, m_controls ) {
|
||||||
layout()->addWidget( control );
|
m_layout->addWidget( control );
|
||||||
|
control->show();
|
||||||
control->setShowPlusButton( control == m_controls.last() );
|
control->setShowPlusButton( control == m_controls.last() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicControlList::paintEvent(QPaintEvent* )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "tomahawk/typedefs.h"
|
#include "tomahawk/typedefs.h"
|
||||||
#include "dynamic/DynamicPlaylist.h"
|
#include "dynamic/DynamicPlaylist.h"
|
||||||
|
|
||||||
|
class QVBoxLayout;
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -43,6 +44,7 @@ public:
|
|||||||
|
|
||||||
void setControls( const QList< dyncontrol_ptr >& controls );
|
void setControls( const QList< dyncontrol_ptr >& controls );
|
||||||
|
|
||||||
|
virtual void paintEvent(QPaintEvent* );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void onHidden(QWidget* );
|
virtual void onHidden(QWidget* );
|
||||||
@@ -51,6 +53,7 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
QVBoxLayout* m_layout;
|
||||||
QList< DynamicControlWidget* > m_controls;
|
QList< DynamicControlWidget* > m_controls;
|
||||||
QWidget* m_summaryWidget;
|
QWidget* m_summaryWidget;
|
||||||
};
|
};
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -39,8 +41,17 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
|||||||
m_layout = new QHBoxLayout;
|
m_layout = new QHBoxLayout;
|
||||||
m_typeSelector = new QComboBox( this );
|
m_typeSelector = new QComboBox( this );
|
||||||
|
|
||||||
|
m_layout->setMargin( 0 );
|
||||||
|
setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
|
||||||
m_plusButton= new QToolButton( this );
|
m_plusButton= new QToolButton( this );
|
||||||
m_plusButton->setIcon( QIcon( RESPATH "images/list-add.png" ) );
|
m_plusButton->setIcon( QIcon( RESPATH "images/list-add.png" ) );
|
||||||
|
m_plusButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||||
|
m_plusButton->setIconSize( QSize( 16, 16 ) );
|
||||||
|
m_plusButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
|
||||||
|
m_plusButton->setAutoRaise( true );
|
||||||
|
m_plusButton->setContentsMargins( 0, 0, 0, 0 );
|
||||||
|
m_plusButton->hide();
|
||||||
|
|
||||||
connect( m_typeSelector, SIGNAL( currentIndexChanged( QString ) ), SLOT( typeSelectorChanged( QString ) ) );
|
connect( m_typeSelector, SIGNAL( currentIndexChanged( QString ) ), SLOT( typeSelectorChanged( QString ) ) );
|
||||||
|
|
||||||
@@ -48,14 +59,15 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
|||||||
foreach( const QString& type, control->typeSelectors() )
|
foreach( const QString& type, control->typeSelectors() )
|
||||||
m_typeSelector->addItem( type );
|
m_typeSelector->addItem( type );
|
||||||
|
|
||||||
m_layout->addWidget( m_typeSelector, 0, Qt::AlignLeft );
|
m_layout->addWidget( m_typeSelector, 1, Qt::AlignLeft );
|
||||||
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
|
m_layout->addWidget( m_control->matchSelector(), 1, Qt::AlignCenter );
|
||||||
m_layout->addWidget( m_control->inputField(), 0, Qt::AlignRight );
|
m_layout->addWidget( m_control->inputField(), 1, Qt::AlignRight );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_showPlus )
|
if( m_showPlus ) {
|
||||||
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
||||||
|
m_plusButton->show();
|
||||||
|
}
|
||||||
setLayout( m_layout );
|
setLayout( m_layout );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,12 +81,11 @@ DynamicControlWidget::typeSelectorChanged( QString type )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( m_layout );
|
Q_ASSERT( m_layout );
|
||||||
// remove the two widgets, change the control,and re-add the new ones
|
// remove the two widgets, change the control,and re-add the new ones
|
||||||
if( m_layout->count() == 3 )
|
if( m_layout->count() >= 3 )
|
||||||
{
|
{
|
||||||
m_layout->takeAt( 1 );
|
m_layout->takeAt( 1 );
|
||||||
m_layout->takeAt( 2 );
|
m_layout->takeAt( 2 );
|
||||||
} else
|
}
|
||||||
Q_ASSERT( m_layout->count() == 1 );
|
|
||||||
|
|
||||||
m_control->setSelectedType( type );
|
m_control->setSelectedType( type );
|
||||||
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
|
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
|
||||||
@@ -88,8 +99,10 @@ DynamicControlWidget::setShowPlusButton(bool show)
|
|||||||
if( m_showPlus != show ) {
|
if( m_showPlus != show ) {
|
||||||
if( show ) {
|
if( show ) {
|
||||||
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
||||||
|
m_plusButton->show();
|
||||||
} else {
|
} else {
|
||||||
m_layout->removeWidget( m_plusButton );
|
m_layout->removeWidget( m_plusButton );
|
||||||
|
m_plusButton->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,3 +114,10 @@ DynamicControlWidget::showPlusButton() const
|
|||||||
{
|
{
|
||||||
return m_showPlus;
|
return m_showPlus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DynamicControlWidget::paintEvent(QPaintEvent* e)
|
||||||
|
{
|
||||||
|
QPainter p;
|
||||||
|
p.fillRect( e->rect(), Qt::yellow );
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ public:
|
|||||||
void setShowPlusButton( bool show );
|
void setShowPlusButton( bool show );
|
||||||
bool showPlusButton() const;
|
bool showPlusButton() const;
|
||||||
|
|
||||||
|
virtual void paintEvent(QPaintEvent* );
|
||||||
private slots:
|
private slots:
|
||||||
void typeSelectorChanged( QString );
|
void typeSelectorChanged( QString );
|
||||||
|
|
||||||
@@ -56,3 +57,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class QPaintEvent;
|
||||||
|
@@ -43,7 +43,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
|||||||
|
|
||||||
m_splitter = new AnimatedSplitter( this );
|
m_splitter = new AnimatedSplitter( this );
|
||||||
m_splitter->setOrientation( Qt::Vertical );
|
m_splitter->setOrientation( Qt::Vertical );
|
||||||
|
layout()->addWidget( m_splitter );
|
||||||
m_controls = new DynamicControlList( m_splitter );
|
m_controls = new DynamicControlList( m_splitter );
|
||||||
m_model = new PlaylistModel( this );
|
m_model = new PlaylistModel( this );
|
||||||
m_view = new PlaylistView( this );
|
m_view = new PlaylistView( this );
|
||||||
@@ -53,6 +53,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
|||||||
m_splitter->addWidget( m_view );
|
m_splitter->addWidget( m_view );
|
||||||
m_splitter->setGreedyWidget( 1 );
|
m_splitter->setGreedyWidget( 1 );
|
||||||
|
|
||||||
|
m_splitter->show( 0 );
|
||||||
if( !m_playlist.isNull() ) {
|
if( !m_playlist.isNull() ) {
|
||||||
m_controls->setControls( m_playlist->generator()->controls() );
|
m_controls->setControls( m_playlist->generator()->controls() );
|
||||||
|
|
||||||
|
@@ -119,6 +119,7 @@ PlaylistManager::show(const Tomahawk::dynplaylist_ptr& playlist)
|
|||||||
|
|
||||||
if( !m_dynamicWidgets.contains( playlist ) ) {
|
if( !m_dynamicWidgets.contains( playlist ) ) {
|
||||||
m_dynamicWidgets[ playlist ] = new Tomahawk::DynamicWidget( playlist, m_stack );
|
m_dynamicWidgets[ playlist ] = new Tomahawk::DynamicWidget( playlist, m_stack );
|
||||||
|
m_stack->addWidget( m_dynamicWidgets[ playlist ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_stack->setCurrentWidget( m_dynamicWidgets.value( playlist ) );
|
m_stack->setCurrentWidget( m_dynamicWidgets.value( playlist ) );
|
||||||
@@ -129,7 +130,7 @@ PlaylistManager::show(const Tomahawk::dynplaylist_ptr& playlist)
|
|||||||
m_modesAvailable = false;
|
m_modesAvailable = false;
|
||||||
linkPlaylist();
|
linkPlaylist();
|
||||||
|
|
||||||
emit numSourcesChanged( APP->sourcelist().count() );\
|
emit numSourcesChanged( APP->sourcelist().count() );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user