Salome HOME
a12421f284288d099b9d66fcd6493b3cd35e90d5
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_InputPanel.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 #include <QDir>
32
33 HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle, bool doInitLayout )
34 : QDockWidget( theModule->application()->desktop() ),
35   myModule( theModule )
36 {
37   setFloating( false );
38   setWindowTitle( theTitle );
39   setAllowedAreas( Qt::RightDockWidgetArea );
40
41
42   QFrame* aFrame = new QFrame( this );
43   setWidget( aFrame );
44   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
45   
46   myMainFrame = new QFrame( aFrame );
47   QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame );
48   aMainLayout->setMargin( 0 );
49   aMainLayout->setSpacing( 5 );
50     
51   aLayout->addWidget( myMainFrame, 1 );
52
53   myBtnFrame = new QFrame( aFrame );
54   aLayout->addWidget( myBtnFrame, 0 );
55
56   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
57   aBtnsLayout->setMargin( 5 );
58   aBtnsLayout->setSpacing( 5 );
59
60   myCancel = new QPushButton( tr( "CLOSE" ), myBtnFrame );
61   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
62
63   if ( doInitLayout ) {
64     myApplyAndClose = new QPushButton( tr( "APPLY_AND_CLOSE" ), myBtnFrame );
65     myApply = new QPushButton( tr( "APPLY" ), myBtnFrame );
66
67     aBtnsLayout->addWidget( myApplyAndClose, 0 );
68     aBtnsLayout->addWidget( myApply, 0 );
69     aBtnsLayout->addWidget( myCancel, 0 );
70     aBtnsLayout->addStretch( 1 );
71     aBtnsLayout->addWidget( myHelp, 0 );
72
73     connect( myApplyAndClose,  SIGNAL( clicked() ), this, SLOT( onApplyAndClose()  ) );
74     connect( myApply,  SIGNAL( clicked() ), this, SLOT( onApply()  ) );
75   }
76   connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
77   connect( myHelp,   SIGNAL( clicked() ), this, SLOT( onHelp()   ) );
78 }
79
80 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
81 {
82 }
83
84 HYDROGUI_Module* HYDROGUI_InputPanel::module() const
85 {
86   return myModule;
87 }
88
89 bool HYDROGUI_InputPanel::isApplyEnabled() const
90 {
91   return myApply->isEnabled();
92 }
93
94 void HYDROGUI_InputPanel::setApplyEnabled( bool on )
95 {
96   myApplyAndClose->setEnabled( on );
97   myApply->setEnabled( on );
98 }
99
100 void HYDROGUI_InputPanel::onApplyAndClose()
101 {
102   emit panelApplyAndClose();
103 }
104
105 void HYDROGUI_InputPanel::onApply()
106 {
107   emit panelApply(); 
108 }
109
110 void HYDROGUI_InputPanel::onCancel()
111 {
112   emit panelCancel();
113 }
114
115 void HYDROGUI_InputPanel::onHelp()
116 {
117   emit panelHelp();
118 }
119
120 void HYDROGUI_InputPanel::closeEvent ( QCloseEvent * event )
121 {
122   emit panelCancel();
123 }
124
125 void HYDROGUI_InputPanel::addWidget( QWidget* theWidget, int theStretch )
126 {
127   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
128   aMainLayout->addWidget( theWidget, theStretch );
129 }
130
131 void HYDROGUI_InputPanel::addLayout( QLayout* theLayout )
132 {
133   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
134   aMainLayout->addLayout( theLayout );
135 }
136
137 void HYDROGUI_InputPanel::addStretch()
138 {
139   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
140   aMainLayout->addStretch();
141 }
142
143 QFrame* HYDROGUI_InputPanel::mainFrame() const
144 {
145   return myMainFrame;
146 }
147
148 QFrame* HYDROGUI_InputPanel::buttonFrame() const
149 {
150   return myBtnFrame;
151 }