3 @author Bruno M. Carvalho and Deniz Sarioz
4 licensed under (open-source) QPL v1.0
5 which accompanies this distribution in the file QPL
13 #include <qbuttongroup.h>
16 #include <qcombobox.h>
17 #include <qlineedit.h>
18 #include <qpushbutton.h>
19 #include <qradiobutton.h>
23 #include <qwhatsthis.h>
24 #include <qmessagebox.h>
27 * Constructs a stopwindow which is a child of 'parent', with the
28 * name 'name' and widget flags set to 'f'
30 * The dialog will by default be modeless, unless you set 'modal' to
31 * TRUE to construct a modal dialog.
33 @author Bruno M. Carvalho
35 stopwindow::stopwindow(QWidget* parent, const char* name, bool modal, WFlags fl) :
36 QDialog(parent, name, modal, fl)
39 setName("stopwindow");
42 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
43 sizePolicy().hasHeightForWidth()));
44 setMinimumSize(QSize(600, 340));
45 setMaximumSize(QSize(600, 340));
46 setCaption(tr("Stop Window"));
48 stoplabel = new QLabel(this, "stoplabel");
49 stoplabel->setGeometry(QRect(10, 10, 70, 30));
50 stoplabel->setSizePolicy(
51 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
52 stoplabel->sizePolicy().hasHeightForWidth()));
53 stoplabel->setMinimumSize(QSize(70, 30));
54 stoplabel->setMaximumSize(QSize(70, 30));
55 stoplabel->setText(tr("STOP"));
57 stopbuttongroup = new QButtonGroup(this, "stopbuttongroup");
58 stopbuttongroup->setGeometry(QRect(15, 45, 575, 205));
59 stopbuttongroup->setTitle(tr("type"));
60 stopbuttongroup->setAlignment(int(QButtonGroup::AlignHCenter));
62 iterationbutton = new QRadioButton(stopbuttongroup, "iterationbutton");
63 iterationbutton->setGeometry(QRect(10, 45, 118, 24));
64 iterationbutton->setText(tr("ITERATION"));
65 QObject::connect(iterationbutton, SIGNAL(clicked()), this,
66 SLOT(activateIterationFields()));
68 terminationbutton = new QRadioButton(stopbuttongroup, "terminationbutton");
69 terminationbutton->setGeometry(QRect(10, 100, 135, 24));
70 terminationbutton->setText(tr("TERMINATION"));
71 QObject::connect(terminationbutton, SIGNAL(clicked()), this,
72 SLOT(activateTerminationFields()));
74 nonebutton = new QRadioButton(stopbuttongroup, "nonebutton");
75 nonebutton->setGeometry(QRect(10, 150, 75, 24));
76 nonebutton->setText(tr("NONE"));
77 QObject::connect(nonebutton, SIGNAL(clicked()), this,
78 SLOT(deactivateFields()));
80 iter = new QLineEdit(stopbuttongroup, "iter");
81 iter->setGeometry(QRect(150, 40, 80, 30));
83 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
84 iter->sizePolicy().hasHeightForWidth()));
85 iter->setEnabled(FALSE);
87 iterlabel = new QLabel(stopbuttongroup, "iterlabel");
88 iterlabel->setGeometry(QRect(180, 20, 40, 20));
89 iterlabel->setText(tr("iter"));
90 iterlabel->setEnabled(FALSE);
92 testname = new QComboBox(stopbuttongroup, "testname");
93 testname->setGeometry(QRect(150, 100, 130, 30));
94 testname->setSizePolicy(
95 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
96 testname->sizePolicy().hasHeightForWidth()));
97 testname->insertItem("VARIANCE", -1);
98 testname->insertItem("MLST", -1);
99 testname->insertItem("KLDS", -1);
100 testname->insertItem("RESI", -1);
101 testname->insertItem("WSQD", -1);
102 testname->insertItem("TRM1", -1);
103 testname->insertItem("TRM2", -1);
104 testname->setEnabled(FALSE);
105 QObject::connect(testname,SIGNAL(activated(int)),this,SLOT(setEpsilon()));
107 testnamelabel = new QLabel(stopbuttongroup, "testnamelabel");
108 testnamelabel->setGeometry(QRect(175, 80, 80, 20));
109 testnamelabel->setText(tr("test_name"));
110 testnamelabel->setEnabled(FALSE);
112 epsilon = new QLineEdit(stopbuttongroup, "epsilon");
113 epsilon->setGeometry(QRect(290, 100, 80, 30));
114 epsilon->setSizePolicy(
115 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
116 epsilon->sizePolicy().hasHeightForWidth()));
117 epsilon->setEnabled(FALSE);
119 epsilonlabel = new QLabel(stopbuttongroup, "epsilonlabel");
120 epsilonlabel->setGeometry(QRect(305, 80, 60, 20));
121 epsilonlabel->setText(tr("epsilon"));
122 epsilonlabel->setEnabled(FALSE);
124 rprtcb = new QCheckBox( this, "rprtcb" );
125 rprtcb->setGeometry(QRect(400, 145, 80, 30));
126 rprtcb->setText( "RPRT" );
127 rprtcb->setChecked(false);
128 rprtcb->setEnabled(FALSE);
129 QObject::connect(rprtcb,SIGNAL(clicked()),this,SLOT(setSkips()));
131 skips = new QLineEdit(stopbuttongroup, "skips");
132 skips->setGeometry(QRect(470, 100, 80, 30));
133 skips->setSizePolicy(
134 QSizePolicy((QSizePolicy::SizeType) 0, (QSizePolicy::SizeType) 0,
135 skips->sizePolicy().hasHeightForWidth()));
136 skips->setEnabled(FALSE);
138 skipslabel = new QLabel(stopbuttongroup, "skipslabel");
139 skipslabel->setGeometry(QRect(485, 80, 60, 20));
140 skipslabel->setText(tr("skips"));
141 skipslabel->setEnabled(FALSE);
143 Line17 = new QFrame(this, "Line17");
144 Line17->setGeometry(QRect(-5, 265, 415, 16));
145 Line17->setFrameStyle(QFrame::HLine | QFrame::Sunken);
147 okbutton = new QPushButton(this, "okbutton");
148 okbutton->setGeometry(QRect(50, 290, 100, 40));
149 okbutton->setText(tr("OK"));
150 QObject::connect(okbutton, SIGNAL(clicked()), this, SLOT(checkValues()));
152 cancelbutton = new QPushButton(this, "cancelbutton");
153 cancelbutton->setGeometry(QRect(280, 290, 100, 40));
154 cancelbutton->setText(tr("Cancel"));
155 QObject::connect(cancelbutton, SIGNAL(clicked()), this, SLOT(reject()));
159 * Destroys the object and frees any allocated resources
161 stopwindow::~stopwindow()
163 // no need to delete child widgets, Qt does it all for us
166 /** Activates iteration fields
168 @author Bruno M. Carvalho
170 void stopwindow::activateIterationFields()
172 if (iterationbutton->isChecked())
174 iter->setEnabled(TRUE);
175 iterlabel->setEnabled(TRUE);
176 testname->setEnabled(FALSE);
177 testnamelabel->setEnabled(FALSE);
178 epsilon->setEnabled(FALSE);
179 epsilonlabel->setEnabled(FALSE);
183 iter->setEnabled(FALSE);
184 iterlabel->setEnabled(FALSE);
188 /** Activates termination fields
190 @author Bruno M. Carvalho
192 void stopwindow::activateTerminationFields()
194 if (terminationbutton->isChecked())
196 testname->setEnabled(TRUE);
197 testnamelabel->setEnabled(TRUE);
198 iter->setEnabled(FALSE);
199 iterlabel->setEnabled(FALSE);
204 testname->setEnabled(FALSE);
205 epsilon->setEnabled(FALSE);
206 epsilonlabel->setEnabled(FALSE);
207 testnamelabel->setEnabled(FALSE);
211 /** Deactivates iteration and termination subfields
213 @author Bruno M. Carvalho
215 void stopwindow::deactivateFields()
217 if (nonebutton->isChecked())
219 iter->setEnabled(FALSE);
220 iterlabel->setEnabled(FALSE);
221 testname->setEnabled(FALSE);
222 epsilon->setEnabled(FALSE);
223 epsilonlabel->setEnabled(FALSE);
224 testnamelabel->setEnabled(FALSE);
228 iter->setEnabled(TRUE);
229 iterlabel->setEnabled(TRUE);
230 testname->setEnabled(TRUE);
231 testnamelabel->setEnabled(TRUE);
236 void stopwindow::setEpsilon()
238 if (testname->currentText().contains("VARIANCE") || testname->currentText().contains("KLDS") || testname->currentText().contains("RESI") || testname->currentText().contains("WSQD"))
240 epsilon->setEnabled(TRUE);
241 epsilonlabel->setEnabled(TRUE);
245 epsilon->setEnabled(FALSE);
246 epsilonlabel->setEnabled(FALSE);
249 if (testname->currentText().contains("MLST") || testname->currentText().contains("KLDS") || testname->currentText().contains("RESI") || testname->currentText().contains("WSQD"))
251 rprtcb->setEnabled(TRUE);
255 rprtcb->setEnabled(FALSE);
259 void stopwindow::setSkips()
261 if (rprtcb->isChecked())
263 skips->setEnabled(TRUE);
264 skipslabel->setEnabled(TRUE);
268 skips->setEnabled(FALSE);
269 skipslabel->setEnabled(FALSE);
273 /** Returns a string for STOP input sequence
276 @author Bruno M. Carvalho
278 QString stopwindow::getOutput()
282 output.sprintf("STOP ");
283 if (iterationbutton->isChecked())
285 output.append("ITERATION ");
286 output += iter->text();
289 if (terminationbutton->isChecked())
291 output.append("TERMINATION ");
292 switch (testname->currentItem())
295 output.append("VARIANCE");
298 output.append("MLST");
301 output.append("KLDS");
304 output.append("RESI");
307 output.append("WSQD");
310 output.append("TRM1");
313 output.append("TRM2");
317 if (testname->currentText().contains("VARIANCE") || testname->currentText().contains("KLDS") || testname->currentText().contains("RESI") || testname->currentText().contains("WSQD"))
319 output += epsilon->text();
322 if (rprtcb->isChecked())
324 output.append(" RPRT");
326 float s = strtof((const char *) skips->text());
330 output += skips->text();
338 void stopwindow::checkValues()
345 if (iterationbutton->isChecked())
347 i = strtoi((const char *) iter->text());
353 if (terminationbutton->isChecked())
355 if (testname->currentText().contains("VARIANCE") || testname->currentText().contains("KLDS") || testname->currentText().contains("RESI") || testname->currentText().contains("WSQD"))
357 e = strtof((const char *) epsilon->text());
371 QMessageBox::information(this, "SnarkInput", "Error!\n"
372 "Invalid iter format.");
376 QMessageBox::information(this, "SnarkInput", "Error!\n"
377 "iter must be greater than 0.");
381 QMessageBox::information(this, "SnarkInput", "Error!\n"
382 "Invalid epsilon format.");
386 QMessageBox::information(this, "SnarkInput", "Error!\n"
387 "epsilon must be greater than 0.");