Salome HOME
Fix for the bug #42: point C is not activated, but point C is shown in preview in...
[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 ( myWizard->count() > 0 )
85   {
86     myBack->setEnabled( true );
87     int aCurIdx = myWizard->currentIndex();
88     if ( aCurIdx == ( myWizard->count() - 2 ) )
89     {
90       // Go to the last page
91       myNext->setVisible( false );
92       myFinish->setVisible( true );
93     }
94     myWizard->setCurrentIndex( aCurIdx + 1 );
95   }
96 }
97
98 void HYDROGUI_Wizard::onBack()
99 {
100   int aCurIdx = myWizard->currentIndex();
101   if ( aCurIdx <= 1 )
102   {
103     // Disable back if go to the first page
104     myBack->setEnabled( false );
105   }
106   if ( myWizard->count() > 1 )
107   {
108     myNext->setVisible( true );
109     myFinish->setVisible( false );
110   }
111   else
112   {
113     // Wizard has a single page - show finish
114     myNext->setVisible( false );
115     myFinish->setVisible( true );
116   }
117   myWizard->setCurrentIndex( aCurIdx - 1 );
118 }
119
120 QAbstractButton* HYDROGUI_Wizard::button( QWizard::WizardButton theBtnId ) const
121 {
122   QAbstractButton* aRes = 0;
123   switch( theBtnId )
124   {
125     case QWizard::BackButton:
126       aRes = myBack;
127       break;
128     case QWizard::NextButton:
129       aRes = myNext;
130       break;
131     case QWizard::FinishButton:
132       aRes = myFinish;
133       break;
134     case QWizard::CancelButton:
135       aRes = myCancel;
136       break;
137     case QWizard::HelpButton:
138       aRes = myHelp;
139   }
140   return aRes;
141 }