UltraScan III
us_widgets.cpp
Go to the documentation of this file.
1 #include <QtSvg>
3 
4 #include "us_widgets.h"
5 #include "us_gui_settings.h"
6 #include "us_gui_util.h"
7 #include "us_settings.h"
8 #include "us_images.h"
9 #include "us_util.h"
10 
11 US_Widgets::US_Widgets( bool set_position, QWidget* w, Qt::WindowFlags f ) : QFrame( w, f )
12 {
13  QApplication::setStyle( QStyleFactory::create( US_GuiSettings::guiStyle() ) );
14 
15  if ( ! g.isValid() )
16  {
17  // Do something for invalid global memory
18  qDebug( "us_win: invalid global memory" );
19  }
20 
21  if ( set_position )
22  {
23  QPoint p = g.global_position();
24  g.set_global_position( p + QPoint( 30, 30 ) );
25  move( p );
26  }
27 
29  vlgray.setColor( QPalette::Base, QColor( 0xe0, 0xe0, 0xe0 ) );
30 
31  QIcon us3_icon = US_Images::getIcon( US_Images::US3_ICON );
32  setWindowIcon( us3_icon );
33 }
34 
36 {
37  QPoint p = g.global_position();
38  g.set_global_position( p - QPoint( 30, 30 ) );
39 }
40 
41 // label
42 QLabel* US_Widgets::us_label( const QString& labelString, int fontAdjust,
43  int weight )
44 {
45  QLabel* newLabel = new QLabel( labelString, this );
46 
47  newLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
48  newLabel->setAlignment ( Qt::AlignVCenter | Qt::AlignLeft );
49  newLabel->setMargin ( 2 );
50  newLabel->setAutoFillBackground( true );
51 
52  newLabel->setFont(
54  US_GuiSettings::fontSize () + fontAdjust,
55  weight ) );
56 
57  newLabel->setPalette( US_GuiSettings::labelColor() );
58 
59  return newLabel;
60 }
61 
62 // textlabel ( defaults to smaller font and changes text colors )
63 QLabel* US_Widgets::us_textlabel( const QString& labelString, int fontAdjust,
64  int weight )
65 {
66  QLabel* newLabel = us_label( labelString, fontAdjust, weight );
67 
68  newLabel->setPalette( US_GuiSettings::editColor() );
69 
70  return newLabel;
71 }
72 
73 // banner ( defaults to Bold and changes text colors )
74 QLabel* US_Widgets::us_banner( const QString& labelString, int fontAdjust,
75  int weight )
76 {
77  QLabel* newLabel = us_label( labelString, fontAdjust, weight );
78 
79  newLabel->setAlignment ( Qt::AlignCenter );
80  newLabel->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
81  newLabel->setMidLineWidth( 2 );
82 
83  // Set label colors
84  newLabel->setPalette( US_GuiSettings::frameColor() );
85 
86  return newLabel;
87 }
88 
89 // pushbutton
90 QPushButton* US_Widgets::us_pushbutton( const QString& labelString, bool enabled,
91  int fontAdjust )
92 {
93  QPushButton* button = new QPushButton( tr( labelString.toAscii() ), this );
94 
95  button->setFont( QFont( US_GuiSettings::fontFamily(),
96  US_GuiSettings::fontSize () + fontAdjust ) );
97 
98  button->setPalette( US_GuiSettings::pushbColor() );
99 
100  button->setAutoDefault( false );
101  button->setEnabled( enabled );
102 
103  return button;
104 }
105 
106 // textedit
107 QTextEdit* US_Widgets::us_textedit( void )
108 {
109  QTextEdit* te = new QTextEdit( this );
110 
111  te->setFont ( QFont( US_GuiSettings::fontFamily(),
112  US_GuiSettings::fontSize () - 1 ) );
113 
114  te->setPalette ( US_GuiSettings::normalColor() );
115  te->setFrameStyle ( WinPanel | Sunken );
116  te->setAcceptRichText( true );
117  te->setReadOnly ( true );
118  te->show();
119 
120  return te;
121 }
122 
123 // lineedit
124 QLineEdit* US_Widgets::us_lineedit( const QString& text, int fontAdjust,
125  bool readonly )
126 {
127  QLineEdit* le = new QLineEdit( this );
128 
129 
130  le->setFont ( QFont( US_GuiSettings::fontFamily(),
131  US_GuiSettings::fontSize () + fontAdjust ) );
132 
133  le->insert ( text );
134  le->setAutoFillBackground( true );
135  us_setReadOnly ( le, readonly );
136  le->show();
137 
138  return le;
139 }
140 
141 // Set read-only flag and associated color palette for a line edit
142 void US_Widgets::us_setReadOnly( QLineEdit* le, bool readonly )
143 {
144  if ( readonly )
145  {
146  le->setPalette ( vlgray );
147  le->setReadOnly( true );
148  }
149 
150  else
151  {
152  le->setPalette ( US_GuiSettings::editColor() );
153  le->setReadOnly( false );
154  }
155 }
156 
157 // Set read-only flag and associated color palette for a text edit
158 void US_Widgets::us_setReadOnly( QTextEdit* te, bool readonly )
159 {
160  if ( readonly )
161  {
162  te->setPalette ( vlgray );
163  te->setReadOnly( true );
164  }
165 
166  else
167  {
168  te->setPalette ( US_GuiSettings::normalColor() );
169  te->setReadOnly( false );
170  }
171 }
172 
173 // List Widget
174 QListWidget* US_Widgets::us_listwidget ( int fontAdjust )
175 {
176  QListWidget* lw = new QListWidget;
177 
178  lw->setAutoFillBackground( true );
179  lw->setPalette( US_GuiSettings::editColor() );
180  lw->setFont ( QFont( US_GuiSettings::fontFamily(),
181  US_GuiSettings::fontSize () + fontAdjust ) );
182 
183  return lw;
184 }
185 
186 // checkbox
188  const QString& text, QCheckBox*& cb, bool state )
189 {
190  QPalette p = US_GuiSettings::normalColor();
191  QFont font = QFont( US_GuiSettings::fontFamily(),
193  QFont::Bold );
194 
195  QFontMetrics fm( font );
196 
197  QLabel* lb_spacer = new QLabel;
198  lb_spacer->setFixedWidth ( fm.width( "w" ) ); // Space as wide as a 'w'
199  lb_spacer->setAutoFillBackground( true );
200  lb_spacer->setPalette ( p );
201 
202  cb = new QCheckBox( text.toAscii(), this );
203  cb->setFont ( font );
204  cb->setPalette ( p );
205  cb->setChecked ( state );
206  cb->setAutoFillBackground( true );
207 
208  QGridLayout* layout = new QGridLayout;
209  layout->setContentsMargins( 0, 0, 0, 0 );
210  layout->setSpacing ( 0 );
211 
212  layout->addWidget( lb_spacer, 0, 0 );
213  layout->addWidget( cb , 0, 1 );
214 
215  return layout;
216 }
217 
218 // radiobutton
220  const QString& text, QRadioButton*& rb, bool state )
221 {
222  QPalette p = US_GuiSettings::normalColor();
223  QFont font = QFont( US_GuiSettings::fontFamily(),
225  QFont::Bold );
226 
227  QFontMetrics fm( font );
228 
229  QLabel* lb_spacer = new QLabel;
230  lb_spacer->setFixedWidth ( fm.width( "w" ) ); // Space as wide as a 'w'
231  lb_spacer->setAutoFillBackground( true );
232  lb_spacer->setPalette ( p );
233 
234  rb = new QRadioButton( text.toAscii(), this );
235  rb->setAutoFillBackground( true );
236  rb->setFont ( font );
237  rb->setPalette ( p );
238  rb->setChecked ( state );
239 
240  QGridLayout* layout = new QGridLayout;
241  layout->setSpacing ( 0 );
242  layout->setContentsMargins( 0, 0, 0, 0 );
243 
244  layout->addWidget( lb_spacer, 0, 0 );
245  layout->addWidget( rb , 0, 1 );
246 
247  return layout;
248 }
249 
250 // Progress Bar
251 QProgressBar* US_Widgets::us_progressBar( int low, int high, int value )
252 {
253  QProgressBar* pb = new QProgressBar;
254 
255  pb->setRange( low, high );
256  pb->setValue( value );
257 
258  pb->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
259  pb->setPalette( US_GuiSettings::normalColor() );
260  pb->setAutoFillBackground( true );
261 
262  pb->setFont( QFont( US_GuiSettings::fontFamily(),
264  QFont::Bold ) );
265 
266  return pb;
267 }
268 
269 // Combo Box
270 QComboBox* US_Widgets::us_comboBox( void )
271 {
272  QComboBox* cb = new QComboBox( this );
273 
274  cb->setPalette( US_GuiSettings::normalColor() );
275  cb->setAutoFillBackground( true );
276  cb->setFont( QFont( US_GuiSettings::fontFamily(),
278 
279  return cb;
280 }
281 
282 // LCD
283 QLCDNumber* US_Widgets::us_lcd( int digits, int value )
284 {
285  QLCDNumber* lcd = new QLCDNumber( digits );
286 
287  lcd->setSegmentStyle( QLCDNumber::Filled );
288  lcd->setMode ( QLCDNumber::Dec );
289  lcd->display ( value );
290  lcd->setAutoFillBackground( true );
291 
292  lcd->setPalette ( US_GuiSettings::lcdColor() );
293 
294  return lcd;
295 }
296 
297 //QwtCounter
298 QwtCounter* US_Widgets::us_counter( int buttons, double low, double high,
299  double value )
300 {
301  QwtCounter* counter = new QwtCounter;
302 #ifdef Q_WS_MAC
303  QList< QObject* > children = counter->children();
304  QStyle *btnstyle = new QPlastiqueStyle();
305 
306  for ( int jj = 0; jj < children.size(); jj++ )
307  {
308  QWidget* cwidg = (QWidget*)children.at( jj );
309  QString clname = cwidg->metaObject()->className();
310 
311  if ( !clname.isEmpty() && clname.contains( "Button" ) )
312  {
313  cwidg->setStyle( btnstyle );
314  }
315  }
316 #endif
318  QFontMetrics fm( vfont );
319  counter->setNumButtons( buttons );
320  counter->setRange ( low, high );
321  counter->setValue ( value );
322  counter->setPalette ( US_GuiSettings::normalColor() );
323  counter->setFont ( vfont );
324  counter->setAutoFillBackground( true );
325 
326  // Set minimum width based on current (value) size and range
327  int ncv = int( log10( value ) ) + 1;
328  int nch = int( log10( high ) ) + 1;
329  ncv = ( ncv > 0 ) ? ncv : ( 4 - ncv );
330  nch = ( nch > 0 ) ? nch : ( 4 - nch );
331  nch = qMax( nch, ncv );
332  int widv = fm.width( QString( "12345678901234" ).left( ncv ) );
333  int widh = fm.width( QString( "12345678901234" ).left( nch ) );
334  counter->adjustSize();
335  int mwidth = counter->width() + widh - widv;
336  counter->resize ( mwidth, counter->height() );
337  counter->setMinimumWidth( mwidth - fm.width( "A" ) );
338 
339  return counter;
340 }
341 
342 QwtPlot* US_Widgets::us_plot( const QString& title, const QString& x_axis,
343  const QString& y_axis )
344 {
345  QwtPlot* plot = new QwtPlot;
346  plot->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
347  plot->setAutoReplot( false );
348  plot->setTitle ( title );
349 
350  plot->setAxisTitle( QwtPlot::xBottom, x_axis );
351  plot->setAxisTitle( QwtPlot::yLeft , y_axis );
352 
353  plot->setAutoFillBackground( true );
354  plot->setPalette ( US_GuiSettings::plotColor() );
355  plot->setCanvasBackground( US_GuiSettings::plotCanvasBG() );
356 
357  return plot;
358 }
359 
360 QwtPlotGrid* US_Widgets::us_grid( QwtPlot* plot )
361 {
362  QwtPlotGrid* grid = new QwtPlotGrid;
363  grid->enableXMin ( true );
364  grid->setMajPen(QPen( US_GuiSettings::plotMajGrid(), 0, Qt::DotLine ) );
365  grid->setMinPen(QPen( US_GuiSettings::plotMinGrid(), 0, Qt::DotLine ) );
366  grid->attach ( plot );
367 
368  return grid;
369 }
370 
371 QwtPlotCurve* US_Widgets::us_curve( QwtPlot* plot, const QString& title )
372 {
373  QwtPlotCurve* curve = new QwtPlotCurve( title );
374  //curve->setRenderHint( QwtPlotItem::RenderAntialiased );
375  curve->setPen ( QPen( US_GuiSettings::plotCurve() ) );
376  curve->setYAxis ( QwtPlot::yLeft );
377  curve->attach ( plot );
378 
379  return curve;
380 }
381 
382 QwtPlotPicker* US_Widgets::us_picker( QwtPlot* plot )
383 {
384  QwtPlotPicker* pick = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,
385  plot->canvas() );
386 
387  pick->setSelectionFlags( QwtPicker::PointSelection );
388  pick->setTrackerMode ( QwtPicker::AlwaysOn );
389  pick->setRubberBand ( QwtPicker::CrossRubberBand );
390 
391  QColor c = US_GuiSettings::plotPicker();
392  pick->setRubberBandPen ( c );
393  pick->setTrackerPen ( c );
394 
395  return pick;
396 }
397 
398 void US_ListWidget::mousePressEvent( QMouseEvent* event )
399 {
400  if ( event->button() == Qt::RightButton )
401  {
402  emit rightClick();
403  event->ignore();
404  return;
405  }
406 
407  QListWidget::mousePressEvent( event );
408 }
409 
410 
411 // find this system's best fixedPitch font
413 {
414  //QFontDataBase database;
415  int fsize = US_GuiSettings::fontSize();
416  QFont ffont( "monospace", fsize );
417  QFont tfont( "monospace", fsize );
418  QFontInfo finfo( tfont );
419  QString family;
420  bool fmatch;
421  bool ffixed;
422  const char* preffam[] = {
423  "Liberation Mono",
424  "FreeMono",
425  "DejaVu Sans Mono",
426  "DejaVu LGC San Mono",
427  "Andale Mono",
428  "Menlo",
429  "Nimbus Mono L",
430  "Luxi Mono",
431  "Lucida Console",
432  "Fixedsys",
433  "Terminal",
434  "QuickType mono",
435  "Monaco",
436  "Courier New",
437  "Courier 10 Pitch",
438  "Courier"
439  };
440  const int pfsize = sizeof( preffam ) / sizeof( preffam[ 0 ] );
441 
442  for ( int ii = 0; ii < pfsize; ii++ )
443  {
444  family = QString( preffam[ ii ] );
445  tfont = QFont( family );
446  finfo = QFontInfo( tfont );
447  fmatch = finfo.exactMatch();
448  ffixed = finfo.fixedPitch();
449  if ( fmatch && ffixed )
450  {
451  ffont = tfont;
452 
453  if ( family.contains( "New" ) ||
454  family.contains( "FreeM" ) )
455  ffont = QFont( family, fsize, QFont::DemiBold );
456 
457  break;
458  }
459  }
460  return ffont;
461 }
462 
463 // tabWidget
464 QTabWidget* US_Widgets::us_tabwidget( int fontAdjust,
465  int weight )
466 {
467  QTabWidget* newtw = new QTabWidget( this );
468 
469  newtw->setAutoFillBackground( true );
470 
471  newtw->setFont(
473  US_GuiSettings::fontSize () + fontAdjust,
474  weight ) );
475 
476  newtw->setPalette( US_GuiSettings::normalColor() );
477 
478  return newtw;
479 }
480 
481 void US_Widgets::write_plot( const QString& fname, const QwtPlot* plot )
482 {
483  US_GuiUtil::save_plot( fname, plot );
484 }
485 
486 // Clean up install and work ./etc directories
487 int US_Widgets::clean_etc_dir( bool report )
488 {
489  int nfmove = 0;
490  int nfcopy = 0;
491  int nfdele = 0;
492  QString ietc_dname = US_Settings::appBaseDir() + "/etc"; // Install etc
493  QString wetc_dname = US_Settings::etcDir(); // Work etc
494  QString list_fname = "etc_belongs_list.txt"; // Files that belong in etc
495  QDir().mkpath( wetc_dname ); // Make sure work etc directory exists
496  QDir ietc_dir( ietc_dname );
497  QDir wetc_dir( wetc_dname );
498  ietc_dname += "/";
499  wetc_dname += "/";
500  QDir::Filters ffilt = QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot;
501  QList< QFileInfo > ie_files = ietc_dir.entryInfoList( ffilt );
502  QList< QFileInfo > we_files = wetc_dir.entryInfoList( ffilt );
503  QStringList keep_files; // Files to keep in install etc
504  QStringList copy_files; // Files to copy to work etc
505  QStringList link_files; // Symbolic links in install etc
506  QStringList dir_names; // Subdirectories in install etc
507  QStringList ietc_files; // All files in install etc
508  QStringList wetc_files; // All files initially in work etc
509  int niefs = ie_files.size(); // Count of install etc files
510  int nwefs = we_files.size(); // Count of work etc files
511 
512  for ( int ii = 0; ii < niefs; ii++ ) // Build list of install etc files
513  ietc_files << ie_files[ ii ].fileName();
514 
515  for ( int ii = 0; ii < nwefs; ii++ ) // Build list of work etc files
516  wetc_files << we_files[ ii ].fileName();
517 
518  QFile lfile( ietc_dname + list_fname ); // Belong in install etc
519 
520  if ( lfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
521  {
522  bool keep_file = false;
523  bool copy_file = false;
524  bool link_file = false;
525  bool dir_file = false;
526 
527  QTextStream ts( &lfile );
528  while( ! ts.atEnd() )
529  { // Read the list of files that belong in install etc
530  QString fline = ts.readLine();
531 
532  if ( fline.startsWith( "#" ) )
533  { // Handle comment line
534  keep_file = copy_file = link_file = dir_file = false;
535  if ( fline.contains( "List of files" ) )
536  keep_file = true; // Keep files follow
537  else if ( fline.contains( "List of directories" ) )
538  dir_file = true; // Subdirectories follow
539  else if ( fline.contains( "COPY" ) )
540  copy_file = true; // Copy files follow
541  else if ( fline.contains( "LINK" ) )
542  link_file = true; // Symbolic links follow
543  }
544 
545  else
546  { // Actual file name: move it to appropriate list
547  QString filename = fline.section( " ", 0, 0 ).simplified();
548  if ( keep_file )
549  keep_files << filename;
550  else if ( copy_file )
551  copy_files << filename;
552  else if ( link_file )
553  link_files << filename.replace( "@", "" );
554  else if ( dir_file )
555  dir_names << filename.replace( "/", "" );
556  }
557 
558  }
559  }
560 
561  int nkeepf = keep_files.size();
562  int ncopyf = copy_files.size();
563  int nlinkf = link_files.size();
564  int nsdir = dir_names .size();
565 qDebug() << "niefs nwefs" << niefs << nwefs << "nkeep/copy/link/dirf"
566  << nkeepf << ncopyf << nlinkf << nsdir;
567 
568  // Examine each file in ie_files (e.g.,"*/ultrascan3/etc") and operate on it
569  for ( int ii = 0; ii < niefs; ii++ )
570  {
571  QString filename = ietc_files[ ii ];
572 
573  if ( filename.contains( "somo" ) ) // Leave SOMO files alone for now
574  continue;
575 
576  bool in_wetc = wetc_files.contains( filename );
577 
578  if ( keep_files.contains( filename ) )
579  { // This file is to be kept in the install-etc directory
580  qDebug() << "KEEP " << filename;
581  }
582 
583  else if ( copy_files.contains( filename ) )
584  { // This file is to be copied to the work-etc directory
585  qDebug() << "COPY " << filename;
586  if ( in_wetc )
587  { // But only copy if it is not already copied
588  QString icksum = US_Util::md5sum_file( ietc_dname + filename );
589  QString wcksum = US_Util::md5sum_file( wetc_dname + filename );
590  qDebug() << " ietc cksum+size " << icksum;
591  qDebug() << " wetc cksum+size " << wcksum;
592 
593  if ( icksum != wcksum )
594  { // They do not match in cksum+size, so copy
595  nfcopy++;
596  qDebug() << " FILE COPY" << nfcopy;
597  QFile( wetc_dname + filename ).remove();
598 
599  QFile( ietc_dname + filename ).copy(
600  wetc_dname + filename );
601  }
602  }
603  else
604  { // Not present in work-etc, so copy
605  qDebug() << " not present in" << wetc_dname;
606  nfcopy++;
607  qDebug() << " FILE COPY" << nfcopy;
608  QFile( ietc_dname + filename ).copy(
609  wetc_dname + filename );
610  }
611  }
612 
613  else if ( link_files.contains( filename ) )
614  { // This is a link, so copy the target file
615  qDebug() << "LINK " << filename;
616  QString sltarg = ie_files[ ii ].symLinkTarget();
617  qDebug() << " ietc sltarg " << sltarg;
618 
619  if ( in_wetc )
620  { // But only copy if not already copied
621  QString icksum = US_Util::md5sum_file( sltarg );
622  QString wcksum = US_Util::md5sum_file( wetc_dname + filename );
623  qDebug() << " ietc cksum+size " << icksum;
624  qDebug() << " wetc cksum+size " << wcksum;
625 
626  if ( icksum != wcksum )
627  { // They do not match in cksum+size, so copy
628  nfcopy++;
629  qDebug() << " FILE COPY" << nfcopy;
630  QFile( wetc_dname + filename ).remove(); // Remove first
631 
632  QFile( sltarg ).copy( wetc_dname + filename ); // Then copy
633  }
634  }
635  else
636  { // Not present in work-etc, so copy
637  qDebug() << " not present in" << wetc_dname;
638  nfcopy++;
639  qDebug() << " FILE COPY" << nfcopy;
640  QFile( sltarg ).copy( wetc_dname + filename );
641  }
642  }
643 
644  else if ( dir_names.contains( filename ) )
645  { // This is a directory, so ignore it
646  qDebug() << "SDIR " << filename;
647  }
648 
649  else if ( filename.contains( "~" ) )
650  { // If name ends in tilde, delete it
651  qDebug() << "DELE " << filename;
652  nfdele++;
653  qDebug() << " FILE DELE" << nfdele;
654  QFile( ietc_dname + filename ).remove();
655  }
656 
657  else
658  { // File not in "belongs" list: move it to work-etc
659  qDebug() << "MOVE " << filename;
660  nfmove++;
661  qDebug() << " FILE MOVE" << nfmove;
662 
663  if ( in_wetc )
664  { // First delete any version in work-etc
665  QFile( wetc_dname + filename ).remove();
666  }
667 
668  QFile( ietc_dname + filename ).rename(
669  wetc_dname + filename );
670  }
671  }
672 
673  int nfmods = nfmove + nfcopy + nfdele;
674 
675  if ( nfmods > 0 && report )
676  { // If so flagged and any exist, pop up a message on modified files
677  QString msg = tr( "%1 files were moved, copied, or deleted from"
678  "<br/>&nbsp;&nbsp; <b>%2</b>.<br/>"
679  "Examine possible new or replaced files in"
680  "<br/>&nbsp;&nbsp; <b>%3</b>." )
681  .arg( nfmods ).arg( ietc_dname ).arg( wetc_dname );
682  QMessageBox::information( this, tr( "Etc Directory Cleaned" ), msg );
683  }
684 
685  return nfmods;
686 }
687 
689 
691 {
692  QButtonGroup* group = new QButtonGroup;
693 
694  QGridLayout* db_layout = us_radiobutton( tr( "Database" ), rb_db );
695  QGridLayout* disk_layout = us_radiobutton( tr( "Local Disk" ), rb_disk );
696 
697  group->addButton( rb_db );
698  group->addButton( rb_disk );
699 
700  if ( state == Default ) state = US_Settings::default_data_location();
701 
702  ( state == Disk ) ? rb_disk->setChecked( true ) : rb_db->setChecked( true );
703 
704  setSpacing ( 0 );
705  setContentsMargins( 0, 0, 0, 0 );
706 
707  addLayout( db_layout );
708  addLayout( disk_layout );
709 
710  connect( rb_db, SIGNAL( toggled( bool ) ), SLOT( rb_changed( bool ) ) );
711 }
712 
714 {
715  return rb_db->isChecked();
716 }
717 
719 {
720  rb_db->disconnect();
721  rb_db->setChecked( true );
722  connect( rb_db, SIGNAL( toggled( bool ) ), SLOT( rb_changed( bool ) ) );
723 }
724 
726 {
727  rb_db ->disconnect();
728  rb_disk->setChecked( true );
729  connect( rb_db, SIGNAL( toggled( bool ) ), SLOT( rb_changed( bool ) ) );
730 }
731 
732 void US_Disk_DB_Controls::rb_changed( bool /* state */ )
733 {
734  emit changed( rb_db->isChecked() );
735 }
736 
737 // Copy from US_Widgets so global is not needed.
739  const QString& text, QRadioButton*& rb, bool state )
740 {
741  QPalette p = US_GuiSettings::normalColor();
742  QFont font = QFont( US_GuiSettings::fontFamily(),
744  QFont::Bold );
745 
746  QFontMetrics fm( font );
747 
748  QLabel* lb_spacer = new QLabel;
749  lb_spacer->setFixedWidth ( fm.width( "w" ) ); // Space as wide as a 'w'
750  lb_spacer->setAutoFillBackground( true );
751  lb_spacer->setPalette ( p );
752 
753  rb = new QRadioButton( text.toAscii() );
754  rb->setAutoFillBackground( true );
755  rb->setFont ( font );
756  rb->setPalette ( p );
757  rb->setChecked ( state );
758 
759  QGridLayout* layout = new QGridLayout;
760  layout->setSpacing ( 0 );
761  layout->setContentsMargins( 0, 0, 0, 0 );
762 
763  layout->addWidget( lb_spacer, 0, 0 );
764  layout->addWidget( rb , 0, 1 );
765 
766  return layout;
767 }
768