1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-19 12:21:52 +02:00

Refactor dynamic control UI to fit in a gridlayout, and remove the AnimatedSplitter to replace with a QStackedWidget

This commit is contained in:
Leo Franchi
2011-01-22 13:31:13 -05:00
parent 992275e174
commit 7eb6822725
9 changed files with 272 additions and 186 deletions

View File

@@ -98,10 +98,11 @@ set( libSources
playlist/dynamic/echonest/EchonestGenerator.cpp playlist/dynamic/echonest/EchonestGenerator.cpp
playlist/dynamic/echonest/EchonestControl.cpp playlist/dynamic/echonest/EchonestControl.cpp
playlist/dynamic/widgets/DynamicWidget.cpp playlist/dynamic/widgets/DynamicWidget.cpp
playlist/dynamic/widgets/DynamicControlWidget.cpp playlist/dynamic/widgets/DynamicControlWrapper.cpp
playlist/dynamic/widgets/DynamicControlList.cpp playlist/dynamic/widgets/DynamicControlList.cpp
playlist/dynamic/widgets/ReadOrWriteWidget.cpp playlist/dynamic/widgets/ReadOrWriteWidget.cpp
playlist/dynamic/widgets/MiscControlWidgets.cpp playlist/dynamic/widgets/MiscControlWidgets.cpp
playlist/dynamic/widgets/CollapsibleControls.cpp
network/bufferiodevice.cpp network/bufferiodevice.cpp
@@ -228,10 +229,11 @@ set( libHeaders
playlist/dynamic/echonest/EchonestGenerator.h playlist/dynamic/echonest/EchonestGenerator.h
playlist/dynamic/echonest/EchonestControl.h playlist/dynamic/echonest/EchonestControl.h
playlist/dynamic/widgets/DynamicWidget.h playlist/dynamic/widgets/DynamicWidget.h
playlist/dynamic/widgets/DynamicControlWidget.h playlist/dynamic/widgets/DynamicControlWrapper.h
playlist/dynamic/widgets/DynamicControlList.h playlist/dynamic/widgets/DynamicControlList.h
playlist/dynamic/widgets/ReadOrWriteWidget.h playlist/dynamic/widgets/ReadOrWriteWidget.h
playlist/dynamic/widgets/MiscControlWidgets.h playlist/dynamic/widgets/MiscControlWidgets.h
playlist/dynamic/widgets/CollapsibleControls.h
utils/querylabel.h utils/querylabel.h
utils/elidedlabel.h utils/elidedlabel.h

View File

@@ -0,0 +1,94 @@
/****************************************************************************************
* Copyright (c) 2010-2011 Leo Franchi <lfranchi@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 *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program 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 *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "CollapsibleControls.h"
#include "DynamicControlList.h"
#include "DynamicControlWrapper.h"
#include "dynamic/GeneratorInterface.h"
#include "dynamic/DynamicControl.h"
#include <QLabel>
#include <QStackedLayout>
using namespace Tomahawk;
CollapsibleControls::CollapsibleControls( QWidget* parent )
: QWidget( parent )
{
init();
}
CollapsibleControls::CollapsibleControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal, QWidget* parent )
: QWidget( parent )
{
init();
setControls( generator, controls, isLocal );
}
Tomahawk::CollapsibleControls::~CollapsibleControls()
{
}
void
CollapsibleControls::init()
{
m_layout = new QStackedLayout;
setContentsMargins( 0, 0, 0, 0 );
m_layout->setContentsMargins( 0, 0, 0, 0 );
m_layout->setSpacing( 0 );
m_controls = new Tomahawk::DynamicControlList( this );
m_layout->addWidget( m_controls );
m_summaryWidget = new QWidget( this );
// TODO replace
// 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 ) );
m_layout->addWidget( m_summaryWidget );
m_layout->setCurrentIndex( 0 );
connect( m_controls, SIGNAL( controlChanged( Tomahawk::dyncontrol_ptr ) ), SIGNAL( controlChanged( Tomahawk::dyncontrol_ptr ) ) );
connect( m_controls, SIGNAL( controlsChanged() ), SIGNAL( controlsChanged() ) );
setLayout( m_layout );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
}
QList< DynamicControlWrapper* >
Tomahawk::CollapsibleControls::controls() const
{
return m_controls->controls();
}
void
CollapsibleControls::setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal )
{
m_controls->setControls( generator, controls, isLocal );
}
void
CollapsibleControls::toggleCollapse()
{
}

View File

@@ -0,0 +1,59 @@
/****************************************************************************************
* Copyright (c) 2010-2011 Leo Franchi <lfranchi@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 *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program 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 *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef COLLAPSIBLE_CONTROLS_H
#define COLLAPSIBLE_CONTROLS_H
#include "typedefs.h"
#include <QWidget>
class QStackedLayout;
namespace Tomahawk
{
class DynamicControlWrapper;
class DynamicControlList;
class CollapsibleControls : public QWidget
{
Q_OBJECT
public:
CollapsibleControls( QWidget* parent );
CollapsibleControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal, QWidget* parent = 0 );
virtual ~CollapsibleControls();
void setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal );
QList< DynamicControlWrapper* > controls() const;
signals:
void controlsChanged();
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
private slots:
void toggleCollapse();
private:
void init();
QStackedLayout* m_layout;
DynamicControlList* m_controls;
QWidget* m_summaryWidget;
};
}
#endif

View File

@@ -22,35 +22,27 @@
#include <QPushButton> #include <QPushButton>
#include <QToolButton> #include <QToolButton>
#include <QPainter> #include <QPainter>
#include <QGridLayout>
#include "DynamicControlWidget.h" #include "DynamicControlWrapper.h"
#include "dynamic/GeneratorInterface.h" #include "dynamic/GeneratorInterface.h"
#include "tomahawk/tomahawkapp.h" #include "tomahawk/tomahawkapp.h"
#include <QHBoxLayout> #include <QHBoxLayout>
using namespace Tomahawk; using namespace Tomahawk;
DynamicControlList::DynamicControlList() DynamicControlList::DynamicControlList( QWidget* parent )
: AnimatedWidget() : QWidget( parent )
, m_layout( new QVBoxLayout ) , m_layout( new QGridLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
{ {
init(); init();
} }
DynamicControlList::DynamicControlList( AnimatedSplitter* parent ) DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal, QWidget* parent )
: AnimatedWidget( parent ) : QWidget( parent )
, m_layout( new QVBoxLayout )
, m_summaryWidget( 0 )
, m_isLocal( true )
{
init();
}
DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent, bool isLocal )
: AnimatedWidget(parent)
, m_generator( generator ) , m_generator( generator )
, m_layout( new QVBoxLayout ) , m_layout( new QGridLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_isLocal( isLocal ) , m_isLocal( isLocal )
{ {
@@ -66,23 +58,14 @@ DynamicControlList::~DynamicControlList()
void void
DynamicControlList::init() DynamicControlList::init()
{ {
qDebug() << "GRIDLAYOUT: " << m_layout->rowCount();
setContentsMargins( 0, 0, 0, 0 );
setLayout( m_layout ); setLayout( m_layout );
m_layout->setColumnStretch( 2, 1 );
m_layout->setMargin( 0 ); m_layout->setMargin( 0 );
m_layout->setSpacing( 0 ); m_layout->setSpacing( 0 );
m_layout->setContentsMargins( 0, 0, 0, 0 ); m_layout->setContentsMargins( 0, 0, 0, 0 );
m_layout->setSizeConstraint( QLayout::SetMinimumSize ); m_layout->setSizeConstraint( QLayout::SetMinimumSize );
// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Ignored );
splitter()->setStretchFactor( 0, 0 );
splitter()->setStretchFactor( 1,1 );
m_summaryWidget = new QWidget( this );
// TODO replace
// 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 ) );
m_collapseLayout = new QHBoxLayout( this ); m_collapseLayout = new QHBoxLayout( this );
m_collapseLayout->setContentsMargins( 0, 0, 0, 0 ); m_collapseLayout->setContentsMargins( 0, 0, 0, 0 );
@@ -100,12 +83,10 @@ DynamicControlList::init()
m_collapseLayout->addWidget( m_addControl ); m_collapseLayout->addWidget( m_addControl );
m_collapse->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); m_collapse->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
// connect( m_collapse, SIGNAL( clicked() ), this, ); connect( m_collapse, SIGNAL( clicked() ), this, SIGNAL( toggleCollapse() ) );
connect( m_addControl, SIGNAL( clicked() ), this, SLOT( addNewControl() ) ); connect( m_addControl, SIGNAL( clicked() ), this, SLOT( addNewControl() ) );
setHiddenSize( m_summaryWidget->size() );
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
emit showWidget();
} }
void void
@@ -115,65 +96,36 @@ DynamicControlList::setControls( const geninterface_ptr& generator, const QList<
qDeleteAll( m_controls ); qDeleteAll( m_controls );
m_controls.clear(); m_controls.clear();
} }
m_layout->removeItem( m_collapseLayout );
m_isLocal = isLocal; m_isLocal = isLocal;
m_generator = generator; m_generator = generator;
if( controls.isEmpty() ) { if( controls.isEmpty() ) {
m_controls << new DynamicControlWidget( generator->createControl(), isLocal, this ); qDebug() << "CREATING DEFAULT CONTROL";
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); DynamicControlWrapper* ctrlW = new DynamicControlWrapper( generator->createControl(), m_layout, m_controls.size(), isLocal, this );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) ); connect( ctrlW, SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( ctrlW, SIGNAL( changed() ), this, SLOT( controlChanged() ) );
m_controls << ctrlW;
} else } else
{ {
foreach( const dyncontrol_ptr& control, controls ) { foreach( const dyncontrol_ptr& control, controls ) {
m_controls << new DynamicControlWidget( control, isLocal, this ); DynamicControlWrapper* ctrlW = new DynamicControlWrapper( control, m_layout, m_controls.size(), isLocal, this );
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); connect( ctrlW, SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) ); connect( ctrlW, SIGNAL( changed() ), this, SLOT( controlChanged() ) );
m_controls << ctrlW;
} }
} }
onShown( this ); m_layout->addItem( m_collapseLayout, m_layout->rowCount(), 0, 1, 4, Qt::AlignCenter );
}
void
DynamicControlList::onHidden( QWidget* w )
{
if( w != this )
return;
AnimatedWidget::onHidden( w );
foreach( DynamicControlWidget* control, m_controls ) {
m_layout->removeWidget( control );
control->hide();
}
m_layout->addWidget( m_summaryWidget );
m_summaryWidget->show();
}
void
DynamicControlList::onShown( QWidget* w )
{
if( w != this )
return;
m_layout->removeWidget( m_summaryWidget );
m_layout->removeItem( m_collapseLayout );
m_summaryWidget->hide();
foreach( DynamicControlWidget* control, m_controls ) {
m_layout->addWidget( control );
}
m_layout->addItem( m_collapseLayout );
m_layout->setStretchFactor( m_collapseLayout, 1 );
AnimatedWidget::onShown( w );
} }
void DynamicControlList::addNewControl() void DynamicControlList::addNewControl()
{ {
dyncontrol_ptr control = m_generator->createControl(); dyncontrol_ptr control = m_generator->createControl();
m_controls.append( new DynamicControlWidget( control, m_isLocal, this ) ); m_controls.append( new DynamicControlWrapper( control, m_layout, m_controls.size(), m_isLocal, this ) );
m_layout->insertWidget( m_layout->count() - 1, m_controls.last() );
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) ); connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
@@ -182,8 +134,8 @@ void DynamicControlList::addNewControl()
void DynamicControlList::removeControl() void DynamicControlList::removeControl()
{ {
DynamicControlWidget* w = qobject_cast<DynamicControlWidget*>( sender() ); DynamicControlWrapper* w = qobject_cast<DynamicControlWrapper*>( sender() );
m_layout->removeWidget( w ); w->removeFromLayout();
m_controls.removeAll( w ); m_controls.removeAll( w );
m_generator->removeControl( w->control() ); m_generator->removeControl( w->control() );
@@ -194,16 +146,11 @@ void DynamicControlList::removeControl()
void DynamicControlList::controlChanged() void DynamicControlList::controlChanged()
{ {
Q_ASSERT( sender() && qobject_cast<DynamicControlWidget*>(sender()) ); Q_ASSERT( sender() && qobject_cast<DynamicControlWrapper*>(sender()) );
DynamicControlWidget* widget = qobject_cast<DynamicControlWidget*>(sender()); DynamicControlWrapper* widget = qobject_cast<DynamicControlWrapper*>(sender());
qDebug() << "control changed!"; qDebug() << "control changed!";
foreach( DynamicControlWidget* c, m_controls ) foreach( DynamicControlWrapper* c, m_controls )
qDebug() << c->control()->id() << c->control()->selectedType() << c->control()->match() << c->control()->input(); qDebug() << c->control()->id() << c->control()->selectedType() << c->control()->match() << c->control()->input();
emit controlChanged( widget->control() ); emit controlChanged( widget->control() );
} }
void DynamicControlList::paintEvent(QPaintEvent* )
{
}

View File

@@ -17,10 +17,12 @@
#ifndef DYNAMIC_CONTROL_LIST_H #ifndef DYNAMIC_CONTROL_LIST_H
#define DYNAMIC_CONTROL_LIST_H #define DYNAMIC_CONTROL_LIST_H
#include "utils/animatedsplitter.h"
#include "typedefs.h" #include "typedefs.h"
#include "dynamic/DynamicPlaylist.h" #include "dynamic/DynamicPlaylist.h"
#include <QStackedWidget>
class QGridLayout;
class QPushButton; class QPushButton;
class QHBoxLayout; class QHBoxLayout;
class QVBoxLayout; class QVBoxLayout;
@@ -29,46 +31,41 @@ class QToolButton;
namespace Tomahawk namespace Tomahawk
{ {
class DynamicControlWidget; class DynamicControlWrapper;
/** /**
* This widget encapsulates the list of dynamic controls and behaves as an animated widget in * This widget encapsulates the list of dynamic controls. It can hide or show the controls.
* the animated splitter
*/ */
class DynamicControlList : public AnimatedWidget class DynamicControlList : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
DynamicControlList(); // bad compiler! DynamicControlList( QWidget* parent = 0 );
explicit DynamicControlList(AnimatedSplitter* parent ); explicit DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal, QWidget* parent = 0 );
explicit DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent, bool isLocal );
virtual ~DynamicControlList(); virtual ~DynamicControlList();
void setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal ); void setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, bool isLocal );
QList< DynamicControlWidget* > controls() const { return m_controls; } QList< DynamicControlWrapper* > controls() const { return m_controls; }
virtual void paintEvent(QPaintEvent* );
signals: signals:
void controlsChanged(); void controlsChanged();
void controlChanged( const Tomahawk::dyncontrol_ptr& control ); void controlChanged( const Tomahawk::dyncontrol_ptr& control );
void toggleCollapse();
public slots: public slots:
virtual void onHidden(QWidget* );
virtual void onShown(QWidget* );
void addNewControl(); void addNewControl();
void removeControl(); void removeControl();
void controlChanged(); void controlChanged();
private: private:
void init(); void init();
geninterface_ptr m_generator; geninterface_ptr m_generator;
QVBoxLayout* m_layout; QGridLayout* m_layout;
QList< DynamicControlWidget* > m_controls; QList< DynamicControlWrapper* > m_controls;
QWidget* m_summaryWidget; QWidget* m_summaryWidget;
QHBoxLayout* m_collapseLayout; QHBoxLayout* m_collapseLayout;

