mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-13 04:21:51 +02:00
finally fix most of the layout issues.
god i hate qlayout...
This commit is contained in:
parent
c345ee6e35
commit
0df8ea0732
@ -59,6 +59,7 @@
|
||||
<file>./data/images/view-toggle-pressed-left.png</file>
|
||||
<file>./data/images/view-toggle-pressed-right.png</file>
|
||||
<file>./data/images/list-add.png</file>
|
||||
<file>./data/images/list-remove.png</file>
|
||||
<file>./data/images/arrow-up-double.png</file>
|
||||
<file>./data/images/volume-icon-full.png</file>
|
||||
<file>./data/images/volume-icon-muted.png</file>
|
||||
|
@ -75,7 +75,7 @@ Tomahawk::EchonestControl::updateWidgets()
|
||||
match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType );
|
||||
|
||||
input->setPlaceholderText( "Artist name" );
|
||||
input->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Ignored );
|
||||
input->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
|
||||
|
||||
connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) );
|
||||
connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) );
|
||||
@ -84,6 +84,9 @@ Tomahawk::EchonestControl::updateWidgets()
|
||||
input->hide();
|
||||
m_match = QWeakPointer< QWidget >( match );
|
||||
m_input = QWeakPointer< QWidget >( input );
|
||||
} else {
|
||||
m_match = QWeakPointer<QWidget>( new QWidget );
|
||||
m_input = QWeakPointer<QWidget>( new QWidget );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,15 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include "DynamicControlList.h"
|
||||
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include "DynamicControlWidget.h"
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#include "DynamicControlWidget.h"
|
||||
#include "GeneratorInterface.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
DynamicControlList::DynamicControlList()
|
||||
@ -39,13 +42,14 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
|
||||
init();
|
||||
}
|
||||
|
||||
DynamicControlList::DynamicControlList( const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent)
|
||||
DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent)
|
||||
: AnimatedWidget(parent)
|
||||
, m_generator( generator )
|
||||
, m_layout( new QVBoxLayout )
|
||||
, m_summaryWidget( 0 )
|
||||
{
|
||||
init();
|
||||
setControls( controls );
|
||||
setControls( generator, controls );
|
||||
}
|
||||
|
||||
DynamicControlList::~DynamicControlList()
|
||||
@ -76,10 +80,12 @@ DynamicControlList::init()
|
||||
}
|
||||
|
||||
void
|
||||
DynamicControlList::setControls(const QList< dyncontrol_ptr >& controls)
|
||||
DynamicControlList::setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls)
|
||||
{
|
||||
m_generator = generator;
|
||||
foreach( const dyncontrol_ptr& control, controls ) {
|
||||
m_controls << new DynamicControlWidget( control, false, false, this );
|
||||
m_controls << new DynamicControlWidget( control, false, false, false, this );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
}
|
||||
onShown( this );
|
||||
}
|
||||
@ -113,11 +119,23 @@ DynamicControlList::onShown( QWidget* w )
|
||||
foreach( DynamicControlWidget* control, m_controls ) {
|
||||
m_layout->addWidget( control );
|
||||
control->show();
|
||||
control->setShowMinusButton( control != m_controls.last() );
|
||||
control->setShowPlusButton( control == m_controls.last() );
|
||||
control->setShowCollapseButton( control == m_controls.last() );
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicControlList::addNewControl()
|
||||
{
|
||||
m_controls.last()->setShowCollapseButton( false );
|
||||
m_controls.last()->setShowPlusButton( false );
|
||||
m_controls.last()->setShowMinusButton( true );
|
||||
m_controls.append( new DynamicControlWidget( m_generator->createControl(), true, false, true, this ) );
|
||||
m_layout->addWidget( m_controls.last() );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
}
|
||||
|
||||
|
||||
void DynamicControlList::paintEvent(QPaintEvent* )
|
||||
{
|
||||
}
|
||||
|
@ -38,20 +38,23 @@ class DynamicControlList : public AnimatedWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
DynamicControlList(); // bad compiler!
|
||||
explicit DynamicControlList( AnimatedSplitter* parent );
|
||||
explicit DynamicControlList( const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent );
|
||||
explicit DynamicControlList(AnimatedSplitter* parent );
|
||||
explicit DynamicControlList( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls, AnimatedSplitter* parent );
|
||||
virtual ~DynamicControlList();
|
||||
|
||||
void setControls( const QList< dyncontrol_ptr >& controls );
|
||||
QList< dyncontrol_ptr >& controls() const;
|
||||
void setControls( const geninterface_ptr& generator, const QList< dyncontrol_ptr >& controls );
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
|
||||
public slots:
|
||||
virtual void onHidden(QWidget* );
|
||||
virtual void onShown(QWidget* );
|
||||
void addNewControl();
|
||||
|
||||
private:
|
||||
void init();
|
||||
geninterface_ptr m_generator;
|
||||
|
||||
QVBoxLayout* m_layout;
|
||||
QList< DynamicControlWidget* > m_controls;
|
||||
|
@ -25,20 +25,24 @@
|
||||
#include <QToolButton>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <qstackedlayout.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool showPlus, bool showCollapse, QWidget* parent )
|
||||
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool showPlus, bool showMinus, bool showCollapse, QWidget* parent )
|
||||
: QWidget(parent)
|
||||
, m_showPlus( showPlus )
|
||||
, m_showMinus( showMinus )
|
||||
, m_showCollapse( showCollapse )
|
||||
, m_plusButton( 0 )
|
||||
, m_minusButton( 0 )
|
||||
, m_collapseButton( 0 )
|
||||
, m_control( control )
|
||||
, m_typeSelector( 0 )
|
||||
, m_layout( 0 )
|
||||
{
|
||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
setMouseTracking( true );
|
||||
|
||||
m_layout = new QHBoxLayout;
|
||||
m_typeSelector = new QComboBox( this );
|
||||
@ -47,42 +51,56 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
||||
m_layout->setSpacing( 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();
|
||||
m_plusButton = initButton();
|
||||
|
||||
m_collapseButton= new QToolButton( this );
|
||||
m_plusButton->setIcon( QIcon( RESPATH "images/list-add.png" ) );
|
||||
connect( m_plusButton, SIGNAL( clicked( bool ) ), this, SIGNAL( addNewControl() ) );
|
||||
m_plusL = new QStackedLayout;
|
||||
m_plusL->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_plusL->addWidget( m_plusButton );
|
||||
m_plusL->addWidget( createDummy( m_plusButton ) ); // :-(
|
||||
m_plusL->setCurrentIndex( 0 );
|
||||
|
||||
m_minusButton = initButton();
|
||||
m_minusButton->setIcon( QIcon( RESPATH "images/list-remove.png" ) );
|
||||
connect( m_minusButton, SIGNAL( clicked( bool ) ), this, SIGNAL( removeControl() ) );
|
||||
m_minusL = new QStackedLayout;
|
||||
m_minusL->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_minusL->addWidget( m_minusButton );
|
||||
m_minusL->addWidget( createDummy( m_plusButton ) ); // :-(
|
||||
m_minusL->setCurrentIndex( 0 );
|
||||
|
||||
m_collapseButton = initButton();
|
||||
m_collapseButton->setIcon( QIcon( RESPATH "images/arrow-up-double.png" ) );
|
||||
m_collapseButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
m_collapseButton->setIconSize( QSize( 16, 16 ) );
|
||||
m_collapseButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
|
||||
m_collapseButton->setAutoRaise( true );
|
||||
m_collapseButton->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_collapseButton->hide();
|
||||
m_collapseL = new QStackedLayout;
|
||||
m_collapseL->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_collapseL->addWidget( m_collapseButton );
|
||||
m_collapseL->addWidget( createDummy( m_collapseButton ) ); // :-(
|
||||
m_collapseL->setCurrentIndex( 0 );
|
||||
|
||||
connect( m_collapseButton, SIGNAL( clicked( bool ) ), this, SIGNAL( collapse() ) );
|
||||
|
||||
connect( m_typeSelector, SIGNAL( currentIndexChanged( QString ) ), SLOT( typeSelectorChanged( QString ) ) );
|
||||
|
||||
m_layout->addWidget( m_typeSelector, 0, Qt::AlignLeft );
|
||||
|
||||
if( !control.isNull() ) {
|
||||
foreach( const QString& type, control->typeSelectors() )
|
||||
m_typeSelector->addItem( type );
|
||||
|
||||
typeSelectorChanged( m_control->selectedType() );
|
||||
}
|
||||
|
||||
if( m_showCollapse ) {
|
||||
m_layout->insertWidget( 3, m_collapseButton, 0, Qt::AlignRight );
|
||||
m_plusButton->show();
|
||||
}
|
||||
if( m_showPlus ) {
|
||||
m_layout->insertWidget( m_showCollapse ? 4 : 3, m_plusButton, 0, Qt::AlignRight );
|
||||
m_plusButton->show();
|
||||
}
|
||||
typeSelectorChanged( m_control.isNull() ? "" : m_control->selectedType() );
|
||||
|
||||
m_layout->addLayout( m_collapseL, 0 );
|
||||
m_layout->addLayout( m_minusL, 0 );
|
||||
m_layout->addLayout( m_plusL, 0 );
|
||||
|
||||
if( m_showCollapse )
|
||||
m_collapseL->setCurrentIndex( 0 );
|
||||
if( m_showPlus )
|
||||
m_plusL->setCurrentIndex( 0 );
|
||||
if( m_showMinus )
|
||||
m_minusL->setCurrentIndex( 0 );
|
||||
|
||||
setLayout( m_layout );
|
||||
}
|
||||
@ -92,30 +110,45 @@ DynamicControlWidget::~DynamicControlWidget()
|
||||
|
||||
}
|
||||
|
||||
QToolButton* DynamicControlWidget::initButton()
|
||||
{
|
||||
QToolButton* btn = new QToolButton( this );
|
||||
btn->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
btn->setIconSize( QSize( 16, 16 ) );
|
||||
btn->setToolButtonStyle( Qt::ToolButtonIconOnly );
|
||||
btn->setAutoRaise( true );
|
||||
btn->setContentsMargins( 0, 0, 0, 0 );
|
||||
return btn;
|
||||
}
|
||||
|
||||
QWidget* DynamicControlWidget::createDummy( QWidget* fromW )
|
||||
{
|
||||
QWidget* dummy = new QWidget( this );
|
||||
dummy->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
dummy->setMinimumSize( fromW->size() );
|
||||
dummy->setMaximumSize( fromW->size() );
|
||||
return dummy;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicControlWidget::typeSelectorChanged( QString type )
|
||||
{
|
||||
Q_ASSERT( m_layout );
|
||||
// remove the two widgets, change the control,and re-add the new ones
|
||||
m_layout->removeWidget( m_control->matchSelector() );
|
||||
m_layout->removeWidget( m_control->inputField() );
|
||||
|
||||
if( m_layout->indexOf( m_control->matchSelector() ) > -1 ) m_layout->removeWidget( m_control->matchSelector() );
|
||||
if( m_layout->indexOf( m_control->inputField() ) > -1 ) m_layout->removeWidget( m_control->inputField() );
|
||||
|
||||
m_control->setSelectedType( type );
|
||||
|
||||
if( m_control->matchSelector() ) {
|
||||
m_control->matchSelector()->show();
|
||||
m_layout->insertWidget( 1, m_control->matchSelector(), 0 );
|
||||
m_control->matchSelector()->show();
|
||||
}
|
||||
if( m_control->inputField() ) {
|
||||
m_control->inputField()->show();
|
||||
m_layout->insertWidget( 2, m_control->inputField(), 1 );
|
||||
m_control->inputField()->show();
|
||||
}
|
||||
|
||||
qDebug() << m_layout->count();
|
||||
for( int i = 0; i < m_layout->count(); i++ ){
|
||||
qDebug() << i << ( m_layout->itemAt( i )->widget() ? m_layout->itemAt( i )->widget()->metaObject()->className() : "null" ) << m_layout->stretch( i ) << m_layout->itemAt( i )->sizeHint();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -123,41 +156,44 @@ DynamicControlWidget::setShowPlusButton(bool show)
|
||||
{
|
||||
|
||||
if( m_showPlus != show ) {
|
||||
if( show ) {
|
||||
m_layout->insertWidget( m_showCollapse ? 4 : 3, m_plusButton, 0, Qt::AlignRight );
|
||||
m_plusButton->show();
|
||||
} else {
|
||||
m_layout->removeWidget( m_plusButton );
|
||||
m_plusButton->hide();
|
||||
}
|
||||
show ? m_plusL->setCurrentIndex( 0 ) : m_plusL->setCurrentIndex( 1 );
|
||||
}
|
||||
|
||||
m_showPlus = show;
|
||||
}
|
||||
|
||||
bool
|
||||
DynamicControlWidget::showPlusButton() const
|
||||
{
|
||||
return m_showPlus;
|
||||
}
|
||||
|
||||
void
|
||||
DynamicControlWidget::setShowCollapseButton(bool show)
|
||||
{
|
||||
|
||||
if( m_showCollapse != show ) {
|
||||
if( show ) {
|
||||
m_layout->insertWidget( 3, m_collapseButton, 0, Qt::AlignRight );
|
||||
m_collapseButton->show();
|
||||
} else {
|
||||
m_layout->removeWidget( m_collapseButton );
|
||||
m_collapseButton->hide();
|
||||
}
|
||||
show ? m_collapseL->setCurrentIndex( 0 ) : m_collapseL->setCurrentIndex( 1 );
|
||||
}
|
||||
|
||||
m_showCollapse = show;
|
||||
}
|
||||
|
||||
void DynamicControlWidget::setShowMinusButton(bool show)
|
||||
{
|
||||
m_showMinus = show;
|
||||
}
|
||||
|
||||
void DynamicControlWidget::enterEvent(QEvent* ev)
|
||||
{
|
||||
if( m_showMinus )
|
||||
m_minusL->setCurrentIndex( 0 );
|
||||
|
||||
QWidget::enterEvent( ev );
|
||||
}
|
||||
|
||||
void DynamicControlWidget::leaveEvent(QEvent* ev)
|
||||
{
|
||||
m_minusL->setCurrentIndex( 1 );
|
||||
|
||||
QWidget::leaveEvent( ev );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicControlWidget::paintEvent(QPaintEvent* )
|
||||
{
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "tomahawk/typedefs.h"
|
||||
|
||||
class QStackedLayout;
|
||||
class QEvent;
|
||||
class QToolButton;
|
||||
class QHBoxLayout;
|
||||
class QComboBox;
|
||||
@ -36,23 +38,38 @@ class DynamicControlWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool showPlus = false, bool showCollaps = false, QWidget* parent = 0);
|
||||
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool showPlus = false, bool showMinus = false, bool showCollapse = false, QWidget* parent = 0);
|
||||
virtual ~DynamicControlWidget();
|
||||
|
||||
void setShowPlusButton( bool show );
|
||||
bool showPlusButton() const;
|
||||
|
||||
void setShowMinusButton( bool show );
|
||||
void setShowCollapseButton( bool show );
|
||||
|
||||
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
virtual void enterEvent(QEvent* );
|
||||
virtual void leaveEvent(QEvent* );
|
||||
|
||||
signals:
|
||||
void addNewControl();
|
||||
void collapse();
|
||||
void removeControl();
|
||||
|
||||
private slots:
|
||||
void typeSelectorChanged( QString );
|
||||
|
||||
private:
|
||||
QToolButton* initButton();
|
||||
QWidget* createDummy( QWidget* fromW );
|
||||
|
||||
bool m_showPlus;
|
||||
bool m_showMinus;
|
||||
bool m_showCollapse;
|
||||
// i hate qlayout
|
||||
QStackedLayout* m_plusL;
|
||||
QToolButton* m_plusButton;
|
||||
QStackedLayout* m_minusL;
|
||||
QToolButton* m_minusButton;
|
||||
QStackedLayout* m_collapseL;
|
||||
QToolButton* m_collapseButton;
|
||||
|
||||
dyncontrol_ptr m_control;
|
||||
|
@ -49,8 +49,9 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
||||
m_headerText = new QLabel( "Dynamic Playlist Type:", this );
|
||||
m_headerLayout->addWidget( m_headerText );
|
||||
m_modeCombo = new QComboBox( this );
|
||||
m_modeCombo->addItem( "Static", 0 );
|
||||
m_modeCombo->addItem( "On Demand", 1 );
|
||||
m_modeCombo->addItem( "On Demand", 0 );
|
||||
m_modeCombo->addItem( "Static", 1 );
|
||||
m_modeCombo->setCurrentIndex( static_cast<int>( playlist->mode() ) );
|
||||
m_headerLayout->addWidget( m_modeCombo );
|
||||
m_generatorCombo = new QComboBox( this );
|
||||
foreach( const QString& type, GeneratorFactory::types() )
|
||||
@ -59,7 +60,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
||||
|
||||
m_headerLayout->addSpacing( 1 );
|
||||
|
||||
m_generateButton = new QPushButton( this );
|
||||
m_generateButton = new QPushButton( "Generate", this );
|
||||
m_generateButton->hide();
|
||||
if( playlist->mode() == Static ) {
|
||||
m_generateButton->show();
|
||||
@ -85,7 +86,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
|
||||
m_splitter->show( 0, false );
|
||||
|
||||
if( !m_playlist.isNull() ) {
|
||||
m_controls->setControls( m_playlist->generator()->controls() );
|
||||
m_controls->setControls( m_playlist->generator(), m_playlist->generator()->controls() );
|
||||
|
||||
m_model->loadPlaylist( m_playlist );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user