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
57 //=======================================================================
58 // name : SVTK_AxisWidget::AxisWg
59 // Purpose : Constructor
60 //=======================================================================
61 SVTK_AxisWidget::SVTK_AxisWidget (QWidget* theParent)
64 QValueList< QLabel* > aLabels;
68 myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
69 myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
71 QHBox* aHBox = new QHBox(myNameGrp);
73 QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
74 myAxisName = new QLineEdit(aHBox);
75 aLabels.append(aLabel);
77 aHBox = new QHBox(myNameGrp);
79 aLabel = new QLabel(tr("FONT"), aHBox);
80 myNameFont = new SVTK_FontWidget(aHBox);
81 aLabels.append(aLabel);
86 myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
87 myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
89 aHBox = new QHBox(myLabelsGrp);
91 aLabel = new QLabel(tr("NUMBER"), aHBox);
92 myLabelNumber = new QtxIntSpinBox(0,25,1,aHBox,"SpinBoxLabelNumber");
93 aLabels.append(aLabel);
95 aHBox = new QHBox(myLabelsGrp);
97 aLabel = new QLabel(tr("OFFSET"), aHBox);
98 myLabelOffset = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxLabellOffset");
99 aLabels.append(aLabel);
101 aHBox = new QHBox(myLabelsGrp);
102 aHBox->setSpacing(5);
103 aLabel = new QLabel(tr("FONT"), aHBox);
104 myLabelsFont = new SVTK_FontWidget(aHBox);
105 aLabels.append(aLabel);
109 myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
110 myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
112 aHBox = new QHBox(myTicksGrp);
113 aHBox->setSpacing(5);
114 aLabel = new QLabel(tr("LENGTH"), aHBox);
115 myTickLength = new QtxIntSpinBox(0,100,1,aHBox,"SpinBoxTickLength");
117 aLabels.append(aLabel);
121 QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
122 aLay->addWidget(myNameGrp);
123 aLay->addWidget(myLabelsGrp);
124 aLay->addWidget(myTicksGrp);
127 myIsNameVisible->setChecked(true);
128 myIsLabelsVisible->setChecked(true);
129 myIsTicksVisible->setChecked(true);
130 updateControlState();
132 // Adjust label widths
133 QValueList< QLabel* >::iterator anIter;
135 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
136 aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
137 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
138 (*anIter)->setFixedWidth(aMaxWidth);
140 // connect signals and slots
141 connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked()));
142 connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked()));
143 connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked()));
146 SVTK_AxisWidget::~SVTK_AxisWidget()
150 void SVTK_AxisWidget::updateControlState()
157 //=======================================================================
158 // name : SVTK_AxisWidget::onNameChecked
160 //=======================================================================
161 void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState)
163 QObjectList aChildren(*theGrp->children());
165 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
166 if (anObj !=0 && anObj->inherits("QHBox"))
167 ((QHBox*)anObj)->setEnabled(theState);
170 //=======================================================================
171 // Labels : SVTK_AxisWidget::onLabelsChecked
173 //=======================================================================
174 void SVTK_AxisWidget::onLabelsChecked()
176 setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
179 //=======================================================================
180 // Labels : SVTK_AxisWidget::onTicksChecked
182 //=======================================================================
183 void SVTK_AxisWidget::onTicksChecked()
185 setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
188 //=======================================================================
189 // name : SVTK_AxisWidget::onNameChecked
191 //=======================================================================
192 void SVTK_AxisWidget::onNameChecked()
194 setEnabled(myNameGrp, myIsNameVisible->isChecked());
197 //=======================================================================
198 // name : SVTK_AxisWidget::UseName
200 //=======================================================================
201 void SVTK_AxisWidget::UseName(const bool toUse)
203 myIsNameVisible->setChecked(toUse);
206 //=======================================================================
207 // name : SVTK_AxisWidget::SetName
209 //================================================== =====================
210 void SVTK_AxisWidget::SetName(const QString& theName)
212 myAxisName->setText(theName);
215 //=======================================================================
216 // name : SVTK_AxisWidget::SetNameFont
218 //=======================================================================
219 void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
221 const bool theIsBold,
222 const bool theIsItalic,
223 const bool theIsShadow)
225 myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
228 //=======================================================================
229 // name : SVTK_AxisWidget::SetNameFont
231 //=======================================================================
232 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
239 bool useName = theActor->GetTitleVisibility();
240 QString aTitle(theActor->GetTitle());
242 QColor aTitleColor(255, 255, 255);
243 int aTitleFontFamily = VTK_ARIAL;
244 bool isTitleBold = false;
245 bool isTitleItalic = false;
246 bool isTitleShadow = false;
248 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
252 aTitleProp->GetColor(c);
253 aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
254 aTitleFontFamily = aTitleProp->GetFontFamily();
255 isTitleBold = aTitleProp->GetBold() ? true : false;
256 isTitleItalic = aTitleProp->GetItalic() ? true : false;
257 isTitleShadow = aTitleProp->GetShadow() ? true : false;
260 myIsNameVisible->setChecked(useName);
261 myAxisName->setText(aTitle);
262 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
266 bool useLabels = theActor->GetLabelVisibility();
267 int nbLabels = theActor->GetNumberOfLabels();
268 int anOffset = theActor->GetTickOffset();
270 QColor aLabelsColor(255, 255, 255);
271 int aLabelsFontFamily = VTK_ARIAL;
272 bool isLabelsBold = false;
273 bool isLabelsItalic = false;
274 bool isLabelsShadow = false;
276 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
280 aLabelsProp->GetColor(c);
281 aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
282 aLabelsFontFamily = aLabelsProp->GetFontFamily();
283 isLabelsBold = aLabelsProp->GetBold() ? true : false;
284 isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
285 isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
288 myIsLabelsVisible->setChecked(useLabels);
289 myLabelNumber->setValue(nbLabels);
290 myLabelOffset->setValue(anOffset);
291 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
294 bool useTickMarks = theActor->GetTickVisibility();
295 int aTickLength = theActor->GetTickLength();
297 myIsTicksVisible->setChecked(useTickMarks);
298 myTickLength->setValue(aTickLength);
303 //=======================================================================
304 // name : SVTK_CubeAxesDlg::Apply
306 //=======================================================================
307 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
314 theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
315 theActor->SetTitle(myAxisName->text().latin1());
317 QColor aTitleColor(255, 255, 255);
318 int aTitleFontFamily = VTK_ARIAL;
319 bool isTitleBold = false;
320 bool isTitleItalic = false;
321 bool isTitleShadow = false;
323 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
324 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
327 aTitleProp->SetColor(aTitleColor.red() / 255.,
328 aTitleColor.green() / 255.,
329 aTitleColor.blue() / 255.);
330 aTitleProp->SetFontFamily(aTitleFontFamily);
332 aTitleProp->SetBold(isTitleBold ? 1 : 0);
333 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
334 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
336 theActor->SetTitleTextProperty(aTitleProp);
341 theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
343 int nbLabels = myLabelNumber->value();
344 theActor->SetNumberOfLabels(nbLabels);
346 int anOffset = myLabelOffset->value();
347 theActor->SetTickOffset(anOffset);
349 QColor aLabelsColor(255, 255, 255);
350 int aLabelsFontFamily = VTK_ARIAL;
351 bool isLabelsBold = false;
352 bool isLabelsItalic = false;
353 bool isLabelsShadow = false;
355 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
356 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
359 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
360 aLabelsColor.green() / 255.,
361 aLabelsColor.blue() / 255.);
362 aLabelsProp->SetFontFamily(aLabelsFontFamily);
364 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
365 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
366 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
368 aLabelsProp->Modified();
369 theActor->SetLabelTextProperty(aLabelsProp);
374 theActor->SetTickVisibility(myIsTicksVisible->isChecked());
375 int aTickLength = myTickLength->value();
376 theActor->SetTickLength(aTickLength);
382 Class : SVTK_CubeAxesDlg
383 Description : Dialog for specifynig cube axes properties
386 //=======================================================================
387 // name : SVTK_CubeAxesDlg::SVTK_CubeAxesDlg
388 // Purpose : Constructor
389 //=======================================================================
390 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(SVTK_MainWindow* theParent,
392 QtxAction* theAction):
396 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
397 myMainWindow(theParent),
400 setCaption(tr("CAPTION"));
402 QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
403 aLay->addWidget(createMainFrame(this));
404 aLay->addWidget(createButtonFrame(this));
407 //=======================================================================
408 // name : SVTK_CubeAxesDlg::createMainFrame
409 // Purpose : Create frame containing dialog's input fields
410 //=======================================================================
411 QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
413 QFrame* aFrame = new QFrame(theParent);
415 myTabWg = new QTabWidget(aFrame);
417 myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
418 myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
419 myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
421 myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
422 myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
423 myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
425 myTabWg->setMargin(5);
427 myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
429 QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
430 aLay->addWidget(myTabWg);
431 aLay->addWidget(myIsVisible);
436 //=======================================================================
437 // name : SVTK_CubeAxesDlg::createButtonFrame
438 // Purpose : Create frame containing buttons
439 //=======================================================================
440 QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
442 QFrame* aFrame = new QFrame(theParent);
443 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
445 myOkBtn = new QPushButton(tr("BUT_OK"), aFrame);
446 myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
447 myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
449 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
451 QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
453 aLay->addWidget(myOkBtn);
454 aLay->addWidget(myApplyBtn);
455 aLay->addItem(aSpacer);
456 aLay->addWidget(myCloseBtn);
458 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
459 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
460 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
465 //=======================================================================
466 // name : SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg
467 // Purpose : Destructor
468 //=======================================================================
469 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
473 //=======================================================================
474 // name : SVTK_CubeAxesDlg::Update
475 // Purpose : Update dialog fields, connect signals and slots, show dialog
476 //=======================================================================
477 void SVTK_CubeAxesDlg::Update()
479 myActor = myMainWindow->GetCubeAxes();
481 myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
482 myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
483 myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
485 myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
488 //=======================================================================
489 // name : SVTK_CubeAxesDlg::isValid
490 // Purpose : Verify validity of entry data
491 //=======================================================================
492 bool SVTK_CubeAxesDlg::isValid() const
497 //=======================================================================
498 // name : SVTK_CubeAxesDlg::onApply
499 // Purpose : Verify validity of entry data
500 //=======================================================================
501 bool SVTK_CubeAxesDlg::onApply()
507 QWidget *aCurrWid = this->focusWidget();
508 aCurrWid->clearFocus();
509 aCurrWid->setFocus();
511 isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
512 isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
513 isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
516 //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
517 //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
518 //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
520 //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
521 if (myIsVisible->isChecked())
522 myActor->VisibilityOn();
524 myActor->VisibilityOff();
527 myMainWindow->Repaint();
537 //=======================================================================
538 // name : SVTK_CubeAxesDlg::onOk
539 // Purpose : SLOT called when "Ok" button pressed.
540 //=======================================================================
541 void SVTK_CubeAxesDlg::onOk()
547 //=======================================================================
548 // name : SVTK_CubeAxesDlg::onClose
549 // Purpose : SLOT called when "Close" button pressed. Close dialog
550 //=======================================================================
551 void SVTK_CubeAxesDlg::onClose()
555 myAction->setOn( false );
558 void SVTK_CubeAxesDlg::done( int r )
560 myAction->setOn( false );