View File

@@ -1,5 +1,5 @@
/**************************************************************************************** /****************************************************************************************
* Copyright (c) 2010 Leo Franchi <lfranchi@kde.org> * * Copyright (c) 2010-2011 Leo Franchi <lfranchi@kde.org> *
* * * *
* This program is free software; you can redistribute it and/or modify it under * * 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 * * the terms of the GNU General Public License as published by the Free Software *
@@ -14,7 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * * this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/ ****************************************************************************************/
#include "DynamicControlWidget.h" #include "DynamicControlWrapper.h"
#include "tomahawk/tomahawkapp.h" #include "tomahawk/tomahawkapp.h"
#include "dynamic/DynamicControl.h" #include "dynamic/DynamicControl.h"
@@ -30,33 +30,28 @@
using namespace Tomahawk; using namespace Tomahawk;
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool isLocal, QWidget* parent ) DynamicControlWrapper::DynamicControlWrapper( const Tomahawk::dyncontrol_ptr& control, QGridLayout* layout, int row, bool isLocal, QWidget* parent )
: QWidget(parent) : QObject( parent )
, m_isLocal( isLocal ) , m_isLocal( isLocal )
, m_mouseOver( false ) , m_mouseOver( false )
, m_parent( parent )
, m_row( row )
, m_minusButton( 0 ) , m_minusButton( 0 )
, m_control( control ) , m_control( control )
, m_typeSelector( 0 ) , m_typeSelector( 0 )
, m_matchSelector( 0 ) , m_matchSelector( 0 )
, m_entryWidget( 0 ) , m_entryWidget( 0 )
, m_layout( 0 ) , m_layout( layout )
{ {
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
m_layout = new QHBoxLayout; qDebug() << "CREATING DYNAMIC CONTROL WRAPPER WITH ROW:" << row << layout;
m_layout->setMargin( 0 );
m_layout->setContentsMargins( 0, 0, 0, 0 );
QComboBox* typeSelector = new QComboBox( this ); QComboBox* typeSelector = new QComboBox( parent );
m_typeSelector = new ReadOrWriteWidget( typeSelector, m_isLocal, this ); m_typeSelector = new ReadOrWriteWidget( typeSelector, m_isLocal, m_parent );
m_matchSelector = new ReadOrWriteWidget( control->matchSelector(), m_isLocal, this );
m_entryWidget = new ReadOrWriteWidget( control->inputField(), m_isLocal, this );
m_layout->setMargin( 0 );
m_layout->setSpacing( 0 );
setContentsMargins( 0, 0, 0, 0 );
m_matchSelector = new ReadOrWriteWidget( control->matchSelector(), m_isLocal, m_parent );
m_entryWidget = new ReadOrWriteWidget( control->inputField(), m_isLocal, m_parent );
if( m_isLocal ) if( m_isLocal )
{ {
m_minusButton = initButton(); m_minusButton = initButton();
@@ -74,7 +69,7 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
connect( typeSelector, SIGNAL( activated( QString) ), SLOT( typeSelectorChanged( QString ) ) ); connect( typeSelector, SIGNAL( activated( QString) ), SLOT( typeSelectorChanged( QString ) ) );
connect( m_control.data(), SIGNAL( changed() ), this, SIGNAL( changed() ) ); connect( m_control.data(), SIGNAL( changed() ), this, SIGNAL( changed() ) );
m_layout->addWidget( m_typeSelector, 0, Qt::AlignLeft ); m_layout->addWidget( m_typeSelector, row, 0, Qt::AlignLeft );
if( !control.isNull() ) { if( !control.isNull() ) {
foreach( const QString& type, control->typeSelectors() ) foreach( const QString& type, control->typeSelectors() )
@@ -85,34 +80,45 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
if( m_isLocal ) if( m_isLocal )
{ {
m_layout->addLayout( m_plusL, 0 ); m_layout->addLayout( m_plusL, m_row, 3, Qt::AlignCenter );
m_plusL->setCurrentIndex( 1 ); m_plusL->setCurrentIndex( 1 );
} }
setMouseTracking( true );
setLayout( m_layout );
} }
DynamicControlWidget::~DynamicControlWidget() DynamicControlWrapper::~DynamicControlWrapper()
{ {
// remove the controls widgets from our layout so they are not parented // remove the controls widgets from our layout so they are not parented
// we don't want to auto-delete them since the control should own them // we don't want to auto-delete them since the control should own them
// if we delete them, then the control will be holding on to null ptrs // if we delete them, then the control will be holding on to null ptrs
m_layout->removeWidget( m_control->inputField() ); removeFromLayout();
m_control->inputField()->setParent( 0 ); m_control->inputField()->setParent( 0 );
m_layout->removeWidget( m_control->matchSelector() );
m_control->matchSelector()->setParent( 0 ); m_control->matchSelector()->setParent( 0 );
delete m_typeSelector;
delete m_matchSelector;
delete m_entryWidget;
} }
dyncontrol_ptr DynamicControlWidget::control() const dyncontrol_ptr
DynamicControlWrapper::control() const
{ {
return m_control; return m_control;
} }
void
QToolButton* DynamicControlWidget::initButton() DynamicControlWrapper::removeFromLayout()
{ {
QToolButton* btn = new QToolButton( this ); m_layout->removeWidget( m_typeSelector );
m_layout->removeWidget( m_matchSelector );
m_layout->removeWidget( m_entryWidget );
m_layout->removeItem( m_plusL );
}
QToolButton* DynamicControlWrapper::initButton()
{
QToolButton* btn = new QToolButton( m_parent );
btn->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); btn->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
btn->setIconSize( QSize( 16, 16 ) ); btn->setIconSize( QSize( 16, 16 ) );
btn->setToolButtonStyle( Qt::ToolButtonIconOnly ); btn->setToolButtonStyle( Qt::ToolButtonIconOnly );
@@ -121,9 +127,9 @@ QToolButton* DynamicControlWidget::initButton()
return btn; return btn;
} }
QWidget* DynamicControlWidget::createDummy( QWidget* fromW ) QWidget* DynamicControlWrapper::createDummy( QWidget* fromW )
{ {
QWidget* dummy = new QWidget( this ); QWidget* dummy = new QWidget( m_parent );
dummy->setContentsMargins( 0, 0, 0, 0 ); dummy->setContentsMargins( 0, 0, 0, 0 );
dummy->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); dummy->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
dummy->setMinimumSize( fromW->size() ); dummy->setMinimumSize( fromW->size() );
@@ -133,7 +139,7 @@ QWidget* DynamicControlWidget::createDummy( QWidget* fromW )
void void
DynamicControlWidget::typeSelectorChanged( const QString& type, bool firstLoad ) DynamicControlWrapper::typeSelectorChanged( const QString& type, bool firstLoad )
{ {
Q_ASSERT( m_layout ); Q_ASSERT( m_layout );
m_layout->removeWidget( m_matchSelector ); m_layout->removeWidget( m_matchSelector );
@@ -155,31 +161,32 @@ DynamicControlWidget::typeSelectorChanged( const QString& type, bool firstLoad )
m_matchSelector->setWritableWidget( m_control->matchSelector() ); m_matchSelector->setWritableWidget( m_control->matchSelector() );
m_matchSelector->setLabel( m_control->matchString() ); m_matchSelector->setLabel( m_control->matchString() );
m_matchSelector->setWritable( m_isLocal ); m_matchSelector->setWritable( m_isLocal );
m_layout->insertWidget( 1, m_matchSelector, 0 ); m_layout->addWidget( m_matchSelector, m_row, 1, Qt::AlignCenter );
} }
if( m_control->inputField() ) { if( m_control->inputField() ) {
m_entryWidget->setWritableWidget( m_control->inputField() ); m_entryWidget->setWritableWidget( m_control->inputField() );
m_entryWidget->setLabel( m_control->input() ); m_entryWidget->setLabel( m_control->input() );
m_entryWidget->setWritable( m_isLocal ); m_entryWidget->setWritable( m_isLocal );
m_layout->insertWidget( 2, m_entryWidget, 1 ); m_layout->addWidget( m_entryWidget, m_row, 2 );
} }
emit changed(); emit changed();
} }
/*
void void
DynamicControlWidget::enterEvent(QEvent* ev) DynamicControlWrapper::enterEvent(QEvent* ev)
{ {
m_mouseOver = true; m_mouseOver = true;
if( m_isLocal ) if( m_isLocal )
m_plusL->setCurrentIndex( 0 ); m_plusL->setCurrentIndex( 0 );
if( ev ) if( ev )
QWidget::enterEvent( ev ); QObject::enterEvent( ev );
} }
void void
DynamicControlWidget::leaveEvent(QEvent* ev) DynamicControlWrapper::leaveEvent(QEvent* ev)
{ {
m_mouseOver = true; m_mouseOver = true;
if( m_isLocal ) if( m_isLocal )
@@ -188,17 +195,5 @@ DynamicControlWidget::leaveEvent(QEvent* ev)
if( ev ) if( ev )
QWidget::leaveEvent( ev ); QWidget::leaveEvent( ev );
} }
*/
void
DynamicControlWidget::mouseMoveEvent(QMouseEvent* ev)
{
m_mouseOver = true;
setMouseTracking( false );
enterEvent( ev );
}
void
DynamicControlWidget::paintEvent(QPaintEvent* )
{
}

View File

@@ -1,5 +1,5 @@
/**************************************************************************************** /****************************************************************************************
* Copyright (c) 2010 Leo Franchi <lfranchi@kde.org> * * Copyright (c) 2010-2011 Leo Franchi <lfranchi@kde.org> *
* * * *
* This program is free software; you can redistribute it and/or modify it under * * 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 * * the terms of the GNU General Public License as published by the Free Software *
@@ -14,13 +14,14 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * * this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/ ****************************************************************************************/
#ifndef DYNAMIC_CONTROL_WIDGET_H #ifndef DYNAMIC_CONTROL_WRAPPER_H
#define DYNAMIC_CONTROL_WIDGET_H #define DYNAMIC_CONTROL_WRAPPER_H
#include <QWidget> #include <QWidget>
#include "typedefs.h" #include "typedefs.h"
class QGridLayout;
class ReadOrWriteWidget; class ReadOrWriteWidget;
class QStackedLayout; class QStackedLayout;
class QEvent; class QEvent;
@@ -33,22 +34,21 @@ namespace Tomahawk
{ {
/** /**
* This widget holds one horizontal control attached to a dynamic playlist. It's a container more than anything. * This abstraction object manages the widgets for 1 dynamic playlist control, laid out in the desired layout
*/ */
class DynamicControlWidget : public QWidget class DynamicControlWrapper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool isLocal = false, QWidget* parent = 0); explicit DynamicControlWrapper( const dyncontrol_ptr& control, QGridLayout* layout, int row, bool isLocal = false, QWidget* parent = 0 );
virtual ~DynamicControlWidget(); virtual ~DynamicControlWrapper();
virtual void paintEvent(QPaintEvent* ); // virtual void enterEvent(QEvent* );
virtual void enterEvent(QEvent* ); // virtual void leaveEvent(QEvent* );
virtual void leaveEvent(QEvent* );
virtual void mouseMoveEvent(QMouseEvent* );
dyncontrol_ptr control() const; dyncontrol_ptr control() const;
void removeFromLayout();
signals: signals:
void collapse(); void collapse();
void removeControl(); void removeControl();
@@ -63,7 +63,8 @@ private:
bool m_isLocal, m_mouseOver; bool m_isLocal, m_mouseOver;
// i hate qlayout QWidget* m_parent;
int m_row;
QStackedLayout* m_plusL; QStackedLayout* m_plusL;
QToolButton* m_minusButton; QToolButton* m_minusButton;
@@ -71,7 +72,7 @@ private:
ReadOrWriteWidget* m_typeSelector; ReadOrWriteWidget* m_typeSelector;
ReadOrWriteWidget* m_matchSelector; ReadOrWriteWidget* m_matchSelector;
ReadOrWriteWidget* m_entryWidget; ReadOrWriteWidget* m_entryWidget;
QHBoxLayout* m_layout; QGridLayout* m_layout;
}; };
}; };

