Salome HOME
fb9144b85a10bb72795da9268034c7ff9a65a63c
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_InputPanel.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_InputPanel.h"
24 #include "HYDROGUI_Module.h"
25
26 #include <CAM_Application.h>
27 #include <SUIT_Desktop.h>
28
29 #include <QLayout>
30 #include <QPushButton>
31
32 HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle )
33 : QDockWidget( theModule->application()->desktop() ),
34   myModule( theModule )
35 {
36   setFloating( false );
37   setWindowTitle( theTitle );
38   setAllowedAreas( Qt::RightDockWidgetArea );
39
40   QFrame* aFrame = new QFrame( this );
41   setWidget( aFrame );
42   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
43   
44   myMainFrame = new QFrame( this );
45   QGridLayout* aMainLayout = new QGridLayout( myMainFrame );
46   myBtnFrame = new QFrame( this );
47   aLayout->addWidget( myMainFrame, 1 );
48   aLayout->addWidget( myBtnFrame, 0 );
49
50   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
51   aBtnsLayout->setMargin( 5 );
52   aBtnsLayout->setSpacing( 5 );
53
54   myApply = new QPushButton( tr( "APPLY" ), myBtnFrame ),
55   myCancel = new QPushButton( tr( "CANCEL" ), myBtnFrame );
56   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
57
58   aBtnsLayout->addWidget( myApply, 0 );
59   aBtnsLayout->addWidget( myCancel, 0 );
60   aBtnsLayout->addStretch( 1 );
61   aBtnsLayout->addWidget( myHelp, 0 );
62
63   connect( myApply,  SIGNAL( clicked() ), this, SLOT( OnApply()  ) );
64   connect( myCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
65   connect( myHelp,   SIGNAL( clicked() ), this, SLOT( OnHelp()   ) );
66 }
67
68 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
69 {
70 }
71
72 HYDROGUI_Module* HYDROGUI_InputPanel::module() const
73 {
74   return myModule;
75 }
76
77 void HYDROGUI_InputPanel::OnApply()
78 {
79   emit panelApply(); 
80 }
81
82 void HYDROGUI_InputPanel::OnCancel()
83 {
84   emit panelCancel();
85 }
86
87 void HYDROGUI_InputPanel::OnHelp()
88 {
89 }
90
91 void HYDROGUI_InputPanel::addWidget( const QString& theLabel, QWidget* theWidget )
92 {
93   QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
94   int aRow = aMainLayout->rowCount();
95   aMainLayout->addWidget( new QLabel( theLabel, this ), aRow, 0 );
96   aMainLayout->addWidget( theWidget, aRow, 1 );
97 }
98
99 void HYDROGUI_InputPanel::addSeparator()
100 {
101   QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
102   int aRow = aMainLayout->rowCount();
103
104   QFrame* aLine = new QFrame();
105   aLine->setFrameShape( QFrame::HLine );
106   aLine->setFrameShadow( QFrame::Sunken );
107
108   aMainLayout->addWidget( aLine, aRow, 0, 1, 2 );
109 }
110
111 void HYDROGUI_InputPanel::setRowStretch()
112 {
113   QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
114   int aRow = aMainLayout->rowCount();
115   aMainLayout->setRowStretch( aRow, 1 );
116 }