Salome HOME
updated copyright message
[modules/gui.git] / src / ViewerTools / ViewerTools_CubeAxesDlgBase.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "ViewerTools_CubeAxesDlgBase.h"
24
25 #include "ViewerTools_FontWidgetBase.h"
26
27 #include "QtxAction.h"
28 #include "QtxIntSpinBox.h"
29
30 #include <QHBoxLayout>
31 #include <QVBoxLayout>
32 #include <QPushButton>
33 #include <QTabWidget>
34 #include <QCheckBox>
35 #include <QGroupBox>
36 #include <QLineEdit>
37 #include <QLabel>
38
39 /*!
40  * Class       : ViewerTools_AxisWidgetBase
41  * Description : Axis tab widget of the "Graduated axis" dialog box
42 */
43
44 /*!
45   Constructor
46 */
47 ViewerTools_AxisWidgetBase::ViewerTools_AxisWidgetBase (QWidget* theParent)
48 : QFrame(theParent)
49 {
50 }
51
52 /*!
53   Destructor
54 */
55 ViewerTools_AxisWidgetBase::~ViewerTools_AxisWidgetBase()
56 {
57 }
58
59 /*!
60   Initialize controls
61 */
62 void ViewerTools_AxisWidgetBase::initialize()
63 {
64   QList< QLabel* > aLabels;
65
66   // "Name" grp
67
68   myNameGrp = new QGroupBox(ViewerTools_CubeAxesDlgBase::tr("AXIS_NAME"), this);
69   myNameGrp->setCheckable( true );
70
71   QVBoxLayout* aVBox = new QVBoxLayout;
72   
73   QHBoxLayout* aHBox = new QHBoxLayout;
74   aHBox->setSpacing(5);
75   QLabel* aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("NAME"));
76   aHBox->addWidget(aLabel);
77   myAxisName = new QLineEdit;
78   aHBox->addWidget(myAxisName);
79   aLabels.append(aLabel);
80   aVBox->addLayout(aHBox);
81
82   aHBox = new QHBoxLayout;
83   aHBox->setSpacing(5);
84   aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("FONT"));
85   aHBox->addWidget(aLabel);
86   myNameFont = createFontWidget(myNameGrp);
87   aHBox->addWidget(myNameFont);
88   aLabels.append(aLabel);
89   aVBox->addLayout(aHBox);
90
91   myNameGrp->setLayout(aVBox);
92
93   // "Labels" grp
94
95   myLabelsGrp = new QGroupBox(ViewerTools_CubeAxesDlgBase::tr("LABELS"), this);
96   myLabelsGrp->setCheckable( true );
97
98   aVBox = new QVBoxLayout;
99
100   aHBox = new QHBoxLayout;
101   aHBox->setSpacing(5);
102   aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("NUMBER"));
103   aHBox->addWidget(aLabel);
104   myLabelNumber = new QtxIntSpinBox(2,25,1,myLabelsGrp);
105   aHBox->addWidget(myLabelNumber);
106   aLabels.append(aLabel);
107   aVBox->addLayout(aHBox);
108
109   aHBox = new QHBoxLayout;
110   aHBox->setSpacing(5);
111   aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("OFFSET"));
112   aHBox->addWidget(aLabel);
113   myLabelOffset = new QtxIntSpinBox(0,100,1,myLabelsGrp);
114   aHBox->addWidget(myLabelOffset);
115   aLabels.append(aLabel);
116   aVBox->addLayout(aHBox);
117
118   aHBox = new QHBoxLayout;
119   aHBox->setSpacing(5);
120   aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("FONT"));
121   aHBox->addWidget(aLabel);
122   myLabelsFont = createFontWidget(myLabelsGrp);
123   aHBox->addWidget(myLabelsFont);
124   aLabels.append(aLabel);
125   aVBox->addLayout(aHBox);
126
127   myLabelsGrp->setLayout(aVBox);
128
129   // "Tick marks" grp
130
131   myTicksGrp = new QGroupBox(ViewerTools_CubeAxesDlgBase::tr("TICK_MARKS"), this);
132   myTicksGrp->setCheckable( true );
133
134   aVBox = new QVBoxLayout;
135
136   aHBox = new QHBoxLayout;
137   aHBox->setSpacing(5);
138   aLabel = new QLabel(ViewerTools_CubeAxesDlgBase::tr("LENGTH"));
139   aHBox->addWidget(aLabel);
140   myTickLength = new QtxIntSpinBox(0,100,1,myTicksGrp);
141   aHBox->addWidget(myTickLength);
142   aLabels.append(aLabel);
143   aVBox->addLayout(aHBox);
144
145   myTicksGrp->setLayout(aVBox);
146
147   // Layout
148
149   QVBoxLayout* aLay = new QVBoxLayout(this);
150   aLay->setMargin(5);
151   aLay->setSpacing(5);
152   aLay->addWidget(myNameGrp);
153   aLay->addWidget(myLabelsGrp);
154   aLay->addWidget(myTicksGrp);
155
156   // init
157   myNameGrp->setChecked( true );
158   myLabelsGrp->setChecked( true );
159   myTicksGrp->setChecked( true );
160
161   // Adjust label widths
162   QList< QLabel* >::iterator anIter;
163   int aMaxWidth = 0;
164   for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
165     aMaxWidth = qMax(aMaxWidth, (*anIter)->sizeHint().width());
166   for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
167     (*anIter)->setFixedWidth(aMaxWidth);
168 }
169
170 void ViewerTools_AxisWidgetBase::UseName(const bool toUse)
171 {
172   myNameGrp->setChecked(toUse);
173 }
174
175 void ViewerTools_AxisWidgetBase::SetName(const QString& theName)
176 {
177   myAxisName->setText(theName);
178 }
179
180 void ViewerTools_AxisWidgetBase::SetNameFont(const QColor& theColor,
181                                              const int theFont,
182                                              const bool theIsBold,
183                                              const bool theIsItalic,
184                                              const bool theIsShadow)
185 {
186   myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
187 }
188
189 /*
190   Class       : ViewerTools_CubeAxesDlgBase
191   Description : Dialog for specifying cube axes properties
192 */
193
194 /*!
195   Constructor
196 */
197 ViewerTools_CubeAxesDlgBase::ViewerTools_CubeAxesDlgBase(QtxAction* theAction,
198                                                          QWidget* theParent,
199                                                          const char* theName):
200   ViewerTools_DialogBase(theAction,
201                          theParent,
202                          theName)
203 {
204   setWindowTitle(tr("CAPTION"));
205 }
206
207 /*!
208   Initialize controls
209 */
210 void ViewerTools_CubeAxesDlgBase::initialize()
211 {
212   QVBoxLayout* aLay = new QVBoxLayout(this);
213   aLay->setMargin(5);
214   aLay->setSpacing(5);
215   aLay->addWidget(createMainFrame(this));
216   aLay->addWidget(createButtonFrame(this));
217 }
218
219 /*!
220   Create frame containing dialog's input fields
221 */
222 QWidget* ViewerTools_CubeAxesDlgBase::createMainFrame(QWidget* theParent)
223 {
224   QFrame* aFrame = new QFrame(theParent);
225
226   myTabWg = new QTabWidget(aFrame);
227
228   myAxes[ 0 ] = createAxisWidget(myTabWg);
229   myAxes[ 1 ] = createAxisWidget(myTabWg);
230   myAxes[ 2 ] = createAxisWidget(myTabWg);
231
232   myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
233   myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
234   myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
235
236   myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
237
238   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
239   aLay->setMargin(0);
240   aLay->setSpacing(5);
241   aLay->addWidget(myTabWg);
242   aLay->addWidget(myIsVisible);
243
244   return aFrame;
245 }
246
247 /*!
248   Create frame containing buttons
249 */
250 QWidget* ViewerTools_CubeAxesDlgBase::createButtonFrame(QWidget* theParent)
251 {
252   QFrame* aFrame = new QFrame(theParent);
253   aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
254
255   myOkBtn    = new QPushButton(tr("BUT_OK"), aFrame);
256   myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
257   myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
258
259   QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
260
261   QHBoxLayout* aLay = new QHBoxLayout(aFrame);
262   aLay->setMargin(5);
263   aLay->setSpacing(5);
264
265   aLay->addWidget(myOkBtn);
266   aLay->addWidget(myApplyBtn);
267   aLay->addItem(aSpacer);
268   aLay->addWidget(myCloseBtn);
269
270   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
271   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
272   connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
273
274   return aFrame;
275 }
276
277 /*!
278   Destructor
279 */
280 ViewerTools_CubeAxesDlgBase::~ViewerTools_CubeAxesDlgBase()
281 {
282 }
283
284 /*!
285   Update dialog fields, connect signals and slots, show dialog
286 */
287 void ViewerTools_CubeAxesDlgBase::Update()
288 {
289 }
290
291 /*!
292   Verify validity of entry data
293 */
294 bool ViewerTools_CubeAxesDlgBase::isValid() const
295 {
296   return true;
297 }
298
299 /*!
300   Verify validity of entry data
301 */
302 bool ViewerTools_CubeAxesDlgBase::onApply()
303 {
304   return true;
305 }
306
307 /*!
308   SLOT called when "Ok" button pressed.
309 */
310 void ViewerTools_CubeAxesDlgBase::onOk()
311 {
312   if (onApply())
313     onClose();
314 }
315
316 /*!
317   SLOT: called when "Close" button pressed. Close dialog
318 */
319 void ViewerTools_CubeAxesDlgBase::onClose()
320 {
321   reject();
322 }