]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/ParametersQtDialog.cxx
Widgets updated
[cpPlugins.git] / lib / cpPlugins / Interface / ParametersQtDialog.cxx
index 9f6aadcdbc910fd960cbcb233ff19cc9b0b64c64..80d73a265f5499e0d8445ca868f471f6455ed6cd 100644 (file)
 #ifdef cpPlugins_Interface_QT4
 
 #include <limits>
-#include <vector>
 
 #include <cpPlugins/Interface/ParametersListWidget.h>
+
+#include <vtkSmartPointer.h>
+#include <cpExtensions/Interaction/SeedWidget.h>
+#include <vtkPointHandleRepresentation3D.h>
+#include <vtkProperty.h>
+#include <vtkSeedRepresentation.h>
+
 #include <QCheckBox>
-#include <QDialog>
 #include <QDialogButtonBox>
 #include <QDoubleSpinBox>
 #include <QHBoxLayout>
-#include <QLabel>
 #include <QLineEdit>
 #include <QWidget>
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::
-ParametersQtDialog(
-  Parameters* parameters, const std::string& title, QWidget* parent
-  )
+cpPlugins::Interface::ParametersQtDialog::
+ParametersQtDialog( QWidget* parent, Qt::WindowFlags f )
+  : QDialog( parent, f ),
+    m_Parameters( NULL ),
+    m_IsModal( false ),
+    m_Interactor( NULL )
 {
-  // Create dialog with a simple layout
-  QDialog* dlg = new QDialog( parent );
-  dlg->setWindowFlags( Qt::FramelessWindowHint ); 
-  dlg->setWindowFlags( Qt::WindowTitleHint );
-  QGridLayout* gridLayout = new QGridLayout( dlg );
-  QVBoxLayout* verticalLayout = new QVBoxLayout( );
+  this->m_Title = new QLabel( this );
+  this->m_Title->setText( "Parameters dialog title" );
 
-  // Put a title
-  QLabel* dlg_title = new QLabel( dlg );
-  dlg_title->setText( title.c_str( ) );
-  verticalLayout->addWidget( dlg_title );
+  this->m_MainLayout = new QGridLayout( this );
+  this->m_ToolsLayout = new QVBoxLayout( );
+  this->m_ToolsLayout->addWidget( this->m_Title );
+  this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::ParametersQtDialog::
+~ParametersQtDialog( )
+{
+  delete this->m_Title;
+  delete this->m_MainLayout;
+  delete this->m_ToolsLayout;
+
+  for( unsigned int i = 0; i < this->m_Widgets.size( ); ++i )
+    this->m_Widgets[ i ]->Delete( );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+IsModal( ) const
+{
+  return( this->m_IsModal );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+Parameters* cpPlugins::Interface::ParametersQtDialog::
+getParameters( ) const
+{
+  return( this->m_Parameters );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+setInteractor( vtkRenderWindowInteractor* interactor )
+{
+  this->m_Interactor = interactor;
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::ParametersQtDialog::
+setParameters( Parameters* parameters )
+{
+  this->m_IsModal = true;
+  this->m_Parameters = parameters;
+  if( this->m_Parameters == NULL )
+    return( false );
 
   // Put values
   std::vector< std::string > names;
-  parameters->GetNames( names );
+  this->m_Parameters->GetNames( names );
   std::vector< std::string >::const_iterator nIt = names.begin( );
   for( ; nIt != names.end( ); ++nIt )
   {
-    Parameters::Type pt = parameters->GetType( *nIt );
+    Parameters::Type pt = this->m_Parameters->GetType( *nIt );
+
+    QWidget* w_input = NULL;
+    if( pt == Parameters::String )
+    {
+      QLineEdit* v_string = new QLineEdit( this );
+      v_string->setText( "Enter some text!!!" );
+      w_input = v_string;
+    }
+    else if( pt == Parameters::Bool )
+    {
+      QCheckBox* v_bool = new QCheckBox( this );
+      v_bool->setText( "[ON/OFF]" );
+      v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) );
+      w_input = v_bool;
+    }
+    else if( pt == Parameters::Uint )
+    {
+      QSpinBox* v_uint = new QSpinBox( this );
+      v_uint->setMinimum( 0 );
+      v_uint->setMaximum( std::numeric_limits< int >::max( ) );
+      v_uint->setValue( this->m_Parameters->GetUint( *nIt ) );
+      w_input = v_uint;
+    }
+    else if( pt == Parameters::Int )
+    {
+      QSpinBox* v_int = new QSpinBox( this );
+      v_int->setMinimum( -std::numeric_limits< int >::max( ) );
+      v_int->setMaximum(  std::numeric_limits< int >::max( ) );
+      v_int->setValue( this->m_Parameters->GetInt( *nIt ) );
+      w_input = v_int;
+    }
+    else if( pt == Parameters::Real )
+    {
+      QDoubleSpinBox* v_double = new QDoubleSpinBox( this );
+      v_double->setDecimals( 3 );
+      v_double->setMinimum( -std::numeric_limits< double >::max( ) );
+      v_double->setMaximum(  std::numeric_limits< double >::max( ) );
+      v_double->setValue( this->m_Parameters->GetReal( *nIt ) );
+      w_input = v_double;
+    }
+    else if(
+      pt == Parameters::StringList ||
+      pt == Parameters::IntList ||
+      pt == Parameters::UintList ||
+      pt == Parameters::RealList
+      )
+    {
+      cpPlugins::Interface::ParametersListWidget* l_double =
+        new cpPlugins::Interface::ParametersListWidget( *nIt, this );
+      w_input = l_double;
+    }
+    else if( pt == Parameters::Point || pt == Parameters::Index )
+    {
+      if( this->m_Interactor != NULL )
+      {
+        // Create a point widget and its representation
+        vtkSmartPointer< vtkPointHandleRepresentation3D > handle =
+          vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+        handle->GetProperty( )->SetColor( 1, 0, 0 );
+        vtkSmartPointer< vtkSeedRepresentation > rep =
+          vtkSmartPointer< vtkSeedRepresentation >::New( );
+        rep->SetHandleRepresentation( handle );
+
+        cpExtensions::Interaction::SeedWidget* widget =
+          cpExtensions::Interaction::SeedWidget::New( );
+        widget->SetInteractor( this->m_Interactor );
+        widget->SetRepresentation( rep );
+        widget->On( );
+
+        this->m_Widgets.push_back( widget );
+        this->m_IsModal = false;
+
+      } // fi
+
+    } // fi
+
+    // Ok, a representation was created
+    if( w_input != NULL )
+    {
+      w_input->setObjectName( QString( nIt->c_str( ) ) );
+
+      QHBoxLayout* new_layout = new QHBoxLayout( );
+      QLabel* label = new QLabel( this );
+      label->setText( QString( nIt->c_str( ) ) );
+      new_layout->addWidget( label );
+      new_layout->addWidget( w_input );
+      this->m_ToolsLayout->addLayout( new_layout );
+
+    } // fi
+
+  } // rof
+  return( this->m_IsModal );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+setTitle( const std::string& title )
+{
+  this->m_Title->setText( title.c_str( ) );
+}
+
+// -------------------------------------------------------------------------
+int cpPlugins::Interface::ParametersQtDialog::
+exec( )
+{
+  if( !this->m_IsModal )
+    return( 0 );
+
+  // Add buttons
+  QDialogButtonBox* bb = new QDialogButtonBox(
+    QDialogButtonBox::Ok | QDialogButtonBox::Cancel
+    );
+  QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) );
+  QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) );
+  this->m_ToolsLayout->addWidget( bb );
+
+  return( this->QDialog::exec( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+show( )
+{
+  if( this->m_IsModal )
+    return;
+
+  this->QDialog::show( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::ParametersQtDialog::
+syncParameters( )
+{
+  std::cout << "TODO: SyncParameters" << std::endl;
+}
+
+
+
+
+
+
+
+
 
     /* TODO
        enum Type
        {
-       Bool,
        Index,
        Point,
        StringList,
@@ -53,9 +241,36 @@ ParametersQtDialog(
        UintList,
        IndexList,
        PointList,
+       Choices,
        NoType
        };
     */
+/*
+bool cpPlugins::Interface::
+ParametersQtDialog(
+  Parameters* parameters, const std::string& title, QWidget* parent
+  )
+{
+  // Create dialog with a simple layout
+  QDialog* dlg = new QDialog( parent );
+  dlg->setWindowFlags( Qt::FramelessWindowHint ); 
+  dlg->setWindowFlags( Qt::WindowTitleHint );
+  QGridLayout* gridLayout = new QGridLayout( dlg );
+  QVBoxLayout* verticalLayout = new QVBoxLayout( );
+
+  // Put a title
+  QLabel* dlg_title = new QLabel( dlg );
+  dlg_title->setText( title.c_str( ) );
+  verticalLayout->addWidget( dlg_title );
+
+  // Put values
+  std::vector< std::string > names;
+  this->m_Parameters->GetNames( names );
+  std::vector< std::string >::const_iterator nIt = names.begin( );
+  for( ; nIt != names.end( ); ++nIt )
+  {
+    Parameters::Type pt = this->m_Parameters->GetType( *nIt );
+
     QWidget* w_input = NULL;
     if( pt == Parameters::String )
     {
@@ -67,7 +282,7 @@ ParametersQtDialog(
     {
       QCheckBox* v_bool = new QCheckBox( dlg );
       v_bool->setText( "[ON/OFF]" );
-      v_bool->setChecked( parameters->GetBool( *nIt ) );
+      v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) );
       w_input = v_bool;
     }
     else if( pt == Parameters::Uint )
@@ -75,7 +290,7 @@ ParametersQtDialog(
       QSpinBox* v_uint = new QSpinBox( dlg );
       v_uint->setMinimum( 0 );
       v_uint->setMaximum( std::numeric_limits< int >::max( ) );
-      v_uint->setValue( parameters->GetUint( *nIt ) );
+      v_uint->setValue( this->m_Parameters->GetUint( *nIt ) );
       w_input = v_uint;
     }
     else if( pt == Parameters::Int )
@@ -83,7 +298,7 @@ ParametersQtDialog(
       QSpinBox* v_int = new QSpinBox( dlg );
       v_int->setMinimum( -std::numeric_limits< int >::max( ) );
       v_int->setMaximum(  std::numeric_limits< int >::max( ) );
-      v_int->setValue( parameters->GetInt( *nIt ) );
+      v_int->setValue( this->m_Parameters->GetInt( *nIt ) );
       w_input = v_int;
     }
     else if( pt == Parameters::Real )
@@ -92,7 +307,7 @@ ParametersQtDialog(
       v_double->setDecimals( 3 );
       v_double->setMinimum( -std::numeric_limits< double >::max( ) );
       v_double->setMaximum(  std::numeric_limits< double >::max( ) );
-      v_double->setValue( parameters->GetReal( *nIt ) );
+      v_double->setValue( this->m_Parameters->GetReal( *nIt ) );
       w_input = v_double;
     }
     else if(
@@ -142,37 +357,37 @@ ParametersQtDialog(
   nIt = names.begin( );
   for( ; nIt != names.end( ); ++nIt )
   {
-    Parameters::Type pt = parameters->GetType( *nIt );
+    Parameters::Type pt = this->m_Parameters->GetType( *nIt );
     if( pt == Parameters::String )
     {
       QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) );
       if( v_string != NULL )
-        parameters->SetString( *nIt, v_string->text( ).toStdString( ) );
+        this->m_Parameters->SetString( *nIt, v_string->text( ).toStdString( ) );
     }
     else if( pt == Parameters::Bool )
     {
       QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) );
       if( v_bool != NULL )
-        parameters->SetBool( *nIt, v_bool->isChecked( ) );
+        this->m_Parameters->SetBool( *nIt, v_bool->isChecked( ) );
     }
     else if( pt == Parameters::Uint )
     {
       QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
       if( v_uint != NULL )
-        parameters->SetUint( *nIt, v_uint->value( ) );
+        this->m_Parameters->SetUint( *nIt, v_uint->value( ) );
     }
     else if( pt == Parameters::Int )
     {
       QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) );
       if( v_int != NULL )
-        parameters->SetInt( *nIt, v_int->value( ) );
+        this->m_Parameters->SetInt( *nIt, v_int->value( ) );
     }
     else if( pt == Parameters::Real )
     {
       QDoubleSpinBox* v_double =
         dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) );
       if( v_double != NULL )
-        parameters->SetReal( *nIt, v_double->value( ) );
+        this->m_Parameters->SetReal( *nIt, v_double->value( ) );
     }
     else if(
       pt == Parameters::StringList ||
@@ -191,25 +406,25 @@ ParametersQtDialog(
         {
           std::vector< std::string > values = l_double->GetStringValues( );
           for( int r = 0; r < values.size( ); ++r )
-            parameters->AddToStringList( *nIt, values[ r ] );
+            this->m_Parameters->AddToStringList( *nIt, values[ r ] );
         }
         else if( pt == Parameters::IntList )
         {
           std::vector< int > values = l_double->GetIntValues( );
           for( int r = 0; r < values.size( ); ++r )
-            parameters->AddToIntList( *nIt, values[ r ] );
+            this->m_Parameters->AddToIntList( *nIt, values[ r ] );
         }
         else if( pt == Parameters::UintList )
         {
           std::vector< unsigned int > values = l_double->GetUintValues( );
           for( int r = 0; r < values.size( ); ++r )
-            parameters->AddToUintList( *nIt, values[ r ] );
+            this->m_Parameters->AddToUintList( *nIt, values[ r ] );
         }
         else if( pt == Parameters::RealList )
         {
           std::vector< double > values = l_double->GetDoubleValues( );
           for( int r = 0; r < values.size( ); ++r )
-            parameters->AddToRealList( *nIt, values[ r ] );
+            this->m_Parameters->AddToRealList( *nIt, values[ r ] );
 
         } // fi
 
@@ -220,6 +435,7 @@ ParametersQtDialog(
   } // rof
   return( true );
 }
+*/
 
 #endif // cpPlugins_Interface_QT4