Salome HOME
Copyright update 2022
[modules/gui.git] / src / SVTK / SVTK_CubeAxesDlg.cxx
index 57c9e56941750a7d701259b2a4b14eecd8c8381f..6056b787542129ab6a2468165606ccae3fc22ff6 100644 (file)
@@ -1,33 +1,33 @@
-//  VISU VISUGUI : GUI for SMESH component
-//
-//  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.
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  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.
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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
+// 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, or (at your option) any later version.
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// 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
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+//  VISU VISUGUI : GUI for SMESH component
 //  File   : SVTK_CubeAxesDlg.cxx
 //  Author : Sergey LITONIN
 //  Module : VISU
-
+//
 #include "SVTK_CubeAxesDlg.h"
 
-#include "SVTK_MainWindow.h"
+#include "SVTK_ViewWindow.h"
 #include "SVTK_FontWidget.h"
 
 #include "SVTK_CubeAxesActor2D.h"
 #include "QtxAction.h"
 #include "QtxIntSpinBox.h"
 
-#include <qlayout.h>
-#include <qframe.h>
-#include <qpushbutton.h>
-#include <qtabwidget.h>
-#include <qcheckbox.h>
-#include <qgroupbox.h>
-#include <qlineedit.h>
-#include <qlabel.h>
-#include <qobjectlist.h>
-#include <qvalidator.h>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QLineEdit>
 
 #include <vtkAxisActor2D.h>
 #include <vtkTextProperty.h>
 
 /*!
- * Class       : AxisWg
- * Description : Tab of dialog
- */
-
-//=======================================================================
-// name    : SVTK_AxisWidget::AxisWg
-// Purpose : Constructor
-//=======================================================================
+  \class SVTK_CubeAxesDlg::AxisWidget
+  \brief Axis tab widget of the "Graduated axis" dialog box
+  \internal
+*/
+
+/*!
+  Constructor
+*/
 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
-:  QFrame(theParent)
+: ViewerTools_AxisWidgetBase(theParent)
 {
-  QValueList< QLabel* > aLabels;
-
-  // "Name" grp
-
-  myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
-  myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
-
-  QHBox* aHBox = new QHBox(myNameGrp);
-  aHBox->setSpacing(5);
-  QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
-  myAxisName = new QLineEdit(aHBox);
-  aLabels.append(aLabel);
-
-  aHBox = new QHBox(myNameGrp);
-  aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("FONT"), aHBox);
-  myNameFont = new SVTK_FontWidget(aHBox);
-  aLabels.append(aLabel);
-
-
-  // "Labels" grp
-
-  myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
-  myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
-
-  aHBox = new QHBox(myLabelsGrp);
-  aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("NUMBER"), aHBox);
-  myLabelNumber = new QtxIntSpinBox(0,25,1,aHBox,"SpinBoxLabelNumber");
-  aLabels.append(aLabel);
-
-  aHBox = new QHBox(myLabelsGrp);
-  aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("OFFSET"), aHBox);
-  myLabelOffset = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxLabellOffset");
-  aLabels.append(aLabel);
-
-  aHBox = new QHBox(myLabelsGrp);
-  aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("FONT"), aHBox);
-  myLabelsFont = new SVTK_FontWidget(aHBox);
-  aLabels.append(aLabel);
-
-  // "Tick marks" grp
-
-  myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
-  myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
-
-  aHBox = new QHBox(myTicksGrp);
-  aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("LENGTH"), aHBox);
-  myTickLength = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxTickLength");
-  
-  aLabels.append(aLabel);
-
-  // Layout
-
-  QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
-  aLay->addWidget(myNameGrp);
-  aLay->addWidget(myLabelsGrp);
-  aLay->addWidget(myTicksGrp);
-
-  // init
-  myIsNameVisible->setChecked(true);
-  myIsLabelsVisible->setChecked(true);
-  myIsTicksVisible->setChecked(true);
-  updateControlState();
-
-  // Adjust label widths
-  QValueList< QLabel* >::iterator anIter;
-  int aMaxWidth = 0;
-  for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
-    aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
-  for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
-    (*anIter)->setFixedWidth(aMaxWidth);
-
-  // connect signals and slots
-  connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked()));
-  connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked()));
-  connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked()));
 }
 
+/*!
+  Destructor
+*/
 SVTK_AxisWidget::~SVTK_AxisWidget()
 {
 }
 