View File

@@ -31,6 +31,7 @@
#include "pipeline.h" #include "pipeline.h"
#include "audio/audioengine.h" #include "audio/audioengine.h"
#include "ReadOrWriteWidget.h" #include "ReadOrWriteWidget.h"
#include "CollapsibleControls.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -47,7 +48,6 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
, m_logo( 0 ) , m_logo( 0 )
, m_generateButton( 0 ) , m_generateButton( 0 )
, m_controls( 0 ) , m_controls( 0 )
, m_splitter( 0 )
, m_view( 0 ) , m_view( 0 )
, m_model() , m_model()
{ {
@@ -81,25 +81,16 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
m_layout->addLayout( m_headerLayout ); m_layout->addLayout( m_headerLayout );
m_splitter = new AnimatedSplitter( this ); m_controls = new CollapsibleControls( this );
m_splitter->setOrientation( Qt::Vertical ); m_layout->addWidget( m_controls );
m_splitter->setChildrenCollapsible( false );
m_layout->addWidget( 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 );
m_view->setModel( m_model ); m_view->setModel( m_model );
m_view->setContentsMargins( 0, 0, 0, 0 ); m_view->setContentsMargins( 0, 0, 0, 0 );
m_layout->addWidget( m_view );
m_splitter->addWidget( m_controls );
m_splitter->addWidget( m_view );
m_splitter->setGreedyWidget( 1 );
m_splitter->setHandleWidth( 0 );
m_splitter->setContentsMargins( 0, 0, 0, 0 );
m_splitter->show( 0, false );
loadDynamicPlaylist( playlist ); loadDynamicPlaylist( playlist );
m_layout->setContentsMargins( 0, 0, 0, 0 ); m_layout->setContentsMargins( 0, 0, 0, 0 );

View File

@@ -38,7 +38,8 @@ class ReadOrWriteWidget;
namespace Tomahawk namespace Tomahawk
{ {
class DynamicControlList; class CollapsibleControls;
/** /**
* This class contains the dynamic playlist config and the playlist view itself * This class contains the dynamic playlist config and the playlist view itself
@@ -90,8 +91,7 @@ private:
QPushButton* m_generateButton; QPushButton* m_generateButton;
QSpinBox* m_genNumber; QSpinBox* m_genNumber;
DynamicControlList* m_controls; CollapsibleControls* m_controls;
AnimatedSplitter* m_splitter;
PlaylistView* m_view; PlaylistView* m_view;
PlaylistModel* m_model; PlaylistModel* m_model;