]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_InputPanel.cxx
Salome HOME
copyrights are updated
[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( "CANCEL" ), myBtnFrame );
57   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
58
59   if ( doInitLayout ) {
60     myApply = new QPushButton( tr( "APPLY" ), myBtnFrame );
61
62     aBtnsLayout->addWidget( myApply, 0 );
63     aBtnsLayout->addWidget( myCancel, 0 );
64     aBtnsLayout->addStretch( 1 );
65     aBtnsLayout->addWidget( myHelp, 0 );
66
67     connect( myApply,  SIGNAL( clicked() ), this, SLOT( onApply()  ) );
68   }
69   connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
70   connect( myHelp,   SIGNAL( clicked() ), this, SLOT( onHelp()   ) );
71 }
72
73 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
74 {
75 }
76
77 HYDROGUI_Module* HYDROGUI_InputPanel::module() const
78 {
79   return myModule;
80 }
81
82 bool HYDROGUI_InputPanel::isApplyEnabled() const
83 {
84     return myApply->isEnabled();
85 }
86
87 void HYDROGUI_InputPanel::setApplyEnabled( bool on )
88 {
89     myApply->setEnabled( on );
90 }
91
92 void HYDROGUI_InputPanel::onApply()
93 {
94   emit panelApply(); 
95 }
96
97 void HYDROGUI_InputPanel::onCancel()
98 {
99   emit panelCancel();
100 }
101
102 void HYDROGUI_InputPanel::onHelp()
103 {
104   emit panelHelp();
105 }
106
107 void HYDROGUI_InputPanel::closeEvent ( QCloseEvent * event )
108 {
109   emit panelCancel();
110 }
111
112 void HYDROGUI_InputPanel::addWidget( QWidget* theWidget, int theStretch )
113 {
114   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
115   aMainLayout->addWidget( theWidget, theStretch );
116 }
117
118 void HYDROGUI_InputPanel::addLayout( QLayout* theLayout )
119 {
120   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
121   aMainLayout->addLayout( theLayout );
122 }
123
124 void HYDROGUI_InputPanel::addStretch()
125 {
126   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
127   aMainLayout->addStretch();
128 }
129
130 QFrame* HYDROGUI_InputPanel::mainFrame() const
131 {
132   return myMainFrame;
133 }
134
135 QFrame* HYDROGUI_InputPanel::buttonFrame() const
136 {
137   return myBtnFrame;
138 }