-void SVTK_AxisWidget::updateControlState()
-{
-  onNameChecked();
-  onLabelsChecked();
-  onTicksChecked();
-}
-
-//=======================================================================
-// name    : SVTK_AxisWidget::onNameChecked
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState)
-{
-  QObjectList aChildren(*theGrp->children());
-  QObject* anObj;
-  for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
-    if (anObj !=0 && anObj->inherits("QHBox"))
-      ((QHBox*)anObj)->setEnabled(theState);
-}
-
-//=======================================================================
-// Labels    : SVTK_AxisWidget::onLabelsChecked
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::onLabelsChecked()
-{
-  setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
-}
-
-//=======================================================================
-// Labels    : SVTK_AxisWidget::onTicksChecked
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::onTicksChecked()
-{
-  setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
-}
-
-//=======================================================================
-// name    : SVTK_AxisWidget::onNameChecked
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::onNameChecked()
-{
-  setEnabled(myNameGrp, myIsNameVisible->isChecked());
-}
-
-//=======================================================================
-// name    : SVTK_AxisWidget::UseName
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::UseName(const bool toUse)
-{
-  myIsNameVisible->setChecked(toUse);
-}
-
-//=======================================================================
-// name    : SVTK_AxisWidget::SetName
-// Purpose :
-//================================================== =====================
-void SVTK_AxisWidget::SetName(const QString& theName)
+ViewerTools_FontWidgetBase* SVTK_AxisWidget::createFontWidget( QWidget* theParent )
 {
-  myAxisName->setText(theName);
+  SVTK_FontWidget* aFontWidget = new SVTK_FontWidget( theParent );
+  aFontWidget->Initialize();
+  return aFontWidget;
 }
 
