]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_InputPanel.cxx
Salome HOME
refs #207 - "Help" button doesn't work
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_InputPanel.cxx
1 // Copyright (C) 2007-2013  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.
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 #include "HYDROGUI_RunBrowser.h"
26
27 #include <CAM_Application.h>
28 #include <SUIT_Desktop.h>
29
30 #include <QLayout>
31 #include <QPushButton>
32 #include <QDir>
33
34 HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle, bool doInitLayout )
35 : QDockWidget( theModule->application()->desktop() ),
36   myModule( theModule )
37 {
38   setFloating( false );
39   setWindowTitle( theTitle );
40   setAllowedAreas( Qt::RightDockWidgetArea );
41
42
43   QFrame* aFrame = new QFrame( this );
44   setWidget( aFrame );
45   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
46   
47   myMainFrame = new QFrame( aFrame );
48   QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame );
49   aMainLayout->setMargin( 0 );
50   aMainLayout->setSpacing( 5 );
51     
52   aLayout->addWidget( myMainFrame, 1 );
53
54   myBtnFrame = new QFrame( aFrame );
55   aLayout->addWidget( myBtnFrame, 0 );
56
57   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
58   aBtnsLayout->setMargin( 5 );
59   aBtnsLayout->setSpacing( 5 );
60
61   myCancel = new QPushButton( tr( "CANCEL" ), myBtnFrame );
62   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
63
64   if ( doInitLayout ) {
65     myApply = new QPushButton( tr( "APPLY" ), myBtnFrame );
66
67     aBtnsLayout->addWidget( myApply, 0 );
68     aBtnsLayout->addWidget( myCancel, 0 );
69     aBtnsLayout->addStretch( 1 );
70     aBtnsLayout->addWidget( myHelp, 0 );
71
72     connect( myApply,  SIGNAL( clicked() ), this, SLOT( onApply()  ) );
73   }
74   connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
75   connect( myHelp,   SIGNAL( clicked() ), this, SLOT( onHelp()   ) );
76 }
77
78 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
79 {
80 }
81
82 HYDROGUI_Module* HYDROGUI_InputPanel::module() const
83 {
84   return myModule;
85 }
86
87 void HYDROGUI_InputPanel::onApply()
88 {
89   emit panelApply(); 
90 }
91
92 void HYDROGUI_InputPanel::onCancel()
93 {
94   emit panelCancel();
95 }
96
97 void HYDROGUI_InputPanel::onHelp()
98 {
99   QString aModuleName = myModule->moduleName();
100
101   QString aPagePath = HYDROGUI_RunBrowser::getPagePath( aModuleName );
102
103   QString aPageName = "";
104   QString aWindowTitle = windowTitle();
105   if ( !aWindowTitle.isEmpty() )
106   {
107     aPageName = QStringList( aWindowTitle.split( " " ) ).join( "_" ).append( ".html" );
108     aPageName.toLower();
109   }
110
111   QString aPage = aPagePath + QDir::separator() + aPageName;
112   HYDROGUI_RunBrowser::showPage( myModule->getApp(), aPage );
113 }
114
115 void HYDROGUI_InputPanel::closeEvent ( QCloseEvent * event )
116 {
117   emit panelCancel();
118 }
119
120 void HYDROGUI_InputPanel::addWidget( QWidget* theWidget, int theStretch )
121 {
122   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
123   aMainLayout->addWidget( theWidget, theStretch );
124 }
125
126 void HYDROGUI_InputPanel::addLayout( QLayout* theLayout )
127 {
128   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
129   aMainLayout->addLayout( theLayout );
130 }
131
132 void HYDROGUI_InputPanel::addStretch()
133 {
134   QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
135   aMainLayout->addStretch();
136 }
137
138 QFrame* HYDROGUI_InputPanel::mainFrame() const
139 {
140   return myMainFrame;
141 }
142
143 QFrame* HYDROGUI_InputPanel::buttonFrame() const
144 {
145   return myBtnFrame;
146 }