Salome HOME
porting to sketcher in GEOM
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Wizard.cxx
index 34c6a04a4da79016077741c5f0774b7cbb53422b..35707867c75380e4f0d562cda2427f3f40e26a4d 100644 (file)
 #include <QFrame>
 #include <QVBoxLayout>
 #include <QWidget>
+#include <QPushButton>
+#include <QAbstractButton>
+#include <QStackedWidget>
+#include <QWizardPage>
 
 HYDROGUI_Wizard::HYDROGUI_Wizard( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle, false )
 {
 
-  myWizard = new QWizard( theModule->application()->desktop() );
-  myWizard->setOption( QWizard::HaveHelpButton );
-  setWidget( myWizard );
+  myWizard = new QStackedWidget( theModule->application()->desktop() );
 
-  connect( myWizard, SIGNAL( accepted() ),      this, SLOT( onApply()  ) );
-  connect( myWizard, SIGNAL( rejected() ),      this, SLOT( onCancel() ) );
-  connect( myWizard, SIGNAL( helpRequested() ), this, SLOT( onHelp()   ) );
+  myNext = new QPushButton( tr( "NEXT" ), buttonFrame() );
+  myBack = new QPushButton( tr( "BACK" ), buttonFrame() );
+  myFinish = new QPushButton( tr( "FINISH" ), buttonFrame() );
+
+  QHBoxLayout* aBtnsLayout = qobject_cast<QHBoxLayout*>(buttonFrame()->layout());
+  aBtnsLayout->addWidget( myBack, 0 );
+  aBtnsLayout->addWidget( myNext, 0 );
+  aBtnsLayout->addWidget( myFinish, 0 );
+  aBtnsLayout->addWidget( myCancel, 0 );
+  aBtnsLayout->addStretch( 1 );
+  aBtnsLayout->addWidget( myHelp, 0 );
+
+  myBack->setEnabled( false );
+  myNext->setVisible( false );
+
+  connect( myNext,  SIGNAL( clicked() ), SLOT( onNext() ) );
+  connect( myBack,  SIGNAL( clicked() ), SLOT( onBack() ) );
+  connect( myFinish, SIGNAL( clicked() ), SLOT( onApply() ) );
+
+  addWidget( myWizard );
 }
 
 HYDROGUI_Wizard::~HYDROGUI_Wizard()
 {
 }
 
-QWizard* HYDROGUI_Wizard::wizard() const
+QStackedWidget* HYDROGUI_Wizard::wizard() const
 {
   return myWizard;
 }
 
-void HYDROGUI_Wizard::show()
+int HYDROGUI_Wizard::addPage( QWizardPage* thePage )
+{
+  if ( myWizard->count() > 0 )
+  {
+    myNext->setVisible( true );
+    myFinish->setVisible( false );
+  }
+  return myWizard->addWidget( thePage );
+}
+
+void HYDROGUI_Wizard::onNext()
+{
+  if ( !acceptCurrent() )
+    return;
+
+  if ( myWizard->count() <= 0 )
+    return;
+
+  myBack->setEnabled( true );
+  int aCurIdx = myWizard->currentIndex();
+  if ( aCurIdx == ( myWizard->count() - 2 ) )
+  {
+    // Go to the last page
+    myNext->setVisible( false );
+    myFinish->setVisible( true );
+  }
+  myWizard->setCurrentIndex( aCurIdx + 1 );
+
+  emit Next( myWizard->currentIndex() );
+}
+
+void HYDROGUI_Wizard::onBack()
+{
+  if ( myWizard->count() <= 0 )
+    return;
+
+  if ( myWizard->count() > 1 )
+  {
+    myNext->setVisible( true );
+    myFinish->setVisible( false );
+  }
+  else
+  {
+    // Wizard has a single page - show finish
+    myNext->setVisible( false );
+    myFinish->setVisible( true );
+  }
+
+  int aCurIdx = myWizard->currentIndex();
+  myWizard->setCurrentIndex( aCurIdx - 1 );
+
+  aCurIdx = myWizard->currentIndex();
+  if ( aCurIdx <= 0 )
+  {
+    // Disable back if go to the first page
+    myBack->setEnabled( false );
+  }
+
+  emit Back( aCurIdx );
+}
+
+bool HYDROGUI_Wizard::acceptCurrent() const
+{
+  return true;
+}
+
+QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
 {
-  HYDROGUI_InputPanel::show();
-  myWizard->show();
+  QAbstractButton* aRes = 0;
+  switch( theBtnId )
+  {
+    case QWizard::BackButton:
+      aRes = myBack;
+      break;
+    case QWizard::NextButton:
+      aRes = myNext;
+      break;
+    case QWizard::FinishButton:
+      aRes = myFinish;
+      break;
+    case QWizard::CancelButton:
+      aRes = myCancel;
+      break;
+    case QWizard::HelpButton:
+      aRes = myHelp;
+  }
+  return aRes;
 }
\ No newline at end of file