mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-19 07:22:32 +02:00
save working but weird splitter sizes
This commit is contained in:
parent
849a01d057
commit
9395712e78
@ -19,10 +19,13 @@
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
#include <QPainter>
|
||||
|
||||
#include "DynamicControlWidget.h"
|
||||
#include "dynamic/GeneratorInterface.h"
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -67,7 +70,10 @@ DynamicControlList::init()
|
||||
m_layout->setMargin( 0 );
|
||||
m_layout->setSpacing( 0 );
|
||||
m_layout->setContentsMargins( 0, 0, 0, 0 );
|
||||
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
|
||||
@ -78,8 +84,28 @@ DynamicControlList::init()
|
||||
m_summaryWidget->layout()->setMargin( 0 );
|
||||
m_summaryWidget->layout()->addWidget( new QLabel( "replace me plz", m_summaryWidget ) );
|
||||
|
||||
setHiddenSize( m_summaryWidget->size() );
|
||||
m_collapseLayout = new QHBoxLayout( this );
|
||||
m_collapseLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_collapseLayout->setMargin( 0 );
|
||||
m_collapseLayout->setSpacing( 0 );
|
||||
m_collapse = new QPushButton( tr( "Click to collapse" ), this );
|
||||
m_collapseLayout->addWidget( m_collapse );
|
||||
m_addControl = new QToolButton( this );
|
||||
m_addControl->setIcon( QIcon( RESPATH "images/list-add.png" ) );
|
||||
m_addControl->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
m_addControl->setIconSize( QSize( 16, 16 ) );
|
||||
m_addControl->setToolButtonStyle( Qt::ToolButtonIconOnly );
|
||||
m_addControl->setAutoRaise( true );
|
||||
m_addControl->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_collapseLayout->addWidget( m_addControl );
|
||||
m_collapse->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
|
||||
m_layout->addLayout( m_collapseLayout );
|
||||
// connect( m_collapse, SIGNAL( clicked() ), this, );
|
||||
connect( m_addControl, SIGNAL( clicked() ), this, SLOT( addNewControl() ) );
|
||||
|
||||
setHiddenSize( m_summaryWidget->size() );
|
||||
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
|
||||
emit showWidget();
|
||||
}
|
||||
|
||||
@ -93,15 +119,13 @@ DynamicControlList::setControls( const geninterface_ptr& generator, const QList<
|
||||
m_isLocal = isLocal;
|
||||
m_generator = generator;
|
||||
if( controls.isEmpty() ) {
|
||||
m_controls << new DynamicControlWidget( generator->createControl(), false, false, false, isLocal, this );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
m_controls << new DynamicControlWidget( generator->createControl(), isLocal, this );
|
||||
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
|
||||
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
|
||||
} else
|
||||
{
|
||||
foreach( const dyncontrol_ptr& control, controls ) {
|
||||
m_controls << new DynamicControlWidget( control, false, false, false, isLocal, this );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
m_controls << new DynamicControlWidget( control, isLocal, this );
|
||||
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
|
||||
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
|
||||
}
|
||||
@ -134,23 +158,21 @@ DynamicControlList::onShown( QWidget* w )
|
||||
AnimatedWidget::onShown( w );
|
||||
|
||||
m_layout->removeWidget( m_summaryWidget );
|
||||
m_layout->removeItem( m_collapseLayout );
|
||||
m_summaryWidget->hide();
|
||||
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() );
|
||||
}
|
||||
|
||||
m_layout->addLayout( m_collapseLayout );
|
||||
m_layout->setStretchFactor( m_collapseLayout, 1 );
|
||||
}
|
||||
|
||||
void DynamicControlList::addNewControl()
|
||||
{
|
||||
m_controls.last()->setShowCollapseButton( false );
|
||||
m_controls.last()->setShowPlusButton( false );
|
||||
m_controls.last()->setShowMinusButton( true );
|
||||
dyncontrol_ptr control = m_generator->createControl();
|
||||
m_controls.append( new DynamicControlWidget( control, true, false, true, m_isLocal, this ) );
|
||||
m_controls.append( new DynamicControlWidget( control, m_isLocal, this ) );
|
||||
m_layout->addWidget( m_controls.last() );
|
||||
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
|
||||
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
|
||||
@ -168,11 +190,6 @@ void DynamicControlList::removeControl()
|
||||
m_generator->removeControl( w->control() );
|
||||
delete w;
|
||||
|
||||
|
||||
m_controls.last()->setShowCollapseButton( true );
|
||||
m_controls.last()->setShowPlusButton( true );
|
||||
m_controls.last()->setShowMinusButton( false );
|
||||
|
||||
emit controlsChanged();
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,11 @@
|
||||
#include "typedefs.h"
|
||||
#include "dynamic/DynamicPlaylist.h"
|
||||
|
||||
class QPushButton;
|
||||
class QHBoxLayout;
|
||||
class QVBoxLayout;
|
||||
class QToolButton;
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
@ -66,6 +70,11 @@ private:
|
||||
QVBoxLayout* m_layout;
|
||||
QList< DynamicControlWidget* > m_controls;
|
||||
QWidget* m_summaryWidget;
|
||||
|
||||
QHBoxLayout* m_collapseLayout;
|
||||
QPushButton* m_collapse;
|
||||
QToolButton* m_addControl;
|
||||
|
||||
bool m_isLocal;
|
||||
};
|
||||
|
||||
|
@ -30,15 +30,11 @@
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool showPlus, bool showMinus, bool showCollapse, bool isLocal, QWidget* parent )
|
||||
DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& control, bool isLocal, QWidget* parent )
|
||||
: QWidget(parent)
|
||||
, m_showPlus( showPlus )
|
||||
, m_showMinus( showMinus )
|
||||
, m_showCollapse( showCollapse )
|
||||
, m_isLocal( isLocal )
|
||||
, m_plusButton( 0 )
|
||||
, m_mouseOver( false )
|
||||
, m_minusButton( 0 )
|
||||
, m_collapseButton( 0 )
|
||||
, m_control( control )
|
||||
, m_typeSelector( 0 )
|
||||
, m_matchSelector( 0 )
|
||||
@ -69,28 +65,13 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
||||
connect( m_minusButton, SIGNAL( clicked( bool ) ), this, SIGNAL( removeControl() ) );
|
||||
|
||||
|
||||
m_plusButton = initButton();
|
||||
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->setMargin( 0 );
|
||||
m_plusL->addWidget( m_plusButton );
|
||||
m_plusL->addWidget( m_minusButton );
|
||||
m_plusL->addWidget( createDummy( m_plusButton ) ); // :-(
|
||||
m_plusL->setCurrentIndex( 2 );
|
||||
m_plusL->addWidget( createDummy( m_minusButton ) ); // :-(
|
||||
}
|
||||
|
||||
m_collapseButton = initButton();
|
||||
m_collapseButton->setIcon( QIcon( RESPATH "images/arrow-up-double.png" ) );
|
||||
m_collapseL = new QStackedLayout;
|
||||
m_collapseL->setContentsMargins( 0, 0, 0, 0 );
|
||||
m_collapseL->setMargin( 0 );
|
||||
m_collapseL->addWidget( m_collapseButton );
|
||||
m_collapseL->addWidget( createDummy( m_collapseButton ) ); // :-(
|
||||
m_collapseL->setCurrentIndex( 1 );
|
||||
|
||||
connect( m_collapseButton, SIGNAL( clicked( bool ) ), this, SIGNAL( collapse() ) );
|
||||
connect( typeSelector, SIGNAL( activated( QString) ), SLOT( typeSelectorChanged( QString ) ) );
|
||||
connect( m_control.data(), SIGNAL( changed() ), this, SIGNAL( changed() ) );
|
||||
|
||||
@ -103,20 +84,13 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
|
||||
|
||||
typeSelectorChanged( m_control.isNull() ? "" : m_control->selectedType(), true );
|
||||
|
||||
m_layout->addLayout( m_collapseL, 0 );
|
||||
|
||||
if( m_isLocal )
|
||||
{
|
||||
m_layout->addLayout( m_plusL, 0 );
|
||||
|
||||
if( m_showPlus )
|
||||
m_plusL->setCurrentIndex( 0 );
|
||||
if( m_showMinus )
|
||||
m_plusL->setCurrentIndex( 1 );
|
||||
m_plusL->setCurrentIndex( 1 );
|
||||
}
|
||||
|
||||
if( m_showCollapse )
|
||||
m_collapseL->setCurrentIndex( 0 );
|
||||
setMouseTracking( true );
|
||||
setLayout( m_layout );
|
||||
}
|
||||
|
||||
@ -186,39 +160,12 @@ DynamicControlWidget::typeSelectorChanged( const QString& type, bool firstLoad )
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void
|
||||
DynamicControlWidget::setShowPlusButton(bool show)
|
||||
{
|
||||
|
||||
if( m_showPlus != show && m_isLocal ) {
|
||||
show ? m_plusL->setCurrentIndex( 0 ) : m_plusL->setCurrentIndex( 2 );
|
||||
}
|
||||
|
||||
m_showPlus = show;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicControlWidget::setShowCollapseButton(bool show)
|
||||
{
|
||||
if( m_showCollapse != show ) {
|
||||
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_isLocal )
|
||||
m_plusL->setCurrentIndex( 1 );
|
||||
m_mouseOver = true;
|
||||
if( m_isLocal )
|
||||
m_plusL->setCurrentIndex( 0 );
|
||||
|
||||
if( ev )
|
||||
QWidget::enterEvent( ev );
|
||||
@ -227,13 +174,22 @@ DynamicControlWidget::enterEvent(QEvent* ev)
|
||||
void
|
||||
DynamicControlWidget::leaveEvent(QEvent* ev)
|
||||
{
|
||||
if( m_showMinus && m_isLocal )
|
||||
m_plusL->setCurrentIndex( 2 );
|
||||
m_mouseOver = true;
|
||||
if( m_isLocal )
|
||||
m_plusL->setCurrentIndex( 1 );
|
||||
|
||||
if( ev )
|
||||
QWidget::leaveEvent( ev );
|
||||
}
|
||||
|
||||
void
|
||||
DynamicControlWidget::mouseMoveEvent(QMouseEvent* ev)
|
||||
{
|
||||
m_mouseOver = true;
|
||||
setMouseTracking( false );
|
||||
enterEvent( ev );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DynamicControlWidget::paintEvent(QPaintEvent* )
|
||||
|
@ -39,21 +39,17 @@ class DynamicControlWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool showPlus = false, bool showMinus = false, bool showCollapse = false, bool isLocal = false, QWidget* parent = 0);
|
||||
explicit DynamicControlWidget( const dyncontrol_ptr& control, bool isLocal = false, QWidget* parent = 0);
|
||||
virtual ~DynamicControlWidget();
|
||||
|
||||
void setShowPlusButton( bool show );
|
||||
void setShowMinusButton( bool show );
|
||||
void setShowCollapseButton( bool show );
|
||||
|
||||
|
||||
virtual void paintEvent(QPaintEvent* );
|
||||
virtual void enterEvent(QEvent* );
|
||||
virtual void leaveEvent(QEvent* );
|
||||
virtual void mouseMoveEvent(QMouseEvent* );
|
||||
|
||||
dyncontrol_ptr control() const;
|
||||
|
||||
signals:
|
||||
void addNewControl();
|
||||
void collapse();
|
||||
void removeControl();
|
||||
void changed();
|
||||
@ -65,17 +61,11 @@ private:
|
||||
QToolButton* initButton();
|
||||
QWidget* createDummy( QWidget* fromW );
|
||||
|
||||
bool m_showPlus;
|
||||
bool m_showMinus;
|
||||
bool m_showCollapse;
|
||||
bool m_isLocal;
|
||||
bool m_isLocal, m_mouseOver;
|
||||
|
||||
// i hate qlayout
|
||||
QStackedLayout* m_plusL;
|
||||
QToolButton* m_plusButton;
|
||||
QToolButton* m_minusButton;
|
||||
QStackedLayout* m_collapseL;
|
||||
QToolButton* m_collapseButton;
|
||||
|
||||
dyncontrol_ptr m_control;
|
||||
ReadOrWriteWidget* m_typeSelector;
|
||||
@ -89,3 +79,5 @@ private:
|
||||
#endif
|
||||
|
||||
class QPaintEvent;
|
||||
|
||||
class QMouseEvent;
|
||||
|
@ -67,7 +67,10 @@ signals:
|
||||
void hideWidget();
|
||||
|
||||
void hiddenSizeChanged();
|
||||
|
||||
protected:
|
||||
|
||||
AnimatedSplitter* splitter() { return m_parent; }
|
||||
|
||||
private:
|
||||
AnimatedSplitter* m_parent;
|
||||
QSize m_hiddenSize;
|
||||
|
Loading…
x
Reference in New Issue
Block a user