Salome HOME
Bug IPAL19464 - Qt4 porting. Orientation. Error on "Add to.." and "Copy from" in...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOpDlg.cxx
index cdefc1e42d5397f93e13f391324842e76ec6f6de..86b655275a48a473eaeef6307a4019aa30a9ca74 100644 (file)
@@ -1,59 +1,61 @@
-//  SMESH SMESHGUI : GUI for SMESH component
+// SMESH SMESHGUI : GUI for SMESH component
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
 //
-//  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.
+// 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. 
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful, 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details. 
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public 
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// File   : SMESHGUI_GroupOpDlg.cxx
+// Author : Sergey LITONIN, Open CASCADE S.A.S.
 //
-//
-//  File   : SMESHGUI_GroupOpDlg.cxx
-//  Author : Sergey LITONIN
-//  Module : SMESH
 
+// SMESH includes
 #include "SMESHGUI_GroupOpDlg.h"
 
 #include "SMESHGUI.h"
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_VTKUtils.h"
 
-#include "SMESH_TypeFilter.hxx"
-
-#include "SUIT_ResourceMgr.h"
-#include "SUIT_Desktop.h"
-
-#include "LightApp_SelectionMgr.h"
-#include "SVTK_Selection.h"
-#include "SVTK_ViewWindow.h"
-#include "SVTK_Selector.h"
-#include "SALOME_ListIO.hxx"
-
-// QT Includes
-#include <qframe.h>
-#include <qlayout.h>
-#include <qpushbutton.h>
-#include <qgroupbox.h>
-#include <qlabel.h>
-#include <qlistbox.h>
-#include <qlineedit.h>
-#include <qmessagebox.h>
-
-#define SPACING 5
-#define MARGIN  10
+#include <SMESH_TypeFilter.hxx>
+
+// SALOME GUI includes
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+
+#include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SVTK_Selection.h>
+#include <SVTK_ViewWindow.h>
+#include <SALOME_ListIO.hxx>
+
+// Qt includes
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QKeyEvent>
+
+#define SPACING 6
+#define MARGIN  11
 
 /*!
  *  Class       : SMESHGUI_GroupOpDlg
 // Purpose : Constructor
 //=======================================================================
 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule, const int theMode )
-     : QDialog( SMESH::GetDesktop( theModule ), "SMESHGUI_GroupOpDlg", false,
-                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
-     mySMESHGUI( theModule ),
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+  : QDialog( SMESH::GetDesktop( theModule ) ),
+    mySMESHGUI( theModule ),
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
 {
+  setModal(false);
+
   myMode = theMode;
 
-  if (myMode == UNION) setCaption(tr("UNION_OF_TWO_GROUPS"));
-  else if (myMode == INTERSECT) setCaption(tr("INTERSECTION_OF_TWO_GROUPS"));
-  else setCaption(tr("CUT_OF_TWO_GROUPS"));
+  if (myMode == UNION) {
+    setWindowTitle(tr("UNION_OF_TWO_GROUPS"));
+    myHelpFileName = "using_operations_on_groups_page.html#union_anchor";
+  }
+  else if (myMode == INTERSECT) {
+    setWindowTitle(tr("INTERSECTION_OF_TWO_GROUPS"));
+    myHelpFileName = "using_operations_on_groups_page.html#intersection_anchor";
+  }
+  else {
+    setWindowTitle(tr("CUT_OF_TWO_GROUPS"));
+    myHelpFileName = "using_operations_on_groups_page.html#cut_anchor";
+  }
 
   mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
 
-  QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
+  QVBoxLayout* aDlgLay = new QVBoxLayout (this);
+  aDlgLay->setMargin(MARGIN);
+  aDlgLay->setSpacing(SPACING);
 
-  QFrame* aMainFrame = createMainFrame  (this);
-  QFrame* aBtnFrame  = createButtonFrame(this);
+  QWidget* aMainFrame = createMainFrame  (this);
+  QWidget* aBtnFrame  = createButtonFrame(this);
 
   aDlgLay->addWidget(aMainFrame);
   aDlgLay->addWidget(aBtnFrame);
 
-  aDlgLay->setStretchFactor(aMainFrame, 1);
-
   Init();
 }
 
@@ -95,24 +107,37 @@ SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule, const int theMode
 // name    : SMESHGUI_GroupOpDlg::createMainFrame
 // Purpose : Create frame containing dialog's input fields
 //=======================================================================
-QFrame* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent)
+QWidget* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent)
 {
-  QGroupBox* aMainGrp = new QGroupBox(1, Qt::Horizontal, theParent);
-  aMainGrp->setFrameStyle(QFrame::NoFrame);
-  aMainGrp->setInsideMargin(0);
-
-  QGroupBox* aNameGrp = new QGroupBox(1, Qt::Vertical, tr("NAME"), aMainGrp);
-  new QLabel(tr("RESULT_NAME"), aNameGrp);
+  QWidget* aMainGrp = new QWidget(theParent);
+  QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
+  aLay->setMargin(0);
+  aLay->setSpacing(SPACING);
+  
+  // ------------------------------------------------------
+  QGroupBox* aNameGrp = new QGroupBox(tr("NAME"), aMainGrp);
+  QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
+  aNameGrpLayout->setMargin(MARGIN);
+  aNameGrpLayout->setSpacing(SPACING);
+
+  QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
   myNameEdit = new QLineEdit(aNameGrp);
 
-  QGroupBox* anArgGrp = new QGroupBox(3, Qt::Horizontal, tr("ARGUMENTS"), aMainGrp);
+  aNameGrpLayout->addWidget(aNameLab);
+  aNameGrpLayout->addWidget(myNameEdit);
+
+  // ------------------------------------------------------
+  QGroupBox* anArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
+  QGridLayout* anArgGrpLayout = new QGridLayout(anArgGrp);
+  anArgGrpLayout->setMargin(MARGIN);
+  anArgGrpLayout->setSpacing(SPACING);
 
-  new QLabel(myMode == CUT ? tr("MAIN_OBJECT") :tr("OBJECT_1"), anArgGrp);
+  QLabel* aObj1Lab = new QLabel(myMode == CUT ? tr("MAIN_OBJECT") :tr("OBJECT_1"), anArgGrp);
   myBtn1 = new QPushButton(anArgGrp);
   myEdit1 = new QLineEdit(anArgGrp);
   myEdit1->setAlignment( Qt::AlignLeft );
 
-  new QLabel(myMode == CUT ? tr("TOOL_OBJECT") :tr("OBJECT_2"), anArgGrp);
+  QLabel* aObj2Lab = new QLabel(myMode == CUT ? tr("TOOL_OBJECT") :tr("OBJECT_2"), anArgGrp);
   myBtn2 = new QPushButton(anArgGrp);
   myEdit2 = new QLineEdit(anArgGrp);
   myEdit2->setAlignment( Qt::AlignLeft );
@@ -121,8 +146,19 @@ QFrame* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent)
   myEdit2->setReadOnly(true);
 
   QPixmap aPix (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
-  myBtn1->setPixmap(aPix);
-  myBtn2->setPixmap(aPix);
+  myBtn1->setIcon(aPix);
+  myBtn2->setIcon(aPix);
+
+  anArgGrpLayout->addWidget(aObj1Lab, 0, 0);
+  anArgGrpLayout->addWidget(myBtn1,   0, 1);
+  anArgGrpLayout->addWidget(myEdit1,  0, 2);
+  anArgGrpLayout->addWidget(aObj2Lab, 1, 0);
+  anArgGrpLayout->addWidget(myBtn2,   1, 1);
+  anArgGrpLayout->addWidget(myEdit2,  1, 2);
+
+  // ------------------------------------------------------
+  aLay->addWidget(aNameGrp);
+  aLay->addWidget(anArgGrp);
 
   return aMainGrp;
 }
@@ -131,28 +167,32 @@ QFrame* SMESHGUI_GroupOpDlg::createMainFrame (QWidget* theParent)
 // name    : SMESHGUI_GroupOpDlg::createButtonFrame
 // Purpose : Create frame containing buttons
 //=======================================================================
-QFrame* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
+QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
 {
-  QFrame* aFrame = new QFrame(theParent);
-  aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
-
-  myOkBtn     = new QPushButton(tr("SMESH_BUT_OK"   ), aFrame);
-  myApplyBtn  = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
-  myCloseBtn  = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
+  QGroupBox* aFrame = new QGroupBox(theParent);
 
-  QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
+  myOkBtn    = new QPushButton(tr("SMESH_BUT_OK"   ), aFrame);
+  myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
+  myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
+  myHelpBtn  = new QPushButton(tr("SMESH_BUT_HELP"),  aFrame);
 
-  QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
+  QHBoxLayout* aLay = new QHBoxLayout(aFrame);
+  aLay->setMargin(MARGIN);
+  aLay->setSpacing(SPACING);
 
   aLay->addWidget(myOkBtn);
+  aLay->addSpacing(10);
   aLay->addWidget(myApplyBtn);
-  aLay->addItem(aSpacer);
+  aLay->addSpacing(10);
+  aLay->addStretch();
   aLay->addWidget(myCloseBtn);
+  aLay->addWidget(myHelpBtn);
 
   // connect signals and slots
   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
+  connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
 
   return aFrame;
 }
@@ -185,17 +225,10 @@ void SMESHGUI_GroupOpDlg::Init()
   connect(myBtn1, SIGNAL(clicked()), this, SLOT(onFocusChanged()));
   connect(myBtn2, SIGNAL(clicked()), this, SLOT(onFocusChanged()));
 
-  int x, y;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
-  this->show();
-
   // set selection mode
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
   mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
-
-  return;
 }
 
 //=======================================================================
@@ -206,15 +239,15 @@ bool SMESHGUI_GroupOpDlg::isValid()
 {
   // Verify validity of group name
   if (myNameEdit->text() == "") {
-    QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
-                             tr("EMPTY_NAME"), QMessageBox::Ok);
+    SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
+                                tr("EMPTY_NAME"));
     return false;
   }
 
   // Verufy wheter arguments speciffiyed
   if (myGroup1->_is_nil() || myGroup2->_is_nil()) {
-    QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
-                             tr("INCORRECT_ARGUMENTS"), QMessageBox::Ok);
+    SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
+                                tr("INCORRECT_ARGUMENTS"));
     return false;
   }
 
@@ -226,15 +259,15 @@ bool SMESHGUI_GroupOpDlg::isValid()
   int aMeshId2 = !aMesh2->_is_nil() ? aMesh2->GetId() : -1;
 
   if (aMeshId1 != aMeshId2 || aMeshId1 == -1) {
-    QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
-                             tr("DIFF_MESHES"), QMessageBox::Ok);
+    SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
+                                tr("DIFF_MESHES"));
     return false;
   }
 
   // Verify whether groups have same types of entities
   if (myGroup1->GetType() != myGroup2->GetType()) {
-    QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
-                             tr("DIFF_TYPES"), QMessageBox::Ok);
+    SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
+                                tr("DIFF_TYPES"));
     return false;
   }
 
@@ -254,17 +287,17 @@ bool SMESHGUI_GroupOpDlg::onApply()
   QString aName = myNameEdit->text();
   SMESH::SMESH_Group_ptr aNewGrp = SMESH::SMESH_Group::_nil();
 
-  if (myMode == UNION) aNewGrp = aMesh->UnionGroups(myGroup1, myGroup2, aName.latin1());
-  else if (myMode == INTERSECT) aNewGrp = aMesh->IntersectGroups(myGroup1, myGroup2, aName.latin1());
-  else aNewGrp = aMesh->CutGroups(myGroup1, myGroup2, aName.latin1());
+  if (myMode == UNION) aNewGrp = aMesh->UnionGroups(myGroup1, myGroup2, aName.toLatin1().data());
+  else if (myMode == INTERSECT) aNewGrp = aMesh->IntersectGroups(myGroup1, myGroup2, aName.toLatin1().data());
+  else aNewGrp = aMesh->CutGroups(myGroup1, myGroup2, aName.toLatin1().data());
 
   if (!aNewGrp->_is_nil()) {
     mySMESHGUI->updateObjBrowser(true);
     reset();
     return true;
   } else {
-    QMessageBox::critical(SMESHGUI::desktop(), tr("SMESH_ERROR"),
-                          tr("SMESH_OPERATION_FAILED"), "OK");
+    SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
+                             tr("SMESH_OPERATION_FAILED"));
     return false;
   }
 }
@@ -294,6 +327,30 @@ void SMESHGUI_GroupOpDlg::onClose()
   reject();
 }
 
+//=================================================================================
+// function : onHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupOpDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+    QString platform;
+#ifdef WIN32
+    platform = "winapplication";
+#else
+    platform = "application";
+#endif
+    SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
+                            tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                            arg(app->resourceMgr()->stringValue("ExternalBrowser",
+                                                                platform)).
+                            arg(myHelpFileName));
+  }
+}
+
 //=======================================================================
 // name    : SMESHGUI_GroupOpDlg::onSelectionDone
 // Purpose : SLOT called when selection changed
@@ -382,3 +439,19 @@ void SMESHGUI_GroupOpDlg::reset()
   myFocusWg = myEdit1;
   myNameEdit->setFocus();
 }
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Qt::Key_F1 ) {
+    e->accept();
+    onHelp();
+  }
+}