From: rkv Date: Wed, 6 Nov 2013 15:59:37 +0000 (+0000) Subject: HYDROGUI_Wizard has been refactored and now uses QStackedWidget instead of QWizard. X-Git-Tag: BR_hydro_v_0_3~37 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cc6e0c0f0c273dce8decc92a2e931f28067042a5;p=modules%2Fhydro.git HYDROGUI_Wizard has been refactored and now uses QStackedWidget instead of QWizard. --- diff --git a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx index 6345e5f5..9b53a249 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationDlg.cxx @@ -58,17 +58,15 @@ #include #include #include +#include HYDROGUI_CalculationDlg::HYDROGUI_CalculationDlg( HYDROGUI_Module* theModule, const QString& theTitle ) : HYDROGUI_Wizard( theModule, theTitle ) { - QWizard* aWizard = wizard(); - aWizard->addPage( createObjectsPage() ); - aWizard->addPage( createZonesPage() ); - connect( aWizard->button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) ); - connect( aWizard->button( QWizard::BackButton ), SIGNAL( clicked() ), SIGNAL( hideZones() ) ); - - aWizard->show(); + addPage( createObjectsPage() ); + addPage( createZonesPage() ); + connect( button( QWizard::NextButton ), SIGNAL( clicked() ), SIGNAL( splitZones() ) ); + connect( button( QWizard::BackButton ), SIGNAL( clicked() ), SIGNAL( hideZones() ) ); } HYDROGUI_CalculationDlg::~HYDROGUI_CalculationDlg() @@ -82,7 +80,7 @@ void HYDROGUI_CalculationDlg::reset() } QWizardPage* HYDROGUI_CalculationDlg::createObjectsPage() { - QWizardPage* aPage = new QWizardPage( wizard() ); + QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); // Calculation name @@ -149,7 +147,7 @@ void HYDROGUI_CalculationDlg::onAlreadyExists( QString theName ) } QWizardPage* HYDROGUI_CalculationDlg::createZonesPage() { - QWizardPage* aPage = new QWizardPage( wizard() ); + QWizardPage* aPage = new QWizardPage( mainFrame() ); QFrame* aFrame = new QFrame( aPage ); QGridLayout* aLayout = new QGridLayout( aPage ); diff --git a/src/HYDROGUI/HYDROGUI_InputPanel.cxx b/src/HYDROGUI/HYDROGUI_InputPanel.cxx index 23a9c06e..d569896e 100644 --- a/src/HYDROGUI/HYDROGUI_InputPanel.cxx +++ b/src/HYDROGUI/HYDROGUI_InputPanel.cxx @@ -37,29 +37,30 @@ HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QStr setWindowTitle( theTitle ); setAllowedAreas( Qt::RightDockWidgetArea ); - if ( doInitLayout ) { - QFrame* aFrame = new QFrame( this ); - setWidget( aFrame ); - QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + QFrame* aFrame = new QFrame( this ); + setWidget( aFrame ); + QVBoxLayout* aLayout = new QVBoxLayout( aFrame ); + + myMainFrame = new QFrame( aFrame ); + QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame ); + aMainLayout->setMargin( 0 ); + aMainLayout->setSpacing( 5 ); - myMainFrame = new QFrame( aFrame ); - QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame ); - aMainLayout->setMargin( 0 ); - aMainLayout->setSpacing( 5 ); - - aLayout->addWidget( myMainFrame, 1 ); + aLayout->addWidget( myMainFrame, 1 ); + + myBtnFrame = new QFrame( aFrame ); + aLayout->addWidget( myBtnFrame, 0 ); - myBtnFrame = new QFrame( aFrame ); - aLayout->addWidget( myBtnFrame, 0 ); + QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); + aBtnsLayout->setMargin( 5 ); + aBtnsLayout->setSpacing( 5 ); - QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame ); - aBtnsLayout->setMargin( 5 ); - aBtnsLayout->setSpacing( 5 ); + myCancel = new QPushButton( tr( "CANCEL" ), myBtnFrame ); + myHelp = new QPushButton( tr( "HELP" ), myBtnFrame ); + if ( doInitLayout ) { myApply = new QPushButton( tr( "APPLY" ), myBtnFrame ); - myCancel = new QPushButton( tr( "CANCEL" ), myBtnFrame ); - myHelp = new QPushButton( tr( "HELP" ), myBtnFrame ); aBtnsLayout->addWidget( myApply, 0 ); aBtnsLayout->addWidget( myCancel, 0 ); @@ -67,9 +68,9 @@ HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QStr aBtnsLayout->addWidget( myHelp, 0 ); connect( myApply, SIGNAL( clicked() ), this, SLOT( onApply() ) ); - connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) ); - connect( myHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); } + connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) ); + connect( myHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) ); } HYDROGUI_InputPanel::~HYDROGUI_InputPanel() @@ -122,3 +123,8 @@ QFrame* HYDROGUI_InputPanel::mainFrame() const { return myMainFrame; } + +QFrame* HYDROGUI_InputPanel::buttonFrame() const +{ + return myBtnFrame; +} diff --git a/src/HYDROGUI/HYDROGUI_InputPanel.h b/src/HYDROGUI/HYDROGUI_InputPanel.h index 81a6e5de..00c2c710 100644 --- a/src/HYDROGUI/HYDROGUI_InputPanel.h +++ b/src/HYDROGUI/HYDROGUI_InputPanel.h @@ -60,15 +60,17 @@ protected slots: protected: QFrame* mainFrame() const; + QFrame* buttonFrame() const; virtual void closeEvent ( QCloseEvent * event ); + QPushButton* myCancel; + QPushButton* myHelp; + private: HYDROGUI_Module* myModule; QFrame* myMainFrame; QFrame* myBtnFrame; QPushButton* myApply; - QPushButton* myCancel; - QPushButton* myHelp; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Wizard.cxx b/src/HYDROGUI/HYDROGUI_Wizard.cxx index 34c6a04a..8acc5641 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.cxx +++ b/src/HYDROGUI/HYDROGUI_Wizard.cxx @@ -27,31 +27,115 @@ #include #include #include +#include +#include +#include +#include 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(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 ( myWizard->count() > 0 ) + { + 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 ); + } +} + +void HYDROGUI_Wizard::onBack() +{ + int aCurIdx = myWizard->currentIndex(); + if ( aCurIdx <= 1 ) + { + // Disable back if go to the first page + myBack->setEnabled( false ); + } + if ( myWizard->count() > 1 ) + { + myNext->setVisible( true ); + myFinish->setVisible( false ); + } + else + { + // Wizard has a single page - show finish + myNext->setVisible( false ); + myFinish->setVisible( true ); + } + myWizard->setCurrentIndex( aCurIdx - 1 ); +} + +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 diff --git a/src/HYDROGUI/HYDROGUI_Wizard.h b/src/HYDROGUI/HYDROGUI_Wizard.h index 1ddf93f1..39f4fbf2 100644 --- a/src/HYDROGUI/HYDROGUI_Wizard.h +++ b/src/HYDROGUI/HYDROGUI_Wizard.h @@ -25,6 +25,9 @@ #include "HYDROGUI_InputPanel.h" #include +class QAbstractButton; +class QStackedWidget; +class QWizardPage; /**\class HYDROGUI_Wizard *\brief The base class representing base wizard for HYDROGUI module @@ -37,12 +40,19 @@ public: HYDROGUI_Wizard( HYDROGUI_Module* theModule, const QString& theTitle ); virtual ~HYDROGUI_Wizard(); - void show(); + QAbstractButton* button( QWizard::WizardButton theBtnId ) const; + int addPage( QWizardPage* thePage ); + QStackedWidget* wizard() const; - QWizard* wizard() const; +public slots: + void onNext(); + void onBack(); private: - QWizard* myWizard; + QStackedWidget* myWizard; + QPushButton* myNext; + QPushButton* myBack; + QPushButton* myFinish; }; #endif diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index e931d9b8..22fdedc0 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -188,6 +188,22 @@ Do you want to continue? + + HYDROGUI_Wizard + + NEXT + Next > + + + BACK + < Back + + + FINISH + Finish + + + HYDROGUI_ImportBathymetryDlg