Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SVTK / SVTK_CubeAxesDlg.cxx
index 94e4af88f0957e40d178debaf8e38164f8343ad9..bcf79ef490095880823d580bedf851d6c14c2cd7 100644 (file)
@@ -1,6 +1,6 @@
-//  VISU VISUGUI : GUI for SMESH component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  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
 //  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
-//
-//
+//  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 <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QTabWidget>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QLineEdit>
+#include <QLabel>
 
 #include <vtkAxisActor2D.h>
 #include <vtkTextProperty.h>
 
 /*!
- * Class       : AxisWg
- * Description : Tab of dialog
- */
+  \class SVTK_CubeAxesDlg::AxisWidget
+  \brief Axis tab widget of the "Graduated axis" dialog box
+  \internal
+*/
+
+class SVTK_CubeAxesDlg::AxisWidget : public QFrame
+{
+public:
+  AxisWidget( QWidget* );
+  ~AxisWidget();
+
+  void             UseName( const bool );
+  void             SetName( const QString& );
+  void             SetNameFont( const QColor&, const int, const bool, const bool, const bool );
+  bool             ReadData( vtkAxisActor2D* );
+  bool             Apply( vtkAxisActor2D* );
+
+private:
+  // name
+  QGroupBox*       myNameGrp;
+  QLineEdit*       myAxisName;
+  SVTK_FontWidget* myNameFont;
+
+  // labels
+  QGroupBox*       myLabelsGrp;
+  QtxIntSpinBox*   myLabelNumber;
+  QtxIntSpinBox*   myLabelOffset;
+  SVTK_FontWidget* myLabelsFont;
+
+  // tick marks
+  QGroupBox*       myTicksGrp;
+  QtxIntSpinBox*   myTickLength;
+
+  friend class SVTK_CubeAxesDlg;
+};
 
 /*!
   Constructor
 */
-SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
+SVTK_CubeAxesDlg::AxisWidget::AxisWidget (QWidget* theParent)
 :  QFrame(theParent)
 {
-  QValueList< QLabel* > aLabels;
+  QList< QLabel* > aLabels;
 
   // "Name" grp
 
-  myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
-  myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
+  myNameGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("AXIS_NAME"), this);
+  myNameGrp->setCheckable( true );
 
-  QHBox* aHBox = new QHBox(myNameGrp);
+  QVBoxLayout* aVBox = new QVBoxLayout;
+  
+  QHBoxLayout* aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
-  myAxisName = new QLineEdit(aHBox);
+  QLabel* aLabel = new QLabel(SVTK_CubeAxesDlg::tr("NAME"));
+  aHBox->addWidget(aLabel);
+  myAxisName = new QLineEdit;
+  aHBox->addWidget(myAxisName);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
 
-  aHBox = new QHBox(myNameGrp);
+  aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("FONT"), aHBox);
-  myNameFont = new SVTK_FontWidget(aHBox);
+  aLabel = new QLabel(SVTK_CubeAxesDlg::tr("FONT"));
+  aHBox->addWidget(aLabel);
+  myNameFont = new SVTK_FontWidget(myNameGrp);
+  aHBox->addWidget(myNameFont);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
 
+  myNameGrp->setLayout(aVBox);
 
   // "Labels" grp
 
-  myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
-  myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
+  myLabelsGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("LABELS"), this);
+  myLabelsGrp->setCheckable( true );
 
-  aHBox = new QHBox(myLabelsGrp);
+  aVBox = new QVBoxLayout;
+
+  aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("NUMBER"), aHBox);
-  myLabelNumber = new QtxIntSpinBox(0,25,1,aHBox,"SpinBoxLabelNumber");
+  aLabel = new QLabel(SVTK_CubeAxesDlg::tr("NUMBER"));
+  aHBox->addWidget(aLabel);
+  myLabelNumber = new QtxIntSpinBox(0,25,1,myLabelsGrp);
+  aHBox->addWidget(myLabelNumber);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
 
-  aHBox = new QHBox(myLabelsGrp);
+  aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("OFFSET"), aHBox);
-  myLabelOffset = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxLabellOffset");
+  aLabel = new QLabel(SVTK_CubeAxesDlg::tr("OFFSET"));
+  aHBox->addWidget(aLabel);
+  myLabelOffset = new QtxIntSpinBox(0,100,1,myLabelsGrp);
+  aHBox->addWidget(myLabelOffset);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
 
-  aHBox = new QHBox(myLabelsGrp);
+  aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("FONT"), aHBox);
-  myLabelsFont = new SVTK_FontWidget(aHBox);
+  aLabel = new QLabel(SVTK_CubeAxesDlg::tr("FONT"));
+  aHBox->addWidget(aLabel);
+  myLabelsFont = new SVTK_FontWidget(myLabelsGrp);
+  aHBox->addWidget(myLabelsFont);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
+
+  myLabelsGrp->setLayout(aVBox);
 
   // "Tick marks" grp
 
-  myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
-  myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
+  myTicksGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("TICK_MARKS"), this);
+  myTicksGrp->setCheckable( true );
 
-  aHBox = new QHBox(myTicksGrp);
+  aVBox = new QVBoxLayout;
+
+  aHBox = new QHBoxLayout;
   aHBox->setSpacing(5);
