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