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 SetButtonsState(false);
73 /*myNext->setVisible( true );
74 myFinish->setVisible( false );*/
76 return myWizard->addWidget( thePage );
79 void HYDROGUI_Wizard::onNext()
81 if ( !acceptCurrent() )
84 if ( myWizard->count() <= 0 )
87 myBack->setEnabled( true );
88 int aCurIdx = myWizard->currentIndex();
91 // Go to the last page
92 SetButtonsState( true );
93 /*myNext->setVisible( false );
94 myFinish->setVisible( true );*/
96 myWizard->setCurrentIndex( aCurIdx + 1 );
98 emit Next( myWizard->currentIndex() );
101 void HYDROGUI_Wizard::onBack()
103 if ( myWizard->count() <= 0 )
106 if ( myWizard->count() > 1 )
108 /*myNext->setVisible( true );
109 myFinish->setVisible( false );*/
110 SetButtonsState( false );
114 // Wizard has a single page - show finish
115 SetButtonsState( true );
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 SetButtonsState( false );
139 myWizard->setCurrentIndex( 0 );
140 myBack->setEnabled( false );
141 emit Back( myWizard->currentIndex() );
145 bool HYDROGUI_Wizard::acceptCurrent() const
150 QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
152 QAbstractButton* aRes = 0;
155 case QWizard::BackButton:
158 case QWizard::NextButton:
161 case QWizard::FinishButton:
164 case QWizard::CancelButton:
167 case QWizard::HelpButton:
173 bool HYDROGUI_Wizard::IsLastPage()
175 if ( myWizard->currentIndex() == ( myWizard->count() - 2 ))
181 void HYDROGUI_Wizard::SetButtonsState (bool IsLastPage)
185 myNext->setVisible( true );
186 myFinish->setVisible( false );
190 myNext->setVisible( false );
191 myFinish->setVisible( true );