Salome HOME
Merge remote-tracking branch 'remotes/origin/BR_2017' into BR_2017_PORTING
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_InputPanel.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROGUI_InputPanel.h>
20 #ifndef LIGHT_MODE
21   #include <HYDROGUI_Module.h>
22   #include <CAM_Application.h>
23   #include <SUIT_Desktop.h>
24 #endif
25
26 #include <QFrame>
27 #include <QLayout>
28 #include <QPushButton>
29 #include <QDir>
30 #include <QSplitter>
31
32 HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle,
33                                           bool doInitLayout, bool isSplitter )
34 #ifdef LIGHT_MODE
35 : QDockWidget( 0 ),
36 #else
37 : QDockWidget( theModule->application()->desktop() ),
38 #endif
39   myModule( theModule )
40 {
41   setFloating( false );
42   setWindowTitle( theTitle );
43   setAllowedAreas( Qt::RightDockWidgetArea );
44
45
46   QFrame* aFrame = new QFrame( this );
47   setWidget( aFrame );
48   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
49   
50   myMainFrame = new QFrame( aFrame );
51   QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame );
52   aMainLayout->setMargin( 0 );
53   aMainLayout->setSpacing( 5 );
54   if( isSplitter )
55   {
56     mySplitter = new QSplitter( myMainFrame );
57     mySplitter->setOrientation( Qt::Vertical );
58     aMainLayout->addWidget( mySplitter, 1 );
59   }
60   else
61     mySplitter = 0;
62     
63   aLayout->addWidget( myMainFrame, 1 );
64
65   myBtnFrame = new QFrame( aFrame );
66   aLayout->addWidget( myBtnFrame, 0 );
67
68   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
69   aBtnsLayout->setMargin( 5 );
70   aBtnsLayout->setSpacing( 5 );
71
72   myCancel = new QPushButton( tr( "CLOSE" ), myBtnFrame );
73   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
74
75   if ( doInitLayout ) {
76     myApplyAndClose = new QPushButton( tr( "APPLY_AND_CLOSE" ), myBtnFrame );
77     myApply = new QPushButton( tr( "APPLY" ), myBtnFrame );
78
79     aBtnsLayout->addWidget( myApplyAndClose, 0 );
80     aBtnsLayout->addWidget( myApply, 0 );
81     aBtnsLayout->addWidget( myCancel, 0 );
82     aBtnsLayout->addStretch( 1 );
83     aBtnsLayout->addWidget( myHelp, 0 );
84
85     connect( myApplyAndClose,  SIGNAL( clicked() ), this, SLOT( onApplyAndClose()  ) );
86     connect( myApply,  SIGNAL( clicked() ), this, SLOT( onApply()  ) );
87   }
88   connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
89   connect( myHelp,   SIGNAL( clicked() ), this, SLOT( onHelp()   ) );
90 }
91
92 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
93 {
94 }
95
96 HYDROGUI_Module* HYDROGUI_InputPanel::module() const
97 {
98   return myModule;
99 }
100
101 bool HYDROGUI_InputPanel::isApplyEnabled() const
102 {
103   return myApply->isEnabled();
104 }
105
106 void HYDROGUI_InputPanel::setApplyEnabled( bool on )
107 {
108   myApplyAndClose->setEnabled( on );
109   myApply->setEnabled( on );
110 }
111
112 void HYDROGUI_InputPanel::onApplyAndClose()
113 {
114   emit panelApplyAndClose();
115 }
116
117 void HYDROGUI_InputPanel::onApply()
118 {
119   emit panelApply(); 
120 }
121
122 void HYDROGUI_InputPanel::onCancel()
123 {
124   emit panelCancel();
125 }
126
127 void HYDROGUI_InputPanel::onHelp()
128 {
129   emit panelHelp();
130 }
131
132 void HYDROGUI_InputPanel::closeEvent ( QCloseEvent * event )
133 {
134   emit panelCancel();
135 }
136
137 void HYDROGUI_InputPanel::insertWidget( QWidget* theWidget, int theIndex, int theStretch )
138 {
139   if( mySplitter )
140   {
141     mySplitter->insertWidget( theIndex, theWidget );
142     mySplitter->setStretchFactor( theIndex, theStretch );
143   }
144   else
145   {
146     QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
147     aMainLayout->insertWidget( theIndex, theWidget, theStretch );
148   }
149 }
150
151 void HYDROGUI_InputPanel::addWidget( QWidget* theWidget, int theStretch )
152 {
153   if( mySplitter )
154   {
155     int s = mySplitter->count();
156     mySplitter->addWidget( theWidget );
157     mySplitter->setStretchFactor( s, theStretch );
158   }
159   else
160   {
161     QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
162     aMainLayout->addWidget( theWidget, theStretch );
163   }
164 }
165
166 void HYDROGUI_InputPanel::addLayout( QLayout* theLayout, int theStretch )
167 {
168   if( mySplitter )
169   {
170   }
171   else
172   {
173     QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
174     aMainLayout->addLayout( theLayout, theStretch );
175   }
176 }
177
178 void HYDROGUI_InputPanel::addStretch()
179 {
180   if( mySplitter )
181   {
182   }
183   else
184   {
185     QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
186     aMainLayout->addStretch();
187   }
188 }
189
190 QFrame* HYDROGUI_InputPanel::mainFrame() const
191 {
192   return myMainFrame;
193 }
194
195 QFrame* HYDROGUI_InputPanel::buttonFrame() const
196 {
197   return myBtnFrame;
198 }
199
200 QSplitter* HYDROGUI_InputPanel::splitter() const
201 {
202   return mySplitter;
203 }