-//=======================================================================
-// name    : SVTK_AxisWidget::SetNameFont
-// Purpose :
-//=======================================================================
-void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
-                                  const int theFont,
-                                  const bool theIsBold,
-                                  const bool theIsItalic,
-                                  const bool theIsShadow)
-{
-  myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
-}
-
-//=======================================================================
-// name    : SVTK_AxisWidget::SetNameFont
-// Purpose :
-//=======================================================================
 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
 {
   if (theActor == 0)
@@ -248,7 +89,7 @@ bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
   vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
   if (aTitleProp !=0)
   {
-    float c[ 3 ];
+    double c[ 3 ];
     aTitleProp->GetColor(c);
     aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
     aTitleFontFamily = aTitleProp->GetFontFamily();
@@ -257,7 +98,7 @@ bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
     isTitleShadow = aTitleProp->GetShadow() ? true : false;
   }
 
-  myIsNameVisible->setChecked(useName);
+  myNameGrp->setChecked(useName);
   myAxisName->setText(aTitle);
   myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
 
@@ -276,7 +117,7 @@ bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
   vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
   if (aLabelsProp !=0)
   {
-    float c[ 3 ];
+    double c[ 3 ];
     aLabelsProp->GetColor(c);
     aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
     aLabelsFontFamily = aLabelsProp->GetFontFamily();
@@ -285,7 +126,7 @@ bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
     isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
   }
 
-  myIsLabelsVisible->setChecked(useLabels);
+  myLabelsGrp->setChecked(useLabels);
   myLabelNumber->setValue(nbLabels);
   myLabelOffset->setValue(anOffset);
   myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
@@ -294,16 +135,12 @@ bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
   bool useTickMarks = theActor->GetTickVisibility();
   int aTickLength = theActor->GetTickLength();
 
-  myIsTicksVisible->setChecked(useTickMarks);
+  myTicksGrp->setChecked(useTickMarks);
   myTickLength->setValue(aTickLength);
 
   return true;
 }
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::Apply
-// Purpose :
-//=======================================================================
 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
 {
    if (theActor == 0)
@@ -311,8 +148,8 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
 
   // Name
 
-  theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
-  theActor->SetTitle(myAxisName->text().latin1());
+  theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
+  theActor->SetTitle(myAxisName->text().toUtf8());
 
   QColor aTitleColor(255, 255, 255);
   int aTitleFontFamily = VTK_ARIAL;
@@ -338,7 +175,7 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
 
   // Labels
 
-  theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
+  theActor->SetLabelVisibility(myLabelsGrp->isChecked() ? 1 : 0);
 
   int nbLabels = myLabelNumber->value();
   theActor->SetNumberOfLabels(nbLabels);
@@ -371,7 +208,7 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
 
 
   // Tick marks
-  theActor->SetTickVisibility(myIsTicksVisible->isChecked());
+  theActor->SetTickVisibility(myTicksGrp->isChecked());
   int aTickLength = myTickLength->value();
   theActor->SetTickLength(aTickLength);
 
@@ -383,124 +220,58 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
   Description : Dialog for specifynig cube axes properties
 */
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::SVTK_CubeAxesDlg
-// Purpose : Constructor
-//=======================================================================
-SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(SVTK_MainWindow* theParent,
-                                  const char* theName,
-                                  QtxAction* theAction):
-  QDialog(theParent, 
-         theName, 
-         false,
-         WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-  myMainWindow(theParent),
-  myAction(theAction)
+/*!
+  Constructor
+*/
+SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
+                                   SVTK_ViewWindow* theParent,
+                                   const char* theName):
+  ViewerTools_CubeAxesDlgBase(theAction,
+                              theParent, 
+                              theName),
+  myMainWindow(theParent)
 {
-  setCaption(tr("CAPTION"));
-
-  QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
-  aLay->addWidget(createMainFrame(this));
-  aLay->addWidget(createButtonFrame(this));
 }
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::createMainFrame
-// Purpose : Create frame containing dialog's input fields
-//=======================================================================
-QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
-{
-  QFrame* aFrame = new QFrame(theParent);
-
-  myTabWg = new QTabWidget(aFrame);
-
-  myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
-  myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
-  myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
-
-  myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
-  myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
-  myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
-
-  myTabWg->setMargin(5);
-
-  myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
-
-  QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
-  aLay->addWidget(myTabWg);
-  aLay->addWidget(myIsVisible);
-
-  return aFrame;
-}
-
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::createButtonFrame
-// Purpose : Create frame containing buttons
-//=======================================================================
-QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
+/*!
+  Destructor
+*/
+SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
 {
-  QFrame* aFrame = new QFrame(theParent);
-  aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
-
-  myOkBtn    = new QPushButton(tr("BUT_OK"), aFrame);
-  myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
-  myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
-
-  QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
-  QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
-
-  aLay->addWidget(myOkBtn);
-  aLay->addWidget(myApplyBtn);
-  aLay->addItem(aSpacer);
-  aLay->addWidget(myCloseBtn);
-
-  connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
-  connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
-  connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
-
-  return aFrame;
 }
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg
-// Purpose : Destructor
-//=======================================================================
-SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
+/*!
+  Create axis widget
+*/
+ViewerTools_AxisWidgetBase* SVTK_CubeAxesDlg::createAxisWidget( QWidget* theParent )
 {
+  SVTK_AxisWidget* anAxisWidget = new SVTK_AxisWidget( theParent );
+  anAxisWidget->initialize();
+  return anAxisWidget;
 }
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::Update
-// Purpose : Update dialog fields, connect signals and slots, show dialog
-//=======================================================================
+/*!
+  Update dialog fields, connect signals and slots, show dialog
+*/
 void SVTK_CubeAxesDlg::Update()
 {
+  ViewerTools_CubeAxesDlgBase::Update();
+
   myActor = myMainWindow->GetCubeAxes();
 
-  myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
-  myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
-  myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
+  ((SVTK_AxisWidget*)myAxes[ 0 ])->ReadData(myActor->GetXAxisActor2D());
+  ((SVTK_AxisWidget*)myAxes[ 1 ])->ReadData(myActor->GetYAxisActor2D());
+  ((SVTK_AxisWidget*)myAxes[ 2 ])->ReadData(myActor->GetZAxisActor2D());
 
   myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
 }
 
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::isValid
-// Purpose : Verify validity of entry data
-//=======================================================================
-bool SVTK_CubeAxesDlg::isValid() const
-{
-  return true;
-}
-
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::onApply
-// Purpose : Verify validity of entry data
-//=======================================================================
+/*!
+  Verify validity of entry data
+*/
 bool SVTK_CubeAxesDlg::onApply()
 {
-  bool isOk = true;
+  bool isOk = ViewerTools_CubeAxesDlgBase::onApply();
 
   try
   {
@@ -508,16 +279,15 @@ bool SVTK_CubeAxesDlg::onApply()
     aCurrWid->clearFocus();
     aCurrWid->setFocus();
 
-    isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
-    isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
-    isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
+    isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 0 ])->Apply(myActor->GetXAxisActor2D());
+    isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 1 ])->Apply(myActor->GetYAxisActor2D());
+    isOk = isOk && ((SVTK_AxisWidget*)myAxes[ 2 ])->Apply(myActor->GetZAxisActor2D());
 
+    //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text()); // to remove?
+    //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text()); // to remove?
+    //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text()); // to remove?
 
-    //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
-    //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
-    //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
-
-    //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
+    //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels()); // to remove?
     if (myIsVisible->isChecked())
       myActor->VisibilityOn();
     else
@@ -533,30 +303,3 @@ bool SVTK_CubeAxesDlg::onApply()
 
   return isOk;
 }
-
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::onOk
-// Purpose : SLOT called when "Ok" button pressed.
-//=======================================================================
-void SVTK_CubeAxesDlg::onOk()
-{
-  if (onApply())
-    onClose();
-}
-
-//=======================================================================
-// name    : SVTK_CubeAxesDlg::onClose
-// Purpose : SLOT called when "Close" button pressed. Close dialog
-//=======================================================================
-void SVTK_CubeAxesDlg::onClose()
-{
-  reject();
-
-  myAction->setOn( false );
-}
-
-void SVTK_CubeAxesDlg::done( int r )
-{
-  myAction->setOn( false );
-  QDialog::done( r );
-}