Salome HOME
refs #426: grammatic error
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Wizard.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Wizard.h"
24 #include "HYDROGUI_Module.h"
25 #include <CAM_Application.h>
26 #include <SUIT_Desktop.h>
27 #include <QFrame>
28 #include <QVBoxLayout>
29 #include <QWidget>
30 #include <QPushButton>
31 #include <QAbstractButton>
32 #include <QStackedWidget>
33 #include <QWizardPage>
34
35 HYDROGUI_Wizard::HYDROGUI_Wizard( HYDROGUI_Module* theModule, const QString& theTitle )
36 : HYDROGUI_InputPanel( theModule, theTitle, false )
37 {
38
39   myWizard = new QStackedWidget( theModule->application()->desktop() );
40
41   myNext = new QPushButton( tr( "NEXT" ), buttonFrame() );
42   myBack = new QPushButton( tr( "BACK" ), buttonFrame() );
43   myFinish = new QPushButton( tr( "FINISH" ), buttonFrame() );
44
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 );
52
53   myBack->setEnabled( false );
54   myNext->setVisible( false );
55
56   connect( myNext,  SIGNAL( clicked() ), SLOT( onNext() ) );
57   connect( myBack,  SIGNAL( clicked() ), SLOT( onBack() ) );
58   connect( myFinish, SIGNAL( clicked() ), SLOT( onApply() ) );
59
60   addWidget( myWizard );
61 }
62
63 HYDROGUI_Wizard::~HYDROGUI_Wizard()
64 {
65 }
66
67 QStackedWidget* HYDROGUI_Wizard::wizard() const
68 {
69   return myWizard;
70 }
71
72 int HYDROGUI_Wizard::addPage( QWizardPage* thePage )
73 {
74   if ( myWizard->count() > 0 )
75   {
76     myNext->setVisible( true );
77     myFinish->setVisible( false );
78   }
79   return myWizard->addWidget( thePage );
80 }
81
82 void HYDROGUI_Wizard::onNext()
83 {
84   if ( !acceptCurrent() )
85     return;
86
87   if ( myWizard->count() <= 0 )
88     return;
89
90   myBack->setEnabled( true );
91   int aCurIdx = myWizard->currentIndex();
92   if ( aCurIdx == ( myWizard->count() - 2 ) )
93   {
94     // Go to the last page
95     myNext->setVisible( false );
96     myFinish->setVisible( true );
97   }
98   myWizard->setCurrentIndex( aCurIdx + 1 );
99
100   emit Next( myWizard->currentIndex() );
101 }
102
103 void HYDROGUI_Wizard::onBack()
104 {
105   if ( myWizard->count() <= 0 )
106     return;
107
108   if ( myWizard->count() > 1 )
109   {
110     myNext->setVisible( true );
111     myFinish->setVisible( false );
112   }
113   else
114   {
115     // Wizard has a single page - show finish
116     myNext->setVisible( false );
117     myFinish->setVisible( true );
118   }
119
120   int aCurIdx = myWizard->currentIndex();
121   myWizard->setCurrentIndex( aCurIdx - 1 );
122
123   aCurIdx = myWizard->currentIndex();
124   if ( aCurIdx <= 0 )
125   {
126     // Disable back if go to the first page
127     myBack->setEnabled( false );
128   }
129
130   emit Back( aCurIdx );
131 }
132
133 bool HYDROGUI_Wizard::acceptCurrent() const
134 {
135   return true;
136 }
137
138 QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
139 {
140   QAbstractButton* aRes = 0;
141   switch( theBtnId )
142   {
143     case QWizard::BackButton:
144       aRes = myBack;
145       break;
146     case QWizard::NextButton:
147       aRes = myNext;
148       break;
149     case QWizard::FinishButton:
150       aRes = myFinish;
151       break;
152     case QWizard::CancelButton:
153       aRes = myCancel;
154       break;
155     case QWizard::HelpButton:
156       aRes = myHelp;
157   }
158   return aRes;
159 }