1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_Wizard.h"
20 #include "HYDROGUI_Module.h"
21 #include <CAM_Application.h>
22 #include <SUIT_Desktop.h>
24 #include <QVBoxLayout>
26 #include <QPushButton>
27 #include <QAbstractButton>
28 #include <QStackedWidget>
29 #include <QWizardPage>
31 HYDROGUI_Wizard::HYDROGUI_Wizard( HYDROGUI_Module* theModule, const QString& theTitle )
32 : HYDROGUI_InputPanel( theModule, theTitle, false )
35 myWizard = new QStackedWidget( theModule->application()->desktop() );
37 myNext = new QPushButton( tr( "NEXT" ), buttonFrame() );
38 myBack = new QPushButton( tr( "BACK" ), buttonFrame() );
39 myFinish = new QPushButton( tr( "FINISH" ), buttonFrame() );
41 QHBoxLayout* aBtnsLayout = qobject_cast<QHBoxLayout*>(buttonFrame()->layout());
42 aBtnsLayout->addWidget( myBack, 0 );
43 aBtnsLayout->addWidget( myNext, 0 );
44 aBtnsLayout->addWidget( myFinish, 0 );
45 aBtnsLayout->addWidget( myCancel, 0 );
46 aBtnsLayout->addStretch( 1 );
47 aBtnsLayout->addWidget( myHelp, 0 );
49 myBack->setEnabled( false );
50 myNext->setVisible( false );
52 connect( myNext, SIGNAL( clicked() ), SLOT( onNext() ) );
53 connect( myBack, SIGNAL( clicked() ), SLOT( onBack() ) );
54 connect( myFinish, SIGNAL( clicked() ), SLOT( onApply() ) );
56 addWidget( myWizard );
59 HYDROGUI_Wizard::~HYDROGUI_Wizard()
63 QStackedWidget* HYDROGUI_Wizard::wizard() const
68 int HYDROGUI_Wizard::addPage( QWizardPage* thePage )
70 if ( myWizard->count() > 0 )
72 myNext->setVisible( true );
73 myFinish->setVisible( false );
75 return myWizard->addWidget( thePage );
78 void HYDROGUI_Wizard::onNext()
80 if ( !acceptCurrent() )
83 if ( myWizard->count() <= 0 )
86 myBack->setEnabled( true );
87 int aCurIdx = myWizard->currentIndex();
88 if ( aCurIdx == ( myWizard->count() - 2 ) )
90 // Go to the last page
91 myNext->setVisible( false );
92 myFinish->setVisible( true );
94 myWizard->setCurrentIndex( aCurIdx + 1 );
96 emit Next( myWizard->currentIndex() );
99 void HYDROGUI_Wizard::onBack()
101 if ( myWizard->count() <= 0 )
104 if ( myWizard->count() > 1 )
106 myNext->setVisible( true );
107 myFinish->setVisible( false );
111 // Wizard has a single page - show finish
112 myNext->setVisible( false );
113 myFinish->setVisible( true );
116 int aCurIdx = myWizard->currentIndex();
117 myWizard->setCurrentIndex( aCurIdx - 1 );
119 aCurIdx = myWizard->currentIndex();
122 // Disable back if go to the first page
123 myBack->setEnabled( false );
126 emit Back( aCurIdx );
129 void HYDROGUI_Wizard::onFirstPage()
131 if ( myWizard->count() > 1 ) {
132 myNext->setVisible( true );
133 myFinish->setVisible( false );
134 myWizard->setCurrentIndex( 0 );
135 myBack->setEnabled( false );
136 emit Back( myWizard->currentIndex() );
140 bool HYDROGUI_Wizard::acceptCurrent() const
145 QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
147 QAbstractButton* aRes = 0;
150 case QWizard::BackButton:
153 case QWizard::NextButton:
156 case QWizard::FinishButton:
159 case QWizard::CancelButton:
162 case QWizard::HelpButton: