Fixed text file permissions
[snark14.git] / tools / Input / skunk.cpp
1 /** @file skunk.cpp
2     @package snark14Input
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
6 */
7
8 /****************************************************************************
9 ** Form implementation generated from reading ui file 'skunk.ui'
10 **
11 ** Created: Wed May 15 18:20:06 2002
12 **      by:  The User Interface Compiler (uic)
13 **
14 ** WARNING! All changes made in this file will be lost!
15 ****************************************************************************/
16 #include "skunk.h"
17 #include "misc.h"
18 #include "variables.h"
19
20 #include <qbuttongroup.h>
21 #include <qframe.h>
22 #include <qlineedit.h>
23 #include <qlabel.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
26 #include <qlayout.h>
27 #include <qvariant.h>
28 #include <qtooltip.h>
29 #include <qwhatsthis.h>
30 #include <qmessagebox.h>
31
32 /** 
33  *  Constructs a skunkwindow which is a child of 'parent', with the 
34  *  name 'name' and widget flags set to 'f' 
35  *
36  *  The dialog will by default be modeless, unless you set 'modal' to
37  *  TRUE to construct a modal dialog.
38 @param void
39 @author Bruno M. Carvalho
40 @version 1.0 */
41 skunkwindow::skunkwindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
42     : QDialog( parent, name, modal, fl )
43 {
44     if ( !name )
45         setName( "skunkwindow" );
46     resize( 400, 450 ); 
47     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
48     setMinimumSize( QSize( 400, 450 ) );
49     setMaximumSize( QSize( 400, 450 ) );
50     setCaption( tr( "Skunk Window" ) );
51
52     skunklabel = new QLabel( this, "skunklabel" );
53     skunklabel->setGeometry( QRect( 10, 10, 90, 30 ) ); 
54     skunklabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, skunklabel->sizePolicy().hasHeightForWidth() ) );
55     skunklabel->setMinimumSize( QSize( 90, 30 ) );
56     skunklabel->setMaximumSize( QSize( 90, 30 ) );
57     skunklabel->setText( tr( "SKUNK" ) );
58
59     skunkbuttongroup = new QButtonGroup( this, "skunkbuttongroup" );
60     skunkbuttongroup->setGeometry( QRect( 40, 40, 160, 120 ) ); 
61     skunkbuttongroup->setTitle( tr( "type" ) );
62     skunkbuttongroup->setAlignment( int( QButtonGroup::AlignHCenter ) );
63
64     phantombutton = new QRadioButton( skunkbuttongroup, "phantombutton" );
65     phantombutton->setGeometry( QRect( 10, 20, 110, 24 ) ); 
66     phantombutton->setText( tr( "PHANTOM" ) ); 
67
68     differencebutton = new QRadioButton( skunkbuttongroup, "differencebutton" );
69     differencebutton->setGeometry( QRect( 10, 50, 130, 24 ) ); 
70     differencebutton->setText( tr( "DIFFERENCE" ) );
71
72     nonebutton = new QRadioButton( skunkbuttongroup, "nonebutton" );
73     nonebutton->setGeometry( QRect( 10, 80, 80, 24 ) ); 
74     nonebutton->setText( tr( "NONE" ) );
75     nonebutton->setChecked(true);
76
77     minimumbutton = new QRadioButton( this, "minimumbutton" );
78     minimumbutton->setGeometry( QRect( 210, 50, 100, 30 ) ); 
79     minimumbutton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, minimumbutton->sizePolicy().hasHeightForWidth() ) );
80     minimumbutton->setMinimumSize( QSize( 100, 30 ) );
81     minimumbutton->setMaximumSize( QSize( 100, 30 ) );
82     minimumbutton->setText( tr( "MINIMUM" ) );
83     QObject::connect(minimumbutton,SIGNAL(clicked()),this,SLOT(activateMinimumFields()));
84
85     min = new QLineEdit( this, "min" );
86     min->setGeometry( QRect( 320, 50, 60, 28 ) ); 
87     min->setEnabled(FALSE);
88
89     minlabel = new QLabel( this, "min" );
90     minlabel->setGeometry( QRect( 335, 30, 40, 20 ) ); 
91     minlabel->setText( tr( "min" ) );
92     minlabel->setEnabled(FALSE);
93
94     maximumbutton = new QRadioButton( this, "maximumbutton" );
95     maximumbutton->setGeometry( QRect( 210, 100, 100, 30 ) ); 
96     maximumbutton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, maximumbutton->sizePolicy().hasHeightForWidth() ) );
97     maximumbutton->setMinimumSize( QSize( 100, 30 ) );
98     maximumbutton->setMaximumSize( QSize( 100, 30 ) );
99     maximumbutton->setText( tr( "MAXIMUM" ) );
100     QObject::connect(maximumbutton,SIGNAL(clicked()),this,SLOT(activateMaximumFields()));
101
102     max = new QLineEdit( this, "max" );
103     max->setGeometry( QRect( 320, 100, 60, 28 ) ); 
104     max->setEnabled(FALSE);
105
106     maxlabel = new QLabel( this, "max" );
107     maxlabel->setGeometry( QRect( 335, 80, 40, 20 ) ); 
108     maxlabel->setText( tr( "max" ) );
109     maxlabel->setEnabled(FALSE);
110
111     skunkbuttongroup2 = new QButtonGroup( this, "skunkbuttongroup2" );
112     skunkbuttongroup2->setGeometry( QRect( 40, 170, 160, 100 ) ); 
113     skunkbuttongroup2->setTitle( tr( "" ) );
114     skunkbuttongroup2->setAlignment( int( QButtonGroup::AlignHCenter ) );
115
116     amplitudebutton = new QRadioButton( skunkbuttongroup2, "amplitudebutton" );
117     amplitudebutton->setGeometry( QRect( 10, 10, 110, 24 ) ); 
118     amplitudebutton->setText( tr( "AMPLITUDE" ) );
119
120     intensitybutton = new QRadioButton( skunkbuttongroup2, "intensitybutton" );
121     intensitybutton->setGeometry( QRect( 10, 40, 130, 24 ) ); 
122     intensitybutton->setText( tr( "INTENSITY" ) ); 
123
124     nonebutton2 = new QRadioButton( skunkbuttongroup2, "nonebutton2" );
125     nonebutton2->setGeometry( QRect( 10, 70, 80, 24 ) ); 
126     nonebutton2->setText( tr( "NONE" ) ); 
127     nonebutton2->setChecked(true);
128
129 //     fuzzbutton = new QRadioButton( this, "fuzzbutton" );
130 //     fuzzbutton->setGeometry( QRect( 210, 190, 90, 30 ) ); 
131 //     fuzzbutton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, fuzzbutton->sizePolicy().hasHeightForWidth() ) );
132 //     fuzzbutton->setMinimumSize( QSize( 90, 30 ) );
133 //     fuzzbutton->setMaximumSize( QSize( 90, 30 ) );
134 //     fuzzbutton->setText( tr( "FUZZ" ) );
135
136     iterationflaglabel = new QLabel( this, "iterationflaglabel" );
137     iterationflaglabel->setGeometry( QRect( 130, 275, 130, 20 ) ); 
138     iterationflaglabel->setText( tr( "iteration_flag_line" ) );
139
140     iterationflagline = new QLineEdit( this, "iterationflagline" );
141     iterationflagline->setGeometry( QRect( 50, 295, 290, 30 ) ); 
142     iterationflagline->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, iterationflagline->sizePolicy().hasHeightForWidth() ) ); 
143
144     Line16 = new QFrame( this, "Line16" );
145     Line16->setGeometry( QRect( 0, 375, 400, 16 ) ); 
146     Line16->setFrameStyle( QFrame::HLine | QFrame::Sunken );
147
148     okbutton = new QPushButton( this, "okbutton" );
149     okbutton->setGeometry( QRect( 50, 390, 100, 40 ) ); 
150     okbutton->setText( tr( "OK" ) );
151     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
152
153     cancelbutton = new QPushButton( this, "cancelbutton" );
154     cancelbutton->setGeometry( QRect( 250, 390, 100, 40 ) ); 
155     cancelbutton->setText( tr( "Cancel" ) );
156     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
157 }
158
159 /**  
160  *  Destroys the object and frees any allocated resources
161  */
162 skunkwindow::~skunkwindow()
163 {
164     // no need to delete child widgets, Qt does it all for us
165 }
166
167
168 /** Activates minimum fields 
169 @param void
170 @author Bruno M. Carvalho
171 @version 1.0 */
172 void skunkwindow::activateMinimumFields()
173 {
174   if(minimumbutton->isChecked()) {
175     min->setEnabled(TRUE);
176     minlabel->setEnabled(TRUE);
177   }
178   else {
179     min->setEnabled(FALSE);
180     minlabel->setEnabled(FALSE);
181   }
182 }
183
184 /** Activates maximum fields 
185 @param void
186 @author Bruno M. Carvalho
187 @version 1.0 */
188 void skunkwindow::activateMaximumFields()
189 {
190   if(maximumbutton->isChecked()) {
191     max->setEnabled(TRUE);
192     maxlabel->setEnabled(TRUE);
193   }
194   else {
195     max->setEnabled(FALSE);
196     maxlabel->setEnabled(FALSE);
197   }
198 }
199
200
201 /** Returns a string for SKUNK input sequence
202 @param void
203 @return skunk
204 @author Bruno M. Carvalho
205 @version 1.0 */
206 QString skunkwindow::getOutput()
207 {
208   QString output;
209
210   output.sprintf("SKUNK ");
211   if(phantombutton->isChecked()) {
212     output.append("PHANTOM ");
213   }
214   else
215     if(differencebutton->isChecked()) {
216       output.append("DIFFERENCE ");
217     }
218   if(minimumbutton->isChecked()) {
219     output.append("MINIMUM ");
220     output+=min->text();
221     output.append(" ");
222   }
223   if(maximumbutton->isChecked()) {
224     output.append("MAXIMUM ");
225     output+=max->text();
226     output.append(" ");
227   }
228   if(amplitudebutton->isChecked()) {
229     output.append("AMPLITUDE ");
230   }
231   else
232     if(intensitybutton->isChecked()) {
233       output.append("INTENSITY ");
234     }
235   //  if(fuzzbutton->isChecked()) {
236   //      output.append("FUZZ ");
237   //  }
238   output.append("\n");
239   output+=iterationflagline->text();
240
241   return output;
242 }
243
244 void skunkwindow::checkValues()
245 {
246   int f=0;
247   float mi=0,ma=0;
248   
249   if(minimumbutton->isChecked()) {
250     mi=strtof((const char *)min->text());
251     if(errnum) 
252       f=1;
253   }
254   if(maximumbutton->isChecked()) {
255     ma=strtof((const char *)max->text());
256     if(errnum) 
257       f=2;
258     if(minimumbutton->isChecked()) {
259       if(mi>=ma && !f) 
260         f=3;
261     }
262   }
263   if(!isintspace(iterationflagline->text()))
264     f=4;
265   switch(f) {
266   case 0: accept();
267     break;
268   case 1: QMessageBox::information(this,"SnarkInput","Error!\n"
269                                    "Invalid min format");
270     break;
271   case 2: QMessageBox::information(this,"SnarkInput","Error!\n"
272                                    "Invalid max format");
273     break;
274   case 3: QMessageBox::information(this,"SnarkInput","Error!\n"
275                                    "min bigger than or equal to max");
276     break;
277   case 4: QMessageBox::information(this,"SnarkInput","Error!\n"
278                                    "iteration_flag_line must contain\n"
279                                    "only 0-9 and spaces and must\n"
280                                    "be non-empty");
281     break;
282   }
283 }
284