1 // Copyright (C) 2007-2013 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
23 // File: CurveCreator_UndoOptsDlg.cxx
24 // Created: Wed Jul 17 12:50:46 2013
25 // Author: Sergey KHROMOV
29 #include <CurveCreator_UndoOptsDlg.h>
30 #include <QButtonGroup>
31 #include <QGridLayout>
33 #include <QIntValidator>
35 #include <QPushButton>
36 #include <QRadioButton>
38 #define UNDO_DEPTH_UNLIMITED 0
39 #define UNDO_DEPTH_DISABLED 1
40 #define UNDO_DEPTH_FIX_SIZE 2
42 //=======================================================================
43 // function: Constructor
45 //=======================================================================
46 CurveCreator_UndoOptsDlg::CurveCreator_UndoOptsDlg(QWidget* parent)
48 myUndoDepth (UNDO_DEPTH_UNLIMITED),
50 myBufferSizeEdit (NULL),
54 setWindowTitle(tr("CC_UNDO_OPTIONS_TITLE"));
56 // Set Undo/Redo options group
57 QGroupBox *anUndoOptsGrp =
58 new QGroupBox(tr("CC_UNDO_OPTIONS_MODIFY"));
59 QGridLayout *anUndoOptsLO = new QGridLayout(anUndoOptsGrp);
60 QRadioButton *aDisabledRdBtn =
61 new QRadioButton(tr("CC_UNDO_OPTIONS_DISABLED"), anUndoOptsGrp);
62 QRadioButton *aFixSizeRdBtn =
63 new QRadioButton(tr("CC_UNDO_OPTIONS_FIXED_SIZE"), anUndoOptsGrp);
64 QRadioButton *anUnlimRdBtn =
65 new QRadioButton(tr("CC_UNDO_OPTIONS_UNLIMITED"), anUndoOptsGrp);
67 myOptsBtnGrp = new QButtonGroup(anUndoOptsGrp);
68 myBufferSizeEdit = new QLineEdit(anUndoOptsGrp);
69 anUndoOptsLO->setMargin(9);
70 anUndoOptsLO->setSpacing(6);
71 anUndoOptsLO->addWidget(aDisabledRdBtn, 0, 0);
72 anUndoOptsLO->addWidget(aFixSizeRdBtn, 1, 0);
73 anUndoOptsLO->addWidget(anUnlimRdBtn, 2, 0);
74 anUndoOptsLO->addWidget(myBufferSizeEdit, 1, 1);
75 myOptsBtnGrp->addButton(anUnlimRdBtn, UNDO_DEPTH_UNLIMITED);
76 myOptsBtnGrp->addButton(aDisabledRdBtn, UNDO_DEPTH_DISABLED);
77 myOptsBtnGrp->addButton(aFixSizeRdBtn, UNDO_DEPTH_FIX_SIZE);
79 // Set OK/Cancel buttons group
80 QGroupBox *anOkCancelGrp = new QGroupBox;
81 QGridLayout *anOkCancelLO = new QGridLayout(anOkCancelGrp);
83 myOkBtn = new QPushButton(tr("GEOM_BUT_OK"), anOkCancelGrp);
84 myCancelBtn = new QPushButton(tr("GEOM_BUT_CANCEL"), anOkCancelGrp);
85 anOkCancelLO->setMargin(9);
86 anOkCancelLO->setSpacing(6);
87 anOkCancelLO->addWidget(myOkBtn, 0, 0);
88 anOkCancelLO->addWidget(myCancelBtn, 0, 1);
91 QGroupBox *aMainGrp = new QGroupBox;
92 QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp);
94 aMainLO->addWidget(anUndoOptsGrp);
95 aMainLO->addWidget(anOkCancelGrp);
102 //=======================================================================
103 // function: Destructor
105 //=======================================================================
106 CurveCreator_UndoOptsDlg::~CurveCreator_UndoOptsDlg()
110 //=======================================================================
111 // function: setUndoDepth
113 //=======================================================================
114 void CurveCreator_UndoOptsDlg::setUndoDepth(const int theDepth)
116 myUndoDepth = theDepth;
118 const int aDepthId = myUndoDepth + 1;
119 int anId = UNDO_DEPTH_FIX_SIZE;
121 if (aDepthId == UNDO_DEPTH_UNLIMITED ||
122 aDepthId == UNDO_DEPTH_DISABLED) {
124 } else if (myUndoDepth > 0) {
125 myBufferSizeEdit->setText(QString::number(myUndoDepth));
128 myOptsBtnGrp->button(anId)->setChecked(true);
132 //=======================================================================
133 // function: getUndoDepth
135 //=======================================================================
136 int CurveCreator_UndoOptsDlg::getUndoDepth() const
141 //=======================================================================
142 // function: isEnabled
144 //=======================================================================
145 bool CurveCreator_UndoOptsDlg::isEnabled() const
147 return (myUndoDepth + 1 != UNDO_DEPTH_DISABLED);
150 //=======================================================================
151 // function: isUnlimited
153 //=======================================================================
154 bool CurveCreator_UndoOptsDlg::isUnlimited() const
156 return (myUndoDepth + 1 == UNDO_DEPTH_UNLIMITED);
159 //=======================================================================
162 //=======================================================================
163 void CurveCreator_UndoOptsDlg::init()
165 // Initialize sections group.
166 myOptsBtnGrp->setExclusive(true);
167 myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED)->setChecked(true);
168 connect(myOptsBtnGrp, SIGNAL(buttonClicked(int)),
169 this, SLOT(optionChanged(int)));
171 // Initialize line edit.
172 QIntValidator *aValidator = new QIntValidator(myBufferSizeEdit);
174 aValidator->setBottom(1);
175 myBufferSizeEdit->setValidator(aValidator);
176 optionChanged(UNDO_DEPTH_UNLIMITED);
179 myOkBtn->setDefault(true);
181 connect(myOkBtn, SIGNAL(clicked()), this, SLOT(accept()));
182 connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
187 //=======================================================================
188 // function: setTabOrder
190 //=======================================================================
191 void CurveCreator_UndoOptsDlg::setTabOrder()
193 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_DISABLED),
194 myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE));
195 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE),
197 QWidget::setTabOrder(myBufferSizeEdit,
198 myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED));
199 QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED), myOkBtn);
200 QWidget::setTabOrder(myOkBtn, myCancelBtn);
203 //=======================================================================
204 // function: optionChanged
206 //=======================================================================
207 void CurveCreator_UndoOptsDlg::optionChanged(int theId)
210 case UNDO_DEPTH_FIX_SIZE:
211 myBufferSizeEdit->setEnabled(true);
213 case UNDO_DEPTH_UNLIMITED:
214 case UNDO_DEPTH_DISABLED:
216 myBufferSizeEdit->setEnabled(false);
221 //=======================================================================
224 //=======================================================================
225 void CurveCreator_UndoOptsDlg::accept()
227 const int anId = myOptsBtnGrp->checkedId();
230 case UNDO_DEPTH_FIX_SIZE:
231 myUndoDepth = myBufferSizeEdit->text().toInt();
233 case UNDO_DEPTH_UNLIMITED:
234 case UNDO_DEPTH_DISABLED:
235 myUndoDepth = anId - 1;