Fixed text file permissions
[snark14.git] / tools / Input / lines.cpp
1 /** @file lines.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 #include "lines.h"
9 #include "misc.h"
10 #include "variables.h"
11
12 #include <qcheckbox.h>
13 #include <qframe.h>
14 #include <qlabel.h>
15 #include <qlineedit.h>
16 #include <qpushbutton.h>
17 #include <qradiobutton.h>
18 #include <qlayout.h>
19 #include <qvariant.h>
20 #include <qtooltip.h>
21 #include <qwhatsthis.h>
22 #include <qmessagebox.h>
23
24 /** 
25  *  Constructs a lineswindow which is a child of 'parent', with the 
26  *  name 'name' and widget flags set to 'f' 
27  *
28  *  The dialog will by default be modeless, unless you set 'modal' to
29  *  TRUE to construct a modal dialog.
30 @param void
31 @author Bruno M. Carvalho
32 @version 1.0 */
33 lineswindow::lineswindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
34     : QDialog( parent, name, modal, fl )
35 {
36     if ( !name )
37         setName( "lineswindow" );
38     resize( 400, 350 ); 
39     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
40     setMinimumSize( QSize( 400, 350 ) );
41     setMaximumSize( QSize( 400, 350 ) );
42     setCaption( tr( "Lines Window" ) );
43
44     lineslabel = new QLabel( this, "lineslabel" );
45     lineslabel->setGeometry( QRect( 10, 10, 70, 30 ) ); 
46     lineslabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, lineslabel->sizePolicy().hasHeightForWidth() ) );
47     lineslabel->setMinimumSize( QSize( 70, 30 ) );
48     lineslabel->setMaximumSize( QSize( 70, 30 ) );
49     lineslabel->setText( tr( "LINES" ) );
50
51     scalebox = new QCheckBox( this, "scalebox" );
52     scalebox->setGeometry( QRect( 30, 60, 80, 30 ) ); 
53     scalebox->setText( tr( "SCALE" ) );
54     QObject::connect(scalebox,SIGNAL(clicked()),this,SLOT(activateScaleFields()));
55
56     scale = new QLineEdit( this, "scale" );
57     scale->setGeometry( QRect( 150, 60, 50, 30 ) ); 
58     scale->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, scale->sizePolicy().hasHeightForWidth() ) );
59     scale->setEnabled(FALSE);
60
61     scalelabel = new QLabel( this, "scalelabel" );
62     scalelabel->setGeometry( QRect( 150, 40, 40, 20 ) ); 
63     scalelabel->setText( tr( "scale" ) );
64     scalelabel->setEnabled(FALSE);
65
66     columnslabel = new QLabel( this, "columnslabel" );
67     columnslabel->setGeometry( QRect( 30, 130, 100, 30 ) ); 
68     columnslabel->setText( tr( "COLUMNS" ) );
69
70     col1 = new QLineEdit( this, "col1" );
71     col1->setGeometry( QRect( 150, 130, 50, 30 ) ); 
72     col1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, col1->sizePolicy().hasHeightForWidth() ) );
73
74     col1label = new QLabel( this, "col1label" );
75     col1label->setGeometry( QRect( 160, 110, 30, 20 ) ); 
76     col1label->setText( tr( "col1" ) );
77
78     col2 = new QLineEdit( this, "col2" );
79     col2->setGeometry( QRect( 210, 130, 50, 30 ) ); 
80     col2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, col2->sizePolicy().hasHeightForWidth() ) );
81
82     col2label = new QLabel( this, "col2label" );
83     col2label->setGeometry( QRect( 220, 110, 30, 20 ) ); 
84     col2label->setText( tr( "col2" ) );
85
86     col3 = new QLineEdit( this, "col3" );
87     col3->setGeometry( QRect( 270, 130, 50, 30 ) ); 
88     col3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, col3->sizePolicy().hasHeightForWidth() ) );
89
90     col3label = new QLabel( this, "col3label" );
91     col3label->setGeometry( QRect( 280, 110, 30, 20 ) ); 
92     col3label->setText( tr( "col3" ) );
93
94     col4 = new QLineEdit( this, "col4" );
95     col4->setGeometry( QRect( 330, 130, 50, 30 ) ); 
96     col4->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, col4->sizePolicy().hasHeightForWidth() ) );
97
98     col4label = new QLabel( this, "col4label" );
99     col4label->setGeometry( QRect( 340, 110, 30, 20 ) ); 
100     col4label->setText( tr( "col4" ) );
101
102     iterationflaglabel = new QLabel( this, "iterationflaglabel" );
103     iterationflaglabel->setGeometry( QRect( 135, 190, 130, 20 ) ); 
104     iterationflaglabel->setText( tr( "iteration_flag_line" ) );
105
106     iterationflagline = new QLineEdit( this, "iterationflagline" );
107     iterationflagline->setGeometry( QRect( 50, 210, 310, 30 ) ); 
108
109     okbutton = new QPushButton( this, "okbutton" );
110     okbutton->setGeometry( QRect( 50, 290, 100, 40 ) ); 
111     okbutton->setText( tr( "OK" ) );
112     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
113
114     cancelbutton = new QPushButton( this, "cancelbutton" );
115     cancelbutton->setGeometry( QRect( 250, 290, 100, 40 ) ); 
116     cancelbutton->setText( tr( "Cancel" ) );
117     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
118
119     Line7 = new QFrame( this, "Line7" );
120     Line7->setGeometry( QRect( 0, 275, 400, 1 ) ); 
121     Line7->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 
122 }
123
124 /**  
125  *  Destroys the object and frees any allocated resources
126  */
127 lineswindow::~lineswindow()
128 {
129     // no need to delete child widgets, Qt does it all for us
130 }
131
132 /** Activates scale subfields 
133 @param void
134 @author Bruno M. Carvalho
135 @version 1.0 */
136 void lineswindow::activateScaleFields()
137 {
138   if(scalebox->isChecked()) {
139     scale->setEnabled(TRUE);
140     scalelabel->setEnabled(TRUE);
141   }
142   else {
143     scale->setEnabled(FALSE);
144     scalelabel->setEnabled(FALSE);
145   }
146 }
147
148 /** Returns a string for LINES input sequence
149 @param void
150 @return lines
151 @author Bruno M. Carvalho
152 @version 1.0 */
153 QString lineswindow::getOutput()
154 {
155   QString output;
156
157  
158   output.sprintf("LINES ");
159   if(scalebox->isChecked()) {
160     output.append("SCALE ");
161     output+=scale->text();
162     output.append(" ");
163   }
164   output.append("COLUMNS ");
165   output+=col1->text();
166   output.append(" ");
167   output+=col2->text();
168   output.append(" ");
169   output+=col3->text();
170   output.append(" ");
171   output+=col4->text();
172   output.append(" ");
173   output.append("\n");
174   output+=iterationflagline->text();
175   //output.append("\n");
176
177   return output;
178 }
179
180 void lineswindow::checkValues()
181 {
182   int f=0,c1,c2,c3,c4;
183   float s=0;
184   
185   if(scalebox->isChecked()) {
186     s=strtof((const char *)scale->text());
187     if(errnum) 
188       f=1;
189     if(s<=0)
190       f=2;
191   }
192   c1=strtoi((const char *)col1->text());
193   if(errnum) 
194     f=3;
195   c2=strtoi((const char *)col2->text());
196   if(errnum==1) 
197     f=4;
198   c3=strtoi((const char *)col3->text());
199   if(errnum==1) 
200     f=5;
201   c4=strtoi((const char *)col4->text());
202   if(errnum==1) 
203     f=6;
204   if(c1<0)
205     f=7;
206   if(c2<0)
207     f=8;
208   if(c3<0)
209     f=9;
210   if(c4<0)
211     f=10;
212   if(!isintspace(iterationflagline->text()))
213     f=11;
214   switch(f) {
215   case 0: accept();
216     break;
217   case 1: QMessageBox::information(this,"SnarkInput","Error!\n"
218                                    "Invalid scale format");
219           scale->setFocus();
220     break;
221   case 2: QMessageBox::information(this,"SnarkInput","Error!\n"
222                                    "scale should be positive");
223           scale->setFocus();
224     break;
225   case 3: QMessageBox::information(this,"SnarkInput","Error!\n"
226                                    "Invalid col1 format");
227           col1->setFocus();
228     break;
229   case 4: QMessageBox::information(this,"SnarkInput","Error!\n"
230                                    "Invalid col2 format");
231           col2->setFocus();
232     break;
233   case 5: QMessageBox::information(this,"SnarkInput","Error!\n"
234                                    "Invalid col3 format");
235           col3->setFocus();
236     break;
237   case 6: QMessageBox::information(this,"SnarkInput","Error!\n"
238                                    "Invalid col4 format");
239           col4->setFocus();
240     break;
241   case 7: QMessageBox::information(this,"SnarkInput","Error!\n"
242                                    "col1 must be positive");
243           col1->setFocus();
244     break;
245   case 8: QMessageBox::information(this,"SnarkInput","Error!\n"
246                                    "col2 must be positive or empty");
247           col2->setFocus();
248     break;
249   case 9: QMessageBox::information(this,"SnarkInput","Error!\n"
250                                    "col3 must be positive or empty");
251           col3->setFocus();
252     break;
253   case 10: QMessageBox::information(this,"SnarkInput","Error!\n"
254                                    "col4 must be positive or empty");
255           col4->setFocus();
256     break;
257   case 11: QMessageBox::information(this,"SnarkInput","Error!\n"
258                                    "iteration_flag_line must contain\n"
259                                    "only 0-9 and spaces and must\n"
260                                    "be non-empty");
261           iterationflagline->setFocus();
262     break;
263   }
264 }