1 // Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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
20 // File: CurveCreator_UndoOptsDlg.cxx
21 // Author: Sergey KHROMOV
23 #include "CurveCreator_UndoOptsDlg.h"
25 #include <QButtonGroup>
26 #include <QGridLayout>
28 #include <QIntValidator>
30 #include <QPushButton>
31 #include <QRadioButton>
33 #define UNDO_DEPTH_UNLIMITED 0
34 #define UNDO_DEPTH_DISABLED 1
35 #define UNDO_DEPTH_FIX_SIZE 2
37 //=======================================================================
38 // function: Constructor
40 //=======================================================================
41 CurveCreator_UndoOptsDlg::CurveCreator_UndoOptsDlg(QWidget* parent)
43 myUndoDepth (UNDO_DEPTH_UNLIMITED),
45 myBufferSizeEdit (NULL),
49 setWindowTitle(tr("CC_UNDO_OPTIONS_TITLE"));
51 // Set Undo/Redo options group
52 QGroupBox *anUndoOptsGrp =
53 new QGroupBox(tr("CC_UNDO_OPTIONS_MODIFY"));
54 QGridLayout *anUndoOptsLO = new QGridLayout(anUndoOptsGrp);
55 QRadioButton *aDisabledRdBtn =
56 new QRadioButton(tr("CC_UNDO_OPTIONS_DISABLED"), anUndoOptsGrp);
57 QRadioButton *aFixSizeRdBtn =
58 new QRadioButton(tr("CC_UNDO_OPTIONS_FIXED_SIZE"), anUndoOptsGrp);
59 QRadioButton *anUnlimRdBtn =
60 new QRadioButton(tr("CC_UNDO_OPTIONS_UNLIMITED"), anUndoOptsGrp);
62 myOptsBtnGrp = new QButtonGroup(anUndoOptsGrp);
63 myBufferSizeEdit = new QLineEdit(anUndoOptsGrp);
64 anUndoOptsLO->setMargin(9);
65 anUndoOptsLO->setSpacing(6);
66 anUndoOptsLO->addWidget(aDisabledRdBtn, 0, 0);
67 anUndoOptsLO->addWidget(aFixSizeRdBtn, 1, 0);
68 anUndoOptsLO->addWidget(anUnlimRdBtn, 2, 0);
69 anUndoOptsLO->addWidget(myBufferSizeEdit, 1, 1);
70 myOptsBtnGrp->addButton(anUnlimRdBtn, UNDO_DEPTH_UNLIMITED);
71 myOptsBtnGrp->addButton(aDisabledRdBtn, UNDO_DEPTH_DISABLED);
72 myOptsBtnGrp->addButton(aFixSizeRdBtn, UNDO_DEPTH_FIX_SIZE);
74 // Set OK/Cancel buttons group
75 QGroupBox *anOkCancelGrp = new QGroupBox;
76 QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp);
78 myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp);
79 myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp);
80 anOkCancelLO->setMargin(9);
81 anOkCancelLO->setSpacing(6);
82 anOkCancelLO->addWidget(myOkBtn, 0, 0);
83 anOkCancelLO->addWidget(myCancelBtn, 0, 1);
86 QGroupBox *aMainGrp = new QGroupBox;
87 QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp);
89 aMainLO->addWidget(anUndoOptsGrp);
90 aMainLO->addWidget(anOkCancelGrp);
97 //=======================================================================
98 // function: Destructor
100 //=======================================================================
101 CurveCreator_UndoOptsDlg::~CurveCreator_UndoOptsDlg()
105 //=======================================================================
106 // function: setUndoDepth
108 //=======================================================================
109 void CurveCreator_UndoOptsDlg::setUndoDepth(const int theDepth)
111 myUndoDepth = theDepth;
113 const int aDepthId = myUndoDepth + 1;
114 int anId = UNDO_DEPTH_FIX_SIZE;
116 if (aDepthId == UNDO_DEPTH_UNLIMITED ||
117 aDepthId == UNDO_DEPTH_DISABLED) {
119 } else if (myUndoDepth > 0) {
120 myBufferSizeEdit->setText(QString::number(myUndoDepth));
123 myOptsBtnGrp->button(anId)->setChecked(true);
127 //=======================================================================
128 // function: getUndoDepth
130 //=======================================================================
131 int CurveCreator_UndoOptsDlg::getUndoDepth() const
136 //=======================================================================
137 // function: isEnabled
139 //=======================================================================
140 bool CurveCreator_UndoOptsDlg::isEnabled() const
142 return (myUndoDepth + 1 != UNDO_DEPTH_DISABLED);
145 //=======================================================================
146 // function: isUnlimited
148 //=======================================================================
149 bool CurveCreator_UndoOptsDlg::isUnlimited() const
151 return (myUndoDepth + 1 == UNDO_DEPTH_UNLIMITED);
154 //=======================================================================
157 //=======================================================================
158 void CurveCreator_UndoOptsDlg::init()
160 // Initialize sections group.
161 myOptsBtnGrp->setExclusive(true);
162 myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)->setChecked(true);
163 connect(myOptsBtnGrp, SIGNAL(buttonClicked(int)),
164 this, SLOT(optionChanged(int)));
166 // Initialize line edit.
167 QIntValidator *aValidator = new QIntValidator(myBufferSizeEdit);
169 aValidator->setBottom(1);
170 myBufferSizeEdit->setValidator(aValidator);
171 optionChanged(UNDO_DEPTH_UNLIMITED);
174 myOkBtn->setDefault(true);
176 connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
177 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
182 //=======================================================================
183 // function: setTabOrder
185 //=======================================================================
186 void CurveCreator_UndoOptsDlg::setTabOrder()
188 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_DISABLED),
189 myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE));
190 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE),
192 QWidget::setTabOrder(myBufferSizeEdit,
193 myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED));
194 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED), myOkBtn);
195 QWidget::setTabOrder(myOkBtn, myCancelBtn);
198 //=======================================================================
199 // function: optionChanged
201 //=======================================================================
202 void CurveCreator_UndoOptsDlg::optionChanged(int theId)
205 case UNDO_DEPTH_FIX_SIZE:
206 myBufferSizeEdit->setEnabled(true);
208 case UNDO_DEPTH_UNLIMITED:
209 case UNDO_DEPTH_DISABLED:
211 myBufferSizeEdit->setEnabled(false);
216 //=======================================================================
219 //=======================================================================
220 void CurveCreator_UndoOptsDlg::accept()
222 const int anId = myOptsBtnGrp->checkedId();
225 case UNDO_DEPTH_FIX_SIZE:
226 myUndoDepth = myBufferSizeEdit->text().toInt();
228 case UNDO_DEPTH_UNLIMITED:
229 case UNDO_DEPTH_DISABLED:
230 myUndoDepth = anId - 1;