Build for /usr/local/qt3
[snark14.git] / tools / Display / lines.cpp
1 /** @file lines.cpp
2     @package snark14Display
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     modification: Joanna Klukowska 1/13/2009
8             added choice of grayScale display for plot
9             in addition to color display
10  */
11
12 #include "lines.hpp"
13 #include "displaylines.hpp"
14 #include "variables.hpp"
15
16 #include <stdio.h>
17 #include <qcombobox.h>
18 #include <qframe.h>
19 #include <qlabel.h>
20 #include <qlineedit.h>
21 #include <qlistbox.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
24 #include <qlayout.h>
25 #include <qvariant.h>
26 #include <qtooltip.h>
27 #include <qwhatsthis.h>
28
29 /* "Lines" (plotting of pixel values in a row or column) dialog for a single image (and maybe phantom)
30  *  Constructs a lineswindow which is a child of 'parent', with the 
31  *  name 'name' and widget flags set to 'f' 
32  *
33  *  The dialog will by default be modeless, unless you set 'modal' to
34  *  TRUE to construct a modal dialog.
35  */
36 lineswindow::lineswindow(QWidget* parent, const char* name, double min, double max, bool modal, bool projrec, WFlags fl)
37 : QDialog(parent, name, modal, fl) {
38
39     if (!name)
40         setName("lineswindow");
41     resize(340, 550);
42     setMinimumSize(QSize(340, 550));
43     setMaximumSize(QSize(340, 550));
44     QString s = name; // dummy (multipurpose) string
45     s += " Profile";
46     setCaption(s);
47
48     isrec = projrec;
49
50     minval = min;
51     maxval = max;
52
53     rowcolbox = new QListBox(this, "rowcolbox");
54     rowcolbox->insertItem("rows"); // rows first. => 0 => false  [ x-axis == columns ] [sic]
55     rowcolbox->insertItem("columns"); // columns later => 1 => true [ x-axis == rows ] [sic]
56     rowcolbox->setGeometry(QRect(20, 10, 80, 50));
57     rowcolbox->setSelectionMode(QListBox::Single);
58     rowcolbox->setSelected(0, true);
59     QObject::connect(rowcolbox, SIGNAL(highlighted(int)), this, SLOT(updateXAxis(int)));
60
61     phantombutton = new QRadioButton(this, "phantombutton");
62     phantombutton->setGeometry(QRect(150, 20, 120, 30));
63     phantombutton->setMinimumSize(QSize(120, 30));
64     phantombutton->setMaximumSize(QSize(120, 30));
65     phantombutton->setText("PHANTOM");
66     if (isrec)
67         phantombutton->setChecked(true);
68     else {
69         phantombutton->setChecked(false);
70         phantombutton->setEnabled(false);
71     }
72
73     line1 = new QLineEdit(this, "line1");
74     line1->setGeometry(QRect(20, 90, 60, 30));
75
76     line2 = new QLineEdit(this, "line2");
77     line2->setGeometry(QRect(100, 90, 60, 30));
78
79     line3 = new QLineEdit(this, "line3");
80     line3->setGeometry(QRect(180, 90, 60, 30));
81
82     line4 = new QLineEdit(this, "line4");
83     line4->setGeometry(QRect(260, 90, 60, 30));
84
85     label1 = new QLabel(this, "label1");
86     label1->setGeometry(QRect(33, 70, 35, 20));
87     label1->setText("row1");
88
89     label2 = new QLabel(this, "label2");
90     label2->setGeometry(QRect(113, 70, 35, 20));
91     label2->setText("row ");
92
93     label3 = new QLabel(this, "label3");
94     label3->setGeometry(QRect(193, 70, 35, 20));
95     label3->setText("row3");
96
97     label4 = new QLabel(this, "label4");
98     label4->setGeometry(QRect(273, 70, 35, 20));
99     label4->setText("row4");
100
101     title = new QLineEdit(this, "title");
102     title->setGeometry(QRect(20, 150, 300, 30));
103     title->setText(name);
104
105     titlelabel = new QLabel(this, "titlelabel");
106     titlelabel->setGeometry(QRect(160, 130, 60, 20));
107     titlelabel->setText("Title");
108
109     //    subtitle =  new QComboBox( this, "subtitle" );
110     //    subtitle->setGeometry( QRect( 20, 210, 140, 30 ) );
111     //    subtitle->insertItem("Column/Line #",-1);
112     //    subtitle->insertItem("Empty",-1);
113
114     //    subtitlelabel = new QLabel( this, "subtitlelabel" );
115     //    subtitlelabel->setGeometry( QRect( 60, 190, 100, 20 ) );
116     //    subtitlelabel->setText( "Subtitle" );
117
118     //    gridstyle = new QComboBox(this,"gridstyle");
119     //    gridstyle->setGeometry( QRect( 180, 210, 140, 30 ) );
120     //    gridstyle->insertItem("Solid",-1);
121     //    gridstyle->insertItem("None",-1);
122     //    gridstyle->insertItem("Dash",-1);
123     //    gridstyle->insertItem("Dot",-1);
124     //    gridstyle->setEnabled(false);
125     //    gridstyle->setSelected(1); // "None"
126
127     //    gridstylelabel = new QLabel( this, "gridstylelabel" );
128     //    gridstylelabel->setGeometry( QRect( 210, 190, 210, 20 ) );
129     //    gridstylelabel->setText( "Grid Style" );
130
131     xaxis = new QLineEdit(this, "xaxis");
132     xaxis->setGeometry(QRect(20, 240, 140, 30));
133     xaxis->setText("Columns");
134
135     yaxis = new QLineEdit(this, "yaxis");
136     yaxis->setGeometry(QRect(180, 240, 140, 30));
137     yaxis->setText("Pixel Values");
138
139     xaxislabel = new QLabel(this, "xaxislabel");
140     xaxislabel->setGeometry(QRect(70, 220, 60, 20));
141     xaxislabel->setText("X Axis");
142
143     yaxislabel = new QLabel(this, "yaxislabel");
144     yaxislabel->setGeometry(QRect(230, 220, 60, 20));
145     yaxislabel->setText("Y Axis");
146
147     minx = new QLineEdit(this, "minx");
148     minx->setGeometry(QRect(20, 300, 140, 30));
149     minx->setText("0");
150
151     s.setNum(isrec ? (Sizex - 1) : (usrays - 1)); // at the bottom, it's set to usrays... why?
152     maxx = new QLineEdit(this, "maxx");
153     maxx->setGeometry(QRect(180, 300, 140, 30));
154     maxx->setText(s);
155
156     s.setNum(minval);
157     miny = new QLineEdit(this, "miny");
158     miny->setGeometry(QRect(20, 360, 140, 30));
159     miny->setText(s);
160
161     s.setNum(maxval);
162     maxy = new QLineEdit(this, "maxy");
163     maxy->setGeometry(QRect(180, 360, 140, 30));
164     maxy->setText(s);
165
166     // these should be sort of exactly the same as in linesimages
167     minxlabel = new QLabel(this, "minxlabel");
168     minxlabel->setGeometry(QRect(60, 280, 60, 20));
169     minxlabel->setText("Min Col");
170
171     maxxlabel = new QLabel(this, "maxxlabel");
172     maxxlabel->setGeometry(QRect(220, 280, 60, 20));
173     maxxlabel->setText("Max Col");
174
175     minylabel = new QLabel(this, "minylabel");
176     minylabel->setGeometry(QRect(70, 340, 60, 20));
177     minylabel->setText("Min Y");
178
179     maxylabel = new QLabel(this, "maxylabel");
180     maxylabel->setGeometry(QRect(230, 340, 60, 20));
181     maxylabel->setText("Max Y");
182
183
184
185     // jk 1/13/2009 adding grayScale option for graphs
186     // jklukowska 6/7/2009 modified to be radio button with option of either
187     // color or grayscale
188     colorbuttongroup = new QButtonGroup(this, "colorbuttongroup");
189     colorbuttongroup->setTitle(tr("Draw graphs in "));
190     colorbuttongroup->setGeometry(QRect(0, 400, 340, 75));
191     colorbuttongroup->setAlignment(int( QButtonGroup::AlignHCenter));
192     grayScaleButton = new QRadioButton(colorbuttongroup, "grayScaleButton");
193     grayScaleButton->setGeometry(QRect(30, 25, 130, 20));
194     grayScaleButton->setText(tr(" grayscale"));
195     grayScaleButton->setEnabled(true);
196     grayScaleButton->setChecked(false);
197     colorButton = new QRadioButton(colorbuttongroup, "colorButton");
198     colorButton->setGeometry(QRect(190, 25, 130, 20));
199     colorButton->setText(tr(" color"));
200     colorButton->setEnabled(true);
201     colorButton->setChecked(true);
202
203     //Line3 = new QFrame(this, "Line3");
204     //Line3->setGeometry(QRect(0, 485, 340, 16));
205     //Line3->setFrameStyle(QFrame::HLine | QFrame::Sunken);
206
207     showbutton = new QPushButton(this, "showbutton");
208     showbutton->setGeometry(QRect(20, 490, 100, 40));
209     showbutton->setText("Show");
210     QObject::connect(showbutton, SIGNAL(clicked()), this, SLOT(accept()));
211
212     cancelbutton = new QPushButton(this, "cancelbutton");
213     cancelbutton->setGeometry(QRect(220, 490, 100, 40));
214     cancelbutton->setText("Cancel");
215     QObject::connect(cancelbutton, SIGNAL(clicked()), this, SLOT(reject()));
216
217     updateXAxis(0); // another HACKish workaround by deniz for bug 98
218 }
219
220 /*  
221  *  Destroys the object and frees any allocated resources
222  */
223 lineswindow::~lineswindow() {
224     // no need to delete child widgets, Qt does it all for us
225 }
226
227 /** 
228 @param void
229 @author Bruno M. Carvalho, a bit cleanup and change by deniz
230 @version 1.0 */
231 void lineswindow::updateXAxis(int i) {
232     QString maxx_str;
233     if (i == 0) { // (i==0), selection is Row, X Axis is columns
234         label1->setText("row1");
235         label2->setText("row2");
236         label3->setText("row3");
237         label4->setText("row4");
238         xaxis->setText("Columns");
239         minxlabel->setText("Min Col");
240         maxxlabel->setText("Max Col");
241         maxx_str.setNum(isrec ? (Sizex - 1) : (prjnum - 1));
242         // i think "-1" for everything makes more sense--deniz
243     } else { // (i==1), selection is Column, X Axis is rows
244         label1->setText("col1");
245         label2->setText("col2");
246         label3->setText("col3");
247         label4->setText("col4");
248         xaxis->setText("Rows");
249         minxlabel->setText("Min Row");
250         maxxlabel->setText("Max Row");
251         maxx_str.setNum(isrec ? (Sizey - 1) : (usrays - 1));
252     }
253     maxx->setText(maxx_str);
254 } // --lineswindow::updateXAxis()
255
256 /** 
257 @param void
258 @author Bruno M. Carvalho
259 @version 1.0 */
260 int lineswindow::getLinetype() {
261     return rowcolbox->currentItem();
262 }
263
264 /** 
265 @param void
266 @author Bruno M. Carvalho
267 @version 1.0 */
268 int lineswindow::getLine1() {
269     int l;
270     bool ok;
271     l = line1->text().toInt(&ok, 10);
272     if (ok)
273         return l;
274     else
275         return NaI;
276 }
277
278 /** 
279 @param void
280 @author Bruno M. Carvalho
281 @version 1.0 */
282 int lineswindow::getLine2() {
283     int l;
284     bool ok;
285     l = line2->text().toInt(&ok, 10);
286     if (ok)
287         return l;
288     else
289         return NaI;
290 }
291
292 /** 
293 @param void
294 @author Bruno M. Carvalho
295 @version 1.0 */
296 int lineswindow::getLine3() {
297     int l;
298     bool ok;
299     l = line3->text().toInt(&ok, 10);
300     if (ok)
301         return l;
302     else
303         return NaI;
304 }
305
306 /** 
307 @param void
308 @author Bruno M. Carvalho
309 @version 1.0 */
310 int lineswindow::getLine4() {
311     int l;
312     bool ok;
313     l = line4->text().toInt(&ok, 10);
314     if (ok)
315         return l;
316     else
317         return NaI;
318 }
319
320 /** 
321 @param void
322 @author Bruno M. Carvalho
323 @version 1.0 */
324 QString lineswindow::getTitle() {
325     return title->text();
326 }
327
328 //  /** 
329 //  @param void
330 //  @author Bruno M. Carvalho
331 //  @version 1.0 */ 
332 //  int lineswindow::getSubtitle()
333 //  {
334 //    return subtitle->currentItem();
335 //  }
336
337 //  /** 
338 //  @param void
339 //  @author Bruno M. Carvalho
340 //  @version 1.0 */ 
341 //  int lineswindow::getGridstyle()
342 //  {
343 //    return gridstyle->currentItem();
344 //  }
345
346 /** 
347 @param void
348 @author Bruno M. Carvalho
349 @version 1.0 */
350 QString lineswindow::getXAxis() {
351     return xaxis->text();
352 }
353
354 /** 
355 @param void
356 @author Bruno M. Carvalho
357 @version 1.0 */
358 QString lineswindow::getYAxis() {
359     return yaxis->text();
360 }
361
362 /** 
363 @param void
364 @author Bruno M. Carvalho
365 @version 1.0 */
366 int lineswindow::getMinX() {
367     bool ok;
368     int t;
369     t = minx->text().toInt(&ok, 10);
370     if (ok)
371         return t;
372     else
373         return 0;
374 }
375
376 /** 
377 @param void
378 @author Bruno M. Carvalho
379 @version 1.0 */
380 int lineswindow::getMaxX() {
381     bool ok;
382     int t;
383     t = maxx->text().toInt(&ok, 10);
384     if (ok)
385         return t;
386     else
387         return Sizex - 1;
388 }
389
390 /** 
391 @param void
392 @author Bruno M. Carvalho
393 @version 1.0 */
394 double lineswindow::getMinY() {
395     bool ok;
396     double t;
397     t = miny->text().toDouble(&ok);
398     if (ok)
399         return t;
400     else
401         return minval;
402 }
403
404 /** 
405 @param void
406 @author Bruno M. Carvalho
407 @version 1.0 */
408 double lineswindow::getMaxY() {
409     bool ok;
410     double t;
411     t = maxy->text().toDouble(&ok);
412     if (ok)
413         return t;
414     else
415         return maxval;
416 }
417
418 /** 
419 @param void
420 @author Bruno M. Carvalho
421 @version 1.0 */
422 bool lineswindow::isPhantomChecked() {
423     return (phantombutton->isChecked());
424 }
425
426 /**
427 @param void
428 @author Joanna Klukowska (added 1/13/2009)
429 @version 1.0 */
430 bool lineswindow::isGrayScaleChecked() {
431     return (grayScaleButton->isChecked());
432 }