UltraScan III
us_plot.cpp
Go to the documentation of this file.
1 
3 #include <QtSvg>
4 
5 #include "us_plot.h"
6 #include "us_gui_settings.h"
7 #include "us_gui_util.h"
8 #include "us_pixmaps.h"
9 #include "us_settings.h"
10 
11 #include "qwt_text_label.h"
12 #include "qwt_plot_layout.h"
13 #include "qwt_legend.h"
14 #include "qwt_scale_engine.h"
15 #include "qwt_scale_map.h"
16 #include "qwt_scale_widget.h"
17 #include "qwt_symbol.h"
18 
19 
20 US_Zoomer::US_Zoomer( int xAxis, int yAxis, QwtPlotCanvas* canvas )
21  : QwtPlotZoomer( xAxis, yAxis, canvas )
22 {
23  setSelectionFlags( QwtPicker::DragSelection | QwtPicker::CornerToCorner );
24  setTrackerMode ( QwtPicker::AlwaysOff );
25  setRubberBand ( QwtPicker::NoRubberBand );
26 
27  // RightButton: zoom out by 1
28  // Ctrl+RightButton: zoom out to full size
29 
30  setMousePattern( QwtEventPattern::MouseSelect2,
31  Qt::RightButton, Qt::ControlModifier );
32 
33  setMousePattern( QwtEventPattern::MouseSelect3,
34  Qt::RightButton );
35 }
36 
37 /********************* US_Plot Class *************************/
38 
39 // A new plot returns a QBoxLayout
40 US_Plot::US_Plot( QwtPlot*& parent_plot, const QString& title,
41  const QString& x_axis, const QString& y_axis ) : QHBoxLayout()
42 {
43  zoomer = NULL;
44  setSpacing( 0 );
45 
46  QFont buttonFont( US_GuiSettings::fontFamily(),
48 
49  // Add the tool bar
50  QToolBar* toolBar = new QToolBar;
51  toolBar->setAutoFillBackground( true );
52  toolBar->setPalette( US_GuiSettings::plotColor() );
53  toolBar->setOrientation( Qt::Vertical );
54 
55  btnZoom = new QToolButton( toolBar );
56  btnZoom->setText( "Zoom" );
57  btnZoom->setIcon(QIcon( zoom_xpm ) );
58  btnZoom->setCheckable( true );
59  btnZoom->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
60  btnZoom->setFont( buttonFont );
61  connect( btnZoom, SIGNAL( toggled( bool ) ), SLOT( zoom( bool ) ) );
62 
63  QToolButton* btnPrint = new QToolButton( toolBar );
64  btnPrint->setText( "Print" );
65  btnPrint->setIcon( QIcon( print_xpm ) );
66  btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
67  btnPrint->setFont( buttonFont );
68  connect( btnPrint, SIGNAL( clicked() ), SLOT( print() ) );
69 
70  QToolButton* btnSVG = new QToolButton( toolBar );
71  btnSVG->setText( "SVG" );
72  btnSVG->setIcon( QIcon( vec_xpm ) );
73  btnSVG->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
74  btnSVG->setFont( buttonFont );
75  connect( btnSVG, SIGNAL( clicked() ), SLOT( svg() ) );
76 
77  QToolButton* btnPNG = new QToolButton( toolBar );
78  btnPNG->setText( "PNG" );
79  btnPNG->setIcon( QIcon( ras_xpm ) );
80  btnPNG->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
81  btnPNG->setFont( buttonFont );
82  connect( btnPNG, SIGNAL( clicked() ), SLOT( png() ) );
83 
84  QToolButton* btnConfig = new QToolButton( toolBar );
85  btnConfig->setText( "Config" );
86  btnConfig->setIcon(QIcon( configure_32_xpm ) );
87  btnConfig->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
88  btnConfig->setFont( buttonFont );
89  connect( btnConfig, SIGNAL( clicked() ), SLOT( config() ) );
90 
91  toolBar->addWidget( btnZoom );
92  toolBar->addWidget( btnPrint );
93  toolBar->addWidget( btnSVG );
94  toolBar->addWidget( btnPNG );
95  toolBar->addWidget( btnConfig );
96 
97  addWidget( toolBar );
98 
99  // Add a 1 pixel black line between the tool bar and the plot
100  QLabel* spacer = new QLabel;
101  QPalette p;
102  p.setColor( QPalette::Window, Qt::black );
103  spacer->setPalette( p );
104  spacer->setAutoFillBackground( true );
105  spacer->setMaximumWidth( 1 );
106  addWidget( spacer );
107 
108  plot = new QwtPlot;
109  parent_plot = plot;
110 
111 
112  configWidget = NULL;
113 
114  plot->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
115  plot->setAutoReplot( false );
116 
117  QFont font( US_GuiSettings::fontFamily(),
119  QFont::Bold );
120 
121  font.setPointSizeF( US_GuiSettings::fontSize() * 1.4 );
122 
123  QwtText qwtTitle( title );
124  qwtTitle.setFont( font );
125  plot->setTitle( qwtTitle );
126 
127  plot->setMargin( US_GuiSettings::plotMargin() );
128 
129  font.setPointSizeF( US_GuiSettings::fontSize() * 1.0 );
130  qwtTitle.setFont( font );
131  qwtTitle.setText( x_axis );
132  plot->setAxisTitle( QwtPlot::xBottom, qwtTitle );
133 
134  qwtTitle.setText( y_axis );
135  plot->setAxisTitle( QwtPlot::yLeft , qwtTitle );
136 
137  font.setBold ( false );
138  font.setPointSizeF( US_GuiSettings::fontSize() * 0.9 );
139  plot->setAxisFont( QwtPlot::xBottom, font );
140  plot->setAxisFont( QwtPlot::yLeft, font );
141  plot->setAxisFont( QwtPlot::yRight, font );
142  if ( plot->legend() != NULL )
143  plot->legend()->setFont( font );
144 
145  plot->setAutoFillBackground( true );
146  plot->setPalette ( US_GuiSettings::plotColor() );
147  plot->setCanvasBackground( US_GuiSettings::plotCanvasBG() );
148 
149  addWidget( plot );
150 }
151 
152 void US_Plot::zoom( bool on )
153 {
154  if ( on )
155  {
156  // Set up for zooming
157  zoomer = new US_Zoomer( QwtPlot::xBottom, QwtPlot::yLeft,
158  plot->canvas() );
159 
160  zoomer->setRubberBand ( QwtPicker::RectRubberBand );
161  zoomer->setRubberBandPen( QColor( Qt::green ) );
162  zoomer->setTrackerMode ( QwtPicker::ActiveOnly );
163  zoomer->setTrackerPen ( QColor( Qt::white ) );
164 
165  connect( zoomer, SIGNAL ( zoomed( QwtDoubleRect ) ),
166  SIGNAL ( zoomedCorners( QwtDoubleRect ) ) );
167 
168  panner = new QwtPlotPanner( plot->canvas() );
169  panner->setMouseButton( Qt::MidButton );
170 
171  picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,
172  QwtPicker::PointSelection | QwtPicker::DragSelection,
173  QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
174  plot->canvas() );
175 
176  picker->setRubberBandPen( QColor( Qt::green ) );
177  picker->setRubberBand ( QwtPicker::CrossRubberBand );
178  picker->setTrackerPen ( QColor( Qt::white ) );
179  }
180 
181  panner->setEnabled( on );
182 
183  zoomer->setEnabled( on );
184  zoomer->zoom( 0 );
185 
186  picker->setEnabled( ! on );
187 
188  if ( ! on && zoomer != NULL )
189  {
190  delete picker;
191  delete panner;
192  delete zoomer;
193  zoomer = NULL;
194  }
195 }
196 
197 void US_Plot::svg( void )
198 {
199  QDir dir;
200  QString reportDir = US_Settings::reportDir();
201  if ( ! dir.exists( reportDir ) ) dir.mkpath( reportDir );
202 
203  QString fileName = QFileDialog::getSaveFileName( plot,
204  tr( "Export File Name" ), reportDir,
205  tr( "SVG Documents (*.svgz)" ) );
206 
207  if ( ! fileName.isEmpty() )
208  {
209  if ( fileName.right( 5 ) != ".svgz" ) fileName += ".svgz";
210 
211  US_GuiUtil::save_svg( fileName, plot );
212  }
213 }
214 
215 void US_Plot::png( void )
216 {
217  QDir dir;
218  QString reportDir = US_Settings::reportDir();
219  if ( ! dir.exists( reportDir ) ) dir.mkpath( reportDir );
220 
221  QString fileName = QFileDialog::getSaveFileName( plot,
222  tr( "Export File Name" ), reportDir,
223  tr( "PNG Documents (*.png)" ) );
224 
225  if ( ! fileName.isEmpty() )
226  {
227  if ( fileName.right( 4 ) != ".png" ) fileName += ".png";
228 
229  US_GuiUtil::save_png( fileName, plot );
230  }
231 }
232 
233 void US_Plot::print( void )
234 {
235  QDir dir;
236  QString reportDir = US_Settings::reportDir();
237  if ( ! dir.exists( reportDir ) ) dir.mkpath( reportDir );
238 
239  QPrinter printer( QPrinter::HighResolution );
240 #ifdef Q_WS_X11
241  printer.setOutputFileName( reportDir + "/ultrascan-plot.pdf" );
242 #endif
243 
244  QString docName = plot->title().text();
245 
246  if ( ! docName.isEmpty() )
247  {
248  docName.replace ( QRegExp( QString::fromLatin1( "\n" ) ), tr ( " -- " ) );
249  printer.setDocName( docName );
250  }
251 
252  printer.setCreator( "UltraScan" );
253  printer.setOrientation( QPrinter::Landscape );
254 
255  QPrintDialog dialog( &printer );
256 
257  if ( dialog.exec() == QDialog::Accepted )
258  {
259  QwtPlotPrintFilter filter;
260  if ( printer.colorMode() == QPrinter::GrayScale )
261  {
262  int options = QwtPlotPrintFilter::PrintAll;
263  options &= ~QwtPlotPrintFilter::PrintBackground;
264  options |= QwtPlotPrintFilter::PrintFrameWithScales;
265  filter.setOptions( options );
266  }
267  plot->print( printer, filter );
268  }
269 }
270 
271 void US_Plot::config( void )
272 {
273  if ( configWidget )
274  {
275  //configWidget->close();
276  }
277  configWidget = new US_PlotConfig( plot );
278  //configWidget->setAttribute( Qt::WA_DeleteOnClose );
279  //connect( configWidget, SIGNAL( plotConfigClosed () ),
280  // SLOT ( plotConfigFinished() ) );
281  //configWidget->show();
282  configWidget->exec();
283  qApp->processEvents();
284  delete configWidget;
285 }
286 
287 /*
288 void US_Plot::plotConfigFinished( void )
289 {
290  configWidget = NULL;
291 }
292 
293 void US_Plot::quit( void )
294 {
295  if ( configWidget )
296  {
297  //configWidget->close();
298  }
299 }
300 */
301 
303 
304 US_PlotPushbutton::US_PlotPushbutton( const QString& labelString,
305  QWidget* w, int index ) : QPushButton( labelString.toAscii(), w )
306 {
307  setFont( QFont( US_GuiSettings::fontFamily(),
309 
310  setPalette( US_GuiSettings::pushbColor() );
311 
312  setAutoDefault( false );
313  setEnabled( true );
314  pb_index = index;
315 
316  connect( this, SIGNAL( clicked() ), SLOT( us_plotClicked() ) );
317 }
318 
320 {
321  emit US_PlotPbPushed( pb_index );
322 };
323 
324 /********************* QwtPlotConfig Class *************************/
325 
332 US_PlotConfig::US_PlotConfig( QwtPlot* current_plot, QWidget* p,
333  Qt::WindowFlags f ) : US_WidgetsDialog( p, f ) //( false, p, f )
334 {
335  setWindowTitle( "Local Plot Configuration" );
336  setPalette( US_GuiSettings::frameColor() );
337 
338  axisWidget = NULL;
339  gridWidget = NULL;
340  curveWidget = NULL;
341  plot = current_plot;
342 
343  // Move this frame to get out of the way
344  //move( pos() + QPoint( plot->rect().width(), 0 ) );
345 
346  int row = 0;
347 
348  QGridLayout* main = new QGridLayout( this );
349  main->setContentsMargins( 2, 2, 2, 2 );
350  main->setSpacing( 2 );
351 
352  // Row 0
353  QLabel* lb_elements = us_banner( tr( "----- Plot Elements -----" ) );
354  lb_elements->setFixedHeight( 40 );
355  main->addWidget( lb_elements, row++, 0, 1, 3 );
356 
357  // Row 1
358  QLabel* lb_title = us_label( tr( "Title Text:" ) );
359 
360  le_titleText = us_lineedit( plot->title().text(), 1 );
361  le_titleText->setMinimumWidth( 500 );
362  connect ( le_titleText, SIGNAL( textChanged ( const QString& ) ),
363  SLOT ( updateTitleText( const QString& ) ) );
364 
365  main->addWidget( lb_title, row, 0 );
366  main->addWidget( le_titleText, row++, 1, 1, 2 );
367 
368  // Row 2
369  QLabel* lb_titleFont = us_label( tr( "Title Font:" ) );
370 
371  QFont titleFont = plot->title().font();
372 
373  le_titleFont = us_lineedit( titleFont.family() + ", "
374  + QString::number( titleFont.pointSize() ) + tr( " points" ), 1 );
375  le_titleFont->setReadOnly( true );
376 
377  QPushButton* pb_titleFont = us_pushbutton( tr("Update Font") );
378  connect( pb_titleFont, SIGNAL( clicked() ), SLOT( updateTitleFont() ) );
379 
380  main->addWidget( lb_titleFont, row, 0 );
381  main->addWidget( le_titleFont, row, 1 );
382  main->addWidget( pb_titleFont, row++, 2 );
383 
384  // Row 3
385  QLabel* lb_frameColor = us_label( tr( "Frame Color: " ) );
386 
387  lb_showFrameColor = us_label( "" , 1 );
388  lb_showFrameColor->setPalette( plot->palette() );
389 
390  QPushButton* pb_showFrameColor = us_pushbutton ( tr( "Update Color" ) );
391  connect( pb_showFrameColor, SIGNAL( clicked() ), SLOT( selectFrameColor() ) );
392 
393  main->addWidget( lb_frameColor, row, 0 );
394  main->addWidget( lb_showFrameColor, row, 1 );
395  main->addWidget( pb_showFrameColor, row++, 2 );
396 
397  // Row 4
398  QLabel* lb_canvasColor = us_label( tr( "Canvas Color: " ) );
399 
400  lb_showCanvasColor = us_label( "" , 1 );
401 
402  // set bg color
403  QColor c = plot->canvasBackground();
404  QPalette palette = US_GuiSettings::plotColor();
405  palette.setColor( QPalette::Active , QPalette::Window, c );
406  palette.setColor( QPalette::Inactive, QPalette::Window, c );
407  lb_showCanvasColor->setPalette( palette );
408 
409  QPushButton* pb_showCanvasColor = us_pushbutton( tr( "Update Color" ) );
410  connect( pb_showCanvasColor, SIGNAL( clicked() ), SLOT( selectCanvasColor() ) );
411 
412  main->addWidget( lb_canvasColor, row, 0 );
413  main->addWidget( lb_showCanvasColor, row, 1 );
414  main->addWidget( pb_showCanvasColor, row++, 2 );
415 
416  // Row 5
417  QLabel* lb_margin = us_label( tr( "Border Margin:" ) );
418  QComboBox* cmbb_margin = us_comboBox();
419 
420  for ( int i = 2; i <= 30; i += 2 )
421  {
422  cmbb_margin->addItem( QString::number( i ) + " pixels" );
423  }
424 
425  cmbb_margin->setCurrentIndex( plot->margin() / 2 - 1 );
426  connect( cmbb_margin, SIGNAL( activated ( int ) ),
427  SLOT ( selectMargin( int ) ) );
428 
429  main->addWidget( lb_margin , row, 0 );
430  main->addWidget( cmbb_margin, row++, 1, 1, 2 );
431 
432  // Row 6
433  QLabel* lb_legendPos = us_label( tr( "Legend Position:" ) );
434 
436 
437  cmbb_legendPos->addItem( "None" );
438  cmbb_legendPos->addItem( "Left" );
439  cmbb_legendPos->addItem( "Right" );
440  cmbb_legendPos->addItem( "Top" );
441  cmbb_legendPos->addItem( "Bottom" );
442 
443  int position = 0;
444 
445  switch ( plot->plotLayout()->legendPosition() )
446  {
447  case QwtPlot::LeftLegend : position = 1; break;
448  case QwtPlot::RightLegend : position = 2; break;
449  case QwtPlot::TopLegend : position = 3; break;
450  case QwtPlot::BottomLegend : position = 4; break;
451  case QwtPlot::ExternalLegend : break; // Shouldn't happen
452  }
453 
454  // Check to see it there is actually a legend in the plot
455  if ( plot->legend() == NULL ) position = 0;
456 
457  cmbb_legendPos->setCurrentIndex( position );
458 
459  connect( cmbb_legendPos, SIGNAL( activated ( int ) ),
460  SLOT ( selectLegendPos( int ) ) );
461 
462  main->addWidget( lb_legendPos , row, 0 );
463  main->addWidget( cmbb_legendPos, row++, 1, 1, 2 );
464 
465  // Row 7
466  QLabel* lb_legendFont = us_label( tr( "Legend Font:" ) );
467 
468  le_legendFont = us_lineedit( "", 1 );
470  le_legendFont->setReadOnly( true );
471 
472  QPushButton* pb_legendFont = us_pushbutton( tr( "Update Font" ) );
473  connect( pb_legendFont, SIGNAL( clicked () ),
474  SLOT ( updateLegendFont() ) );
475 
476  main->addWidget( lb_legendFont, row, 0 );
477  main->addWidget( le_legendFont, row, 1 );
478  main->addWidget( pb_legendFont, row++, 2 );
479 
480  // Row 8
481  US_PlotPushbutton* pb_leftAxis =
482  new US_PlotPushbutton( tr( "Update Left Axis" ), this, QwtPlot::yLeft );
483 
484  US_PlotPushbutton* pb_rightAxis =
485  new US_PlotPushbutton( tr( "Update Right Axis" ), this, QwtPlot::yRight );
486 
487  US_PlotPushbutton* pb_topAxis =
488  new US_PlotPushbutton( tr( "Update Top Axis" ), this, QwtPlot::xTop );
489 
490  US_PlotPushbutton* pb_bottomAxis =
491  new US_PlotPushbutton( tr( "Update Bottom Axis" ), this, QwtPlot::xBottom );
492 
493  connect( pb_leftAxis, SIGNAL( US_PlotPbPushed( int ) ),
494  SLOT ( updateAxis ( int ) ) );
495 
496  connect( pb_rightAxis, SIGNAL( US_PlotPbPushed( int ) ),
497  SLOT ( updateAxis ( int ) ) );
498 
499  connect( pb_topAxis, SIGNAL( US_PlotPbPushed( int ) ),
500  SLOT ( updateAxis ( int ) ) );
501 
502  connect( pb_bottomAxis, SIGNAL( US_PlotPbPushed( int ) ),
503  SLOT ( updateAxis ( int ) ) );
504 
505  QBoxLayout* axes = new QHBoxLayout();
506  axes->addWidget( pb_leftAxis );
507  axes->addWidget( pb_rightAxis );
508  axes->addWidget( pb_topAxis );
509  axes->addWidget( pb_bottomAxis );
510 
511  main->addLayout( axes, row++, 0, 1, 3 );
512 
513  // Row 9
514  QPushButton* pb_grid = us_pushbutton( tr( "Update Gridlines" ) );
515  connect( pb_grid, SIGNAL( clicked() ), SLOT( updateGrid() ) );
516  main->addWidget( pb_grid, row++, 0, 1, 3 );
517 
518  // Row 10
519  QLabel* lb_curve = us_banner( tr( "----- Curve Elements -----" ) );
520  lb_curve->setFixedHeight( 40 );
521 
522  main->addWidget( lb_curve, row++, 0, 1, 3 );
523 
524  // Row 11
525  lw_curves = us_listwidget( 1 );
526  lw_curves->setMinimumHeight( 26 * 5 );
527  lw_curves->setSelectionMode( QAbstractItemView::ExtendedSelection );
528 
529  // Populate list widget
530  QwtPlotItemList list = plot->itemList();
531 
532  int j = 1;
533 
534  for ( int i = 0; i < list.size(); i++ )
535  {
536  if ( list[ i ]->rtti() == QwtPlotItem::Rtti_PlotCurve )
537  {
538  QString label = "(" + QString::number( j++ ) + ") ";
539  lw_curves->addItem( label + list[ i ]->title().text() );
540  }
541  }
542 
543  main->addWidget( lw_curves, row++, 0, 1, 3 );
544 
545  // Row 12
546  QPushButton* pb_curve = us_pushbutton( tr( "Update Selected Curve(s)" ) );
547  connect( pb_curve, SIGNAL( clicked() ), SLOT( updateCurve() ) );
548 
549  main->addWidget( pb_curve, row++, 0, 1, 3 );
550 
551  // Row 13
552  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
553  connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
554 
555  main->addWidget( pb_close, row++, 0, 1, 3 );
556 }
557 
561 void US_PlotConfig::updateTitleText( const QString &newText )
562 {
563  plot->setTitle( newText );
564  plot->updateLayout();
565 }
566 
569 {
570  bool ok;
571  QFont currentFont = plot->title().font();
572  QFont newFont = QFontDialog::getFont( &ok, currentFont, this,
573  tr( "Set Title Font" ), 0 );
574 
575  if ( ok )
576  {
577  QwtText title = plot->title();
578  title.setFont( newFont );
579  plot->setTitle( title );
580 
581  le_titleFont->setText( newFont.family() + ", "
582  + QString::number( newFont.pointSize() ) + tr( " points" ) );
583  }
584 }
585 
588 {
589  QPalette p = lb_showCanvasColor->palette();
590  QColor current = p.color( QPalette::Active, QPalette::Window );
591  QColor c = QColorDialog::getColor( current, this, tr( "Select canvas color" ) );
592 
593  if ( c.isValid() )
594  {
595  p.setColor( QPalette::Active , QPalette::Window, c );
596  p.setColor( QPalette::Inactive, QPalette::Window, c );
597  lb_showCanvasColor->setPalette( p );
598  plot->setCanvasBackground( c );
599  plot->replot();
600  }
601 }
602 
605 {
606  QPalette p = plot->palette();
607  QColor current = p.color( QPalette::Active, QPalette::Window );
608  QColor c = QColorDialog::getColor( current, this, tr( "Select canvas color" ) );
609 
610  if ( c.isValid() )
611  {
612  p.setColor( QPalette::Active , QPalette::Window, c );
613  p.setColor( QPalette::Inactive, QPalette::Window, c );
614  lb_showFrameColor->setPalette( p );
615  plot->setPalette( p );
616  }
617 }
618 
623 {
624  plot->setMargin( ( index + 1 ) * 2 );
625 }
626 
631 {
632  QwtLegend* legend = NULL;
633 
634  if ( index > 0 )
635  {
636  legend = new QwtLegend;
637  legend->setFrameStyle( QFrame::Box | QFrame::Sunken );
638  }
639 
640  plot->insertLegend( NULL, QwtPlot::BottomLegend );
641 
642  switch ( index )
643  {
644  case 1: plot->insertLegend( legend, QwtPlot::LeftLegend ); break;
645  case 2: plot->insertLegend( legend, QwtPlot::RightLegend ); break;
646  case 3: plot->insertLegend( legend, QwtPlot::TopLegend ); break;
647  case 4: plot->insertLegend( legend, QwtPlot::BottomLegend ); break;
648  }
649 
651  plot->replot();
652 }
653 
655 {
656  QString legendFontString;
657 
658  // Update font description
659  if ( cmbb_legendPos->currentIndex() == 0 )
660  {
661  legendFontString = tr( "No legend for this plot" );
662  }
663  else
664  {
665  QFont legendFont = plot->legend()->font();
666  legendFontString = legendFont.family() + ", "
667  + QString::number( legendFont.pointSize() ) + tr( " points" );
668  }
669 
670  le_legendFont->setText( legendFontString );
671 }
672 
675 {
676  if ( cmbb_legendPos->currentIndex() == 0 )
677  {
678  QMessageBox::warning( this,
679  tr( "Plog Config Warning" ),
680  tr( "The layout does not exist. Set the legend position first." ) );
681  return;
682  }
683 
684  QFont font = plot->legend()->font();
685 
686  bool ok;
687  QFont newFont = QFontDialog::getFont( &ok, font, this,
688  tr( "Set Legend Font" ), 0 );
689 
690  plot->legend()->setFont( newFont );
692  plot->replot();
693 }
694 
696 {
697  // Prevent opening more than one axis configuration
698  if ( axisWidget != NULL )
699  {
700  axisWidget->close();
701  }
702 
703  axisWidget = new US_PlotAxisConfig( axis, plot );
704  //axisWidget->setAttribute( Qt::WA_DeleteOnClose );
705  //connect( axisWidget, SIGNAL( axisConfigClosed( void ) ),
706  // SLOT ( axisConfigFinish( void ) ) );
707  //axisWidget->show();
708  axisWidget->exec();
709  qApp->processEvents();
710  delete axisWidget;
711  axisWidget = NULL;
712 
713 }
714 
719 {
720  if ( lw_curves->selectedItems().count() == 0 )
721  {
722  QMessageBox::information( this,
723  tr( "Attention" ),
724  tr( "No curves have been selected." ) );
725 
726  return;
727  }
728 
729  if ( curveWidget != NULL )
730  {
731  curveWidget->close();
732  }
733 
734  QStringList selected;
735  QList< QListWidgetItem* > items = lw_curves->selectedItems();
736 
737  for ( int i = 0; i < items.count(); i++ )
738  selected << items[i]->text();
739 
740  curveWidget = new US_PlotCurveConfig( plot, selected );
741  //curveWidget->setAttribute( Qt::WA_DeleteOnClose );
742  //connect( curveWidget, SIGNAL( curveConfigClosed( void ) ),
743  // SLOT ( curveConfigFinish( void ) ) );
744  //curveWidget->show();
745  curveWidget->exec();
746  qApp->processEvents();
747  delete curveWidget;
748  curveWidget = NULL;
749 #ifdef Q_WS_MAC
750  QMessageBox::information( this, tr( "Curve Config" ),
751  tr( "Curve Update Complete" ) );
752 #endif
753  qApp->processEvents();
754 }
755 
757 {
758  // Prevent opening more than one grid configuration
759  if ( gridWidget != NULL )
760  {
761  //gridWidget->close();
762  }
763 
765  //gridWidget->setAttribute( Qt::WA_DeleteOnClose );
766  //connect( gridWidget, SIGNAL( gridConfigClosed( void ) ),
767  // SLOT ( gridConfigFinish( void ) ) );
768  //gridWidget->show();
769  gridWidget->exec();
770  qApp->processEvents();
771  delete gridWidget;
772  gridWidget = NULL;
773 #ifdef Q_WS_MAC
774  QMessageBox::information( this, tr( "Grid Config" ),
775  tr( "Grid Update Complete" ) );
776  qApp->processEvents();
777 #endif
778 }
779 /*
780 void US_PlotConfig::closeEvent( QCloseEvent* e )
781 {
782  if ( axisWidget != NULL ) axisWidget->close();
783  if ( gridWidget != NULL ) gridWidget->close();
784  //if ( curveWidget != NULL ) curveWidget->close();
785 
786  //emit plotConfigClosed();
787  e->accept();
788 }
789 
790 void US_PlotConfig::axisConfigFinish( void )
791 {
792  axisWidget = NULL;
793 }
794 
795 void US_PlotConfig::curveConfigFinish( void )
796 {
797  curveWidget = NULL;
798 }
799 
800 void US_PlotConfig::gridConfigFinish( void )
801 {
802  gridWidget = NULL;
803 }
804 */
805 /******************* QwtPlotCurveConfig Class ***********************/
806 
815  const QStringList& selected, QWidget* parent, Qt::WindowFlags f )
816  : US_WidgetsDialog( parent, f ) //( false, parent, f )
817 {
818  plot = currentPlot;
819  selectedItems = selected;
820 
821  // Keep out of the way
822  //move( pos() + QPoint( plot->rect().width(), 0 ) );
823 
824  setWindowTitle( tr( "Curve Configuration" ) );
825  setPalette( US_GuiSettings::frameColor() );
826 
827  // Find the first curve selected
828  QwtPlotItemList list = plot->itemList();
829 
830  // Remove passed '(number) '
831  QString firstSelectedText = selected[ 0 ];
832  firstSelectedText.replace( QRegExp( "^\\(\\d+\\) " ), "" );
833 
834  firstSelectedCurve = NULL;
835 
836  for ( int i = 0; i < list.size(); i++ )
837  {
838  if ( list[ i ]->rtti() == QwtPlotItem::Rtti_PlotCurve &&
839  list[ i ]->title().text() == firstSelectedText )
840  {
841  firstSelectedCurve = dynamic_cast< QwtPlotCurve* >( list[ i ] );
842  break;
843  }
844  }
845 
846  if ( firstSelectedCurve == NULL )
847  {
848  qDebug() << "Could not find first selected curve";
849  return;
850  }
851 
852  // Set up the dialog
853  int row = 0;
854 
855  QGridLayout* main = new QGridLayout( this );
856  main->setContentsMargins( 2, 2, 2, 2 );
857  main->setSpacing( 2 );
858 
859  // Row 0
860  QLabel* lb_sample1 = us_label( tr( "Sample:" ) );
861 
862  lb_sample2 = new US_PlotLabel( this );
863  QPalette p = lb_sample2->palette();
864  p.setColor( QPalette::Window, plot->canvasBackground() );
865  lb_sample2->setPalette( p );
866 
867  main->addWidget( lb_sample1, row , 0 );
868  main->addWidget( lb_sample2, row++, 1, 1, 2 );
869 
870  // Row 1
871  QLabel* lb_curve = us_banner( tr( "---- Update Curve Elements ----" ) );
872  main->addWidget( lb_curve, row++, 0, 1, 3 );
873 
874  // Row 2
875  QLabel* lb_curveTitle = us_label( tr( "Title:" ) );
876  le_curveTitle = us_lineedit( "" );
877 
878  if ( selected.size() > 1 )
879  {
880  le_curveTitle->insert( tr( "Multiple curves selected - not changeable" ) );
881  le_curveTitle->setReadOnly( true );
882  }
883  else
884  le_curveTitle->insert( firstSelectedText );
885 
886  main->addWidget( lb_curveTitle, row , 0 );
887  main->addWidget( le_curveTitle, row++, 1, 1, 2 );
888 
889  // Row 3 - Style and width
890  QLabel* lb_curveStyle = us_label( tr( "Style:" ) );
892  cmbb_curveStyle->addItem( tr( "None" ), QwtPlotCurve::NoCurve );
893  cmbb_curveStyle->addItem( tr( "Lines" ), QwtPlotCurve::Lines );
894  cmbb_curveStyle->addItem( tr( "Sticks" ), QwtPlotCurve::Sticks );
895  cmbb_curveStyle->addItem( tr( "Steps" ), QwtPlotCurve::Steps );
896  cmbb_curveStyle->addItem( tr( "Dots" ), QwtPlotCurve::Dots );
897 
898  QList< int > curveStyles;
899  curveStyles << QwtPlotCurve::NoCurve << QwtPlotCurve::Lines
900  << QwtPlotCurve::Sticks << QwtPlotCurve::Steps
901  << QwtPlotCurve::Dots;
902 
903  curveStyle = firstSelectedCurve->style();
904 
905  for ( int i = 0; i < curveStyles.size(); i++ )
906  if ( curveStyles [ i ] == firstSelectedCurve->style() )
907  {
908  cmbb_curveStyle->setCurrentIndex ( i );
909  break;
910  }
911 
912  connect( cmbb_curveStyle, SIGNAL( currentIndexChanged( int ) ),
913  SLOT ( curveStyleChanged ( int ) ) );
914 
915  QBoxLayout* stylewidth = new QHBoxLayout();
916  stylewidth->addWidget( cmbb_curveStyle );
917 
918  QLabel* lb_curveWidth = us_label( tr( "Width (pixels):" ) );
919  stylewidth->addWidget( lb_curveWidth );
920 
921  sb_curveWidth = new QSpinBox;
922  sb_curveWidth->setRange( 1, 10 );
923  sb_curveWidth->setValue( firstSelectedCurve->pen().width() );
924  connect( sb_curveWidth, SIGNAL( valueChanged( int ) ),
925  SLOT ( updateSample( int ) ) );
926 
927  stylewidth->addWidget( sb_curveWidth );
928 
929  main->addWidget( lb_curveStyle, row , 0 );
930  main->addLayout( stylewidth , row++, 1, 1, 2 );
931  // Row 4 - Color
932  QLabel* lb_curveColor = us_label( tr( "Color:" ) );
933 
934  lb_showCurveColor = us_label( "" , 1 );
935  p = lb_showCurveColor->palette();
936  p.setColor( QPalette::Window, firstSelectedCurve->pen().color() );
937  lb_showCurveColor->setPalette( p );
938 
939  QPushButton* pb_showCurveColor = us_pushbutton ( tr( "Update Color" ) );
940  connect( pb_showCurveColor, SIGNAL( clicked () ),
941  SLOT ( selectCurveColor() ) );
942 
943  main->addWidget( lb_curveColor , row , 0 );
944  main->addWidget( lb_showCurveColor, row , 1 );
945  main->addWidget( pb_showCurveColor, row++, 2 );
946 
947  // Row 5
948  QLabel* lb_symbol = us_banner( tr( "---- Update Symbol Elements ----" ) );
949  main->addWidget( lb_symbol, row++, 0, 1, 3 );
950 
951  // Row 6 Symbol Style
952  QLabel* lb_symbolStyle = us_label( tr( "Style:" ) );
954  cmbb_symbolStyle->addItem( tr( "No Symbol" ), QwtSymbol::NoSymbol );
955  cmbb_symbolStyle->addItem( tr( "Ellipse" ), QwtSymbol::Ellipse );
956  cmbb_symbolStyle->addItem( tr( "Rectangle" ), QwtSymbol::Rect );
957  cmbb_symbolStyle->addItem( tr( "Diamond" ), QwtSymbol::Diamond );
958  cmbb_symbolStyle->addItem( tr( "Down Triangle" ), QwtSymbol::DTriangle );
959  cmbb_symbolStyle->addItem( tr( "Up Triangle" ), QwtSymbol::UTriangle );
960  cmbb_symbolStyle->addItem( tr( "Left Triangle" ), QwtSymbol::LTriangle );
961  cmbb_symbolStyle->addItem( tr( "Right Triangle" ), QwtSymbol::RTriangle );
962  cmbb_symbolStyle->addItem( tr( "Cross" ), QwtSymbol::Cross );
963  cmbb_symbolStyle->addItem( tr( "X Cross" ), QwtSymbol::XCross );
964  cmbb_symbolStyle->addItem( tr( "Horizontal Line" ), QwtSymbol::HLine );
965  cmbb_symbolStyle->addItem( tr( "Vertical Line" ), QwtSymbol::VLine );
966  cmbb_symbolStyle->addItem( tr( "Star 1" ), QwtSymbol::Star1 );
967  cmbb_symbolStyle->addItem( tr( "Star 2" ), QwtSymbol::Star2 );
968  cmbb_symbolStyle->addItem( tr( "Hexagon" ), QwtSymbol::Hexagon );
969 
970  QList< int > symbolStyles;
971  symbolStyles
972  << QwtSymbol::NoSymbol << QwtSymbol::Rect << QwtSymbol::Diamond
973  << QwtSymbol::Triangle << QwtSymbol::DTriangle << QwtSymbol::UTriangle
974  << QwtSymbol::LTriangle << QwtSymbol::RTriangle << QwtSymbol::Cross
975  << QwtSymbol::XCross << QwtSymbol::HLine << QwtSymbol::VLine
976  << QwtSymbol::Star1 << QwtSymbol::Star2 << QwtSymbol::Hexagon;
977 
978  symbolStyle = firstSelectedCurve->symbol().style();
979 
980  for ( int i = 0; i < symbolStyles.size(); i++ )
981  if ( symbolStyles [ i ] == symbolStyle )
982  {
983  cmbb_symbolStyle->setCurrentIndex ( i );
984  break;
985  }
986 
987  connect( cmbb_symbolStyle, SIGNAL( currentIndexChanged( int ) ),
988  SLOT ( symbolStyleChanged ( int ) ) );
989 
990  main->addWidget( lb_symbolStyle , row , 0 );
991  main->addWidget( cmbb_symbolStyle, row++, 1, 1, 2 );
992 
993  // Row 7 Symbol width and height
994  QLabel* lb_symbolWidth = us_label( tr( "Width (pixels):" ) );
995 
996  sb_symbolWidth = new QSpinBox;
997  sb_symbolWidth->setRange( 1, 30 );
998  sb_symbolWidth->setValue( firstSelectedCurve->symbol().size().width() );
999  connect( sb_symbolWidth, SIGNAL( valueChanged( int ) ),
1000  SLOT ( updateSample( int ) ) );
1001 
1002  QLabel* lb_symbolHeight = us_label( tr( "Height (pixels):" ) );
1003 
1004  sb_symbolHeight = new QSpinBox;
1005  sb_symbolHeight->setRange( 1, 30 );
1006  sb_symbolHeight->setValue( firstSelectedCurve->symbol().size().height() );
1007  connect( sb_symbolWidth, SIGNAL( valueChanged( int ) ),
1008  SLOT ( updateSample( int ) ) );
1009 
1010  QBoxLayout* heightwidth = new QHBoxLayout();
1011  heightwidth->addWidget( sb_symbolWidth );
1012  heightwidth->addWidget( lb_symbolHeight );
1013  heightwidth->addWidget( sb_symbolHeight );
1014 
1015  main->addWidget( lb_symbolWidth, row , 0 );
1016  main->addLayout( heightwidth , row++, 1, 1, 2 );
1017 
1018  // Row 8 Symbol Color -- Interior and Exterior
1019  QLabel* lb_symbolOutlineColor = us_label( tr( "Outline Color:" ) );
1020 
1021  lb_showSymbolOutlineColor = us_label( "" , 1 );
1022  p = lb_showSymbolOutlineColor->palette();
1023  p.setColor( QPalette::Window, firstSelectedCurve->symbol().pen().color() );
1024  lb_showSymbolOutlineColor->setPalette( p );
1025 
1026  QPushButton* pb_symOutlineColor = us_pushbutton ( tr( "Update Color" ) );
1027  connect( pb_symOutlineColor, SIGNAL( clicked () ),
1028  SLOT ( selectSymbolOutlineColor() ) );
1029 
1030  QLabel* lb_symbolInteriorColor = us_label( tr( "Interior Color:" ) );
1031 
1033  p = lb_showSymbolInteriorColor->palette();
1034  p.setColor( QPalette::Window, firstSelectedCurve->symbol().brush().color() );
1035  lb_showSymbolInteriorColor->setPalette( p );
1036 
1037  QPushButton* pb_symInteriorColor = us_pushbutton ( tr( "Update Color" ) );
1038  connect( pb_symInteriorColor, SIGNAL( clicked () ),
1039  SLOT ( selectSymbolInteriorColor() ) );
1040 
1041  QBoxLayout* symbolcolor = new QHBoxLayout();
1042  symbolcolor->addWidget( lb_showSymbolOutlineColor );
1043  symbolcolor->addWidget( pb_symOutlineColor );
1044  symbolcolor->addWidget( lb_symbolInteriorColor );
1045  symbolcolor->addWidget( lb_showSymbolInteriorColor );
1046  symbolcolor->addWidget( pb_symInteriorColor );
1047 
1048  main->addWidget( lb_symbolOutlineColor, row , 0 );
1049  main->addLayout( symbolcolor , row++, 1, 1, 2 );
1050 
1051  // Row 9
1052  QPushButton* pb_apply = us_pushbutton( tr( "Apply" ) );
1053  connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
1054 
1055  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
1056  connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
1057 
1058  QBoxLayout* applyClose = new QHBoxLayout();
1059  applyClose->addWidget( pb_apply );
1060  applyClose->addWidget( pb_close );
1061 
1062  main->addLayout( applyClose, row++, 0, 1, 3 );
1063 }
1064 /*
1065 void US_PlotCurveConfig::closeEvent( QCloseEvent* e )
1066 {
1067  emit curveConfigClosed();
1068  e->accept();
1069 }
1070 */
1072 {
1073  lb_sample2->update();
1074 }
1075 
1077 {
1078  int style = cmbb_curveStyle->itemData( index ).toInt();
1079  curveStyle = static_cast< QwtPlotCurve::CurveStyle > ( style );
1080  lb_sample2->update();
1081 }
1082 
1084 {
1085  int style = cmbb_symbolStyle->itemData( index ).toInt();
1086  symbolStyle = static_cast< QwtSymbol::Style > ( style );
1087  lb_sample2->update();
1088 }
1089 
1091 {
1092  QPalette p = lb_showCurveColor->palette();
1093  QColor current = p.color( QPalette::Active, QPalette::Window );
1094  QColor c = QColorDialog::getColor( current, this,
1095  tr( "Select curve color" ) );
1096 
1097  if ( c.isValid() )
1098  {
1099  p.setColor( QPalette::Window, c );
1100  lb_showCurveColor->setPalette( p );
1101  lb_sample2->update();
1102  }
1103 }
1104 
1106 {
1107  QPalette p = lb_showSymbolInteriorColor->palette();
1108  QColor current = p.color( QPalette::Active, QPalette::Window );
1109  QColor c = QColorDialog::getColor( current, this,
1110  tr( "Select symbol interior color" ) );
1111 
1112  if ( c.isValid() )
1113  {
1114  p.setColor( QPalette::Window, c );
1115  lb_showSymbolInteriorColor->setPalette( p );
1116  lb_sample2->update();
1117  }
1118 }
1119 
1121 {
1122  QPalette p = lb_showSymbolOutlineColor->palette();
1123  QColor current = p.color( QPalette::Active, QPalette::Window );
1124  QColor c = QColorDialog::getColor( current, this,
1125  tr( "Select symbol outline color" ) );
1126 
1127  if ( c.isValid() )
1128  {
1129  p.setColor( QPalette::Window, c );
1130  lb_showSymbolOutlineColor->setPalette( p );
1131  lb_sample2->update();
1132  }
1133 }
1134 
1136 {
1137  QwtSymbol oldSymbol = firstSelectedCurve->symbol();
1138  QPen symbolPen = oldSymbol.pen();
1139  QBrush symbolBrush = oldSymbol.brush();
1140 
1141  QPalette palette = lb_showSymbolOutlineColor->palette();
1142  symbolPen.setColor( palette.color( QPalette::Window ) );
1143 
1144  palette = lb_showSymbolInteriorColor->palette();
1145  symbolBrush.setColor( palette.color( QPalette::Window ) );
1146 
1147  QSize symbolSize( sb_symbolWidth->value(), sb_symbolHeight->value() );
1148 
1149  QwtSymbol newSymbol( symbolStyle, symbolBrush, symbolPen, symbolSize );
1150 
1151  palette = lb_showCurveColor->palette();
1152  QPen curvePen( palette.color( QPalette::Window ) );
1153  curvePen.setWidth( sb_curveWidth->value() );
1154 
1155 
1156  QwtPlotItemList list = plot->itemList(); // All items
1157 
1158  int j = 0;
1159 
1160  // Iterate through the selected curves
1161  for ( int i = 0; i < selectedItems.size(); i++ )
1162  {
1163  // Remove Numbering from passed titles
1164  QString title = selectedItems[ i ];
1165  title.replace( QRegExp( "^\\(\\d+\\) " ), "" );
1166 
1167  // There is no need to reiterate over the full list
1168  // This assumes the selected list and the full list
1169  // are in the same order
1170 
1171  for ( /* no intitalizer */; j < list.size(); j++ )
1172  {
1173  if ( list[ j ]->rtti() != QwtPlotItem::Rtti_PlotCurve ) continue;
1174  if ( list[ j ]->title() == title )
1175  {
1176  QwtPlotCurve* curve = dynamic_cast< QwtPlotCurve* > ( list[ j ] );
1177  if ( selectedItems.size() == 1 )
1178  curve->setTitle( le_curveTitle->text() );
1179 
1180  curve->setSymbol( newSymbol);
1181  curve->setPen ( curvePen );
1182  curve->setStyle ( curveStyle );
1183  break;
1184  }
1185  }
1186 
1187  }
1188  plot->replot();
1189 }
1190 
1191 //**** Custom class to display curve configuration ********
1192 
1194  QWidget* p, Qt::WindowFlags f ) : QWidget( p, f )
1195 {
1196  data = caller;
1197  label = new QLabel;
1198 }
1199 
1200 void US_PlotLabel::paintEvent( QPaintEvent* e )
1201 {
1202  QRect r = e->rect();
1203 
1204  int height = r.y() + r.height() / 2;
1205  int first = r.x() + r.width() / 10;
1206  int last = r.x() + r.width() * 9 / 10;
1207  int length = last - first;
1208 
1209  QPoint p1 = QPoint( first , height ); // 0%
1210  QPoint p2 = QPoint( first + length / 4, height ); // 25%
1211  QPoint p3 = QPoint( first + length / 2, height ); // 50%
1212  QPoint p4 = QPoint( last - length / 4, height ); // 75%
1213  QPoint p5 = QPoint( last , height ); // 100%
1214 
1215  int y1;
1216  int y2;
1217 
1218  QPainter p( this );
1219  p.save();
1220 
1221  // Paint the background
1222  QBrush brush( data->plot->canvasBackground() );
1223  p.fillRect( e->rect(), brush );
1224 
1225  QPen pen ( data->firstSelectedCurve->pen() );
1226  QPalette foreground = data->lb_showCurveColor->palette();
1227  pen.setColor( foreground.color( QPalette::Window ) );
1228  pen.setWidth( data->sb_curveWidth->value() );
1229  p.setPen ( pen );
1230 
1231  // Paint the curve
1232  switch( data->curveStyle )
1233  {
1234  case QwtPlotCurve::NoCurve:
1235  break;
1236 
1237  case QwtPlotCurve::Lines:
1238  p.drawLine( p1, p5 );
1239  break;
1240 
1241  case QwtPlotCurve::Sticks:
1242  y1 = p1.y() - 6;
1243  y2 = p1.y() + 6;
1244 
1245  for( int i = p1.x(); i < p5.x(); i += 8 )
1246  p.drawLine( i, y1, i, y2 );
1247  break;
1248 
1249  case QwtPlotCurve::Steps:
1250  y1 = p1.y() + 3;
1251  y2 = p1.y() - 3;
1252 
1253  for ( int i = p1.x(); i < p5.x(); i += 10 )
1254  {
1255  p.drawLine( i , y1, i + 10, y2 );
1256  p.drawLine( i + 10, y2, i + 10, y1 );
1257  }
1258  break;
1259 
1260  case QwtPlotCurve::Dots:
1261  for ( int i = p1.x(); i < p5.x() ; i += 6 )
1262  p.drawPoint( i, p1.y() );
1263  break;
1264 
1265  default:
1266  break;
1267  }
1268 
1269  if ( data->symbolStyle != QwtSymbol::NoSymbol )
1270  {
1271  QSize size( data->sb_symbolWidth->value(),
1272  data->sb_symbolHeight->value() );
1273 
1274  QPalette palette = data->lb_showSymbolOutlineColor->palette();
1275  pen.setColor( palette.color( QPalette::Window ) );
1276 
1277  palette = data->lb_showSymbolInteriorColor->palette();
1278  brush.setColor( palette.color( QPalette::Window ) );
1279 
1280  QwtSymbol s( data->symbolStyle, brush, pen, size );
1281 
1282  s.draw( &p, p2 );
1283  s.draw( &p, p3 );
1284  s.draw( &p, p4 );
1285  }
1286 
1287  p.restore();
1288 }
1289 
1290 /**************** QwtPlotAxisConfig Class *********************/
1291 
1299 US_PlotAxisConfig::US_PlotAxisConfig( int currentAxis, QwtPlot* currentPlot,
1300  QWidget* parent, Qt::WindowFlags flags ) : US_WidgetsDialog( parent, flags )//( false, parent, flags )
1301 {
1302  plot = currentPlot;
1303  axis = currentAxis;
1304 
1305  // Keep out of the way
1306  //move( pos() + QPoint( plot->rect().width(), 0 ) );
1307 
1308  QString axisLocation;
1309 
1310  switch ( axis )
1311  {
1312  case QwtPlot::yLeft : axisLocation = tr( "Left" ); break;
1313  case QwtPlot::yRight : axisLocation = tr( "Right" ); break;
1314  case QwtPlot::xTop : axisLocation = tr( "Top" ); break;
1315  case QwtPlot::xBottom: axisLocation = tr( "Bottom" ); break;
1316  }
1317 
1318  setWindowTitle( axisLocation + tr( " Axis Configuration" ) );
1319  setPalette( US_GuiSettings::frameColor() );
1320 
1321  int row = 0;
1322 
1323  QGridLayout* main = new QGridLayout( this );
1324  main->setContentsMargins( 2, 2, 2, 2 );
1325  main->setSpacing( 2 );
1326 
1327  // Row 0
1328  QLabel* lb_present = us_label( axisLocation + tr( " Axis Present:" ) );
1329  Qt::CheckState checked = ( plot->axisEnabled( axis ) )
1330  ? Qt::Checked : Qt::Unchecked;
1331 
1332  QGridLayout* present = us_checkbox( "", cb_present, checked );
1333 
1334  main->addWidget( lb_present, row , 0 );
1335  main->addLayout( present , row++, 1 );
1336 
1337  // Row 1
1338  QLabel* lb_title = us_label( tr( "Axis Title:" ) );
1339 
1340  le_titleText = us_lineedit( plot->axisTitle( axis ).text(), 1 );
1341  le_titleText->setMinimumWidth( 350 );
1342 
1343  main->addWidget( lb_title , row , 0 );
1344  main->addWidget( le_titleText, row++, 1, 1, 2 );
1345 
1346  // Row 2
1347  QLabel* lb_axisTitleFont = us_label( tr( "Axis Title Font:" ) );
1348 
1349  axisTitleFont = plot->axisTitle( axis ).font();
1350 
1351  le_axisTitleFont = us_lineedit( axisTitleFont.family() + ", "
1352  + QString::number( axisTitleFont.pointSize() ) + tr( " points" ), 1 );
1353  le_axisTitleFont->setReadOnly( true );
1354 
1355  QPushButton* pb_axisTitleFont = us_pushbutton( tr("Update Font") );
1356  connect( pb_axisTitleFont, SIGNAL( clicked() ), SLOT( selectTitleFont() ) );
1357 
1358  main->addWidget( lb_axisTitleFont, row, 0 );
1359  main->addWidget( le_axisTitleFont, row, 1 );
1360  main->addWidget( pb_axisTitleFont, row++, 2 );
1361 
1362 
1363  // Row 3
1364  QLabel* lb_axisTitleColor = us_label( tr( "Axis Title Color:" ) );
1365 
1366  lb_showAxisTitleColor = us_label( "" , 1 );
1367 
1368  QPalette p = plot->axisWidget( axis )->palette();
1369  p.setColor( QPalette::Window, p.color( QPalette::Text ) );
1370  lb_showAxisTitleColor->setPalette( p );
1371 
1372  QPushButton* pb_axisTitleColor = us_pushbutton ( tr( "Update Color" ) );
1373  connect( pb_axisTitleColor, SIGNAL( clicked () ),
1374  SLOT ( selectAxisTitleColor() ) );
1375 
1376  main->addWidget( lb_axisTitleColor , row, 0 );
1377  main->addWidget( lb_showAxisTitleColor, row, 1 );
1378  main->addWidget( pb_axisTitleColor , row++, 2 );
1379 
1380  // Row 4
1381  QLabel* lb_axisScaleFont = us_label( tr( "Axis Scale Font:" ) );
1382 
1383  axisScaleFont = plot->axisFont( axis );
1384 
1385  le_axisScaleFont = us_lineedit( axisScaleFont.family() + ", "
1386  + QString::number( axisScaleFont.pointSize() ) + tr( " points" ), 1 );
1387  le_axisScaleFont->setReadOnly( true );
1388 
1389  QPushButton* pb_axisScaleFont = us_pushbutton( tr("Update Font") );
1390  connect( pb_axisScaleFont, SIGNAL( clicked() ), SLOT( selectScaleFont() ) );
1391 
1392  main->addWidget( lb_axisScaleFont, row, 0 );
1393  main->addWidget( le_axisScaleFont, row, 1 );
1394  main->addWidget( pb_axisScaleFont, row++, 2 );
1395 
1396  // Row 5
1397  QLabel* lb_scaleColor = us_label( tr( "Axis Scale Color:" ) );
1398  lb_showScaleColor = us_label( "" , 1 );
1399 
1400  p = plot->axisWidget( axis )->palette();
1401  p.setColor( QPalette::Window, p.color( QPalette::WindowText ) );
1402  lb_showScaleColor->setPalette( p );
1403 
1404  QPushButton* pb_scaleColor = us_pushbutton ( tr( "Update Color" ) );
1405  connect( pb_scaleColor, SIGNAL( clicked() ), SLOT( selectScaleColor() ) );
1406 
1407  main->addWidget( lb_scaleColor , row, 0 );
1408  main->addWidget( lb_showScaleColor, row, 1 );
1409  main->addWidget( pb_scaleColor , row++, 2 );
1410 
1411  // Row 5a
1412  QLabel* lb_tickColor = us_label( tr( "Axis Tick Color:" ) );
1413  lb_showTickColor = us_label( "" , 1 );
1414 
1415  p = plot->axisWidget( axis )->palette();
1416  p.setColor( QPalette::Window, p.color( QPalette::WindowText ) );
1417  lb_showTickColor->setPalette( p );
1418 
1419  QPushButton* pb_tickColor = us_pushbutton ( tr( "Update Color" ) );
1420  connect( pb_tickColor, SIGNAL( clicked() ), SLOT( selectTickColor() ) );
1421 
1422  main->addWidget( lb_tickColor , row, 0 );
1423  main->addWidget( lb_showTickColor, row, 1 );
1424  main->addWidget( pb_tickColor , row++, 2 );
1425 
1426  // Row 6
1427  QLabel* lb_scaleFrom = us_label( tr( "Scale From:" ) );
1428  QLabel* lb_scaleTo = us_label( tr( "To:" ) );
1429  QLabel* lb_scaleStep = us_label( tr( "Step:" ) );
1430 
1432  QString::number( plot->axisScaleDiv( axis )->lowerBound() ), 1 );
1433 
1435  QString::number( plot->axisScaleDiv( axis )->upperBound() ), 1 );
1436 
1438  QString::number( plot->axisStepSize( axis ) ), 1 );
1439 
1440  QBoxLayout* scale = new QHBoxLayout;
1441  scale->addWidget( le_scaleFrom );
1442  scale->addWidget( lb_scaleTo );
1443  scale->addWidget( le_scaleTo );
1444  scale->addWidget( lb_scaleStep );
1445  scale->addWidget( le_scaleStep );
1446 
1447  main->addWidget( lb_scaleFrom, row , 0 );
1448  main->addLayout( scale , row++, 1, 1, 2 );
1449 
1450  // Row 7
1451  QLabel* lb_scaleType = us_label( tr( "Scale Type:" ) );
1452 
1453  QBoxLayout* scaleRadio = new QHBoxLayout();
1454  scaleRadio->setSpacing( 0 );
1455 
1456  QGridLayout* rb1 = us_radiobutton( tr( "Linear" ), rb_linear, true );
1457  QGridLayout* rb2 = us_radiobutton( tr( "Logarithmic" ), rb_log , false );
1458 
1459  if ( plot->axisScaleEngine( axis )->transformation()->type() ==
1460  QwtScaleTransformation::Log10 ) rb_log->setChecked( true );
1461 
1462  scaleRadio->addLayout( rb1 );
1463  scaleRadio->addLayout( rb2 );
1464 
1465  main->addWidget( lb_scaleType, row, 0 );
1466  main->addLayout( scaleRadio , row++, 1, 1, 2 );
1467 
1468  // Row 8
1469  QLabel* lb_reference = us_label( tr( "Scale Reference:" ) );
1470 
1472  QString::number( plot->axisScaleEngine( axis )->reference() ), 1 );
1473 
1474  QGridLayout* refValue = us_checkbox( QString( "Include" ), cb_refValue );
1475  QGridLayout* symmetric = us_checkbox( QString( "Symmetric" ), cb_symmetric );
1476 
1477  QBoxLayout* reference = new QHBoxLayout;
1478  reference->addWidget( le_reference );
1479  reference->addLayout( refValue );
1480  reference->addLayout( symmetric );
1481 
1482  main->addWidget( lb_reference, row, 0 );
1483  main->addLayout( reference , row++, 1, 1, 2 );
1484 
1485  // Row 9
1486  QLabel* lb_options = us_label( tr( "Scale Options:" ) );
1487 
1488  int attributes = plot->axisScaleEngine( axis )->attributes();
1489 
1490  checked = ( attributes & QwtScaleEngine::Floating )
1491  ? Qt::Checked : Qt::Unchecked;
1492 
1493  QGridLayout* floating
1494  = us_checkbox( QString( "Floating Endpoints" ), cb_floating, checked );
1495 
1496  checked = ( attributes & QwtScaleEngine::Inverted )
1497  ? Qt::Checked : Qt::Unchecked;
1498 
1499  QGridLayout* inverted
1500  = us_checkbox( QString( "Inverted Scale"), cb_inverted, checked );
1501 
1502  checked = ( plot->axisAutoScale( axis ) ) ? Qt::Checked : Qt::Unchecked;
1503  QGridLayout* autoscale
1504  = us_checkbox( QString( "Autoscale" ), cb_autoscale, checked );
1505 
1506  QBoxLayout* options = new QHBoxLayout;
1507  options->addLayout( floating );
1508  options->addLayout( inverted );
1509  options->addLayout( autoscale );
1510 
1511  main->addWidget( lb_options, row, 0 );
1512  main->addLayout( options , row++, 1, 1, 2 );
1513 
1514  // Row 10
1515  QPushButton* pb_apply = us_pushbutton( tr( "Apply" ) );
1516  connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
1517 
1518  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
1519  connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
1520 
1521  QBoxLayout* applyClose = new QHBoxLayout();
1522  applyClose->addWidget( pb_apply );
1523  applyClose->addWidget( pb_close );
1524 
1525  main->addLayout( applyClose, row++, 0, 1, 3 );
1526 }
1527 /*
1528 void US_PlotAxisConfig::closeEvent( QCloseEvent* e )
1529 {
1530  emit axisConfigClosed();
1531  e->accept();
1532 }
1533 */
1535 {
1536  bool ok;
1537  QFont currentFont = plot->axisTitle( axis ).font();
1538  QFont newFont = QFontDialog::getFont( &ok, currentFont, this,
1539  tr( "Set Axis Title Font" ), 0 );
1540 
1541  if ( ok )
1542  {
1543  axisTitleFont = newFont;
1544  le_axisTitleFont->setText( newFont.family() + ", "
1545  + QString::number( newFont.pointSize() ) + tr( " points" ) );
1546  }
1547 }
1548 
1550 {
1551  QPalette p = lb_showAxisTitleColor->palette();
1552  QColor current = p.color( QPalette::Window );
1553  QColor c = QColorDialog::getColor( current, this,
1554  tr( "Select Axis Title Color" ) );
1555 
1556  if ( c.isValid() )
1557  {
1558  p.setColor( QPalette::Window, c );
1559  lb_showAxisTitleColor->setPalette( p );
1560  }
1561 }
1562 
1564 {
1565  bool ok;
1566  QFont currentFont = plot->axisFont( axis );
1567  QFont newFont = QFontDialog::getFont( &ok, currentFont, this,
1568  tr( "Set Axis Scale Font" ), 0 );
1569 
1570  if ( ok )
1571  {
1572  axisScaleFont = newFont;
1573  le_axisScaleFont->setText( newFont.family() + ", "
1574  + QString::number( newFont.pointSize() ) + tr( " points" ) );
1575  }
1576 }
1577 
1579 {
1580  QPalette p = lb_showScaleColor->palette();
1581  QColor current = p.color( QPalette::Window );
1582  QColor c = QColorDialog::getColor( current, this,
1583  tr( "Select Scale Color" ) );
1584 
1585  if ( c.isValid() )
1586  {
1587  p.setColor( QPalette::Window, c );
1588  lb_showScaleColor->setPalette( p );
1589  }
1590 }
1591 
1593 {
1594  QPalette p = lb_showTickColor->palette();
1595  QColor current = p.color( QPalette::Window );
1596  QColor c = QColorDialog::getColor( current, this,
1597  tr( "Select Tick Color" ) );
1598 
1599  if ( c.isValid() )
1600  {
1601  p.setColor( QPalette::Window, c );
1602  lb_showTickColor->setPalette( p );
1603  }
1604 }
1605 
1607 {
1608  // This is where the work is done.
1609  // Turn the axis on or off.
1610  plot->enableAxis( axis, cb_present->isChecked() );
1611 
1612  // Set the title text
1613  plot->axisWidget( axis )->setTitle( le_titleText->text() );
1614 
1615  // Set the title font
1616  QwtText title = plot->axisTitle( axis );
1617  title.setFont( axisTitleFont );
1618 
1619  // Set the title color
1620  QPalette p = lb_showAxisTitleColor->palette();
1621  title.setColor( p.color( QPalette::Window ) );
1622 
1623  plot->setAxisTitle( axis, title );
1624 
1625  // Set the scale font
1626  plot->setAxisFont( axis, axisScaleFont );
1627 
1628  // Set the scale color
1629  p = lb_showScaleColor->palette();
1630  QPalette axisPalette = plot->axisWidget( axis )->palette();
1631  axisPalette.setColor( QPalette::Text, p.color( QPalette::Window ) );
1632 
1633  p = lb_showTickColor->palette();
1634  axisPalette.setColor( QPalette::WindowText, p.color( QPalette::Window ) );
1635 
1636  plot->axisWidget( axis )->setPalette( axisPalette );
1637 
1638  // Set the scale From, To, Step
1639  double from = le_scaleFrom->text().toDouble();
1640  double to = le_scaleTo ->text().toDouble();
1641  double step = le_scaleStep->text().toDouble();
1642 
1643  if ( ! cb_autoscale->isChecked() )
1644  plot->setAxisScale( axis, from, to, step );
1645 
1646  // Scale type - Linear or Log -- Do nothing if unchanged
1647  int plotType = plot->axisScaleEngine( axis )->transformation()->type();
1648  if ( ( plotType == QwtScaleTransformation::Log10 && rb_linear->isChecked() )
1649  || ( plotType == QwtScaleTransformation::Linear && rb_log ->isChecked() ) )
1650  {
1651  if ( rb_linear->isChecked() )
1652  plot->setAxisScaleEngine( axis, new QwtLinearScaleEngine );
1653  else
1654  plot->setAxisScaleEngine( axis, new QwtLog10ScaleEngine );
1655  }
1656 
1657  // Set scale reference
1658  double reference = le_reference->text().toDouble();
1659  plot->axisScaleEngine( axis )->setReference( reference );
1660 
1661  int attributes = 0;
1662  if ( cb_refValue ->isChecked() ) attributes |= QwtScaleEngine::IncludeReference;
1663  if ( cb_symmetric->isChecked() ) attributes |= QwtScaleEngine::Symmetric;
1664 
1665  // Set other attributes
1666 
1667  if ( cb_floating->isChecked() ) attributes |= QwtScaleEngine::Floating;
1668  if ( cb_inverted->isChecked() ) attributes |= QwtScaleEngine::Inverted;
1669  plot->axisScaleEngine( axis )->setAttributes( attributes );
1670 
1671  if ( cb_autoscale->isChecked() ) plot->setAxisAutoScale( axis );
1672 
1673  plot->replot();
1674 }
1675 
1676 /************************** US_PlotGridConfig Class *********************/
1677 
1684  QWidget* parent, Qt::WindowFlags flags ) : US_WidgetsDialog( parent, flags )//( false, parent, flags )
1685 {
1686  setWindowTitle( tr( "Grid Configuration" ) );
1687  setPalette( US_GuiSettings::frameColor() );
1688 
1689  plot = currentPlot;
1690  grid = NULL;
1691  int ngrid = 0;
1692 
1693  // Keep out of the way
1694  //move( pos() + QPoint( plot->rect().width(), 0 ) );
1695 
1696  // Get the grid - if it exists
1697  QwtPlotItemList list = plot->itemList();
1698 
1699  for ( int i = 0; i< list.size(); i++ )
1700  {
1701  if ( list[i]->rtti() == QwtPlotItem::Rtti_PlotGrid )
1702  {
1703  ngrid++;
1704  if ( ngrid == 1 )
1705  grid = dynamic_cast<QwtPlotGrid*>( list[ i ] );
1706  else
1707  list[ i ]->detach();
1708  }
1709  }
1710 qDebug() << "GRID COUNT" << ngrid;
1711 
1712  // Add an inactive grid if necessary
1713  if ( grid == NULL )
1714  {
1715  grid = new QwtPlotGrid;
1716  grid->enableX ( false );
1717  grid->enableY ( false );
1718  grid->enableXMin( false );
1719  grid->enableYMin( false );
1720  grid->attach( plot );
1721  }
1722 
1723 
1724  QGridLayout* main = new QGridLayout( this );
1725  main->setContentsMargins( 2, 2, 2, 2 );
1726  main->setSpacing( 2 );
1727  int row = 0;
1728 
1729  // Row 0
1730  QLabel* lb_major = us_banner( tr( " ---- Major Gridlines ----" ) );
1731  lb_major->setFixedHeight( 40 );
1732 
1733  main->addWidget( lb_major, row++, 0, 1, 3 );
1734 
1735  // Row 1
1736  QLabel* lb_enableMajor = us_label( tr( "Enable:" ) );
1737 
1738  Qt::CheckState checked = ( grid->xEnabled() ) ? Qt::Checked : Qt::Unchecked;
1739  QGridLayout* enableX = us_checkbox( tr( "Vertical" ), cb_enableX, checked );
1740 
1741  checked = ( grid->yEnabled() ) ? Qt::Checked : Qt::Unchecked;
1742  QGridLayout* enableY = us_checkbox( tr( "Horizontal" ), cb_enableY, checked );
1743 
1744  QBoxLayout* enableMajor = new QHBoxLayout;
1745  enableMajor->addLayout( enableX );
1746  enableMajor->addLayout( enableY );
1747 
1748  main->addWidget( lb_enableMajor, row , 0 );
1749  main->addLayout( enableMajor , row++, 1, 1, 2 );
1750 
1751  // Row 2
1752  QLabel* lb_majorColor = us_label( tr( "Color:" ) );
1753 
1754  lb_showMajorColor = us_label( "" , 1 );
1755 
1756  QPen majorPen = grid->majPen();
1757  QPalette p;
1758  p.setColor( QPalette::Window, majorPen.color() );
1759  lb_showMajorColor->setPalette( p );
1760 
1761  QPushButton* pb_majorColor = us_pushbutton ( tr( "Update Color" ) );
1762  connect( pb_majorColor, SIGNAL( clicked() ), SLOT( selectMajorColor() ) );
1763 
1764  main->addWidget( lb_majorColor , row, 0 );
1765  main->addWidget( lb_showMajorColor, row, 1 );
1766  main->addWidget( pb_majorColor , row++, 2 );
1767 
1768  // Row 3
1769  QLabel* lb_majorStyle = us_label( tr( "Style:" ) );
1770 
1771  QBoxLayout* majorStyle = new QHBoxLayout;
1772 
1773  QStringList styles;
1774  styles << tr( "Solid" ) << tr( "Dash" ) << tr( "Dot" ) << tr( "DashDotDot" )
1775  << tr( "DashDotDot" );
1776 
1777  QList< int > penStyle;
1778  penStyle << Qt::SolidLine << Qt::DashLine << Qt::DotLine << Qt::DashDotLine
1779  << Qt::DashDotDotLine;
1780 
1782  int currentStyle = majorPen.style();
1783 
1784  for ( int i = 0; i < styles.size(); i++ )
1785  {
1786  cmbb_majorStyle->addItem( styles[ i ], penStyle[ i ] );
1787 
1788  if ( currentStyle == penStyle[ i ] )
1789  cmbb_majorStyle->setCurrentIndex( i );
1790  }
1791 
1792  majorStyle->addWidget( cmbb_majorStyle );
1793 
1794  QLabel* lb_majorWidth = us_label( tr( "Width (pixels):" ) );
1795  majorStyle->addWidget( lb_majorWidth );
1796 
1797  sb_majorWidth = new QSpinBox;
1798  sb_majorWidth->setRange( 1, 5 );
1799  sb_majorWidth->setValue( majorPen.width() );
1800 
1801  majorStyle->addWidget( sb_majorWidth );
1802 
1803  main->addWidget( lb_majorStyle, row, 0 );
1804  main->addLayout( majorStyle , row++, 1, 1, 2 );
1805 
1806  // Start Minor gridline settings
1807  // Row 4
1808  QLabel* lb_minor = us_banner( tr( " ---- Minor Gridlines ----" ) );
1809  lb_minor->setFixedHeight( 40 );
1810  main->addWidget( lb_minor, row++, 0, 1, 3 );
1811 
1812  // Row 5
1813  QLabel* lb_enableMinor = us_label( tr( "Enable:" ) );
1814 
1815  checked = ( grid->xMinEnabled() ) ? Qt::Checked : Qt::Unchecked;
1816  QGridLayout* enableXminor
1817  = us_checkbox( tr( "Vertical" ), cb_enableXminor, checked );
1818 
1819  checked = ( grid->yMinEnabled() ) ? Qt::Checked : Qt::Unchecked;
1820  QGridLayout* enableYminor
1821  = us_checkbox( tr( "Horizontal" ), cb_enableYminor, checked );
1822 
1823  QBoxLayout* enableMinor = new QHBoxLayout;
1824  enableMinor->addLayout( enableXminor );
1825  enableMinor->addLayout( enableYminor );
1826 
1827  main->addWidget( lb_enableMinor, row , 0 );
1828  main->addLayout( enableMinor , row++, 1, 1, 2 );
1829 
1830  // Row 6
1831  QLabel* lb_minorColor = us_label( tr( "Color:" ) );
1832 
1833  lb_showMinorColor = us_label( "" , 1 );
1834 
1835  QPen minorPen = grid->minPen();
1836  p.setColor( QPalette::Window, minorPen.color() );
1837  lb_showMinorColor->setPalette( p );
1838 
1839  QPushButton* pb_minorColor = us_pushbutton ( tr( "Update Color" ) );
1840  connect( pb_minorColor, SIGNAL( clicked() ), SLOT( selectMinorColor() ) );
1841 
1842  main->addWidget( lb_minorColor , row, 0 );
1843  main->addWidget( lb_showMinorColor, row, 1 );
1844  main->addWidget( pb_minorColor , row++, 2 );
1845 
1846  // Row 7
1847  QLabel* lb_minorStyle = us_label( tr( "Style:" ) );
1848 
1849  QBoxLayout* minorStyle = new QHBoxLayout;
1850 
1852  currentStyle = minorPen.style();
1853 
1854  for ( int i = 0; i < styles.size(); i++ )
1855  {
1856  cmbb_minorStyle->addItem( styles[ i ], penStyle[ i ] );
1857  if ( currentStyle == penStyle[ i ] )
1858  cmbb_minorStyle->setCurrentIndex( i );
1859 
1860  }
1861 
1862  minorStyle->addWidget( cmbb_minorStyle );
1863 
1864  QLabel* lb_minorWidth = us_label( tr( "Width (pixels):" ) );
1865  minorStyle->addWidget( lb_minorWidth );
1866 
1867  sb_minorWidth = new QSpinBox;
1868  sb_minorWidth->setRange( 1, 5 );
1869  sb_minorWidth->setValue( minorPen.width() );
1870 
1871  minorStyle->addWidget( sb_minorWidth );
1872 
1873  main->addWidget( lb_minorStyle, row, 0 );
1874  main->addLayout( minorStyle , row++, 1, 1, 2 );
1875 
1876  // Row 8
1877  QPushButton* pb_apply = us_pushbutton( tr( "Apply" ) );
1878  connect( pb_apply, SIGNAL( clicked() ), SLOT( apply() ) );
1879 
1880  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
1881  connect( pb_close, SIGNAL( clicked() ), SLOT( close() ) );
1882 
1883  QBoxLayout* applyClose = new QHBoxLayout();
1884  applyClose->addWidget( pb_apply );
1885  applyClose->addWidget( pb_close );
1886 
1887  main->addLayout( applyClose, row++, 0, 1, 3 );
1888 }
1889 
1891 {
1892  QPalette p = lb_showMajorColor->palette();
1893  QColor current = p.color( QPalette::Window );
1894  QColor c = QColorDialog::getColor( current, this,
1895  tr( "Select major grid line color" ) );
1896  if ( c.isValid() )
1897  {
1898  p.setColor( QPalette::Window, c );
1899  lb_showMajorColor->setPalette( p );
1900  }
1901 }
1902 
1904 {
1905  QPalette p = lb_showMinorColor->palette();
1906  QColor current = p.color( QPalette::Window );
1907  QColor c = QColorDialog::getColor( current, this,
1908  tr( "Select minor grid line color" ) );
1909  if ( c.isValid() )
1910  {
1911  p.setColor( QPalette::Window, c );
1912  lb_showMinorColor->setPalette( p );
1913  }
1914 }
1915 
1917 {
1918  // Set the major pen
1919  QPen pen = grid->majPen();
1920 
1921  pen.setColor( lb_showMajorColor->palette().color( QPalette::Window ) );
1922  pen.setWidth( sb_majorWidth->value() );
1923 
1924  int style;
1925  style = cmbb_majorStyle->itemData( cmbb_majorStyle->currentIndex() ).toInt();
1926  pen.setStyle( static_cast< Qt::PenStyle >( style ) );
1927 
1928  grid->setMajPen( pen );
1929 
1930  // Set the minor pen
1931  pen = grid->minPen();
1932 
1933  pen.setColor( lb_showMinorColor->palette().color( QPalette::Window ) );
1934  pen.setWidth( sb_minorWidth->value() );
1935 
1936  style = cmbb_minorStyle->itemData( cmbb_minorStyle->currentIndex() ).toInt();
1937  pen.setStyle( static_cast< Qt::PenStyle >( style ) );
1938 
1939  grid->setMinPen( pen );
1940 
1941  // Enable/disable grid lines and re-plot
1942  grid->enableX ( cb_enableX ->isChecked() );
1943  grid->enableY ( cb_enableY ->isChecked() );
1944  grid->enableXMin( cb_enableXminor->isChecked() );
1945  grid->enableYMin( cb_enableYminor->isChecked() );
1946 
1947  plot->replot();
1948 }
1949 
1950 /************************** US_PlotPicker Class *********************/
1951 
1957  : QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft, plot->canvas() )
1958 {
1959  setSelectionFlags( QwtPicker::PointSelection );
1960  setTrackerMode ( QwtPicker::AlwaysOn );
1961  setRubberBand ( QwtPicker::CrossRubberBand );
1962 
1963  QColor c = US_GuiSettings::plotPicker();
1964  setRubberBandPen ( c );
1965  setTrackerPen ( c );
1966 }
1967 
1969 {
1970  // Prevent spurious clicks
1971  static QTime last_click;
1972 
1973  if ( last_click.isNull() || last_click.elapsed() > 300 )
1974  {
1975  last_click.start();
1976  if ( e->button() == Qt::LeftButton )
1977  emit mouseDown( invTransform( e->pos() ) );
1978  if ( e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier )
1979  {
1980  emit cMouseDown ( invTransform( e->pos() ) );
1981  emit cMouseDownRaw( e );
1982  }
1983  }
1984 
1985  QwtPlotPicker::widgetMousePressEvent( e );
1986 }
1987 
1989 {
1990  static QTime last_click;
1991 
1992  if ( last_click.isNull() || last_click.elapsed() > 300 )
1993  {
1994  last_click.start();
1995  if ( e->button() == Qt::LeftButton )
1996  emit mouseUp( invTransform( e->pos() ) );
1997 
1998  if ( e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier )
1999  emit cMouseUp( invTransform( e->pos() ) );
2000  }
2001 
2002  QwtPlotPicker::widgetMouseReleaseEvent( e );
2003 }
2004 
2006 {
2007  static QTime last_click;
2008 
2009  // Slow things down a bit
2010  if ( last_click.isNull() || last_click.elapsed() > 100 )
2011  {
2012  last_click.start();
2013  if ( e->button() == Qt::LeftButton )
2014  emit mouseDrag( invTransform( e->pos() ) );
2015 
2016  if ( e->modifiers() == Qt::ControlModifier )
2017  {
2018  emit cMouseDrag( invTransform( e->pos() ) );
2019  }
2020  }
2021 
2022  QwtPlotPicker::widgetMouseMoveEvent( e );
2023 }
2024 
2025