Fixed text file permissions
[snark14.git] / tools / Input / display.cpp
1 /** @file display.cpp
2     @package snark14Input
3     @author Bruno M. Carvalho and Deniz Sarioz 
4     modified by Joanna Klukowska (June 2008)
5         added two fields in LAST line fore agreement with snark14
6     licensed under (open-source) QPL v1.0
7     which accompanies this distribution in the file QPL
8 */
9
10 /****************************************************************************
11 ** Form implementation generated from reading ui file 'display.ui'
12 **
13 ** Created: Tue May 14 10:50:39 2002
14 **      by:  The User Interface Compiler (uic)
15 **
16 ** WARNING! All changes made in this file will be lost!
17 ****************************************************************************/
18 #include "display.h"
19 #include "misc.h"
20 #include "variables.h"
21
22 #include <qcheckbox.h>
23 #include <qframe.h>
24 #include <qlabel.h>
25 #include <qlineedit.h>
26 #include <qpushbutton.h>
27 #include <qradiobutton.h>
28 #include <qlayout.h>
29 #include <qvariant.h>
30 #include <qtooltip.h>
31 #include <qwhatsthis.h>
32 #include <qmessagebox.h>
33
34 /** 
35  *  Constructs a displaywindow which is a child of 'parent', with the 
36  *  name 'name' and widget flags set to 'f' 
37  *
38  *  The dialog will by default be modeless, unless you set 'modal' to
39  *  TRUE to construct a modal dialog.
40  */
41 displaywindow::displaywindow( QWidget* parent,  const char* name, bool modal, WFlags fl )
42     : QDialog( parent, name, modal, fl )
43 {
44     if ( !name )
45         setName( "displaywindow" );
46     resize( 400, 350 ); 
47     setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, sizePolicy().hasHeightForWidth() ) );
48     setMinimumSize( QSize( 400, 350 ) );
49     setMaximumSize( QSize( 400, 350 ) );
50     setCaption( tr( "Display Window" ) );
51
52     displaylabel = new QLabel( this, "displaylabel" );
53     displaylabel->setGeometry( QRect( 10, 10, 100, 30 ) ); 
54     displaylabel->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, displaylabel->sizePolicy().hasHeightForWidth() ) );
55     displaylabel->setMinimumSize( QSize( 100, 30 ) );
56     displaylabel->setMaximumSize( QSize( 100, 30 ) );
57     displaylabel->setText( tr( "DISPLAY" ) );
58
59     scalebox = new QCheckBox( this, "scalebox" );
60     scalebox->setGeometry( QRect( 30, 60, 80, 30 ) ); 
61     scalebox->setText( tr( "SCALE" ) );
62     QObject::connect(scalebox,SIGNAL(clicked()),this,SLOT(activateScaleFields()));
63
64     scale = new QLineEdit( this, "lowervalue" );
65     scale->setGeometry( QRect( 150, 60, 50, 30 ) ); 
66     scale->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, scale->sizePolicy().hasHeightForWidth() ) );
67     scale->setEnabled(FALSE);
68
69     scalelabel = new QLabel( this, "scalelabel" );
70     scalelabel->setGeometry( QRect( 150, 40, 40, 20 ) ); 
71     scalelabel->setText( tr( "scale" ) );
72     scalelabel->setEnabled(FALSE);
73
74     phantombox = new QCheckBox( this, "columnsbox" );
75     phantombox->setGeometry( QRect( 30, 130, 110, 30 ) ); 
76     phantombox->setText( tr( "PHANTOM" ) );
77
78     iterationflagline = new QLineEdit( this, "iterationflagline" );
79     iterationflagline->setGeometry( QRect( 50, 200, 310, 30 ) ); 
80     iterationflagline->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, iterationflagline->sizePolicy().hasHeightForWidth() ) );
81
82     iterationflaglabel = new QLabel( this, "iterationflaglabel" );
83     iterationflaglabel->setGeometry( QRect( 140, 180, 130, 20 ) ); 
84     iterationflaglabel->setText( tr( "iteration_flag_line" ) );
85
86     Line1 = new QFrame( this, "Line1" );
87     Line1->setGeometry( QRect( 0, 275, 400, 16 ) ); 
88     Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
89
90     okbutton = new QPushButton( this, "okbutton" );
91     okbutton->setGeometry( QRect( 50, 290, 100, 40 ) ); 
92     okbutton->setText( tr( "OK" ) );
93     QObject::connect(okbutton,SIGNAL(clicked()),this,SLOT(checkValues()));
94
95     cancelbutton = new QPushButton( this, "cancelbutton" );
96     cancelbutton->setGeometry( QRect( 250, 290, 100, 40 ) ); 
97     cancelbutton->setText( tr( "Cancel" ) );
98     QObject::connect(cancelbutton,SIGNAL(clicked()),this,SLOT(reject()));
99 }
100
101 /**  
102  *  Destroys the object and frees any allocated resources
103  */
104 displaywindow::~displaywindow()
105 {
106     // no need to delete child widgets, Qt does it all for us
107 }
108
109 /** Activates scale subfields 
110 @param void
111 @author Bruno M. Carvalho
112 @version 1.0 */
113 void displaywindow::activateScaleFields()
114 {
115   if(scalebox->isChecked()) {
116     scale->setEnabled(TRUE);
117     scalelabel->setEnabled(TRUE);
118   }
119   else {
120     scale->setEnabled(FALSE);
121     scalelabel->setEnabled(FALSE);
122   }
123 }
124
125 /** Returns a string for DISPLAY input sequence
126 @param void
127 @return display
128 @author Bruno M. Carvalho
129 @version 1.0 */
130 QString displaywindow::getOutput()
131 {
132   QString output;
133
134   output.sprintf("DISPLAY ");
135   if(scalebox->isChecked()) {
136     output.append("SCALE ");
137     output+=scale->text();
138     output.append(" ");
139   }
140   if(phantombox->isChecked()) {
141     output.append("PHANTOM");
142   }
143   output.append("\n");
144   output+=iterationflagline->text();
145   return output;
146 }
147
148 void displaywindow::checkValues()
149 {
150   int f=0;
151   float s=0;
152   
153   if(scalebox->isChecked()) {
154     s=strtof((const char *)scale->text().lower());
155     if(errnum) 
156       f=1;
157     if(s<=0)
158       f=2;
159   }
160   if(!isintspace(iterationflagline->text()))
161     f=3;
162   switch(f) {
163   case 0: accept();
164     break;
165   case 1: QMessageBox::information(this,"SnarkInput","Error!\n"
166                                    "Invalid scale format");
167     break;
168   case 2: QMessageBox::information(this,"SnarkInput","Error!\n"
169                                    "scale should be positive");
170     break;
171   case 3: QMessageBox::information(this,"SnarkInput","Error!\n"
172                                    "iteration_flag_line must contain\n"
173                                    "only 0-9 and spaces and must\n"
174                                    "be non-empty");
175     break;
176   }
177 }