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"
39 #include <qpushbutton.h>
40 #include <qtabwidget.h>
41 #include <qcheckbox.h>
42 #include <qgroupbox.h>
43 #include <qlineedit.h>
45 #include <qobjectlist.h>
46 #include <qvalidator.h>
48 #include <vtkAxisActor2D.h>
49 #include <vtkTextProperty.h>
53 * Description : Tab of dialog
56 //=======================================================================
57 // name : SVTK_AxisWidget::AxisWg
58 // Purpose : Constructor
59 //=======================================================================
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 QLineEdit(aHBox);
92 myLabelNumber->setValidator(new QIntValidator(0, 25, this));
93 myLabelNumber->installEventFilter(this);
94 aLabels.append(aLabel);
96 aHBox = new QHBox(myLabelsGrp);
98 aLabel = new QLabel(tr("OFFSET"), aHBox);
99 myLabelOffset = new QLineEdit(aHBox);
100 aLabels.append(aLabel);
102 aHBox = new QHBox(myLabelsGrp);
103 aHBox->setSpacing(5);
104 aLabel = new QLabel(tr("FONT"), aHBox);
105 myLabelsFont = new SVTK_FontWidget(aHBox);
106 aLabels.append(aLabel);
110 myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
111 myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
113 aHBox = new QHBox(myTicksGrp);
114 aHBox->setSpacing(5);
115 aLabel = new QLabel(tr("LENGTH"), aHBox);
116 myTickLength = new QLineEdit(aHBox);
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 bool SVTK_AxisWidget::eventFilter(QObject* o, QEvent* e)
159 if (e->type() == QEvent::FocusOut) {
161 int k = myLabelNumber->text().toInt(&isOK);
162 if (isOK && k > 25) myLabelNumber->setText("25");
167 //=======================================================================
168 // name : SVTK_AxisWidget::onNameChecked
170 //=======================================================================
171 void SVTK_AxisWidget::setEnabled(QGroupBox* theGrp, const bool theState)
173 QObjectList aChildren(*theGrp->children());
175 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
176 if (anObj !=0 && anObj->inherits("QHBox"))
177 ((QHBox*)anObj)->setEnabled(theState);
180 //=======================================================================
181 // Labels : SVTK_AxisWidget::onLabelsChecked
183 //=======================================================================
184 void SVTK_AxisWidget::onLabelsChecked()
186 setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
189 //=======================================================================
190 // Labels : SVTK_AxisWidget::onTicksChecked
192 //=======================================================================
193 void SVTK_AxisWidget::onTicksChecked()
195 setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
198 //=======================================================================
199 // name : SVTK_AxisWidget::onNameChecked
201 //=======================================================================
202 void SVTK_AxisWidget::onNameChecked()
204 setEnabled(myNameGrp, myIsNameVisible->isChecked());
207 //=======================================================================
208 // name : SVTK_AxisWidget::UseName
210 //=======================================================================
211 void SVTK_AxisWidget::UseName(const bool toUse)
213 myIsNameVisible->setChecked(toUse);
216 //=======================================================================
217 // name : SVTK_AxisWidget::SetName
219 //================================================== =====================
220 void SVTK_AxisWidget::SetName(const QString& theName)
222 myAxisName->setText(theName);
225 //=======================================================================
226 // name : SVTK_AxisWidget::SetNameFont
228 //=======================================================================
229 void SVTK_AxisWidget::SetNameFont(const QColor& theColor,
231 const bool theIsBold,
232 const bool theIsItalic,
233 const bool theIsShadow)
235 myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
238 //=======================================================================
239 // name : SVTK_AxisWidget::SetNameFont
241 //=======================================================================
242 bool SVTK_AxisWidget::ReadData(vtkAxisActor2D* theActor)
249 bool useName = theActor->GetTitleVisibility();
250 QString aTitle(theActor->GetTitle());
252 QColor aTitleColor(255, 255, 255);
253 int aTitleFontFamily = VTK_ARIAL;
254 bool isTitleBold = false;
255 bool isTitleItalic = false;
256 bool isTitleShadow = false;
258 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
262 aTitleProp->GetColor(c);
263 aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
264 aTitleFontFamily = aTitleProp->GetFontFamily();
265 isTitleBold = aTitleProp->GetBold() ? true : false;
266 isTitleItalic = aTitleProp->GetItalic() ? true : false;
267 isTitleShadow = aTitleProp->GetShadow() ? true : false;
270 myIsNameVisible->setChecked(useName);
271 myAxisName->setText(aTitle);
272 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
276 bool useLabels = theActor->GetLabelVisibility();
277 int nbLabels = theActor->GetNumberOfLabels();
278 int anOffset = theActor->GetTickOffset();
280 QColor aLabelsColor(255, 255, 255);
281 int aLabelsFontFamily = VTK_ARIAL;
282 bool isLabelsBold = false;
283 bool isLabelsItalic = false;
284 bool isLabelsShadow = false;
286 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
290 aLabelsProp->GetColor(c);
291 aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
292 aLabelsFontFamily = aLabelsProp->GetFontFamily();
293 isLabelsBold = aLabelsProp->GetBold() ? true : false;
294 isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
295 isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
298 myIsLabelsVisible->setChecked(useLabels);
299 myLabelNumber->setText(QString("%1").arg(nbLabels));
300 myLabelOffset->setText(QString("%1").arg(anOffset));
301 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
304 bool useTickMarks = theActor->GetTickVisibility();
305 int aTickLength = theActor->GetTickLength();
307 myIsTicksVisible->setChecked(useTickMarks);
308 myTickLength->setText(QString("%1").arg(aTickLength));
313 //=======================================================================
314 // name : SVTK_CubeAxesDlg::Apply
316 //=======================================================================
317 bool SVTK_AxisWidget::Apply(vtkAxisActor2D* theActor)
324 theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
325 theActor->SetTitle(myAxisName->text().latin1());
327 QColor aTitleColor(255, 255, 255);
328 int aTitleFontFamily = VTK_ARIAL;
329 bool isTitleBold = false;
330 bool isTitleItalic = false;
331 bool isTitleShadow = false;
333 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
334 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
337 aTitleProp->SetColor(aTitleColor.red() / 255.,
338 aTitleColor.green() / 255.,
339 aTitleColor.blue() / 255.);
340 aTitleProp->SetFontFamily(aTitleFontFamily);
342 aTitleProp->SetBold(isTitleBold ? 1 : 0);
343 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
344 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
346 theActor->SetTitleTextProperty(aTitleProp);
351 theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
354 int nbLabels = myLabelNumber->text().toInt(&isOk);
356 theActor->SetNumberOfLabels(nbLabels);
358 int anOffset = myLabelOffset->text().toInt(&isOk);
360 theActor->SetTickOffset(anOffset);
362 QColor aLabelsColor(255, 255, 255);
363 int aLabelsFontFamily = VTK_ARIAL;
364 bool isLabelsBold = false;
365 bool isLabelsItalic = false;
366 bool isLabelsShadow = false;
368 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
369 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
372 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
373 aLabelsColor.green() / 255.,
374 aLabelsColor.blue() / 255.);
375 aLabelsProp->SetFontFamily(aLabelsFontFamily);
377 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
378 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
379 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
381 aLabelsProp->Modified();
382 theActor->SetLabelTextProperty(aLabelsProp);
387 theActor->SetTickVisibility(myIsTicksVisible->isChecked());
388 int aTickLength = myTickLength->text().toInt(&isOk);
390 theActor->SetTickLength(aTickLength);
396 Class : SVTK_CubeAxesDlg
397 Description : Dialog for specifynig cube axes properties
400 //=======================================================================
401 // name : SVTK_CubeAxesDlg::SVTK_CubeAxesDlg
402 // Purpose : Constructor
403 //=======================================================================
404 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(SVTK_MainWindow* theParent,
406 QtxAction* theAction):
410 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
411 myMainWindow(theParent),
414 setCaption(tr("CAPTION"));
416 QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
417 aLay->addWidget(createMainFrame(this));
418 aLay->addWidget(createButtonFrame(this));
421 //=======================================================================
422 // name : SVTK_CubeAxesDlg::createMainFrame
423 // Purpose : Create frame containing dialog's input fields
424 //=======================================================================
425 QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
427 QFrame* aFrame = new QFrame(theParent);
429 myTabWg = new QTabWidget(aFrame);
431 myAxes[ 0 ] = new SVTK_AxisWidget(myTabWg);
432 myAxes[ 1 ] = new SVTK_AxisWidget(myTabWg);
433 myAxes[ 2 ] = new SVTK_AxisWidget(myTabWg);
435 myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
436 myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
437 myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
439 myTabWg->setMargin(5);
441 myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
443 QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
444 aLay->addWidget(myTabWg);
445 aLay->addWidget(myIsVisible);
450 //=======================================================================
451 // name : SVTK_CubeAxesDlg::createButtonFrame
452 // Purpose : Create frame containing buttons
453 //=======================================================================
454 QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
456 QFrame* aFrame = new QFrame(theParent);
457 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
459 myOkBtn = new QPushButton(tr("BUT_OK"), aFrame);
460 myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
461 myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
463 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
465 QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
467 aLay->addWidget(myOkBtn);
468 aLay->addWidget(myApplyBtn);
469 aLay->addItem(aSpacer);
470 aLay->addWidget(myCloseBtn);
472 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
473 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
474 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
479 //=======================================================================
480 // name : SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg
481 // Purpose : Destructor
482 //=======================================================================
483 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
487 //=======================================================================
488 // name : SVTK_CubeAxesDlg::Update
489 // Purpose : Update dialog fields, connect signals and slots, show dialog
490 //=======================================================================
491 void SVTK_CubeAxesDlg::Update()
493 myActor = myMainWindow->GetCubeAxes();
495 myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
496 myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
497 myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
499 myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
502 //=======================================================================
503 // name : SVTK_CubeAxesDlg::isValid
504 // Purpose : Verify validity of entry data
505 //=======================================================================
506 bool SVTK_CubeAxesDlg::isValid() const
511 //=======================================================================
512 // name : SVTK_CubeAxesDlg::onApply
513 // Purpose : Verify validity of entry data
514 //=======================================================================
515 bool SVTK_CubeAxesDlg::onApply()
521 isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
522 isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
523 isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
526 //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
527 //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
528 //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
530 //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
531 if (myIsVisible->isChecked())
532 myActor->VisibilityOn();
534 myActor->VisibilityOff();
537 myMainWindow->Repaint();
547 //=======================================================================
548 // name : SVTK_CubeAxesDlg::onOk
549 // Purpose : SLOT called when "Ok" button pressed.
550 //=======================================================================
551 void SVTK_CubeAxesDlg::onOk()
557 //=======================================================================
558 // name : SVTK_CubeAxesDlg::onClose
559 // Purpose : SLOT called when "Close" button pressed. Close dialog
560 //=======================================================================
561 void SVTK_CubeAxesDlg::onClose()
565 myAction->setOn( false );
568 void SVTK_CubeAxesDlg::done( int r )
570 myAction->setOn( false );