1 // VISU VISUGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SVTK_CubeAxesDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SVTK_CubeAxesDlg.h"
30 #include "SVTK_MainWindow.h"
31 #include "SVTK_FontWidget.h"
33 #include "SVTK_CubeAxesActor2D.h"
35 #include "QtxAction.h"
36 #include "QtxIntSpinBox.h"
40 #include <qpushbutton.h>
41 #include <qtabwidget.h>
42 #include <qcheckbox.h>
43 #include <qgroupbox.h>
44 #include <qlineedit.h>
46 #include <qobjectlist.h>
47 #include <qvalidator.h>
49 #include <vtkAxisActor2D.h>
50 #include <vtkTextProperty.h>
54 * Description : Tab of dialog
60 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
63 QValueList< QLabel* > aLabels;
67 myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
68 myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
70 QHBox* aHBox = new QHBox(myNameGrp);
72 QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
73 myAxisName = new QLineEdit(aHBox);
74 aLabels.append(aLabel);
76 aHBox = new QHBox(myNameGrp);
78 aLabel = new QLabel(tr("FONT"), aHBox);
79 myNameFont = new SVTK_FontWidget(aHBox);
80 aLabels.append(aLabel);
85 myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
86 myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
88 aHBox = new QHBox(myLabelsGrp);
90 aLabel = new QLabel(tr("NUMBER"), aHBox);
91 myLabelNumber = new QtxIntSpinBox(0,25,1,aHBox,"SpinBoxLabelNumber");
92 aLabels.append(aLabel);
94 aHBox = new QHBox(myLabelsGrp);
96 aLabel = new QLabel(tr("OFFSET"), aHBox);
97 myLabelOffset = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxLabellOffset");
98 aLabels.append(aLabel);
100 aHBox = new QHBox(myLabelsGrp);
101 aHBox->setSpacing(5);
102 aLabel = new QLabel(tr("FONT"), aHBox);
103 myLabelsFont = new SVTK_FontWidget(aHBox);
104 aLabels.append(aLabel);
108 myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
109 myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
111 aHBox = new QHBox(myTicksGrp);
112 aHBox->setSpacing(5);
113 aLabel = new QLabel(tr("LENGTH"), aHBox);
114 myTickLength = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxTickLength");
116 aLabels.append(aLabel);
120 QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
121 aLay->addWidget(myNameGrp);
122 aLay->addWidget(myLabelsGrp);
123 aLay->addWidget(myTicksGrp);
126 myIsNameVisible->setChecked(true);
127 myIsLabelsVisible->setChecked(true);
128 myIsTicksVisible->setChecked(true);
129 updateControlState();
131 // Adjust label widths
132 QValueList< QLabel* >::iterator anIter;
134 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
135 aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
136 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
137 (*anIter)->setFixedWidth(aMaxWidth);
139 // connect signals and slots
140 connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked()));
141 connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked()));
142 connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked()));
148 SVTK_AxisWidget::~SVTK_AxisWidget()
152 void SVTK_AxisWidget::updateControlState()
159 void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState)
161 QObjectList aChildren(*theGrp->children());
163 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
164 if (anObj !=0 && anObj->inherits("QHBox"))
165 ((QHBox*)anObj)->setEnabled(theState);
168 void SVTK_AxisWidget::onLabelsChecked()
170 setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
173 void SVTK_AxisWidget::onTicksChecked()
175 setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
178 void SVTK_AxisWidget::onNameChecked()
180 setEnabled(myNameGrp, myIsNameVisible->isChecked());
183 void SVTK_AxisWidget::UseName(const bool toUse)
185 myIsNameVisible->setChecked(toUse);
188 void SVTK_AxisWidget::SetName(const QString& theName)
190 myAxisName->setText(theName);
193 void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
195 const bool theIsBold,
196 const bool theIsItalic,
197 const bool theIsShadow)
199 myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
202 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
209 bool useName = theActor->GetTitleVisibility();
210 QString aTitle(theActor->GetTitle());
212 QColor aTitleColor(255, 255, 255);
213 int aTitleFontFamily = VTK_ARIAL;
214 bool isTitleBold = false;
215 bool isTitleItalic = false;
216 bool isTitleShadow = false;
218 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
221 vtkFloatingPointType c[ 3 ];
222 aTitleProp->GetColor(c);
223 aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
224 aTitleFontFamily = aTitleProp->GetFontFamily();
225 isTitleBold = aTitleProp->GetBold() ? true : false;
226 isTitleItalic = aTitleProp->GetItalic() ? true : false;
227 isTitleShadow = aTitleProp->GetShadow() ? true : false;
230 myIsNameVisible->setChecked(useName);
231 myAxisName->setText(aTitle);
232 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
236 bool useLabels = theActor->GetLabelVisibility();
237 int nbLabels = theActor->GetNumberOfLabels();
238 int anOffset = theActor->GetTickOffset();
240 QColor aLabelsColor(255, 255, 255);
241 int aLabelsFontFamily = VTK_ARIAL;
242 bool isLabelsBold = false;
243 bool isLabelsItalic = false;
244 bool isLabelsShadow = false;
246 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
249 vtkFloatingPointType c[ 3 ];
250 aLabelsProp->GetColor(c);
251 aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
252 aLabelsFontFamily = aLabelsProp->GetFontFamily();
253 isLabelsBold = aLabelsProp->GetBold() ? true : false;
254 isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
255 isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
258 myIsLabelsVisible->setChecked(useLabels);
259 myLabelNumber->setValue(nbLabels);
260 myLabelOffset->setValue(anOffset);
261 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
264 bool useTickMarks = theActor->GetTickVisibility();
265 int aTickLength = theActor->GetTickLength();
267 myIsTicksVisible->setChecked(useTickMarks);
268 myTickLength->setValue(aTickLength);
273 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
280 theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
281 theActor->SetTitle(myAxisName->text().latin1());
283 QColor aTitleColor(255, 255, 255);
284 int aTitleFontFamily = VTK_ARIAL;
285 bool isTitleBold = false;
286 bool isTitleItalic = false;
287 bool isTitleShadow = false;
289 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
290 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
293 aTitleProp->SetColor(aTitleColor.red() / 255.,
294 aTitleColor.green() / 255.,
295 aTitleColor.blue() / 255.);
296 aTitleProp->SetFontFamily(aTitleFontFamily);
298 aTitleProp->SetBold(isTitleBold ? 1 : 0);
299 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
300 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
302 theActor->SetTitleTextProperty(aTitleProp);
307 theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
309 int nbLabels = myLabelNumber->value();
310 theActor->SetNumberOfLabels(nbLabels);
312 int anOffset = myLabelOffset->value();
313 theActor->SetTickOffset(anOffset);
315 QColor aLabelsColor(255, 255, 255);
316 int aLabelsFontFamily = VTK_ARIAL;
317 bool isLabelsBold = false;
318 bool isLabelsItalic = false;
319 bool isLabelsShadow = false;
321 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
322 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
325 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
326 aLabelsColor.green() / 255.,
327 aLabelsColor.blue() / 255.);
328 aLabelsProp->SetFontFamily(aLabelsFontFamily);
330 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
331 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
332 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
334 aLabelsProp->Modified();
335 theActor->SetLabelTextProperty(aLabelsProp);
340 theActor->SetTickVisibility(myIsTicksVisible->isChecked());
341 int aTickLength = myTickLength->value();
342 theActor->SetTickLength(aTickLength);
348 Class : SVTK_CubeAxesDlg
349 Description : Dialog for specifynig cube axes properties
355 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
356 SVTK_MainWindow* theParent,
357 const char* theName):
358 SVTK_DialogBase(theAction,
361 myMainWindow(theParent)
363 setCaption(tr("CAPTION"));
365 QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
366 aLay->addWidget(createMainFrame(this));
367 aLay->addWidget(createButtonFrame(this));
369 connect(theParent, SIGNAL(Show( QShowEvent * )), this, SLOT(onParentShow()));
370 connect(theParent, SIGNAL(Hide( QHideEvent * )), this, SLOT(onParentHide()));
374 Create frame containing dialog's input fields
376 QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
378 QFrame* aFrame = new QFrame(theParent);
380 myTabWg = new QTabWidget(aFrame);
382 myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
383 myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
384 myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
386 myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
387 myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
388 myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
390 myTabWg->setMargin(5);
392 myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
394 QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
395 aLay->addWidget(myTabWg);
396 aLay->addWidget(myIsVisible);
402 Create frame containing buttons
404 QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
406 QFrame* aFrame = new QFrame(theParent);
407 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
409 myOkBtn = new QPushButton(tr("BUT_OK"), aFrame);
410 myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
411 myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
413 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
415 QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
417 aLay->addWidget(myOkBtn);
418 aLay->addWidget(myApplyBtn);
419 aLay->addItem(aSpacer);
420 aLay->addWidget(myCloseBtn);
422 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
423 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
424 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
432 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
437 Update dialog fields, connect signals and slots, show dialog
439 void SVTK_CubeAxesDlg::Update()
441 myActor = myMainWindow->GetCubeAxes();
443 myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
444 myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
445 myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
447 myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
451 Verify validity of entry data
453 bool SVTK_CubeAxesDlg::isValid() const
459 Verify validity of entry data
461 bool SVTK_CubeAxesDlg::onApply()
467 QWidget *aCurrWid = this->focusWidget();
468 aCurrWid->clearFocus();
469 aCurrWid->setFocus();
471 isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
472 isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
473 isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
476 //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
477 //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
478 //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
480 //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
481 if (myIsVisible->isChecked())
482 myActor->VisibilityOn();
484 myActor->VisibilityOff();
487 myMainWindow->Repaint();
498 SLOT called when "Ok" button pressed.
500 void SVTK_CubeAxesDlg::onOk()
507 SLOT: called when "Close" button pressed. Close dialog
509 void SVTK_CubeAxesDlg::onClose()