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

Visibility management of UIParam and UIParamSet improved.

parent 90a0c98a
......@@ -415,9 +415,7 @@ DisplayableInterface* GLViewer::addDisplayable( GenericUIData *m )
if( !m->GetDisplayOptions()->IsEmpty() )
{
m_DisplayOptionsLayout->addWidget( m->GetDisplayOptions() );
m->GetDisplayOptions()->show();
if( m->GetDisplayOptions()->AreAllHidden() )
m->GetDisplayOptions()->hide();
m->GetDisplayOptions()->SetVisible();
}
if( isSelectionEnabled() )
......@@ -659,7 +657,7 @@ GLViewer::DisplayableMap::iterator GLViewer::removeDisplayable_Internal( Display
{
if( item->GetDisplayOptions()->GetAnimationCtrl() )
item->GetDisplayOptions()->GetAnimationCtrl()->stop();
item->GetDisplayOptions()->hide();
item->GetDisplayOptions()->SetHidden();
m_DisplayOptionsLayout->removeWidget( item->GetDisplayOptions() );
item->GetDisplayOptions()->setParent( NULL );
}
......
......@@ -70,7 +70,7 @@ void AlgorithmSelector::populateTools( ToolInterface *plugin )
tool.id = i;
tool.param = new UIParamSet( "Tool options", this );
plugin->declareParameters( i, *tool.param );
tool.param->hide();
tool.param->SetHidden();
//tool.param->setMaximumWidth(360);
connect( tool.param, SIGNAL(parameterUpdated(UIParam*)), tool.plugin, SLOT(updateParameter(UIParam*)) );
......@@ -197,7 +197,7 @@ void AlgorithmSelector::selectTool( int n )
{
if( m_SelectedToolParam )
{
m_SelectedToolParam->hide();
m_SelectedToolParam->SetHidden();
m_SelectedToolParam = NULL;
}
......@@ -230,7 +230,7 @@ void AlgorithmSelector::selectTool( int n )
if( !m_SelectedTool->param->IsEmpty() )
{
m_SelectedToolParam = m_SelectedTool->param;
m_SelectedToolParam->show();
m_SelectedToolParam->SetVisible();
}
m_LastUsedInCategory[m_SelectedCategory] = n;
......
......@@ -21,15 +21,22 @@ UIParam::UIParam( const QString& id,
m_Name( name ),
m_Description( description ),
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() );
m_Widget->setParent( l->parentWidget() );
assert( m_LayoutRow >= 0 );
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() )
{
......@@ -37,24 +44,73 @@ void UIParam::ArrangeInLayout( QGridLayout *l, int line )
m_Widget->setToolTip( m_Description );
}
l->addWidget( m_Label , line,0 );
l->addWidget( m_Widget, line,1 );
l->addWidget( m_Label , m_LayoutRow,0 );
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 )
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 )
{
m_Widget->setEnabled( enabled );
if( enabled != IsEnabled() )
{
m_Widget->setEnabled( enabled );
if( m_Label )
m_Label->setEnabled( enabled );
if( m_Label )
m_Label->setEnabled( enabled );
}
}
......@@ -14,6 +14,7 @@
#include <QString>
#include <QtWidgets>
#include <cassert>
class UIParamSet;
......@@ -21,6 +22,8 @@ class UIParam : public QObject
{
Q_OBJECT
friend class UIParamSet;
protected:
UIParamSet *m_Group;
QString m_Id;
......@@ -28,6 +31,10 @@ protected:
QString m_Description;
QLabel *m_Label;
QWidget *m_Widget;
bool m_IsVisible;
int m_LayoutRow;
bool UpdateVisibility( bool visible );
public:
UIParam( const QString& id, const QString& name, const QString& description );
......@@ -40,13 +47,15 @@ public:
inline void SetGroup( UIParamSet *g ) { m_Group = g; }
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;
void SetVisible( bool visible = true );
inline void SetHidden ( bool hidden = true ) { SetVisible( !hidden ); }
inline bool IsVisible() const { return m_Widget->isVisible(); }
inline bool IsHidden () const { return m_Widget->isHidden (); }
inline bool IsVisible() const { return m_IsVisible; }
inline bool IsHidden () const { return !m_IsVisible; }
void SetEnabled ( bool enabled = true );
inline void SetDisabled( bool disabled = true ) { SetEnabled( !disabled ); }
......
......@@ -25,7 +25,7 @@ public:
inline const QPushButton* Widget() const { 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 virtual QString ValueString() const { return QString(); }
......@@ -41,11 +41,13 @@ inline UIParamAction::UIParamAction( const QString& id,
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() )
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()
......
......@@ -27,7 +27,7 @@ public:
inline const QComboBox* Widget() const { 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 virtual QString ValueString() const { return QString(); }
......@@ -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()
......
......@@ -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() )
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:
inline const QWidget* Widget() const { return m_Widget; }
inline QWidget* Widget() { return m_Widget; }
void ArrangeInLayout( QGridLayout *l, int line );
void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal();
virtual QString ValueString() const;
......
......@@ -30,7 +30,7 @@ public:
inline const QWidget* Widget() const { 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 virtual QString ValueString() const { return QString(); }
......@@ -78,9 +78,10 @@ inline UIParamFunction::UIParamFunction( const QString& id,
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()
......
......@@ -41,7 +41,7 @@ public:
inline const GradientWidget* Widget() const { return (const 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 virtual QString ValueString() const;
......@@ -71,9 +71,10 @@ inline UIParamGradient::UIParamGradient( const QString& id,
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()
......
......@@ -29,7 +29,7 @@ public:
inline const LightDirectionWidget* Widget() const { return (const 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 virtual QString ValueString() const;
......@@ -46,9 +46,10 @@ inline UIParamLightDirection::UIParamLightDirection( const QString& id,
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()
......
......@@ -14,13 +14,15 @@
UIParamSet::UIParamSet( const QString &title, QWidget *parent ) :
QGroupBox( title, parent ),
m_AnimationCtrl( NULL ),
m_RowCount( 0 )
m_RowCount( 0 ),
m_IsVisible( false )
{
m_Layout = new QGridLayout();
m_Layout->setVerticalSpacing( 2 );
m_Layout->setHorizontalSpacing( 4 );
m_Layout->setContentsMargins( 4, 4, 4, 4 );
setLayout( m_Layout );
hide();
}
......@@ -53,8 +55,17 @@ void UIParamSet::Add( UIParam *param )
m_ParamById[ param->Id() ] = param;
}
param->ArrangeInLayout( /*(QGridLayout*)layout()*/m_Layout, m_RowCount );
++ m_RowCount;
param->SetLayoutPosition( m_RowCount++ );
param->ArrangeInLayout( m_Layout );
ParamVisibilityChanged( param );
}
void UIParamSet::AddHidden( UIParam *param )
{
Add( param );
param->SetHidden();
}
......@@ -64,8 +75,7 @@ void UIParamSet::AddSeparator()
line->setFrameShape( QFrame::HLine );
line->setFrameShadow( QFrame::Sunken );
line->setMinimumHeight( QApplication::fontMetrics().height()*3/4 );
m_Layout->addWidget( line, m_RowCount, 0, 1, 2 );
++ m_RowCount;
m_Layout->addWidget( line, m_RowCount++, 0, 1, 2 );
}
......@@ -73,8 +83,7 @@ void UIParamSet::AddTitle( const QString &labelText )
{
QLabel *label = new QLabel( labelText );
label->setAlignment( Qt::AlignHCenter );
m_Layout->addWidget( label, m_RowCount, 0, 1, 2 );
++ m_RowCount;
m_Layout->addWidget( label, m_RowCount++, 0, 1, 2 );
}
......@@ -94,16 +103,45 @@ void UIParamSet::updateChildrenLists( GenericUIData *d )
}
bool UIParamSet::AreAllHidden() const
void UIParamSet::ParamVisibilityChanged( UIParam *p )
{
for( auto p : m_ParamById )
if( p->IsVisible() )
return false;
UpdateVisibility( m_IsVisible );
}
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
QList<UIParamChildren*> m_ChildrenLists;
QGridLayout *m_Layout;
UIParamAnimation *m_AnimationCtrl;
bool m_IsVisible;
template <typename TUIParam>
inline TUIParam* GetParam( const QString &paramName ) const
......@@ -58,11 +59,14 @@ class UIParamSet : public QGroupBox
return dynamic_cast<TUIParam*>( Get(paramName) );
}
void UpdateVisibility( bool visible );
public:
UIParamSet( const QString &title, QWidget *parent );
~UIParamSet();
void Add( UIParam *param );
void AddHidden( UIParam *param );
void AddSeparator();
void AddTitle( const QString &labelText );
UIParam* Get( const QString &paramName ) const;
......@@ -94,7 +98,9 @@ public:
inline const QList<UIParamAction*>& GetActions() const { return m_Actions; }
inline bool IsEmpty() const { return m_ParamById.empty() && !m_AnimationCtrl; }
bool AreAllHidden() const;
void ParamVisibilityChanged( UIParam *p );
void SetVisible( bool visible = true );
inline void SetHidden( bool hidden = true ) { SetVisible( !hidden ); }
bool SetValueString( const QString &paramName, const QString &valueString );
QString ValueString( const QString &paramName );
......
......@@ -56,8 +56,10 @@ UIParamTable::UIParamTable( const QString& id,
}
void UIParamTable::ArrangeInLayout( QGridLayout *l, int line )
void UIParamTable::ArrangeInLayout( QGridLayout *l )
{
assert( m_LayoutRow >= 0 );
QVBoxLayout *lpanel = new QVBoxLayout();
lpanel->setContentsMargins( 0, 0, 0, 0 );
lpanel->setSpacing( 4 );
......@@ -75,5 +77,5 @@ void UIParamTable::ArrangeInLayout( QGridLayout *l, int line )
m_Widget->setToolTip( m_Description );
label->setToolTip( m_Description );
}
l->addWidget( panel, line,0, 1,2 );
l->addWidget( panel, m_LayoutRow,0, 1,2 );
}
......@@ -27,7 +27,7 @@ public:
inline const QTableWidget* Widget() const { return (QTableWidget*) m_Widget; }
inline QTableWidget* Widget() { return (QTableWidget*) m_Widget; }
inline void ArrangeInLayout( QGridLayout *l, int line );
inline void ArrangeInLayout( QGridLayout *l );
inline void ConnectModificationSignal() {}
inline virtual QString ValueString() const { return QString(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment