QRealSpinBox Class Reference

#include <QRealSpinBox.hpp>

List of all members.

Public Slots

void setValue (real_t value)
void setPercentage (int value)

Signals

void valueChanged (real_t value)

Public Member Functions

 QRealSpinBox (QWidget *parent=0)
 QRealSpinBox (const real_t &minValue, const real_t &maxValue, const int &decimals=2, const real_t &step=1.0, QWidget *parent=0)
 ~QRealSpinBox ()
virtual QSize sizeHint () const
real_t value () const
int percentage () const
real_t minValue () const
real_t maxValue () const
void setRange (real_t minValue, real_t maxValue)

Protected Member Functions

virtual QString mapValueToText (int value)
virtual int mapTextToValue (bool *ok=0)
virtual void valueChange ()

Private Attributes

QDoubleValidator * __validator
int __decimals


Detailed Description

Definition at line 39 of file QRealSpinBox.hpp.


Constructor & Destructor Documentation

QRealSpinBox::QRealSpinBox ( QWidget *  parent = 0  ) 

Definition at line 26 of file QRealSpinBox.cpp.

References fferr(), setRange(), and setValue().

00027   : QSpinBox(parent),
00028   __validator(new QDoubleValidator( -2e10, 2e10, 2, this))
00029 {
00030   this->setRange(int(-2e10), int(2e10));
00031   fferr(1) << __FILE__ << ':' << __LINE__ << ":warning: Validator not inactivated\n";
00032 //   this->setValidator( __validator ); 
00033   this->setValue( 0.0 );
00034 }

Here is the call graph for this function:

QRealSpinBox::QRealSpinBox ( const real_t &  minValue,
const real_t &  maxValue,
const int &  decimals = 2,
const real_t &  step = 1.0,
QWidget *  parent = 0 
)

Definition at line 36 of file QRealSpinBox.cpp.

References fferr(), setRange(), and setValue().

00041   : QSpinBox(parent ),
00042     __validator(new QDoubleValidator( minValue, maxValue, 2, this)),
00043     __decimals( decimals )
00044 {
00045   this->setRange(int( minValue * std::pow( 10., decimals )), int( maxValue * std::pow( 10., decimals ) ));
00046   this->setSingleStep(int(rint(step * std::pow(10., decimals))));
00047   fferr(1) << __FILE__ << ':' << __LINE__ << ":warning: Validator not inactivated\n";
00048 //   setValidator( __validator ); 
00049   this->setValue( 0.5*(minValue+maxValue) );
00050 }

Here is the call graph for this function:

QRealSpinBox::~QRealSpinBox (  ) 

Definition at line 52 of file QRealSpinBox.cpp.

00053 {
00054   ;
00055 }  


Member Function Documentation

QSize QRealSpinBox::sizeHint (  )  const [virtual]

Definition at line 118 of file QRealSpinBox.cpp.

References __decimals, maxValue(), and minValue().

00119 {
00120   QFontMetrics fm = fontMetrics();
00121   int h = fm.height();
00122   if ( h < 12 )       // ensure enough space for the button pixmaps
00123     h = 12;
00124   int w = 35;         // minimum width for the value
00125   int wx = fm.width( "  " );
00126   QString s;
00127   s.setNum( minValue(), 'f', __decimals );
00128   s.prepend( prefix() );
00129   s.append( suffix() );
00130   w = std::max( w, fm.width( s ) + wx );
00131   s.setNum( maxValue(), 'f', __decimals );
00132   s.prepend( prefix() );
00133   s.append( suffix() );
00134   w = std::max( w, fm.width( s ) + wx );
00135   s = specialValueText();
00136   w = std::max( w, fm.width( s ) + wx );
00137 
00138   QSize r ( h // buttons AND frame both sides
00139           + 6 // right/left margins
00140           + w, // widest value
00141 //        frameWidth() * 2 // top/bottom frame
00142 //        w * 2
00143           + 4 // top/bottom margins
00144           + h // font height
00145           );
00146     return r;
00147 }

