Salome HOME
refs #568: Land Cover: a draft of data model and implementation of dialog box and...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_InputPanel.cxx
index fb9144b85a10bb72795da9268034c7ff9a65a63c..f89653dbe2039ba7eadd9bce4077d48502704648 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,8 +24,9 @@
 
 #include <QLayout>
 #include <QPushButton>
+#include <QDir>
 
-HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle )
+HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QString& theTitle, bool doInitLayout )
 : QDockWidget( theModule->application()->desktop() ),
   myModule( theModule )
 {
@@ -37,32 +34,43 @@ HYDROGUI_InputPanel::HYDROGUI_InputPanel( HYDROGUI_Module* theModule, const QStr
   setWindowTitle( theTitle );
   setAllowedAreas( Qt::RightDockWidgetArea );
 
+
   QFrame* aFrame = new QFrame( this );
   setWidget( aFrame );
   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
   
-  myMainFrame = new QFrame( this );
-  QGridLayout* aMainLayout = new QGridLayout( myMainFrame );
-  myBtnFrame = new QFrame( this );
+  myMainFrame = new QFrame( aFrame );
+  QBoxLayout* aMainLayout = new QVBoxLayout( myMainFrame );
+  aMainLayout->setMargin( 0 );
+  aMainLayout->setSpacing( 5 );
+    
   aLayout->addWidget( myMainFrame, 1 );
+
+  myBtnFrame = new QFrame( aFrame );
   aLayout->addWidget( myBtnFrame, 0 );
 
   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
   aBtnsLayout->setMargin( 5 );
   aBtnsLayout->setSpacing( 5 );
 
-  myApply = new QPushButton( tr( "APPLY" ), myBtnFrame ),
-  myCancel = new QPushButton( tr( "CANCEL" ), myBtnFrame );
+  myCancel = new QPushButton( tr( "CLOSE" ), myBtnFrame );
   myHelp = new QPushButton( tr( "HELP" ), myBtnFrame );
 
-  aBtnsLayout->addWidget( myApply, 0 );
-  aBtnsLayout->addWidget( myCancel, 0 );
-  aBtnsLayout->addStretch( 1 );
-  aBtnsLayout->addWidget( myHelp, 0 );
-
-  connect( myApply,  SIGNAL( clicked() ), this, SLOT( OnApply()  ) );
-  connect( myCancel, SIGNAL( clicked() ), this, SLOT( OnCancel() ) );
-  connect( myHelp,   SIGNAL( clicked() ), this, SLOT( OnHelp()   ) );
+  if ( doInitLayout ) {
+    myApplyAndClose = new QPushButton( tr( "APPLY_AND_CLOSE" ), myBtnFrame );
+    myApply = new QPushButton( tr( "APPLY" ), myBtnFrame );
+
+    aBtnsLayout->addWidget( myApplyAndClose, 0 );
+    aBtnsLayout->addWidget( myApply, 0 );
+    aBtnsLayout->addWidget( myCancel, 0 );
+    aBtnsLayout->addStretch( 1 );
+    aBtnsLayout->addWidget( myHelp, 0 );
+
+    connect( myApplyAndClose,  SIGNAL( clicked() ), this, SLOT( onApplyAndClose()  ) );
+    connect( myApply,  SIGNAL( clicked() ), this, SLOT( onApply()  ) );
+  }
+  connect( myCancel, SIGNAL( clicked() ), this, SLOT( onCancel() ) );
+  connect( myHelp,   SIGNAL( clicked() ), this, SLOT( onHelp()   ) );
 }
 
 HYDROGUI_InputPanel::~HYDROGUI_InputPanel()
@@ -74,43 +82,66 @@ HYDROGUI_Module* HYDROGUI_InputPanel::module() const
   return myModule;
 }
 
-void HYDROGUI_InputPanel::OnApply()
+bool HYDROGUI_InputPanel::isApplyEnabled() const
+{
+  return myApply->isEnabled();
+}
+
+void HYDROGUI_InputPanel::setApplyEnabled( bool on )
+{
+  myApplyAndClose->setEnabled( on );
+  myApply->setEnabled( on );
+}
+
+void HYDROGUI_InputPanel::onApplyAndClose()
+{
+  emit panelApplyAndClose();
+}
+
+void HYDROGUI_InputPanel::onApply()
 {
   emit panelApply(); 
 }
 
-void HYDROGUI_InputPanel::OnCancel()
+void HYDROGUI_InputPanel::onCancel()
 {
   emit panelCancel();
 }
 
-void HYDROGUI_InputPanel::OnHelp()
+void HYDROGUI_InputPanel::onHelp()
 {
+  emit panelHelp();
 }
 
-void HYDROGUI_InputPanel::addWidget( const QString& theLabel, QWidget* theWidget )
+void HYDROGUI_InputPanel::closeEvent ( QCloseEvent * event )
 {
-  QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
-  int aRow = aMainLayout->rowCount();
-  aMainLayout->addWidget( new QLabel( theLabel, this ), aRow, 0 );
-  aMainLayout->addWidget( theWidget, aRow, 1 );
+  emit panelCancel();
 }
 
-void HYDROGUI_InputPanel::addSeparator()
+void HYDROGUI_InputPanel::addWidget( QWidget* theWidget, int theStretch )
 {
-  QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
-  int aRow = aMainLayout->rowCount();
+  QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
+  aMainLayout->addWidget( theWidget, theStretch );
+}
 
-  QFrame* aLine = new QFrame();
-  aLine->setFrameShape( QFrame::HLine );
-  aLine->setFrameShadow( QFrame::Sunken );
+void HYDROGUI_InputPanel::addLayout( QLayout* theLayout )
+{
+  QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
+  aMainLayout->addLayout( theLayout );
+}
 
-  aMainLayout->addWidget( aLine, aRow, 0, 1, 2 );
+void HYDROGUI_InputPanel::addStretch()
+{
+  QBoxLayout* aMainLayout = dynamic_cast<QBoxLayout*>( myMainFrame->layout() );
+  aMainLayout->addStretch();
+}
+
+QFrame* HYDROGUI_InputPanel::mainFrame() const
+{
+  return myMainFrame;
 }
 
-void HYDROGUI_InputPanel::setRowStretch()
+QFrame* HYDROGUI_InputPanel::buttonFrame() const
 {
-  QGridLayout* aMainLayout = dynamic_cast<QGridLayout*>( myMainFrame->layout() );
-  int aRow = aMainLayout->rowCount();
-  aMainLayout->setRowStretch( aRow, 1 );
+  return myBtnFrame;
 }