UltraScan III
us_widgets_dialog.cpp
Go to the documentation of this file.
1 #include "us_widgets_dialog.h"
3 #include "us_gui_settings.h"
4 #include "us_images.h"
5 
6 US_WidgetsDialog::US_WidgetsDialog( QWidget* w, Qt::WindowFlags f )
7  : QDialog( w, f )
8 {
9  QApplication::setStyle( QStyleFactory::create( US_GuiSettings::guiStyle() ) );
10 
11  if ( ! g.isValid() )
12  {
13  // Do something for invalid global memory
14  qDebug( "us_win: invalid global memory" );
15  }
16 
18  vlgray.setColor( QPalette::Base, QColor( 0xe0, 0xe0, 0xe0 ) );
19 
20  QIcon us3_icon = US_Images::getIcon( US_Images::US3_ICON );
21  setWindowIcon( us3_icon );
22 }
23 
24 QLabel* US_WidgetsDialog::us_label( const QString& labelString, int fontAdjust,
25  int weight )
26 {
27  QLabel* newLabel = new QLabel( labelString, this );
28 
29 // newLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
30  newLabel->setAlignment ( Qt::AlignVCenter | Qt::AlignLeft );
31  newLabel->setMargin ( 2 );
32  newLabel->setAutoFillBackground( true );
33 
34  newLabel->setFont(
36  US_GuiSettings::fontSize() + fontAdjust,
37  weight ) );
38 
39  newLabel->setPalette( US_GuiSettings::labelColor() );
40 
41  return newLabel;
42 }
43 
44 // textlabel ( defaults to smaller font and changes text colors )
45 QLabel* US_WidgetsDialog::us_textlabel( const QString& labelString, int fontAdjust,
46  int weight )
47 {
48  QLabel* newLabel = us_label( labelString, fontAdjust, weight );
49 
50  newLabel->setPalette( US_GuiSettings::editColor() );
51 
52  return newLabel;
53 }
54 
55 // banner ( defaults to Bold and changes text colors )
56 QLabel* US_WidgetsDialog::us_banner( const QString& labelString, int fontAdjust,
57  int weight )
58 {
59  QLabel* newLabel = us_label( labelString, fontAdjust, weight );
60 
61  newLabel->setAlignment ( Qt::AlignCenter );
62  newLabel->setFrameStyle( QFrame::WinPanel | QFrame::Raised );
63  newLabel->setMidLineWidth( 2 );
64 
65  // Set label colors
66  newLabel->setPalette( US_GuiSettings::frameColor() );
67 
68  return newLabel;
69 }
70 
71 // pushbutton
72 QPushButton* US_WidgetsDialog::us_pushbutton( const QString& labelString, bool enabled,
73  int fontAdjust )
74 {
75  QPushButton* button = new QPushButton( tr( labelString.toAscii() ), this );
76 
77  button->setFont( QFont( US_GuiSettings::fontFamily(),
78  US_GuiSettings::fontSize() + fontAdjust ) );
79 
80  button->setPalette( US_GuiSettings::pushbColor() );
81 
82  button->setAutoDefault( false );
83  button->setEnabled( enabled );
84 
85  return button;
86 }
87 
88 // textedit
90 {
91  QTextEdit* te = new QTextEdit( this );
92 
93  te->setFont ( QFont( US_GuiSettings::fontFamily(),
94  US_GuiSettings::fontSize() - 1 ) );
95 
96  te->setPalette ( US_GuiSettings::normalColor() );
97  te->setFrameStyle ( QFrame::WinPanel | QFrame::Sunken );
98  te->setAcceptRichText( true );
99  te->setReadOnly ( true );
100  te->show();
101 
102  return te;
103 }
104 
105 // lineedit
106 QLineEdit* US_WidgetsDialog::us_lineedit( const QString& text, int fontAdjust,
107  bool readonly )
108 {
109  QLineEdit* le = new QLineEdit( this );
110 
111 
112  le->setFont ( QFont( US_GuiSettings::fontFamily(),
113  US_GuiSettings::fontSize() + fontAdjust ) );
114 
115  le->insert ( text );
116  le->setAutoFillBackground( true );
117  us_setReadOnly ( le, readonly );
118  le->show();
119 
120  return le;
121 }
122 
123 // Set ReadOnly and corresponding color for us_lineedit
124 void US_WidgetsDialog::us_setReadOnly( QLineEdit* le, bool readonly )
125 {
126  if ( readonly )
127  {
128  le->setPalette ( vlgray );
129  le->setReadOnly( true );
130  }
131  else
132  {
133  le->setPalette ( US_GuiSettings::editColor() );
134  le->setReadOnly( false );
135  }
136 }
137 
138 // Set ReadOnly and corresponding color for us_textedit
139 void US_WidgetsDialog::us_setReadOnly( QTextEdit* te, bool readonly )
140 {
141  if ( readonly )
142  {
143  te->setPalette ( vlgray );
144  te->setReadOnly( true );
145  }
146  else
147  {
148  te->setPalette ( US_GuiSettings::normalColor() );
149  te->setReadOnly( false );
150  }
151 }
152 
153 // List Widget
154 QListWidget* US_WidgetsDialog::us_listwidget ( int fontAdjust )
155 {
156  QListWidget* lw = new QListWidget;
157 
158  lw->setAutoFillBackground( true );
159  lw->setPalette( US_GuiSettings::editColor() );
160  lw->setFont ( QFont( US_GuiSettings::fontFamily(),
161  US_GuiSettings::fontSize() + fontAdjust ) );
162 
163  return lw;
164 }
165 
166 // checkbox
168  const QString& text, QCheckBox*& cb, bool state )
169 {
170  QPalette p = US_GuiSettings::normalColor();
171  QFont font = QFont( US_GuiSettings::fontFamily(),
173  QFont::Bold );
174 
175  QFontMetrics fm( font );
176 
177  QLabel* lb_spacer = new QLabel;
178  lb_spacer->setFixedWidth ( fm.width( "w" ) ); // Space as wide as a 'w'
179  lb_spacer->setAutoFillBackground( true );
180  lb_spacer->setPalette ( p );
181 
182  cb = new QCheckBox( text.toAscii(), this );
183  cb->setFont ( font );
184  cb->setPalette ( p );
185  cb->setAutoFillBackground( true );
186  cb->setChecked ( state );
187 
188  QGridLayout* layout = new QGridLayout;
189  layout->setContentsMargins( 0, 0, 0, 0 );
190  layout->setSpacing ( 0 );
191 
192  layout->addWidget( lb_spacer, 0, 0 );
193  layout->addWidget( cb , 0, 1 );
194 
195  return layout;
196 }
197 
198 // radiobutton
200  const QString& text, QRadioButton*& rb, bool state )
201 {
202  QPalette p = US_GuiSettings::normalColor();
203  QFont font = QFont( US_GuiSettings::fontFamily(),
205  QFont::Bold );
206 
207  QFontMetrics fm( font );
208 
209  QLabel* lb_spacer = new QLabel;
210  lb_spacer->setFixedWidth ( fm.width( "w" ) ); // Space as wide as a 'w'
211  lb_spacer->setAutoFillBackground( true );
212  lb_spacer->setPalette ( p );
213 
214  rb = new QRadioButton( text.toAscii(), this );
215  rb->setAutoFillBackground( true );
216  rb->setFont ( font );
217  rb->setPalette ( p );
218  rb->setChecked ( state );
219 
220  QGridLayout* layout = new QGridLayout;
221  layout->setSpacing ( 0 );
222  layout->setContentsMargins( 0, 0, 0, 0 );
223 
224  layout->addWidget( lb_spacer, 0, 0 );
225  layout->addWidget( rb , 0, 1 );
226 
227  return layout;
228 }
229 
230 // Progress Bar
231 QProgressBar* US_WidgetsDialog::us_progressBar( int low, int high, int value )
232 {
233  QProgressBar* pb = new QProgressBar;
234 
235  pb->setRange( low, high );
236  pb->setValue( value );
237 
238  pb->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
239  pb->setPalette( US_GuiSettings::normalColor() );
240  pb->setAutoFillBackground( true );
241 
242  pb->setFont( QFont( US_GuiSettings::fontFamily(),
244  QFont::Bold ) );
245 
246  return pb;
247 }
248 
249 // Combo Box
251 {
252  QComboBox* cb = new QComboBox( this );
253 
254  cb->setPalette( US_GuiSettings::normalColor() );
255  cb->setAutoFillBackground( true );
256  cb->setFont( QFont( US_GuiSettings::fontFamily(),
258 
259  return cb;
260 }
261 
262 // LCD
263 QLCDNumber* US_WidgetsDialog::us_lcd( int digits, int value )
264 {
265  QLCDNumber* lcd = new QLCDNumber( digits );
266 
267  lcd->setSegmentStyle( QLCDNumber::Filled );
268  lcd->setMode ( QLCDNumber::Dec );
269  lcd->display ( value );
270  lcd->setAutoFillBackground( true );
271 
272  lcd->setPalette ( US_GuiSettings::lcdColor() );
273 
274  return lcd;
275 }
276 
277 //QwtCounter
278 QwtCounter* US_WidgetsDialog::us_counter( int buttons, double low, double high,
279  double value )
280 {
281  QwtCounter* counter = new QwtCounter;
282 #ifdef Q_WS_MAC
283  QList< QObject* > children = counter->children();
284  QStyle *btnstyle = new QPlastiqueStyle();
285 
286  for ( int jj = 0; jj < children.size(); jj++ )
287  {
288  QWidget* cwidg = (QWidget*)children.at( jj );
289  QString clname = cwidg->metaObject()->className();
290 
291  if ( !clname.isEmpty() && clname.contains( "Button" ) )
292  {
293  cwidg->setStyle( btnstyle );
294  }
295  }
296 #endif
298  QFontMetrics fm( vfont );
299  counter->setNumButtons( buttons );
300  counter->setRange ( low, high );
301  counter->setValue ( value );
302  counter->setPalette ( US_GuiSettings::normalColor() );
303  counter->setFont ( vfont );
304  counter->setAutoFillBackground( true );
305 
306  // Set width based on current value and high-value sizes
307  int ncv = int( log10( value ) ) + 1;
308  int nch = int( log10( high ) ) + 1;
309  ncv = ( ncv > 0 ) ? ncv : ( 4 - ncv );
310  nch = ( nch > 0 ) ? nch : ( 4 - nch );
311  nch = qMax( nch, ncv );
312  int widv = fm.width( QString( "12345678901234" ).left( ncv ) );
313  int widh = fm.width( QString( "12345678901234" ).left( nch ) );
314  counter->adjustSize();
315  int mwidth = counter->width() + widh - widv;
316  counter->resize ( mwidth, counter->height() );
317  counter->setMinimumWidth( mwidth - fm.width( "A" ) );
318 
319  return counter;
320 }
321 
322 QwtPlot* US_WidgetsDialog::us_plot( const QString& title, const QString& x_axis,
323  const QString& y_axis )
324 {
325  QwtPlot* plot = new QwtPlot;
326  plot->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
327  plot->setAutoReplot( false );
328  plot->setTitle ( title );
329 
330  plot->setAxisTitle( QwtPlot::xBottom, x_axis );
331  plot->setAxisTitle( QwtPlot::yLeft , y_axis );
332 
333  plot->setAutoFillBackground( true );
334  plot->setPalette ( US_GuiSettings::plotColor() );
335  plot->setCanvasBackground( US_GuiSettings::plotCanvasBG() );
336 
337  return plot;
338 }
339 
340 QwtPlotGrid* US_WidgetsDialog::us_grid( QwtPlot* plot )
341 {
342  QwtPlotGrid* grid = new QwtPlotGrid;
343  grid->enableXMin ( true );
344  grid->setMajPen(QPen( US_GuiSettings::plotMajGrid(), 0, Qt::DotLine ) );
345  grid->setMinPen(QPen( US_GuiSettings::plotMinGrid(), 0, Qt::DotLine ) );
346  grid->attach ( plot );
347 
348  return grid;
349 }
350 
351 QwtPlotCurve* US_WidgetsDialog::us_curve( QwtPlot* plot, const QString& title )
352 {
353  QwtPlotCurve* curve = new QwtPlotCurve( title );
354  //curve->setRenderHint( QwtPlotItem::RenderAntialiased );
355  curve->setPen ( QPen( US_GuiSettings::plotCurve() ) );
356  curve->setYAxis ( QwtPlot::yLeft );
357  curve->attach ( plot );
358 
359  return curve;
360 }
361 
362 QwtPlotPicker* US_WidgetsDialog::us_picker( QwtPlot* plot )
363 {
364  QwtPlotPicker* pick = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,
365  plot->canvas() );
366 
367  pick->setSelectionFlags( QwtPicker::PointSelection );
368  pick->setTrackerMode ( QwtPicker::AlwaysOn );
369  pick->setRubberBand ( QwtPicker::CrossRubberBand );
370 
371  QColor c = US_GuiSettings::plotPicker();
372  pick->setRubberBandPen ( c );
373  pick->setTrackerPen ( c );
374 
375  return pick;
376 }
377 
378 // tabWidget
379 QTabWidget* US_WidgetsDialog::us_tabwidget( int fontAdjust,
380  int weight )
381 {
382  QTabWidget* newtw = new QTabWidget( this );
383 
384  newtw->setAutoFillBackground( true );
385 
386  newtw->setFont(
388  US_GuiSettings::fontSize () + fontAdjust,
389  weight ) );
390 
391  newtw->setPalette( US_GuiSettings::normalColor() );
392 
393  return newtw;
394 }
395 
396