Here is the call graph for this function:

real_t QRealSpinBox::value (  )  const

Definition at line 69 of file QRealSpinBox.cpp.

References __decimals.

Referenced by ContourWidget::setPercentage(), and valueChange().

00070 {
00071   return QSpinBox::value()/std::pow( 10., __decimals );
00072 }

int QRealSpinBox::percentage (  )  const

Definition at line 74 of file QRealSpinBox.cpp.

Referenced by ContourWidget::setPercentage(), and ContourWidget::setValue().

00075 {
00076   if (maximum() != minimum()) {
00077     return 100 * (QSpinBox::value() - minimum())
00078       / (maximum() - minimum());
00079   } else {
00080     return 100;
00081   }
00082 }

real_t QRealSpinBox::minValue (  )  const

Definition at line 91 of file QRealSpinBox.cpp.

References __decimals.

Referenced by sizeHint().

00092 {
00093   return minimum()/std::pow( 10., __decimals );
00094 }

real_t QRealSpinBox::maxValue (  )  const

Definition at line 96 of file QRealSpinBox.cpp.

References __decimals.

Referenced by sizeHint().

00097 {
00098   return maximum()/std::pow( 10., __decimals );
00099 }

void QRealSpinBox::setRange ( real_t  minValue,
real_t  maxValue 
)

Definition at line 106 of file QRealSpinBox.cpp.

References __decimals, and __validator.

Referenced by QRealSpinBox(), and ContourWidget::set().

00107 {
00108   QSpinBox::setRange(int(minValue *  std::pow(10., __decimals )), 
00109                      int(maxValue *  std::pow(10., __decimals )));
00110   __validator->setRange(minValue, maxValue, 2);
00111 }

void QRealSpinBox::setValue ( real_t  value  )  [slot]

Definition at line 101 of file QRealSpinBox.cpp.

References __decimals.

Referenced by QRealSpinBox().

00102 {
00103   this->QSpinBox::setValue(int(givenValue * std::pow( 10., __decimals )));
00104 }

void QRealSpinBox::setPercentage ( int  value  )  [slot]

Definition at line 83 of file QRealSpinBox.cpp.

Referenced by ContourWidget::setPercentage().

00084 {
00085 //   this->QSpinBox::setPercentage(i);
00086   this->QSpinBox::setValue(int((QSpinBox::minimum()*(99.-i)
00087                                 + QSpinBox::maximum()*i)/99.));
00088 }

void QRealSpinBox::valueChanged ( real_t  value  )  [signal]

Referenced by valueChange().

QString QRealSpinBox::mapValueToText ( int  value  )  [protected, virtual]

Definition at line 57 of file QRealSpinBox.cpp.

References __decimals.

00058 {
00059   QString s;
00060   s.setNum(givenValue/std::pow( 10., __decimals ), 'f', __decimals );
00061   return s;
00062 }

int QRealSpinBox::mapTextToValue ( bool *  ok = 0  )  [protected, virtual]

Definition at line 64 of file QRealSpinBox.cpp.

References __decimals.

00065 {
00066   return int( cleanText().toFloat( ok ) * std::pow( 10., __decimals ) );
00067 }

void QRealSpinBox::valueChange (  )  [protected, virtual]

Definition at line 113 of file QRealSpinBox.cpp.

References value(), and valueChanged().

00114 {
00115   emit valueChanged(value());
00116 }

Here is the call graph for this function:


Member Data Documentation

QDoubleValidator* QRealSpinBox::__validator [private]

Definition at line 44 of file QRealSpinBox.hpp.

Referenced by setRange().

int QRealSpinBox::__decimals [private]


The documentation for this class was generated from the following files:

Generated on Wed Nov 19 00:12:04 2008 for FreeFEM3D (aka ff3d) by  doxygen 1.5.6