UltraScan III
us_edit_scan.cpp
Go to the documentation of this file.
1 
3 #include "us_edit_scan.h"
4 #include "us_settings.h"
5 #include "us_gui_settings.h"
6 
8  const QVector< double >& r,
9  double invertValue, double left, double right )
10  : US_WidgetsDialog( 0, 0 ), originalScan( s ), allRadii( r ),
11  invert( invertValue ),
12  range_left( left ), range_right( right )
13 {
14  dragging = false;
16  changes.clear();
17 
18  setWindowTitle( tr( "Scan Editor" ) );
19  setPalette( US_GuiSettings::frameColor() );
20 
21  QVBoxLayout* main = new QVBoxLayout( this );
22  main->setSpacing ( 2 );
23  main->setContentsMargins( 2, 2, 2, 2 );
24 
25  // Plot Rows
26  QBoxLayout* plot = new US_Plot( data_plot,
27  tr( "Edit Single Scan" ),
28  tr( "Radius (cm)" ),
29  tr( "Absorbance" ) );
30 
31  data_plot->setMinimumSize( 500, 300 );
32  main->addLayout( plot );
33 
34  us_grid( data_plot );
35  pick = new US_PlotPicker( data_plot );
36 
37  // Draw the curve
38  int size = originalScan.rvalues.size();
39  radii = new double[ size ];
40  values = new double[ size ];
41 
42  curve = us_curve( data_plot, tr( "Scan Curve" ) );
43 
44  fgPen = QPen( US_GuiSettings::plotCurve() );
46 
47  fgSym.setStyle( QwtSymbol::Ellipse );
48  fgSym.setBrush( US_GuiSettings::plotCurve() );
49  fgSym.setPen ( fgPen );
50  fgSym.setSize ( 6 );
51 
52 
53  bgSym = fgSym;
54  bgSym.setBrush( US_GuiSettings::plotCanvasBG() );
55  bgSym.setPen ( bgPen );
56 
57  //curve->setRawData( radii, values, count );
58  curve->setSymbol ( fgSym );
59  curve->attach ( data_plot );
60 
61  //data_plot->replot();
62  redraw();
63 
64  // Instructions
65  QHBoxLayout* instructions = new QHBoxLayout;
66 
67  QLabel* lb_instructions = us_label( tr( "Step-by-Step\nInstructions:" ) );
68  instructions->addWidget( lb_instructions );
69 
70  QTextEdit* te_instructions = us_textedit();
71  us_setReadOnly( te_instructions, true );
72 
73  QFont f = te_instructions->font();
74  QFontMetrics fm( f );
75 
76  te_instructions->setMaximumHeight( fm.lineSpacing() * 5 );
77 
78  te_instructions->setText(
79  tr( "1. Use the zoom function as needed to focus on a point.\n"
80  "2. Use Control-Left Press to select the point desired.\n"
81  "3. Drag the point to the value desired." ) );
82 
83  instructions->addWidget( te_instructions );
84  main ->addLayout( instructions );
85 
86  // Button Row
87  QHBoxLayout* buttons = new QHBoxLayout;
88 
89  QPushButton* pb_reset = us_pushbutton( tr( "Reset" ) );
90  connect( pb_reset, SIGNAL( clicked() ), SLOT( reset() ) );
91  buttons->addWidget( pb_reset );
92 
93  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
94  connect( pb_help, SIGNAL( clicked() ), SLOT( help() ) );
95  buttons->addWidget( pb_help );
96 
97  QPushButton* pb_cancel = us_pushbutton( tr( "Cancel" ) );
98  connect( pb_cancel, SIGNAL( clicked() ), SLOT( close() ) );
99  buttons->addWidget( pb_cancel );
100 
101  QPushButton* pb_accept = us_pushbutton( tr( "Accept" ) );
102  connect( pb_accept, SIGNAL( clicked() ), SLOT( done() ) );
103  buttons->addWidget( pb_accept );
104 
105  main->addLayout( buttons );
106 
107  connect( pick, SIGNAL( cMouseDownRaw( QMouseEvent* ) ),
108  SLOT ( start_drag ( QMouseEvent* ) ) );
109 
110  connect( pick, SIGNAL( cMouseUp ( const QwtDoublePoint& ) ),
111  SLOT ( end_drag ( const QwtDoublePoint& ) ) );
112 
113  connect( pick, SIGNAL( cMouseDrag ( const QwtDoublePoint& ) ),
114  SLOT ( drag ( const QwtDoublePoint& ) ) );
115 }
116 
117 void US_EditScan::done( void )
118 {
119  emit scan_updated( changes );
120  close();
121 }
122 
123 void US_EditScan::drag( const QwtDoublePoint& p )
124 {
125  // Ignore drag events after Mouse Up
126  if ( ! dragging ) return;
127 
128  values[ point ] = p.y();
129  data_plot->replot();
130 }
131 
132 void US_EditScan::start_drag( QMouseEvent* e )
133 {
134  dragging = true;
135 
136  // Find the nearest point
137  point = curve->closestPoint( e->pos() );
138 }
139 
140 void US_EditScan::end_drag( const QwtDoublePoint& p )
141 {
142  dragging = false;
143 
144  // Save the change
145  values[ point ] = p.y();
146  // Use offset to provide an index to the full data set
147  changes << QPointF( (double)( point + offset ), values[ point ] );
148 
149  data_plot->replot();
150 }
151 
152 void US_EditScan::reset( void )
153 {
154  dragging = false;
156  changes.clear();
157  redraw();
158 }
159 
161 {
162  offset = 0;
163  int count = 0;
164 
165  int indexLeft = US_DataIO::index( allRadii, range_left );
166  int indexRight = US_DataIO::index( allRadii, range_right );
167 
168  offset = indexLeft;
169 
170  for ( int j = indexLeft; j <= indexRight; j++ )
171  {
172  radii [ count ] = allRadii[ j ];
173  values[ count ] = workingScan.rvalues[ j ] * invert;
174  count++;
175  }
176 
177  curve->setRawData( radii, values, count );
178  data_plot->replot();
179 }