Commit d61cb734 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Visibility management of UIParam and UIParamSet improved.

parent 90a0c98a
...@@ -415,9 +415,7 @@ DisplayableInterface* GLViewer::addDisplayable( GenericUIData *m ) ...@@ -415,9 +415,7 @@ DisplayableInterface* GLViewer::addDisplayable( GenericUIData *m )
if( !m->GetDisplayOptions()->IsEmpty() ) if( !m->GetDisplayOptions()->IsEmpty() )
{ {
m_DisplayOptionsLayout->addWidget( m->GetDisplayOptions() ); m_DisplayOptionsLayout->addWidget( m->GetDisplayOptions() );
m->GetDisplayOptions()->show(); m->GetDisplayOptions()->SetVisible();
if( m->GetDisplayOptions()->AreAllHidden() )
m->GetDisplayOptions()->hide();
} }
if( isSelectionEnabled() ) if( isSelectionEnabled() )
...@@ -659,7 +657,7 @@ GLViewer::DisplayableMap::iterator GLViewer::removeDisplayable_Internal( Display ...@@ -659,7 +657,7 @@ GLViewer::DisplayableMap::iterator GLViewer::removeDisplayable_Internal( Display
{ {
if( item->GetDisplayOptions()->GetAnimationCtrl() ) if( item->GetDisplayOptions()->GetAnimationCtrl() )
item->GetDisplayOptions()->GetAnimationCtrl()->stop(); item->GetDisplayOptions()->GetAnimationCtrl()->stop();
item->GetDisplayOptions()->hide(); item->GetDisplayOptions()->SetHidden();
m_DisplayOptionsLayout->removeWidget( item->GetDisplayOptions() ); m_DisplayOptionsLayout->removeWidget( item->GetDisplayOptions() );
item->GetDisplayOptions()->setParent( NULL ); item->GetDisplayOptions()->setParent( NULL );
} }
......
...@@ -70,7 +70,7 @@ void AlgorithmSelector::populateTools( ToolInterface *plugin ) ...@@ -70,7 +70,7 @@ void AlgorithmSelector::populateTools( ToolInterface *plugin )
tool.id = i; tool.id = i;
tool.param = new UIParamSet( "Tool options", this ); tool.param = new UIParamSet( "Tool options", this );
plugin->declareParameters( i, *tool.param ); plugin->declareParameters( i, *tool.param );
tool.param->hide(); tool.param->SetHidden();
//tool.param->setMaximumWidth(360); //tool.param->setMaximumWidth(360);
connect( tool.param, SIGNAL(parameterUpdated(UIParam*)), tool.plugin, SLOT(updateParameter(UIParam*)) ); connect( tool.param, SIGNAL(parameterUpdated(UIParam*)), tool.plugin, SLOT(updateParameter(UIParam*)) );
...@@ -197,7 +197,7 @@ void AlgorithmSelector::selectTool( int n ) ...@@ -197,7 +197,7 @@ void AlgorithmSelector::selectTool( int n )
{ {
if( m_SelectedToolParam ) if( m_SelectedToolParam )
{ {
m_SelectedToolParam->hide(); m_SelectedToolParam->SetHidden();
m_SelectedToolParam = NULL; m_SelectedToolParam = NULL;
} }
...@@ -230,7 +230,7 @@ void AlgorithmSelector::selectTool( int n ) ...@@ -230,7 +230,7 @@ void AlgorithmSelector::selectTool( int n )
if( !m_SelectedTool->param->IsEmpty() ) if( !m_SelectedTool->param->IsEmpty() )
{ {
m_SelectedToolParam = m_SelectedTool->param; m_SelectedToolParam = m_SelectedTool->param;
m_SelectedToolParam->show(); m_SelectedToolParam->SetVisible();
} }
m_LastUsedInCategory[m_SelectedCategory] = n; m_LastUsedInCategory[m_SelectedCategory] = n;
......
...@@ -21,15 +21,22 @@ UIParam::UIParam( const QString& id, ...@@ -21,15 +21,22 @@ UIParam::UIParam( const QString& id,
m_Name( name ), m_Name( name ),
m_Description( description ), m_Description( description ),
m_Label( NULL ), m_Label( NULL ),
m_Widget( NULL ) m_Widget( NULL ),
m_IsVisible( true ),
m_LayoutRow( -1 )
{ {
} }
void UIParam::ArrangeInLayout( QGridLayout *l, int line ) void UIParam::ArrangeInLayout( QGridLayout *l )
{ {
m_Label = new QLabel( Name()+':', l->parentWidget() ); assert( m_LayoutRow >= 0 );
m_Widget->setParent( l->parentWidget() );
if( !m_Label )
m_Label = new QLabel( Name()+':' );
m_Label->setParent( l->parentWidget() );
m_Widget->setParent( l->parentWidget() );
if( !m_Description.isNull() && !m_Description.isEmpty() ) if( !m_Description.isNull() && !m_Description.isEmpty() )
{ {
...@@ -37,24 +44,73 @@ void UIParam::ArrangeInLayout( QGridLayout *l, int line ) ...@@ -37,24 +44,73 @@ void UIParam::ArrangeInLayout( QGridLayout *l, int line )
m_Widget->setToolTip( m_Description ); m_Widget->setToolTip( m_Description );
} }
l->addWidget( m_Label , line,0 ); l->addWidget( m_Label , m_LayoutRow,0 );
l->addWidget( m_Widget, line,1 ); l->addWidget( m_Widget, m_LayoutRow,1 );
} }
void UIParam::SetVisible( bool visible ) void UIParam::RemoveFromLayout( QGridLayout *l )
{ {
m_Widget->setVisible( visible ); l->removeWidget( m_Widget );
m_Widget->setParent( NULL );
if( m_Label ) if( m_Label )
m_Label->setVisible( visible ); {
l->removeWidget( m_Label );
m_Label->setParent( NULL );
}
}
void UIParam::SetVisible( bool visible )
{
if( visible == m_IsVisible )
return;
m_IsVisible = visible;
if( !m_Group )
return;
QGridLayout *l = (QGridLayout*) m_Group->layout();
if( visible )
{
ArrangeInLayout( l );
UpdateVisibility( m_Group->isVisible() );
}
else
{
UpdateVisibility( false );
RemoveFromLayout( l );
}
m_Group->ParamVisibilityChanged( this );
}
bool UIParam::UpdateVisibility( bool visible )
{
visible = (visible && m_IsVisible);
if( visible != m_Widget->isVisible() )
{
m_Widget->setVisible( visible );
if( m_Label )
m_Label->setVisible( visible );
}
return visible;
} }
void UIParam::SetEnabled( bool enabled ) void UIParam::SetEnabled( bool enabled )
{ {
m_Widget->setEnabled( enabled ); if( enabled != IsEnabled() )
{
m_Widget->setEnabled( enabled );
if( m_Label ) if( m_Label )
m_Label->setEnabled( enabled ); m_Label->setEnabled( enabled );
}
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <QString> #include <QString>
#include <QtWidgets> #include <QtWidgets>
#include <cassert>
class UIParamSet; class UIParamSet;
...@@ -21,6 +22,8 @@ class UIParam : public QObject ...@@ -21,6 +22,8 @@ class UIParam : public QObject
{ {
Q_OBJECT Q_OBJECT
friend class UIParamSet;
protected: protected:
UIParamSet *m_Group; UIParamSet *m_Group;
QString m_Id; QString m_Id;
...@@ -28,6 +31,10 @@ protected: ...@@ -28,6 +31,10 @@ protected:
QString m_Description; QString m_Description;
QLabel *m_Label; QLabel *m_Label;
QWidget *m_Widget; QWidget *m_Widget;
bool m_IsVisible;
int m_LayoutRow;
bool UpdateVisibility( bool visible );
public: public:
UIParam( const QString& id, const QString& name, const QString& description ); UIParam( const QString& id, const QString& name, const QString& description );
...@@ -40,13 +47,15 @@ public: ...@@ -40,13 +47,15 @@ public:
inline void SetGroup( UIParamSet *g ) { m_Group = g; } inline void SetGroup( UIParamSet *g ) { m_Group = g; }
inline UIParamSet* Group() const { return m_Group; } inline UIParamSet* Group() const { return m_Group; }
virtual void ArrangeInLayout( QGridLayout *l, int line ); inline void SetLayoutPosition( int row ) { m_LayoutRow = row; }
virtual void ArrangeInLayout( QGridLayout *l );
virtual void RemoveFromLayout( QGridLayout *l );
virtual void ConnectModificationSignal() = 0; virtual void ConnectModificationSignal() = 0;
void SetVisible( bool visible = true ); void SetVisible( bool visible = true );
inline void SetHidden ( bool hidden = true ) { SetVisible( !hidden ); } inline void SetHidden ( bool hidden = true ) { SetVisible( !hidden ); }
inline bool IsVisible() const { return m_Widget->isVisible(); } inline bool IsVisible() const { return m_IsVisible; }
inline bool IsHidden () const { return m_Widget->isHidden (); } inline bool IsHidden () const { return !m_IsVisible; }
void SetEnabled ( bool enabled = true ); void SetEnabled ( bool enabled = true );
inline void SetDisabled( bool disabled = true ) { SetEnabled( !disabled ); } inline void SetDisabled( bool disabled = true ) { SetEnabled( !disabled ); }
......
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
inline const QPushButton* Widget() const { return (QPushButton*) m_Widget; } inline const QPushButton* Widget() const { return (QPushButton*) m_Widget; }
inline QPushButton* Widget() { return (QPushButton*) m_Widget; } inline QPushButton* Widget() { return (QPushButton*) m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line ); inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); } inline virtual QString ValueString() const { return QString(); }
...@@ -41,11 +41,13 @@ inline UIParamAction::UIParamAction( const QString& id, ...@@ -41,11 +41,13 @@ inline UIParamAction::UIParamAction( const QString& id,
m_Widget = new QPushButton( name ); m_Widget = new QPushButton( name );
} }
inline void UIParamAction::ArrangeInLayout( QGridLayout *l, int line ) inline void UIParamAction::ArrangeInLayout( QGridLayout *l )
{ {
assert( m_LayoutRow >= 0 );
if( !m_Description.isNull() && !m_Description.isEmpty() ) if( !m_Description.isNull() && !m_Description.isEmpty() )
m_Widget->setToolTip( m_Description ); m_Widget->setToolTip( m_Description );
l->addWidget( m_Widget, line,0, 1,2 ); l->addWidget( m_Widget, m_LayoutRow,0, 1,2 );
} }
inline void UIParamAction::ConnectModificationSignal() inline void UIParamAction::ConnectModificationSignal()
......
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
inline const QComboBox* Widget() const { return (QComboBox*) m_Widget; } inline const QComboBox* Widget() const { return (QComboBox*) m_Widget; }
inline QComboBox* Widget() { return (QComboBox*) m_Widget; } inline QComboBox* Widget() { return (QComboBox*) m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line ); inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); } inline virtual QString ValueString() const { return QString(); }
...@@ -51,9 +51,10 @@ public slots: ...@@ -51,9 +51,10 @@ public slots:
}; };
inline void UIParamAnimation::ArrangeInLayout( QGridLayout *l, int line ) inline void UIParamAnimation::ArrangeInLayout( QGridLayout *l )
{ {
l->addWidget( m_Widget, line,0, 1,2 ); assert( m_LayoutRow >= 0 );
l->addWidget( m_Widget, m_LayoutRow,0, 1,2 );
} }
inline void UIParamAnimation::ConnectModificationSignal() inline void UIParamAnimation::ConnectModificationSignal()
......
...@@ -56,11 +56,13 @@ UIParamChoice::UIParamChoice( const QString& id, ...@@ -56,11 +56,13 @@ UIParamChoice::UIParamChoice( const QString& id,
} }
void UIParamChoice::ArrangeInLayout( QGridLayout *l, int line ) void UIParamChoice::ArrangeInLayout( QGridLayout *l )
{ {
assert( m_LayoutRow >= 0 );
if( !m_Description.isNull() && !m_Description.isEmpty() ) if( !m_Description.isNull() && !m_Description.isEmpty() )
m_Widget->setToolTip( m_Description ); m_Widget->setToolTip( m_Description );
l->addWidget( m_Widget, line,0, 1,2 ); l->addWidget( m_Widget, m_LayoutRow,0, 1,2 );
} }
......
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
inline const QWidget* Widget() const { return m_Widget; } inline const QWidget* Widget() const { return m_Widget; }
inline QWidget* Widget() { return m_Widget; } inline QWidget* Widget() { return m_Widget; }
void ArrangeInLayout( QGridLayout *l, int line ); void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
virtual QString ValueString() const; virtual QString ValueString() const;
......
...@@ -30,7 +30,7 @@ public: ...@@ -30,7 +30,7 @@ public:
inline const QWidget* Widget() const { return m_Widget; } inline const QWidget* Widget() const { return m_Widget; }
inline QWidget* Widget() { return m_Widget; } inline QWidget* Widget() { return m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line ); inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
inline virtual QString ValueString() const { return QString(); } inline virtual QString ValueString() const { return QString(); }
...@@ -78,9 +78,10 @@ inline UIParamFunction::UIParamFunction( const QString& id, ...@@ -78,9 +78,10 @@ inline UIParamFunction::UIParamFunction( const QString& id,
QObject::connect( buttons[5], SIGNAL(clicked()), m_FuncWidget, SLOT(setGemanMcLure()) ); QObject::connect( buttons[5], SIGNAL(clicked()), m_FuncWidget, SLOT(setGemanMcLure()) );
} }
inline void UIParamFunction::ArrangeInLayout( QGridLayout *l, int line ) inline void UIParamFunction::ArrangeInLayout( QGridLayout *l )
{ {
l->addWidget( m_Widget, line,0, 1,2 ); assert( m_LayoutRow >= 0 );
l->addWidget( m_Widget, m_LayoutRow,0, 1,2 );
} }
inline void UIParamFunction::ConnectModificationSignal() inline void UIParamFunction::ConnectModificationSignal()
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
inline const GradientWidget* Widget() const { return (const GradientWidget*) m_Widget; } inline const GradientWidget* Widget() const { return (const GradientWidget*) m_Widget; }
inline GradientWidget* Widget() { return (GradientWidget*) m_Widget; } inline GradientWidget* Widget() { return (GradientWidget*) m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line ); inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
inline virtual QString ValueString() const; inline virtual QString ValueString() const;
...@@ -71,9 +71,10 @@ inline UIParamGradient::UIParamGradient( const QString& id, ...@@ -71,9 +71,10 @@ inline UIParamGradient::UIParamGradient( const QString& id,
InitWidget( new GradientWidget( colors, values ) ); InitWidget( new GradientWidget( colors, values ) );
} }
inline void UIParamGradient::ArrangeInLayout( QGridLayout *l, int line ) inline void UIParamGradient::ArrangeInLayout( QGridLayout *l )
{ {
l->addWidget( (QWidget*) m_Widget->parent(), line,0, 1,2 ); assert( m_LayoutRow >= 0 );
l->addWidget( (QWidget*) m_Widget->parent(), m_LayoutRow,0, 1,2 );
} }
inline void UIParamGradient::ConnectModificationSignal() inline void UIParamGradient::ConnectModificationSignal()
......
...@@ -29,7 +29,7 @@ public: ...@@ -29,7 +29,7 @@ public:
inline const LightDirectionWidget* Widget() const { return (const LightDirectionWidget*) m_Widget; } inline const LightDirectionWidget* Widget() const { return (const LightDirectionWidget*) m_Widget; }
inline LightDirectionWidget* Widget() { return (LightDirectionWidget*) m_Widget; } inline LightDirectionWidget* Widget() { return (LightDirectionWidget*) m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line ); inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal(); inline void ConnectModificationSignal();
inline virtual QString ValueString() const; inline virtual QString ValueString() const;
...@@ -46,9 +46,10 @@ inline UIParamLightDirection::UIParamLightDirection( const QString& id, ...@@ -46,9 +46,10 @@ inline UIParamLightDirection::UIParamLightDirection( const QString& id,
m_Widget->setToolTip( m_Description ); m_Widget->setToolTip( m_Description );
} }
inline void UIParamLightDirection::ArrangeInLayout( QGridLayout *l, int line ) inline void UIParamLightDirection::ArrangeInLayout( QGridLayout *l )
{ {
l->addWidget( m_Widget, line,0, 1,2 ); assert( m_LayoutRow >= 0 );
l->addWidget( m_Widget, m_LayoutRow,0, 1,2 );
} }
inline void UIParamLightDirection::ConnectModificationSignal() inline void UIParamLightDirection::ConnectModificationSignal()
......
...@@ -14,13 +14,15 @@ ...@@ -14,13 +14,15 @@
UIParamSet::UIParamSet( const QString &title, QWidget *parent ) : UIParamSet::UIParamSet( const QString &title, QWidget *parent ) :
QGroupBox( title, parent ), QGroupBox( title, parent ),
m_AnimationCtrl( NULL ), m_AnimationCtrl( NULL ),
m_RowCount( 0 ) m_RowCount( 0 ),
m_IsVisible( false )
{ {
m_Layout = new QGridLayout(); m_Layout = new QGridLayout();
m_Layout->setVerticalSpacing( 2 ); m_Layout->setVerticalSpacing( 2 );
m_Layout->setHorizontalSpacing( 4 ); m_Layout->setHorizontalSpacing( 4 );
m_Layout->setContentsMargins( 4, 4, 4, 4 ); m_Layout->setContentsMargins( 4, 4, 4, 4 );
setLayout( m_Layout ); setLayout( m_Layout );
hide();
} }
...@@ -53,8 +55,17 @@ void UIParamSet::Add( UIParam *param ) ...@@ -53,8 +55,17 @@ void UIParamSet::Add( UIParam *param )
m_ParamById[ param->Id() ] = param; m_ParamById[ param->Id() ] = param;
} }
param->ArrangeInLayout( /*(QGridLayout*)layout()*/m_Layout, m_RowCount ); param->SetLayoutPosition( m_RowCount++ );
++ m_RowCount; param->ArrangeInLayout( m_Layout );
ParamVisibilityChanged( param );
}
void UIParamSet::AddHidden( UIParam *param )
{
Add( param );
param->SetHidden();
} }
...@@ -64,8 +75,7 @@ void UIParamSet::AddSeparator() ...@@ -64,8 +75,7 @@ void UIParamSet::AddSeparator()
line->setFrameShape( QFrame::HLine ); line->setFrameShape( QFrame::HLine );
line->setFrameShadow( QFrame::Sunken ); line->setFrameShadow( QFrame::Sunken );
line->setMinimumHeight( QApplication::fontMetrics().height()*3/4 ); line->setMinimumHeight( QApplication::fontMetrics().height()*3/4 );
m_Layout->addWidget( line, m_RowCount, 0, 1, 2 ); m_Layout->addWidget( line, m_RowCount++, 0, 1, 2 );
++ m_RowCount;
} }
...@@ -73,8 +83,7 @@ void UIParamSet::AddTitle( const QString &labelText ) ...@@ -73,8 +83,7 @@ void UIParamSet::AddTitle( const QString &labelText )
{ {
QLabel *label = new QLabel( labelText ); QLabel *label = new QLabel( labelText );
label->setAlignment( Qt::AlignHCenter ); label->setAlignment( Qt::AlignHCenter );
m_Layout->addWidget( label, m_RowCount, 0, 1, 2 ); m_Layout->addWidget( label, m_RowCount++, 0, 1, 2 );
++ m_RowCount;
} }
...@@ -94,16 +103,45 @@ void UIParamSet::updateChildrenLists( GenericUIData *d ) ...@@ -94,16 +103,45 @@ void UIParamSet::updateChildrenLists( GenericUIData *d )
} }
bool UIParamSet::AreAllHidden() const void UIParamSet::ParamVisibilityChanged( UIParam *p )
{ {
for( auto p : m_ParamById ) UpdateVisibility( m_IsVisible );
if( p->IsVisible() ) }
return false;
if( m_AnimationCtrl && m_AnimationCtrl->IsVisible() )
return false;
return true; void UIParamSet::SetVisible( bool visible )
{
if( visible != m_IsVisible )
{
m_IsVisible = visible;
UpdateVisibility( visible );
}
}
void UIParamSet::UpdateVisibility( bool visible )
{
visible = (visible && m_IsVisible);
unsigned int nVisible = 0;
if( visible )
{
for( auto p : m_ParamById )
if( p->IsVisible() )
nVisible ++;
}
if( nVisible /* && !isVisible()*/ )
{
show();
for( auto p : m_ParamById )
if( p->IsVisible() )
p->UpdateVisibility( true );
}
else// if( isVisible() )
{
hide();
}
} }
......
...@@ -51,6 +51,7 @@ class UIParamSet : public QGroupBox ...@@ -51,6 +51,7 @@ class UIParamSet : public QGroupBox