1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI for SMESH component
23 // File : SVTK_CubeAxesDlg.cxx
24 // Author : Sergey LITONIN
27 #include "SVTK_CubeAxesDlg.h"
29 #include "SVTK_ViewWindow.h"
30 #include "SVTK_FontWidget.h"
32 #include "SVTK_CubeAxesActor2D.h"
34 #include "QtxAction.h"
35 #include "QtxIntSpinBox.h"
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QPushButton>
46 #include <vtkAxisActor2D.h>
47 #include <vtkTextProperty.h>
50 \class SVTK_CubeAxesDlg::AxisWidget
51 \brief Axis tab widget of the "Graduated axis" dialog box
55 class SVTK_CubeAxesDlg::AxisWidget : public QFrame
58 AxisWidget( QWidget* );
61 void UseName( const bool );
62 void SetName( const QString& );
63 void SetNameFont( const QColor&, const int, const bool, const bool, const bool );
64 bool ReadData( vtkAxisActor2D* );
65 bool Apply( vtkAxisActor2D* );
70 QLineEdit* myAxisName;
71 SVTK_FontWidget* myNameFont;
74 QGroupBox* myLabelsGrp;
75 QtxIntSpinBox* myLabelNumber;
76 QtxIntSpinBox* myLabelOffset;
77 SVTK_FontWidget* myLabelsFont;
80 QGroupBox* myTicksGrp;
81 QtxIntSpinBox* myTickLength;
83 friend class SVTK_CubeAxesDlg;
89 SVTK_CubeAxesDlg::AxisWidget::AxisWidget (QWidget* theParent)
92 QList< QLabel* > aLabels;
96 myNameGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("AXIS_NAME"), this);
97 myNameGrp->setCheckable( true );
99 QVBoxLayout* aVBox = new QVBoxLayout;
101 QHBoxLayout* aHBox = new QHBoxLayout;
102 aHBox->setSpacing(5);
103 QLabel* aLabel = new QLabel(SVTK_CubeAxesDlg::tr("NAME"));
104 aHBox->addWidget(aLabel);
105 myAxisName = new QLineEdit;
106 aHBox->addWidget(myAxisName);
107 aLabels.append(aLabel);
108 aVBox->addLayout(aHBox);
110 aHBox = new QHBoxLayout;
111 aHBox->setSpacing(5);
112 aLabel = new QLabel(SVTK_CubeAxesDlg::tr("FONT"));
113 aHBox->addWidget(aLabel);
114 myNameFont = new SVTK_FontWidget(myNameGrp);
115 aHBox->addWidget(myNameFont);
116 aLabels.append(aLabel);
117 aVBox->addLayout(aHBox);
119 myNameGrp->setLayout(aVBox);
123 myLabelsGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("LABELS"), this);
124 myLabelsGrp->setCheckable( true );
126 aVBox = new QVBoxLayout;
128 aHBox = new QHBoxLayout;
129 aHBox->setSpacing(5);
130 aLabel = new QLabel(SVTK_CubeAxesDlg::tr("NUMBER"));
131 aHBox->addWidget(aLabel);
132 myLabelNumber = new QtxIntSpinBox(0,25,1,myLabelsGrp);
133 aHBox->addWidget(myLabelNumber);
134 aLabels.append(aLabel);
135 aVBox->addLayout(aHBox);
137 aHBox = new QHBoxLayout;
138 aHBox->setSpacing(5);
139 aLabel = new QLabel(SVTK_CubeAxesDlg::tr("OFFSET"));
140 aHBox->addWidget(aLabel);
141 myLabelOffset = new QtxIntSpinBox(0,100,1,myLabelsGrp);
142 aHBox->addWidget(myLabelOffset);
143 aLabels.append(aLabel);
144 aVBox->addLayout(aHBox);
146 aHBox = new QHBoxLayout;
147 aHBox->setSpacing(5);
148 aLabel = new QLabel(SVTK_CubeAxesDlg::tr("FONT"));
149 aHBox->addWidget(aLabel);
150 myLabelsFont = new SVTK_FontWidget(myLabelsGrp);
151 aHBox->addWidget(myLabelsFont);
152 aLabels.append(aLabel);
153 aVBox->addLayout(aHBox);
155 myLabelsGrp->setLayout(aVBox);
159 myTicksGrp = new QGroupBox(SVTK_CubeAxesDlg::tr("TICK_MARKS"), this);
160 myTicksGrp->setCheckable( true );
162 aVBox = new QVBoxLayout;
164 aHBox = new QHBoxLayout;
165 aHBox->setSpacing(5);
166 aLabel = new QLabel(SVTK_CubeAxesDlg::tr("LENGTH"));
167 aHBox->addWidget(aLabel);
168 myTickLength = new QtxIntSpinBox(0,100,1,myTicksGrp);
169 aHBox->addWidget(myTickLength);
170 aLabels.append(aLabel);
171 aVBox->addLayout(aHBox);
173 myTicksGrp->setLayout(aVBox);
177 QVBoxLayout* aLay = new QVBoxLayout(this);
180 aLay->addWidget(myNameGrp);
181 aLay->addWidget(myLabelsGrp);
182 aLay->addWidget(myTicksGrp);
185 myNameGrp->setChecked( true );
186 myLabelsGrp->setChecked( true );
187 myTicksGrp->setChecked( true );
189 // Adjust label widths
190 QList< QLabel* >::iterator anIter;
192 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
193 aMaxWidth = qMax(aMaxWidth, (*anIter)->sizeHint().width());
194 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
195 (*anIter)->setFixedWidth(aMaxWidth);
201 SVTK_CubeAxesDlg::AxisWidget::~AxisWidget()
205 void SVTK_CubeAxesDlg::AxisWidget::UseName(const bool toUse)
207 myNameGrp->setChecked(toUse);
210 void SVTK_CubeAxesDlg::AxisWidget::SetName(const QString& theName)
212 myAxisName->setText(theName);
215 void SVTK_CubeAxesDlg::AxisWidget::SetNameFont(const QColor& theColor,
217 const bool theIsBold,
218 const bool theIsItalic,
219 const bool theIsShadow)
221 myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
224 bool SVTK_CubeAxesDlg::AxisWidget::ReadData(vtkAxisActor2D* theActor)
231 bool useName = theActor->GetTitleVisibility();
232 QString aTitle(theActor->GetTitle());
234 QColor aTitleColor(255, 255, 255);
235 int aTitleFontFamily = VTK_ARIAL;
236 bool isTitleBold = false;
237 bool isTitleItalic = false;
238 bool isTitleShadow = false;
240 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
243 vtkFloatingPointType c[ 3 ];
244 aTitleProp->GetColor(c);
245 aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
246 aTitleFontFamily = aTitleProp->GetFontFamily();
247 isTitleBold = aTitleProp->GetBold() ? true : false;
248 isTitleItalic = aTitleProp->GetItalic() ? true : false;
249 isTitleShadow = aTitleProp->GetShadow() ? true : false;
252 myNameGrp->setChecked(useName);
253 myAxisName->setText(aTitle);
254 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
258 bool useLabels = theActor->GetLabelVisibility();
259 int nbLabels = theActor->GetNumberOfLabels();
260 int anOffset = theActor->GetTickOffset();
262 QColor aLabelsColor(255, 255, 255);
263 int aLabelsFontFamily = VTK_ARIAL;
264 bool isLabelsBold = false;
265 bool isLabelsItalic = false;
266 bool isLabelsShadow = false;
268 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
271 vtkFloatingPointType c[ 3 ];
272 aLabelsProp->GetColor(c);
273 aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
274 aLabelsFontFamily = aLabelsProp->GetFontFamily();
275 isLabelsBold = aLabelsProp->GetBold() ? true : false;
276 isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
277 isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
280 myLabelsGrp->setChecked(useLabels);
281 myLabelNumber->setValue(nbLabels);
282 myLabelOffset->setValue(anOffset);
283 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
286 bool useTickMarks = theActor->GetTickVisibility();
287 int aTickLength = theActor->GetTickLength();
289 myTicksGrp->setChecked(useTickMarks);
290 myTickLength->setValue(aTickLength);
295 bool SVTK_CubeAxesDlg::AxisWidget::Apply(vtkAxisActor2D* theActor)
302 theActor->SetTitleVisibility(myNameGrp->isChecked() ? 1 : 0);
303 theActor->SetTitle(myAxisName->text().toLatin1());
305 QColor aTitleColor(255, 255, 255);
306 int aTitleFontFamily = VTK_ARIAL;
307 bool isTitleBold = false;
308 bool isTitleItalic = false;
309 bool isTitleShadow = false;
311 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
312 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
315 aTitleProp->SetColor(aTitleColor.red() / 255.,
316 aTitleColor.green() / 255.,
317 aTitleColor.blue() / 255.);
318 aTitleProp->SetFontFamily(aTitleFontFamily);
320 aTitleProp->SetBold(isTitleBold ? 1 : 0);
321 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
322 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
324 theActor->SetTitleTextProperty(aTitleProp);
329 theActor->SetLabelVisibility(myLabelsGrp->isChecked() ? 1 : 0);
331 int nbLabels = myLabelNumber->value();
332 theActor->SetNumberOfLabels(nbLabels);
334 int anOffset = myLabelOffset->value();
335 theActor->SetTickOffset(anOffset);
337 QColor aLabelsColor(255, 255, 255);
338 int aLabelsFontFamily = VTK_ARIAL;
339 bool isLabelsBold = false;
340 bool isLabelsItalic = false;
341 bool isLabelsShadow = false;
343 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
344 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
347 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
348 aLabelsColor.green() / 255.,
349 aLabelsColor.blue() / 255.);
350 aLabelsProp->SetFontFamily(aLabelsFontFamily);
352 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
353 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
354 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
356 aLabelsProp->Modified();
357 theActor->SetLabelTextProperty(aLabelsProp);
362 theActor->SetTickVisibility(myTicksGrp->isChecked());
363 int aTickLength = myTickLength->value();
364 theActor->SetTickLength(aTickLength);
370 Class : SVTK_CubeAxesDlg
371 Description : Dialog for specifynig cube axes properties
377 SVTK_CubeAxesDlg::SVTK_CubeAxesDlg(QtxAction* theAction,
378 SVTK_ViewWindow* theParent,
379 const char* theName):
380 SVTK_DialogBase(theAction,
383 myMainWindow(theParent)
385 setWindowTitle(tr("CAPTION"));
387 QVBoxLayout* aLay = new QVBoxLayout(this);
390 aLay->addWidget(createMainFrame(this));
391 aLay->addWidget(createButtonFrame(this));
393 connect(theParent, SIGNAL(Show( QShowEvent * )), this, SLOT(onParentShow()));
394 connect(theParent, SIGNAL(Hide( QHideEvent * )), this, SLOT(onParentHide()));
398 Create frame containing dialog's input fields
400 QWidget* SVTK_CubeAxesDlg::createMainFrame(QWidget* theParent)
402 QFrame* aFrame = new QFrame(theParent);
404 myTabWg = new QTabWidget(aFrame);
406 myAxes[ 0 ] = new AxisWidget(myTabWg);
407 myAxes[ 1 ] = new AxisWidget(myTabWg);
408 myAxes[ 2 ] = new AxisWidget(myTabWg);
410 myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
411 myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
412 myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
414 myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
416 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
419 aLay->addWidget(myTabWg);
420 aLay->addWidget(myIsVisible);
426 Create frame containing buttons
428 QWidget* SVTK_CubeAxesDlg::createButtonFrame(QWidget* theParent)
430 QFrame* aFrame = new QFrame(theParent);
431 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
433 myOkBtn = new QPushButton(tr("BUT_OK"), aFrame);
434 myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
435 myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
437 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
439 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
443 aLay->addWidget(myOkBtn);
444 aLay->addWidget(myApplyBtn);
445 aLay->addItem(aSpacer);
446 aLay->addWidget(myCloseBtn);
448 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
449 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
450 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
458 SVTK_CubeAxesDlg::~SVTK_CubeAxesDlg()
463 Update dialog fields, connect signals and slots, show dialog
465 void SVTK_CubeAxesDlg::Update()
467 myActor = myMainWindow->GetCubeAxes();
469 myAxes[ 0 ]->ReadData(myActor->GetXAxisActor2D());
470 myAxes[ 1 ]->ReadData(myActor->GetYAxisActor2D());
471 myAxes[ 2 ]->ReadData(myActor->GetZAxisActor2D());
473 myIsVisible->setChecked(myActor->GetVisibility() ? true : false);
477 Verify validity of entry data
479 bool SVTK_CubeAxesDlg::isValid() const
485 Verify validity of entry data
487 bool SVTK_CubeAxesDlg::onApply()
493 QWidget *aCurrWid = this->focusWidget();
494 aCurrWid->clearFocus();
495 aCurrWid->setFocus();
497 isOk = isOk && myAxes[ 0 ]->Apply(myActor->GetXAxisActor2D());
498 isOk = isOk && myAxes[ 1 ]->Apply(myActor->GetYAxisActor2D());
499 isOk = isOk && myAxes[ 2 ]->Apply(myActor->GetZAxisActor2D());
502 //myActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
503 //myActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
504 //myActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
506 //myActor->SetNumberOfLabels(myActor->GetXAxisActor2D()->GetNumberOfLabels());
507 if (myIsVisible->isChecked())
508 myActor->VisibilityOn();
510 myActor->VisibilityOff();
513 myMainWindow->Repaint();
524 SLOT called when "Ok" button pressed.
526 void SVTK_CubeAxesDlg::onOk()
533 SLOT: called when "Close" button pressed. Close dialog
535 void SVTK_CubeAxesDlg::onClose()