Fixed text file permissions
[snark14.git] / tools / Input / picture.cpp
1 /** @file picture.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 "picture.h"
9 #include "variables.h"
10 #include "misc.h"
11
12 #include <qbuttongroup.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 picturewindow 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 picturewindow::picturewindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
34     : QDialog( parent, name, modal, fl )
35 {
36     if ( !name )
37         setName( "picturewindow" );
38     resize( 400, 250 ); 
39     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
40     setMinimumSize( QSize( 400, 250 ) );
41     setMaximumSize( QSize( 400, 250 ) );
42     setCaption( tr( "Picture Window" ) );
43
44     picturelabel = new QLabel( this, "picturelabel" );
45     picturelabel->setGeometry( QRect( 10, 10, 100, 30 ) ); 
46     picturelabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, picturelabel->sizePolicy().hasHeightForWidth() ) );
47     picturelabel->setMinimumSize( QSize( 100, 30 ) );
48     picturelabel->setMaximumSize( QSize( 100, 30 ) );
49     picturelabel->setText( tr( "PICTURE" ) );
50
51     picturebuttongroup = new QButtonGroup( this, "picturebuttongroup" );
52     picturebuttongroup->setGeometry( QRect( 5, 35, 385, 130 ) ); 
53     picturebuttongroup->setTitle( tr( "type" ) );
54     picturebuttongroup->setAlignment( int( QButtonGroup::AlignHCenter ) );
55
56     reconstructionbutton = new QRadioButton( picturebuttongroup, "reconstructionbutton" );
57     reconstructionbutton->setGeometry( QRect( 10, 40, 180, 24 ) ); 
58     reconstructionbutton->setText( tr( "RECONSTRUCTION" ) );
59     QObject::connect(reconstructionbutton,SIGNAL(clicked()),this,SLOT(activateReconstructionFields()));
60
61     testbutton = new QRadioButton( picturebuttongroup, "testbutton" );
62     testbutton->setGeometry( QRect( 10, 80, 65, 24 ) ); 
63     testbutton->setText( tr( "TEST" ) );
64     QObject::connect(testbutton,SIGNAL(clicked()),this,SLOT(deactivateReconstructionFields()));
65
66     nelem = new QLineEdit( picturebuttongroup, "nelem" );
67     nelem->setGeometry( QRect( 200, 35, 80, 30 ) ); 
68     nelem->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, nelem->sizePolicy().hasHeightForWidth() ) );
69     nelem->setEnabled(FALSE);
70
71     nelemlabel = new QLabel( picturebuttongroup, "nelemlabel" );
72     nelemlabel->setGeometry( QRect( 220, 15, 50, 20 ) ); 
73     nelemlabel->setText( tr( "nelem" ) );
74     nelemlabel->setEnabled(FALSE);
75
76     pixelsize = new QLineEdit( picturebuttongroup, "pixelsize" );
77     pixelsize->setGeometry( QRect( 295, 35, 80, 30 ) ); 
78     pixelsize->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, pixelsize->sizePolicy().hasHeightForWidth() ) );
79     pixelsize->setEnabled(FALSE);
80
81     pixelsizelabel = new QLabel( picturebuttongroup, "pixelsizelabel" );
82     pixelsizelabel->setGeometry( QRect( 305, 15, 70, 20 ) ); 
83     pixelsizelabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, pixelsizelabel->sizePolicy().hasHeightForWidth() ) );
84     pixelsizelabel->setMinimumSize( QSize( 70, 20 ) );
85     pixelsizelabel->setMaximumSize( QSize( 70, 20 ) );
86     pixelsizelabel->setText( tr( "pixel-size" ) );
87     pixelsizelabel->setEnabled(FALSE);
88
89     Line10 = new QFrame( this, "Line10" );
90     Line10->setGeometry( QRect( 0, 175, 420, 16 ) ); 
91     Line10->setFrameStyle( QFrame::HLine | QFrame::Sunken );
92
93     okbutton = new QPushButton( this, "okbutton" );
94     okbutton->setGeometry( QRect( 50, 195, 100, 40 ) ); 
95     okbutton->setText( tr( "OK" ) );
96     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
97
98     cancelbutton = new QPushButton( this, "cancelbutton" );
99     cancelbutton->setGeometry( QRect( 250, 195, 100, 40 ) ); 
100     cancelbutton->setText( tr( "Cancel" ) );
101     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
102 }
103
104 /**  
105  *  Destroys the object and frees any allocated resources
106  */
107 picturewindow::~picturewindow()
108 {
109     // no need to delete child widgets, Qt does it all for us
110 }
111
112 /** Activates type fields 
113 @param void
114 @author Bruno M. Carvalho
115 @version 1.0 */
116 /* void picturewindow::activateFields()
117 {
118   if(picturebutton->isChecked()) {
119     reconstructionbutton->setEnabled(TRUE);
120     testbutton->setEnabled(TRUE);
121     picturebuttongroup->setEnabled(TRUE);
122   }
123   else {
124     picturebuttongroup->setEnabled(FALSE);
125     reconstructionbutton->setEnabled(FALSE);
126     testbutton->setEnabled(FALSE);
127     nelem->setEnabled(FALSE);
128     pixelsize->setEnabled(FALSE);
129     nelemlabel->setEnabled(FALSE);
130     pixelsizelabel->setEnabled(FALSE);
131   }
132 } */
133
134 /** Activates reconstruction fields 
135 @param void
136 @author Bruno M. Carvalho
137 @version 1.0 */
138 void picturewindow::activateReconstructionFields()
139 {
140   if(reconstructionbutton->isChecked()) {
141     nelem->setEnabled(TRUE);
142     pixelsize->setEnabled(TRUE);
143     nelemlabel->setEnabled(TRUE);
144     pixelsizelabel->setEnabled(TRUE);
145   }
146   else {
147     nelem->setEnabled(FALSE);
148     pixelsize->setEnabled(FALSE);
149     nelemlabel->setEnabled(FALSE);
150     pixelsizelabel->setEnabled(FALSE);
151   }
152 }
153
154 /** Deactivates reconstruction fields 
155 @param void
156 @author Bruno M. Carvalho
157 @version 1.0 */
158 void picturewindow::deactivateReconstructionFields()
159 {
160   if(testbutton->isChecked()) {
161     nelem->setEnabled(FALSE);
162     pixelsize->setEnabled(FALSE);
163     nelemlabel->setEnabled(FALSE);
164     pixelsizelabel->setEnabled(FALSE);
165   }
166 }
167
168 /** Returns a string for PICTUE input sequence
169 @param void
170 @return picture
171 @author Bruno M. Carvalho
172 @version 1.0 */
173 QString picturewindow::getOutput()
174 {
175   QString output;
176
177   output.sprintf("PICTURE ");
178   if(reconstructionbutton->isChecked()) {
179     output.append("RECONSTRUCTION ");
180     output+=nelem->text();
181     output.append(" ");
182     output+=pixelsize->text();
183     output.append(" ");
184   }
185   if(testbutton->isChecked()) 
186     output.append("TEST");
187   //output.append("\n");
188
189   return output;
190 }
191
192
193 void picturewindow::checkValues()
194 {
195   int f=0,n=0;
196   float p=0;
197
198   if(reconstructionbutton->isChecked()) {
199     n=strtoi((const char *)nelem->text());
200     if(errnum) 
201       f=1;
202     if(n<1 || !(n%2))
203       f=2;
204     p=strtof((const char *)pixelsize->text());
205     if(errnum) 
206       f=3;
207     if(p<=0)
208       f=4;
209   }
210   switch(f) {
211   case 0: accept();
212     break;
213   case 1: QMessageBox::information(this,"SnarkInput","Error!\n"
214                                    "Invalid nelem format.");
215           nelem->setFocus();
216     break;
217   case 2: QMessageBox::information(this,"SnarkInput","Error!\n"
218                                    "nelem must be positive and odd.");
219           nelem->setFocus();
220     break;
221   case 3: QMessageBox::information(this,"SnarkInput","Error!\n"
222                                    "Invalid pixel-size format.");
223           pixelsize->setFocus();
224     break;
225   case 4: QMessageBox::information(this,"SnarkInput","Error!\n"
226                                    "pixel-size must be greater than 0.");
227           pixelsize->setFocus();
228     break;
229   }
230 }