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