]> SALOME platform Git repositories - modules/geom.git/blob - src/CurveCreator/CurveCreator_UndoOptsDlg.cxx
Salome HOME
CurveCreator was updated
[modules/geom.git] / src / CurveCreator / CurveCreator_UndoOptsDlg.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, 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.
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 // File:        CurveCreator_UndoOptsDlg.cxx
24 // Created:     Wed Jul  17 12:50:46 2013
25 // Author:      Sergey KHROMOV
26 //
27
28
29 #include <CurveCreator_UndoOptsDlg.h>
30 #include <QButtonGroup>
31 #include <QGridLayout>
32 #include <QGroupBox>
33 #include <QIntValidator>
34 #include <QLineEdit>
35 #include <QPushButton>
36 #include <QRadioButton>
37
38 #define UNDO_DEPTH_UNLIMITED  0
39 #define UNDO_DEPTH_DISABLED   1
40 #define UNDO_DEPTH_FIX_SIZE   2
41
42 //=======================================================================
43 // function: Constructor
44 // purpose:
45 //=======================================================================
46 CurveCreator_UndoOptsDlg::CurveCreator_UndoOptsDlg(QWidget* parent)
47   : QDialog          (parent),
48     myUndoDepth      (UNDO_DEPTH_UNLIMITED),
49     myOptsBtnGrp     (NULL),
50     myBufferSizeEdit (NULL),
51     myOkBtn          (NULL),
52     myCancelBtn      (NULL)
53 {
54   setWindowTitle(tr("CC_UNDO_OPTIONS_TITLE"));
55
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);
66
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);
78
79   // Set OK/Cancel buttons group
80   QGroupBox   *anOkCancelGrp  = new QGroupBox;
81   QGridLayout *anOkCancelLO   = new QGridLayout(anOkCancelGrp);
82
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);
89
90   // Set main group
91   QGroupBox   *aMainGrp = new QGroupBox;
92   QVBoxLayout *aMainLO = new QVBoxLayout(aMainGrp);
93
94   aMainLO->addWidget(anUndoOptsGrp);
95   aMainLO->addWidget(anOkCancelGrp);
96
97   setLayout(aMainLO);
98
99   init();
100 }
101
102 //=======================================================================
103 // function: Destructor
104 // purpose:
105 //=======================================================================
106 CurveCreator_UndoOptsDlg::~CurveCreator_UndoOptsDlg()
107 {
108 }
109
110 //=======================================================================
111 // function: setUndoDepth
112 // purpose:
113 //=======================================================================
114 void CurveCreator_UndoOptsDlg::setUndoDepth(const int theDepth)
115 {
116   myUndoDepth = theDepth;
117
118   const int aDepthId = myUndoDepth + 1;
119   int       anId     = UNDO_DEPTH_FIX_SIZE;
120
121   if (aDepthId == UNDO_DEPTH_UNLIMITED ||
122       aDepthId == UNDO_DEPTH_DISABLED) {
123     anId = aDepthId;
124   } else if (myUndoDepth > 0) {
125     myBufferSizeEdit->setText(QString::number(myUndoDepth));
126   }
127
128   myOptsBtnGrp->button(anId)->setChecked(true);
129   optionChanged(anId);
130 }
131
132 //=======================================================================
133 // function: getUndoDepth
134 // purpose:
135 //=======================================================================
136 int CurveCreator_UndoOptsDlg::getUndoDepth() const
137 {
138   return myUndoDepth;
139 }
140
141 //=======================================================================
142 // function: isEnabled
143 // purpose:
144 //=======================================================================
145 bool CurveCreator_UndoOptsDlg::isEnabled() const
146 {
147   return (myUndoDepth + 1 != UNDO_DEPTH_DISABLED);
148 }
149
150 //=======================================================================
151 // function: isUnlimited
152 // purpose:
153 //=======================================================================
154 bool CurveCreator_UndoOptsDlg::isUnlimited() const
155 {
156   return (myUndoDepth + 1 == UNDO_DEPTH_UNLIMITED);
157 }
158
159 //=======================================================================
160 // function: init
161 // purpose:
162 //=======================================================================
163 void CurveCreator_UndoOptsDlg::init()
164 {
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)));
170
171   // Initialize line edit.
172   QIntValidator *aValidator = new QIntValidator(myBufferSizeEdit);
173
174   aValidator->setBottom(1);
175   myBufferSizeEdit->setValidator(aValidator);
176   optionChanged(UNDO_DEPTH_UNLIMITED);
177
178   // Init buttons.
179   myOkBtn->setDefault(true);
180
181   connect(myOkBtn,     SIGNAL(clicked()), this, SLOT(accept()));
182   connect(myCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
183
184   setTabOrder();
185 }
186
187 //=======================================================================
188 // function: setTabOrder
189 // purpose:
190 //=======================================================================
191 void CurveCreator_UndoOptsDlg::setTabOrder()
192 {
193   QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_DISABLED),
194                        myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE));
195   QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_FIX_SIZE),
196                        myBufferSizeEdit);
197   QWidget::setTabOrder(myBufferSizeEdit,
198                        myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED));
199   QWidget::setTabOrder(myOptsBtnGrp->button(UNDO_DEPTH_UNLIMITED), myOkBtn);
200   QWidget::setTabOrder(myOkBtn, myCancelBtn);
201 }
202
203 //=======================================================================
204 // function: optionChanged
205 // purpose:
206 //=======================================================================
207 void CurveCreator_UndoOptsDlg::optionChanged(int theId)
208 {
209   switch (theId) {
210     case UNDO_DEPTH_FIX_SIZE:
211       myBufferSizeEdit->setEnabled(true);
212       break;
213     case UNDO_DEPTH_UNLIMITED:
214     case UNDO_DEPTH_DISABLED:
215     default:
216       myBufferSizeEdit->setEnabled(false);
217       break;
218   }
219 }
220
221 //=======================================================================
222 // function: accept
223 // purpose:
224 //=======================================================================
225 void CurveCreator_UndoOptsDlg::accept()
226 {
227   const int anId = myOptsBtnGrp->checkedId();
228
229   switch (anId) {
230     case UNDO_DEPTH_FIX_SIZE:
231       myUndoDepth = myBufferSizeEdit->text().toInt();
232       break;
233     case UNDO_DEPTH_UNLIMITED:
234     case UNDO_DEPTH_DISABLED:
235       myUndoDepth = anId - 1;
236       break;
237     default:
238       break;
239   }
240
241   QDialog::accept();
242 }