1 // Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "OCCViewer_SetRotationPointDlg.h"
21 #include <QtxAction.h>
23 #include "OCCViewer_ViewWindow.h"
25 #include <qlineedit.h>
26 #include <qgroupbox.h>
28 #include <qpushbutton.h>
30 #include <qvalidator.h>
31 #include <qbuttongroup.h>
32 #include <qobjectlist.h>
33 #include <qcheckbox.h>
38 \param view - view window
39 \param parent - parent widget
40 \param name - dialog name
41 \param modal - is this dialog modal
44 OCCViewer_SetRotationPointDlg::OCCViewer_SetRotationPointDlg( OCCViewer_ViewWindow* view, QWidget* parent, const char* name, bool modal, WFlags fl )
45 : QDialog( parent, "OCCViewer_SetRotationPointDlg", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
48 setCaption(tr("CAPTION"));
49 setSizeGripEnabled(TRUE);
51 // Create layout for this dialog
52 QGridLayout* layoutDlg = new QGridLayout (this);
53 layoutDlg->setSpacing(6);
54 layoutDlg->setMargin(11);
56 // Create check box "Use Bounding Box Center"
57 QHBox* aCheckBox = new QHBox(this);
59 myIsBBCenter = new QCheckBox(tr("USE_BBCENTER"), aCheckBox);
60 myIsBBCenter->setChecked(true);
61 connect(myIsBBCenter, SIGNAL(stateChanged(int)), SLOT(onBBCenterChecked()));
63 // Create croup button with radio buttons
64 myGroupSelButton = new QButtonGroup(2,Qt::Vertical,"",this);
65 myGroupSelButton->setMargin(11);
67 // Create "Set to Origin" button
68 myToOrigin = new QPushButton(myGroupSelButton);
69 myToOrigin->setText(tr("LBL_TOORIGIN"));
70 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
72 // Create "Select Point from View" button
73 mySelectPoint = new QPushButton(myGroupSelButton);
74 mySelectPoint->setText(tr("LBL_SELECTPOINT"));
75 mySelectPoint->setToggleButton(true);
76 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
78 // Create croup box with grid layout
79 myGroupBoxCoord = new QGroupBox(this, "GroupBox");
80 QHBoxLayout* aHBoxLayout = new QHBoxLayout(myGroupBoxCoord);
81 aHBoxLayout->setMargin(11);
82 aHBoxLayout->setSpacing(6);
85 QLabel* TextLabelX = new QLabel (tr("LBL_X"), myGroupBoxCoord, "TextLabelX");
86 TextLabelX->setFixedWidth(15);
87 myX = new QLineEdit(myGroupBoxCoord);
88 myX->setValidator(new QDoubleValidator(myX));
89 myX->setText(QString::number(0.0));
90 connect(myX, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
93 QLabel* TextLabelY = new QLabel (tr("LBL_Y"), myGroupBoxCoord, "TextLabelY");
94 TextLabelY->setFixedWidth(15);
95 myY = new QLineEdit(myGroupBoxCoord);
96 myY->setValidator(new QDoubleValidator(myY));
97 myY->setText(QString::number(0.0));
98 connect(myY, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
101 QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), myGroupBoxCoord, "TextLabelZ");
102 TextLabelZ->setFixedWidth(15);
103 myZ = new QLineEdit(myGroupBoxCoord);
104 myZ->setValidator(new QDoubleValidator(myZ));
105 myZ->setText(QString::number(0.0));
106 connect(myZ, SIGNAL(textChanged(const QString&)), this, SLOT(onCoordChanged()));
108 // Layout widgets in the horizontal group box
109 aHBoxLayout->addWidget(TextLabelX);
110 aHBoxLayout->addWidget(myX);
111 aHBoxLayout->addWidget(TextLabelY);
112 aHBoxLayout->addWidget(myY);
113 aHBoxLayout->addWidget(TextLabelZ);
114 aHBoxLayout->addWidget(myZ);
117 QGroupBox* aGroupBox = new QGroupBox(this);
118 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
119 aHBoxLayout2->setMargin(11);
120 aHBoxLayout2->setSpacing(6);
122 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox, "m_bClose");
123 m_bClose->setAutoDefault(TRUE);
124 m_bClose->setFixedSize(m_bClose->sizeHint());
125 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
128 aHBoxLayout2->addWidget(m_bClose);
130 // Layout top level widgets
131 layoutDlg->addWidget(aCheckBox,0,0);
132 layoutDlg->addWidget(myGroupSelButton,1,0);
133 layoutDlg->addWidget(myGroupBoxCoord,2,0);
134 layoutDlg->addWidget(aGroupBox,3,0);
136 setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
137 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
139 this->resize(400, this->sizeHint().height());
141 connect(view, SIGNAL(Show( QShowEvent * )), this, SLOT(onViewShow()));
142 connect(view, SIGNAL(Hide( QHideEvent * )), this, SLOT(onViewHide()));
146 * Destroys the object and frees any allocated resources
148 OCCViewer_SetRotationPointDlg
149 ::~OCCViewer_SetRotationPointDlg()
151 // no need to delete child widgets, Qt does it all for us
155 Return true if it is the first show for this dialog
158 OCCViewer_SetRotationPointDlg
161 return myIsBBCenter->isChecked() && myX->text().toDouble() == 0.
162 && myY->text().toDouble() == 0. && myZ->text().toDouble() == 0.;
166 OCCViewer_SetRotationPointDlg
167 ::setEnabled(QGroupBox* theGrp, const bool theState)
169 QObjectList aChildren(*theGrp->children());
171 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
173 if (anObj !=0 && anObj->inherits("QLineEdit"))
174 ((QLineEdit*)anObj)->setReadOnly(!theState);
175 if (anObj !=0 && anObj->inherits("QPushButton"))
176 ((QLineEdit*)anObj)->setEnabled(theState);
182 OCCViewer_SetRotationPointDlg
183 ::onBBCenterChecked()
185 setEnabled(myGroupSelButton,!myIsBBCenter->isChecked());
186 setEnabled(myGroupBoxCoord,!myIsBBCenter->isChecked());
188 if ( myIsBBCenter->isChecked() )
190 if ( mySelectPoint->state() == QButton::On )
191 mySelectPoint->toggle();
192 myView->activateSetRotationGravity();
195 myView->activateSetRotationSelected(myX->text().toDouble(),
196 myY->text().toDouble(),
197 myZ->text().toDouble());
201 OCCViewer_SetRotationPointDlg
204 if ( mySelectPoint->state() == QButton::On )
205 mySelectPoint->toggle();
207 myView->activateSetRotationSelected(myX->text().toDouble(),
208 myY->text().toDouble(),
209 myZ->text().toDouble());
213 OCCViewer_SetRotationPointDlg
216 if ( mySelectPoint->state() == QButton::On )
217 myView->activateStartPointSelection();
219 mySelectPoint->toggle();
223 OCCViewer_SetRotationPointDlg
226 if ( !myIsBBCenter->isChecked() )
228 if ( mySelectPoint->state() == QButton::On
230 ( myX->hasFocus() || myY->hasFocus() || myZ->hasFocus() ) )
231 mySelectPoint->toggle();
232 myView->activateSetRotationSelected(myX->text().toDouble(),
233 myY->text().toDouble(),
234 myZ->text().toDouble());
239 OCCViewer_SetRotationPointDlg
240 ::setCoords(double theX, double theY, double theZ)
242 myX->setText(QString::number(theX));
243 myY->setText(QString::number(theY));
244 myZ->setText(QString::number(theZ));
248 OCCViewer_SetRotationPointDlg
251 if ( !myIsBBCenter->isChecked() )
252 mySelectPoint->toggle();
256 OCCViewer_SetRotationPointDlg
259 myAction->setOn( false );
264 OCCViewer_SetRotationPointDlg
274 OCCViewer_SetRotationPointDlg