-  aLabel = new QLabel(tr("LENGTH"), aHBox);
-  myTickLength = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxTickLength");
-  
+  aLabel = new QLabel(SVTK_CubeAxesDlg::tr("LENGTH"));
+  aHBox->addWidget(aLabel);
+  myTickLength = new QtxIntSpinBox(0,100,1,myTicksGrp);
+  aHBox->addWidget(myTickLength);
   aLabels.append(aLabel);
+  aVBox->addLayout(aHBox);
+
+  myTicksGrp->setLayout(aVBox);
 
   // Layout
 
-  QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
+  QVBoxLayout* aLay = new QVBoxLayout(this);
+  aLay->setMargin(5);
+  aLay->setSpacing(5);
   aLay->addWidget(myNameGrp);
   aLay->addWidget(myLabelsGrp);
   aLay->addWidget(myTicksGrp);
 
   // init
-  myIsNameVisible->setChecked(true);
-  myIsLabelsVisible->setChecked(true);
-  myIsTicksVisible->setChecked(true);
-  updateControlState();
+  myNameGrp->setChecked( true );
+  myLabelsGrp->setChecked( true );
+  myTicksGrp->setChecked( true );
 
   // Adjust label widths
-  QValueList< QLabel* >::iterator anIter;
+  QList< QLabel* >::iterator anIter;
   int aMaxWidth = 0;
   for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
-    aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
+    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()
+SVTK_CubeAxesDlg::AxisWidget::~AxisWidget()
 {
 }
 
-void SVTK_AxisWidget::updateControlState()
+void SVTK_CubeAxesDlg::AxisWidget::UseName(const bool toUse)
 {
-  onNameChecked();
-  onLabelsChecked();
-  onTicksChecked();
+  myNameGrp->setChecked(toUse);
 }
 
-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);
-}
-
-void SVTK_AxisWidget::onLabelsChecked()
-{
-  setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
-}
-
-void SVTK_AxisWidget::onTicksChecked()
-{
-  setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
-}
-
-void SVTK_AxisWidget::onNameChecked()
-{
-  setEnabled(myNameGrp, myIsNameVisible->isChecked());
-}
-
-void SVTK_AxisWidget::UseName(const bool toUse)
-{
-  myIsNameVisible->setChecked(toUse);
-}
-
-void SVTK_AxisWidget::SetName(const QString& theName)
+void SVTK_CubeAxesDlg::AxisWidget::SetName(const QString& theName)
 {
   myAxisName->setText(theName);
 }
 
-void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
-                                  const int theFont,
-                                  const bool theIsBold,
-                                  const bool theIsItalic,
-                                  const bool theIsShadow)
+void SVTK_CubeAxesDlg::AxisWidget::SetNameFont(const QColor& theColor,
+                                              const int theFont,
+                                              const bool theIsBold,
+                                              const bool theIsItalic,
+                                              const bool theIsShadow)
 {
   myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
 }
 
-bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
+bool SVTK_CubeAxesDlg::AxisWidget::ReadData(vtkAxisActor2D* theActor)
 {
   if (theActor == 0)
     return false;
@@ -227,7 +249,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);
 
@@ -255,7 +277,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);
@@ -264,21 +286,21 @@ 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;
 }
 
-bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
+bool SVTK_CubeAxesDlg::AxisWidget::Apply(vtkAxisActor2D* theActor)
 {
    if (theActor == 0)
     return false;
 
   // Name
 
-  theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
-  theActor->SetTitle(myAxisName->text().latin1());
+  theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
+  theActor->SetTitle(myAxisName->text().toLatin1());
 
   QColor aTitleColor(255, 255, 255);
   int aTitleFontFamily = VTK_ARIAL;
@@ -304,7 +326,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);
@@ -337,7 +359,7 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
 
 
   // Tick marks
-  theActor->SetTickVisibility(myIsTicksVisible->isChecked());
+  theActor->SetTickVisibility(myTicksGrp->isChecked());
   int aTickLength = myTickLength->value();
   theActor->SetTickLength(aTickLength);
 
@@ -353,16 +375,18 @@ bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
   Constructor
 */
 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
-                                  SVTK_MainWindow* theParent,
+                                  SVTK_ViewWindow* theParent,
                                   const char* theName):
   SVTK_DialogBase(theAction,
                  theParent, 
                  theName),
   myMainWindow(theParent)
 {
-  setCaption(tr("CAPTION"));
+  setWindowTitle(tr("CAPTION"));
 
-  QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
+  QVBoxLayout* aLay = new QVBoxLayout(this);
+  aLay->setMargin(5);
+  aLay->setSpacing(5);
   aLay->addWidget(createMainFrame(this));
   aLay->addWidget(createButtonFrame(this));
 
@@ -379,19 +403,19 @@ QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
 
   myTabWg = new QTabWidget(aFrame);
 
-  myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
-  myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
-  myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
+  myAxes[ 0 ] = new AxisWidget(myTabWg);
+  myAxes[ 1 ] = new AxisWidget(myTabWg);
+  myAxes[ 2 ] = new 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);
+  QVBoxLayout* aLay = new QVBoxLayout(aFrame);
+  aLay->setMargin(0);
+  aLay->setSpacing(5);
   aLay->addWidget(myTabWg);
   aLay->addWidget(myIsVisible);
 
@@ -412,7 +436,9 @@ QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
 
   QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
 
-  QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
+  QHBoxLayout* aLay = new QHBoxLayout(aFrame);
+  aLay->setMargin(5);
+  aLay->setSpacing(5);
 
   aLay->addWidget(myOkBtn);
   aLay->addWidget(myApplyBtn);