1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_Wizard.h"
24 #include "HYDROGUI_Module.h"
25 #include <CAM_Application.h>
26 #include <SUIT_Desktop.h>
28 #include <QVBoxLayout>
30 #include <QPushButton>
31 #include <QAbstractButton>
32 #include <QStackedWidget>
33 #include <QWizardPage>
35 HYDROGUI_Wizard::HYDROGUI_Wizard( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle, false )
39 myWizard = new QStackedWidget( theModule->application()->desktop() );
41 myNext = new QPushButton( tr( "NEXT" ), buttonFrame() );
42 myBack = new QPushButton( tr( "BACK" ), buttonFrame() );
43 myFinish = new QPushButton( tr( "FINISH" ), buttonFrame() );
45 QHBoxLayout* aBtnsLayout = qobject_cast<QHBoxLayout*>(buttonFrame()->layout());
46 aBtnsLayout->addWidget( myBack, 0 );
47 aBtnsLayout->addWidget( myNext, 0 );
48 aBtnsLayout->addWidget( myFinish, 0 );
49 aBtnsLayout->addWidget( myCancel, 0 );
50 aBtnsLayout->addStretch( 1 );
51 aBtnsLayout->addWidget( myHelp, 0 );
53 myBack->setEnabled( false );
54 myNext->setVisible( false );
56 connect( myNext, SIGNAL( clicked() ), SLOT( onNext() ) );
57 connect( myBack, SIGNAL( clicked() ), SLOT( onBack() ) );
58 connect( myFinish, SIGNAL( clicked() ), SLOT( onApply() ) );
60 addWidget( myWizard );
63 HYDROGUI_Wizard::~HYDROGUI_Wizard()
67 QStackedWidget* HYDROGUI_Wizard::wizard() const
72 int HYDROGUI_Wizard::addPage( QWizardPage* thePage )
74 if ( myWizard->count() > 0 )
76 myNext->setVisible( true );
77 myFinish->setVisible( false );
79 return myWizard->addWidget( thePage );
82 void HYDROGUI_Wizard::onNext()
84 if ( !acceptCurrent() )
87 if ( myWizard->count() <= 0 )
90 myBack->setEnabled( true );
91 int aCurIdx = myWizard->currentIndex();
92 if ( aCurIdx == ( myWizard->count() - 2 ) )
94 // Go to the last page
95 myNext->setVisible( false );
96 myFinish->setVisible( true );
98 myWizard->setCurrentIndex( aCurIdx + 1 );
100 emit Next( myWizard->currentIndex() );
103 void HYDROGUI_Wizard::onBack()
105 if ( myWizard->count() <= 0 )
108 if ( myWizard->count() > 1 )
110 myNext->setVisible( true );
111 myFinish->setVisible( false );
115 // Wizard has a single page - show finish
116 myNext->setVisible( false );
117 myFinish->setVisible( true );
120 int aCurIdx = myWizard->currentIndex();
121 myWizard->setCurrentIndex( aCurIdx - 1 );
123 aCurIdx = myWizard->currentIndex();
126 // Disable back if go to the first page
127 myBack->setEnabled( false );
130 emit Back( aCurIdx );
133 void HYDROGUI_Wizard::onFirstPage()
135 if ( myWizard->count() > 1 ) {
136 myNext->setVisible( true );
137 myFinish->setVisible( false );
138 myWizard->setCurrentIndex( 0 );
139 myBack->setEnabled( false );
140 emit Back( myWizard->currentIndex() );
144 bool HYDROGUI_Wizard::acceptCurrent() const
149 QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
151 QAbstractButton* aRes = 0;
154 case QWizard::BackButton:
157 case QWizard::NextButton:
160 case QWizard::FinishButton:
163 case QWizard::CancelButton:
166 case QWizard::HelpButton: