Salome HOME
updated copyright message
[modules/gui.git] / src / OCCViewer / OCCViewer_SetRotationPointDlg.cxx
index 0aed2c230fd9a64bd963ae236085d65edb686f6b..412234da1a3416fbfb50b23e87b8691adda48646 100644 (file)
@@ -1,11 +1,14 @@
-// Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  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.
+// 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
+// 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.
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "OCCViewer_SetRotationPointDlg.h"
 
 #include <QtxAction.h>
 
 #include "OCCViewer_ViewWindow.h"
 
-#include <qlineedit.h>
-#include <qgroupbox.h>
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qlayout.h>
-#include <qvalidator.h>
-#include <qbuttongroup.h>
-#include <qobjectlist.h>
-#include <qcheckbox.h>
-#include <qhbox.h>
+#include <QLineEdit>
+#include <QGroupBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QMenu>
+#include <QGridLayout>
+#include <QDoubleValidator>
+#include <QCheckBox>
+#include <QHBoxLayout>
 
 /*!
   Constructor
   \param modal - is this dialog modal
   \param fl - flags
 */
-OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, QWidget* parent, const char* name, bool modal, WFlags fl )
-: QDialog( parent, "OCCViewer_SetRotationPointDlg", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
+OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, const char* /*name*/, bool modal, Qt::WindowFlags /*fl*/ )
+: QDialog( view, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
   myView( view )
 {
-  setCaption(tr("CAPTION"));
-  setSizeGripEnabled(TRUE);
+  setObjectName( "OCCViewer_SetRotationPointDlg" );
+  setModal( modal );
+
+  setWindowTitle(tr("CAPTION"));
+  setSizeGripEnabled(true);
 
   // Create layout for this dialog
   QGridLayout* layoutDlg = new QGridLayout (this);
@@ -54,35 +60,51 @@ OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWind
   layoutDlg->setMargin(11);
 
   // Create check box "Use Bounding Box Center"
-  QHBox* aCheckBox = new QHBox(this);
+  QHBoxLayout* aCheckBox = new QHBoxLayout;
 
-  myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"), aCheckBox);
+  myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"));
   myIsBBCenter->setChecked(true);
+  aCheckBox->addWidget(myIsBBCenter);
   connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
 
   // Create croup button with radio buttons
-  myGroupSelButton = new QButtonGroup(2,Qt::Vertical,"",this);
-  myGroupSelButton->setMargin(11);
+  myGroupBoxSel = new QGroupBox( "", this );
+  QVBoxLayout *vbox = new QVBoxLayout;
+  vbox->setMargin(11);
+  vbox->addStretch(1);
   
   // Create "Set to Origin" button
-  myToOrigin = new QPushButton(myGroupSelButton);
-  myToOrigin->setText(tr("LBL_TOORIGIN"));
+  myToOrigin = new QPushButton(tr("LBL_TOORIGIN"));
+  vbox->addWidget(myToOrigin);
   connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
 
-  // Create "Select Point from View" button
-  mySelectPoint = new QPushButton(myGroupSelButton);
-  mySelectPoint->setText(tr("LBL_SELECTPOINT"));
-  mySelectPoint->setToggleButton(true);
-  connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
+  // Create "Gravity Center of Select Object" button
+  mySelectPoint = new QPushButton(tr("LBL_SELECTPOINT"));
+  mySelectPoint->setCheckable(true);
+
+  QMenu* menuType = new QMenu( this );
+  mySelectActions[ menuType->addAction( tr("LBL_POINT") ) ] = TopAbs_VERTEX;
+  mySelectActions[ menuType->addAction( tr("LBL_EDGE") ) ] = TopAbs_EDGE;
+  mySelectActions[ menuType->addAction( tr("LBL_FACE") ) ] = TopAbs_FACE;
+  mySelectActions[ menuType->addAction( tr("LBL_SOLID") ) ] = TopAbs_SOLID;
+  connect( menuType, SIGNAL( triggered( QAction* ) ),  this, SLOT( onSelectMenu( QAction* ) ) );
+
+  mySelectPoint->setMenu( menuType );
+
+  vbox->addWidget(mySelectPoint);
+
+  myGroupBoxSel->setLayout(vbox);
 
   // Create croup box with grid layout
-  myGroupBoxCoord = new QGroupBox(this, "GroupBox");
+  myGroupBoxCoord = new QGroupBox(this);
+  myGroupBoxCoord->setObjectName("GroupBox");
   QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
   aHBoxLayout->setMargin(11);
   aHBoxLayout->setSpacing(6);
 
   // "X" coordinate
-  QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord, "TextLabelX");
+  QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord );
+  TextLabelX->setObjectName("TextLabelX");
   TextLabelX->setFixedWidth(15);
   myX = new QLineEdit(myGroupBoxCoord);
   myX->setValidator(new QDoubleValidator(myX));
@@ -90,7 +112,8 @@ OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWind
   connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
 
   // "Y" coordinate
-  QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord, "TextLabelY");
+  QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord );
+  TextLabelY->setObjectName("TextLabelY");
   TextLabelY->setFixedWidth(15);
   myY = new QLineEdit(myGroupBoxCoord);
   myY->setValidator(new QDoubleValidator(myY));
@@ -98,7 +121,8 @@ OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWind
   connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
 
   // "Z" coordinate
-  QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord, "TextLabelZ");
+  QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord );
+  TextLabelZ->setObjectName("TextLabelZ");
   TextLabelZ->setFixedWidth(15);
   myZ = new QLineEdit(myGroupBoxCoord);
   myZ->setValidator(new QDoubleValidator(myZ));
@@ -119,8 +143,9 @@ OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWind
   aHBoxLayout2->setMargin(11);
   aHBoxLayout2->setSpacing(6);
 
-  QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox, "m_bClose");
-  m_bClose->setAutoDefault(TRUE);
+  QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
+  m_bClose->setObjectName("m_bClose");
+  m_bClose->setAutoDefault(true);
   m_bClose->setFixedSize(m_bClose->sizeHint());
   connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
 
@@ -128,12 +153,12 @@ OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWind
   aHBoxLayout2->addWidget(m_bClose);
 
   // Layout top level widgets
-  layoutDlg->addWidget(aCheckBox,0,0);
-  layoutDlg->addWidget(myGroupSelButton,1,0);
+  layoutDlg->addLayout(aCheckBox,0,0);
+  layoutDlg->addWidget(myGroupBoxSel,1,0);
   layoutDlg->addWidget(myGroupBoxCoord,2,0);
   layoutDlg->addWidget(aGroupBox,3,0);
   
-  setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
+  setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
 
   this->resize(400, this->sizeHint().height());
@@ -166,10 +191,11 @@ void
 OCCViewer_SetRotationPointDlg
 ::setEnabled(QGroupBox* theGrp, const bool theState)
 {
-  QObjectList aChildren(*theGrp->children());
+  QObjectList aChildren(theGrp->children());
   QObject* anObj;
-  for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
+  for(int i = 0; i < aChildren.size(); i++)
   {
+    anObj = aChildren.at(i);
     if (anObj !=0 && anObj->inherits("QLineEdit"))
       ((QLineEdit*)anObj)->setReadOnly(!theState);
     if (anObj !=0 && anObj->inherits("QPushButton"))
@@ -182,41 +208,38 @@ void
 OCCViewer_SetRotationPointDlg
 ::onBBCenterChecked()
 {
-  setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
+  setEnabled(myGroupBoxSel,!myIsBBCenter->isChecked());
   setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
   
   if ( myIsBBCenter->isChecked() )
   {
-    if ( mySelectPoint->state() == QButton::On )
+    if ( mySelectPoint->isChecked() )
       mySelectPoint->toggle();
     myView->activateSetRotationGravity();
   }
   else
     myView->activateSetRotationSelected(myX->text().toDouble(), 
-                                       myY->text().toDouble(), 
-                                       myZ->text().toDouble());
+                                        myY->text().toDouble(), 
+                                        myZ->text().toDouble());
 }
 
 void
 OCCViewer_SetRotationPointDlg
 ::onToOrigin()
 {
-  if ( mySelectPoint->state() == QButton::On )
-    mySelectPoint->toggle();
+  mySelectPoint->setChecked( false );
   setCoords();
   myView->activateSetRotationSelected(myX->text().toDouble(), 
-                                     myY->text().toDouble(), 
-                                     myZ->text().toDouble());
+                                      myY->text().toDouble(), 
+                                      myZ->text().toDouble());
 }
 
 void
 OCCViewer_SetRotationPointDlg
-::onSelectPoint()
+::onSelectMenu( QAction* theAction )
 {
-  if ( mySelectPoint->state() == QButton::On )
-    myView->activateStartPointSelection();
-  else
-    mySelectPoint->toggle();
+  mySelectPoint->setChecked( true );
+  myView->activateStartPointSelection( mySelectActions[theAction] );
 }
 
 void
@@ -225,13 +248,13 @@ OCCViewer_SetRotationPointDlg
 {
   if ( !myIsBBCenter->isChecked() )
   {
-    if ( mySelectPoint->state() == QButton::On
-        &&
-        ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
+    if ( mySelectPoint->isChecked()
+         &&
+         ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
       mySelectPoint->toggle();
     myView->activateSetRotationSelected(myX->text().toDouble(), 
-                                       myY->text().toDouble(), 
-                                       myZ->text().toDouble());
+                                        myY->text().toDouble(), 
+                                        myZ->text().toDouble());
   }
 }
 
@@ -256,7 +279,7 @@ void
 OCCViewer_SetRotationPointDlg
 ::onClickClose()
 {
-  myAction->setOn( false );
+  myAction->setChecked( false );
   reject();
 }
 
@@ -264,7 +287,7 @@ void
 OCCViewer_SetRotationPointDlg
 ::onViewShow()
 {
-  if(myAction->isOn())
+  if(myAction->isChecked())
     show();
   else
     hide();
@@ -276,3 +299,14 @@ OCCViewer_SetRotationPointDlg
 {
   hide();
 }
+
+/*!
+  Custom handling of close event: toggle action
+*/
+void
+OCCViewer_SetRotationPointDlg
+::closeEvent( QCloseEvent* e )
+{
+  myAction->setChecked( false );
+  QDialog::closeEvent( e );
+}