mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-21 00:12:06 +02:00
hook up the dynamic GUI a bit
This commit is contained in:
parent
6ae37541e2
commit
eed7a33578
@ -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/QSharedPointer>
|
||||
#include <QStringList>
|
||||
|
||||
#include "dynamic/DynamicControl.h"
|
||||
#include <tomahawk/typedefs.h>
|
||||
#include "tomahawk/typedefs.h"
|
||||
|
||||
namespace Tomahawk {
|
||||
|
||||
@ -47,7 +47,7 @@ public:
|
||||
|
||||
// Can't make it pure otherwise we can't shove it in QVariants :-/
|
||||
// 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
|
||||
@ -57,7 +57,7 @@ public:
|
||||
* 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
|
||||
QString type() const { return m_type; }
|
||||
@ -66,10 +66,10 @@ public:
|
||||
void setMode( GeneratorMode mode ) { m_mode = mode; }
|
||||
|
||||
// control functions
|
||||
QList< dyncontrol_ptr > controls() const { return m_controls; }
|
||||
void addControl( const dyncontrol_ptr& control ) { m_controls << control; }
|
||||
void clearControls() { m_controls.clear(); }
|
||||
void setControls( const QList< dyncontrol_ptr>& controls ) { m_controls = controls; }
|
||||
QList< dyncontrol_ptr > controls() const;
|
||||
void addControl( const dyncontrol_ptr& control );
|
||||
void clearControls();
|
||||
void setControls( const QList< dyncontrol_ptr>& controls );
|
||||
|
||||
QStringList typeSelectors() const { return m_typeSelectors; }
|
||||
|
||||
@ -81,9 +81,6 @@ protected:
|
||||
GeneratorMode m_mode;
|
||||
QList< dyncontrol_ptr > m_controls;
|
||||
QStringList m_typeSelectors;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(GeneratorInterface)
|
||||
};
|
||||
|
||||
typedef QSharedPointer<GeneratorInterface> geninterface_ptr;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
Tomahawk::EchonestControl::EchonestControl( const QString& type, QObject* parent )
|
||||
: DynamicControl ( type, parent )
|
||||
: DynamicControl ( type.isEmpty() ? "Artist" : type, parent )
|
||||
{
|
||||
updateWidgets();
|
||||
}
|
||||
|
@ -18,11 +18,14 @@
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include "DynamicControlWidget.h"
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
DynamicControlList::DynamicControlList()
|
||||
: AnimatedWidget()
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
{
|
||||
init();
|
||||
@ -30,6 +33,7 @@ DynamicControlList::DynamicControlList()
|
||||
|
||||
DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
||||
: AnimatedWidget( parent )
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
{
|
||||
init();
|
||||
@ -37,6 +41,7 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
||||
|
||||
DynamicControlList::DynamicControlList( const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent)
|
||||
: AnimatedWidget(parent)
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
{
|
||||
init();
|
||||
@ -51,26 +56,32 @@ DynamicControlList::~DynamicControlList()
|
||||
void
|
||||
DynamicControlList::init()
|
||||
{
|
||||
setLayout( new QVBoxLayout );
|
||||
layout()->setMargin( 0 );
|
||||
layout()->setSpacing( 0 );
|
||||
setLayout( m_layout );
|
||||
m_layout->setMargin( 0 );
|
||||
m_layout->setSpacing( 0 );
|
||||
// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Ignored );
|
||||
|
||||
m_summaryWidget = new QWidget();
|
||||
m_summaryWidget = new QWidget( this );
|
||||
// TODO replace
|
||||
m_summaryWidget->setMaximumHeight( 24 );
|
||||
// m_summaryWidget->setMinimumHeight( 24 );
|
||||
// m_summaryWidget->setMaximumHeight( 24 );
|
||||
m_summaryWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
m_summaryWidget->setLayout( new QVBoxLayout );
|
||||
m_summaryWidget->layout()->setMargin( 0 );
|
||||
m_summaryWidget->layout()->addWidget( new QLabel( "replace me plz", m_summaryWidget ) );
|
||||
|
||||
setHiddenSize( m_summaryWidget->size() );
|
||||
|
||||
emit showWidget();
|
||||
}
|
||||
|
||||
void
|
||||
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 );
|
||||
}
|
||||
onShown( this );
|
||||
}
|
||||
|
||||
void
|
||||
@ -82,9 +93,11 @@ DynamicControlList::onHidden( QWidget* w )
|
||||
AnimatedWidget::onHidden( w );
|
||||
|
||||
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
|
||||
@ -95,10 +108,15 @@ DynamicControlList::onShown( QWidget* w )
|
||||
|
||||
AnimatedWidget::onShown( w );
|
||||
|
||||
layout()->removeWidget( m_summaryWidget );
|
||||
m_layout->removeWidget( m_summaryWidget );
|
||||
m_summaryWidget->hide();
|
||||
foreach( DynamicControlWidget* control, m_controls ) {
|
||||
layout()->addWidget( control );
|
||||
|
||||
m_layout->addWidget( control );
|
||||
control->show();
|
||||
control->setShowPlusButton( control == m_controls.last() );
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicControlList::paintEvent(QPaintEvent* )
|
||||
{
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "tomahawk/typedefs.h"
|
||||
#include "dynamic/DynamicPlaylist.h"
|
||||
|
||||
class QVBoxLayout;
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
@ -43,6 +44,7 @@ public:
|
||||
|
||||
void setControls( const QList< dyncontrol_ptr >& controls );
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
|
||||
public slots:
|
||||
virtual void onHidden(QWidget* );
|
||||
@ -51,6 +53,7 @@ public slots:
|
||||
private:
|
||||
void init();
|
||||
|
||||
QVBoxLayout* m_layout;
|
||||
QList< DynamicControlWidget* > m_controls;
|
||||
QWidget* m_summaryWidget;
|
||||
};
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include <QComboBox>
|
||||
#include <QLayout>
|
||||
#include <QToolButton>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -39,8 +41,17 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
||||
m_layout = new QHBoxLayout;
|
||||
m_typeSelector = new QComboBox( this );
|
||||
|
||||
m_layout->setMargin( 0 );
|
||||
setContentsMargins( 0, 0, 0, 0 );
|
||||
|
||||
m_plusButton= new QToolButton( this );
|
||||
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 ) ) );
|
||||
|
||||
@ -48,14 +59,15 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
||||
foreach( const QString& type, control->typeSelectors() )
|
||||
m_typeSelector->addItem( type );
|
||||
|
||||
m_layout->addWidget( m_typeSelector, 0, Qt::AlignLeft );
|
||||
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
|
||||
m_layout->addWidget( m_control->inputField(), 0, Qt::AlignRight );
|
||||
m_layout->addWidget( m_typeSelector, 1, Qt::AlignLeft );
|
||||
m_layout->addWidget( m_control->matchSelector(), 1, Qt::AlignCenter );
|
||||
m_layout->addWidget( m_control->inputField(), 1, Qt::AlignRight );
|
||||
}
|
||||
|
||||
if( m_showPlus )
|
||||
if( m_showPlus ) {
|
||||
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
||||
|
||||
m_plusButton->show();
|
||||
}
|
||||
setLayout( m_layout );
|
||||
}
|
||||
|
||||
@ -69,12 +81,11 @@ DynamicControlWidget::typeSelectorChanged( QString type )
|
||||
{
|
||||
Q_ASSERT( m_layout );
|
||||
// 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( 2 );
|
||||
} else
|
||||
Q_ASSERT( m_layout->count() == 1 );
|
||||
}
|
||||
|
||||
m_control->setSelectedType( type );
|
||||
m_layout->addWidget( m_control->matchSelector(), 0, Qt::AlignCenter );
|
||||
@ -88,8 +99,10 @@ DynamicControlWidget::setShowPlusButton(bool show)
|
||||
if( m_showPlus != show ) {
|
||||
if( show ) {
|
||||
m_layout->addWidget( m_plusButton, 0, Qt::AlignRight );
|
||||
m_plusButton->show();
|
||||
} else {
|
||||
m_layout->removeWidget( m_plusButton );
|
||||
m_plusButton->hide();
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,3 +114,10 @@ DynamicControlWidget::showPlusButton() const
|
||||
{
|
||||
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 );
|
||||
bool showPlusButton() const;
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
private slots:
|
||||
void typeSelectorChanged( QString );
|
||||
|
||||
@ -56,3 +57,5 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class QPaintEvent;
|
||||
|
@ -43,7 +43,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
||||
|
||||
m_splitter = new AnimatedSplitter( this );
|
||||
m_splitter->setOrientation( Qt::Vertical );
|
||||
|
||||
layout()->addWidget( m_splitter );
|
||||
m_controls = new DynamicControlList( m_splitter );
|
||||
m_model = new PlaylistModel( 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->setGreedyWidget( 1 );
|
||||
|
||||
m_splitter->show( 0 );
|
||||
if( !m_playlist.isNull() ) {
|
||||
m_controls->setControls( m_playlist->generator()->controls() );
|
||||
|
||||
|
@ -119,6 +119,7 @@ PlaylistManager::show(const Tomahawk::dynplaylist_ptr& playlist)
|
||||
|
||||
if( !m_dynamicWidgets.contains( playlist ) ) {
|
||||
m_dynamicWidgets[ playlist ] = new Tomahawk::DynamicWidget( playlist, m_stack );
|
||||
m_stack->addWidget( m_dynamicWidgets[ playlist ] );
|
||||
}
|
||||
|
||||
m_stack->setCurrentWidget( m_dynamicWidgets.value( playlist ) );
|
||||
@ -129,7 +130,7 @@ PlaylistManager::show(const Tomahawk::dynplaylist_ptr& playlist)
|
||||
m_modesAvailable = false;
|
||||
linkPlaylist();
|
||||
|
||||
emit numSourcesChanged( APP->sourcelist().count() );\
|
||||
emit numSourcesChanged( APP->sourcelist().count() );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user