2 // File : QAD_SpinBoxDbl.cxx
3 // Created : UI team, 21.11.02
4 // Descr : Spin box for double values
6 // Modified : Fri Nov 22 09:30:11 2002
7 // Author : Vadim SANDLER
10 // Copyright : Open CASCADE 2002
13 #include "QAD_SpinBoxDbl.h"
14 #include <qpushbutton.h>
17 #include <qlineedit.h>
18 #include <qvalidator.h>
19 #include <qpixmapcache.h>
20 #include <qapplication.h>
23 //******************************************************************************
24 // QDblRangeControl class
25 //******************************************************************************
28 Constructs a range control with min value 0.00, max value 99.99,
29 line step 0.1, page step 1.00, precision 6, double precision 10e-6,
30 convertion flag 'g' and initial value 0.00.
32 QDblRangeControl::QDblRangeControl()
37 minVal = roundPrecision( 0.00 );
38 maxVal = roundPrecision( 99.99 );
39 line = roundPrecision( 0.10 );
40 page = roundPrecision( 1.00 );
41 prevVal = roundPrecision( -0.10 );
46 Constructs a range control whose value can never be smaller than
47 <minValue> or greater than <maxValue>, whose line step size is
48 <lineStep> and page step size is <pageStep> and whose value is
49 initially <value> (which is guaranteed to be in range using bound()),
50 precision is <precision>, double precision is <dblPrecision> and
51 convertion flag is <cFlag>
53 QDblRangeControl::QDblRangeControl( double minValue, double maxValue,
54 double lineStep, double pageStep,
61 dblPrec = dblPrecision;
63 minVal = roundPrecision( minValue );
64 maxVal = roundPrecision( maxValue );
65 line = roundPrecision( QABS( lineStep ) );
66 page = roundPrecision( QABS( pageStep ) );
67 prevVal = roundPrecision( minVal - 0.1 );
72 Destroys the range control
74 QDblRangeControl::~QDblRangeControl()
79 Returns the current range control value. This is guaranteed to be
80 within the range [minValue(), maxValue()].
82 inline double QDblRangeControl::value() const
86 Sets the range control's value to <value> and forces it to be within
88 Calls the virtual valueChange() function if the new value is
89 different from the previous value. The old value can still be
90 retrieved using prevValue().
92 void QDblRangeControl::setValue( double value )
94 directSetValue( value );
95 if ( !equal(prevVal, val ) )
100 Equivalent to {setValue( value() + pageStep() )}.
101 If the value is changed, then valueChange() is called.
103 void QDblRangeControl::addPage()
105 setValue( value() + pageStep() );
109 Equivalent to {setValue( value() - pageStep() )}.
110 If the value is changed, then valueChange() is called.
112 void QDblRangeControl::subtractPage()
114 setValue( value() - pageStep() );
118 Equivalent to {setValue( value() + lineStep() )}.
119 If the value is changed, then valueChange() is called.
121 void QDblRangeControl::addLine()
123 setValue( value() + lineStep() );
127 Equivalent to {setValue( value() - lineStep() )}.
128 If the value is changed, then valueChange() is called.
130 void QDblRangeControl::subtractLine()
132 setValue( value() - lineStep() );
136 Returns the current minimum value of the range.
138 inline double QDblRangeControl::minValue() const
142 Returns the current maximum value of the range.
144 inline double QDblRangeControl::maxValue() const
148 Sets the range control's min value to <minValue> and its max value
151 Calls the virtual rangeChange() function if one or both of the new
152 min and max values are different from the previous setting. Calls
153 the virtual valueChange() function if the current value is adjusted
154 because it was outside the new range.
156 If <maxValue> is smaller than <minValue>, <minValue> becomes the
159 void QDblRangeControl::setRange( double minValue, double maxValue )
161 minValue = roundPrecision( minValue );
162 maxValue = roundPrecision( maxValue );
163 if ( minValue > maxValue ) {
166 if ( equal( minValue, minVal ) && equal( maxValue, maxVal ) )
170 double tmp = bound( val );
172 if ( !equal( tmp, val ) ) {
180 Sets the current minimum value of the range to <minVal>.
181 If necessary, the maxValue() is adjusted so that the range remains
184 void QDblRangeControl::setMinValue( double minVal )
186 double maxVal = maxValue();
187 if ( maxVal < minVal )
189 setRange( minVal, maxVal );
193 Sets the current maximum value of the range to <maxVal>.
194 If necessary, the minValue() is adjusted so that the range remains
197 void QDblRangeControl::setMaxValue( double maxVal )
199 double minVal = minValue();
200 if ( minVal > maxVal )
202 setRange( minVal, maxVal );
206 Returns the current line step.
208 inline double QDblRangeControl::lineStep() const
212 Returns the current page step.
214 inline double QDblRangeControl::pageStep() const
218 Sets the range line step to <lineStep> and page step to <pageStep>.
219 Calls the virtual stepChange() function if the new line step and/or
220 page step are different from the previous settings.
222 void QDblRangeControl::setSteps( double lineStep, double pageStep )
224 lineStep = roundPrecision( QABS( lineStep ) );
225 pageStep = roundPrecision( QABS( pageStep ) );
226 if ( !equal( lineStep, line ) || !equal( pageStep, page ) ) {
234 Returs precision ( see QString::setNum() for details )
236 int QDblRangeControl::precision() const
240 Sets precision ( see QString::setNum() for details )
242 void QDblRangeControl::setPrecision( int precision )
244 if ( precision > 0 && prec != precision ) {
246 setRange( minValue(), maxValue() );
247 setSteps( lineStep(), pageStep() );
252 Returns double precision which is used for rounding amd comparing
255 double QDblRangeControl::dblPrecision() const
259 Sets double precision which is used for rounding amd comparing
262 void QDblRangeControl::setDblPrecision( double dblPrecision )
264 dblPrecision = QABS( dblPrecision );
265 if ( dblPrecision > 0 && dblPrecision != dblPrec ) {
266 dblPrec = dblPrecision;
267 setRange( minValue(), maxValue() );
268 setSteps( lineStep(), pageStep() );
273 Returns convertion flag ( see QString::setNum() for details )
275 char QDblRangeControl::convertFlag() const
279 Sets convertion flag ( see QString::setNum() for details )
281 void QDblRangeControl::setConvertFlag( char cFlag )
283 if ( ( cFlag == 'f' || cFlag == 'F' || cFlag == 'e' ||
284 cFlag == 'E' || cFlag == 'g' || cFlag == 'G' ) &&
285 ( cFlag != convFlag ) ) {
287 setRange( minValue(), maxValue() );
288 setSteps( lineStep(), pageStep() );
293 Forces the value <v> to be within the range from minValue() to
294 maxValue() inclusive, and returns the result.
296 This function is provided so that you can easily force other numbers
297 than value() into the allowed range. You do not need to call it in
298 order to use QDblRangeControl itself.
300 double QDblRangeControl::bound( double v ) const
306 return roundPrecision( v );
310 Sets the range control value directly without calling valueChange().
311 Forces the new value to be within the legal range.
313 You will rarely have to call this function. However, if you want to
314 change the range control's value inside the overloaded method
315 valueChange(), setValue() would call the function valueChange()
316 again. To avoid this recursion you must use directSetValue()
319 void QDblRangeControl::directSetValue( double value )
322 val = bound( value );
326 Returns the previous value of the range control. "Previous value"
327 means the value before the last change occurred. Setting a new range
328 may affect the value, too, because the value is forced to be inside
329 the specified range. When the range control is initially created,
330 this is the same as value().
332 prevValue() can be outside the current legal range if a call to
333 setRange() causes the current value to change. For example, if the
334 range was [0, 1000] and the current value is 500, setRange(0, 400)
335 makes value() return 400 and prevValue() return 500.
337 inline double QDblRangeControl::prevValue() const
341 This virtual function is called whenever the range control value
342 changes. You can reimplement it if you want to be notified when the
343 value changes. The default implementation does nothing.
345 Note that this method is called after the value changed. The previous
346 value can be retrieved using prevValue().
348 void QDblRangeControl::valueChange()
353 This virtual function is called whenever the range control's range
354 changes. You can reimplement it if you want to be notified when the range
355 changes. The default implementation does nothing.
357 Note that this method is called after the range changed.
359 void QDblRangeControl::rangeChange()
364 This virtual function is called whenever the range control's
365 line/page step settings change. You can reimplement it if you want
366 to be notified when the step changes. The default implementation
369 Note that this method is called after the step settings change.
371 void QDblRangeControl::stepChange()
376 returns true if values qre equal ( with tolerance = dblPrecision() )
378 bool QDblRangeControl::equal( double first, double second ) const
380 return QABS( first - second ) < dblPrecision();
386 double QDblRangeControl::roundPrecision( double value) const
390 convertor.setNum( value, convertFlag(), precision() );
391 double newValue = convertor.toDouble(&bOk);
393 if ( QABS( newValue ) < dblPrecision() )
402 //******************************************************************************
404 //******************************************************************************
407 Returns true if <str> ends by <substr> [ static ]
409 static bool endsWith(const QString& str, const QString& substr)
411 #if QT_VERSION < 0x030000
412 if ( str.length() < substr.length() )
414 return ( str.right( substr.length() ) == substr );
416 return str.endsWith(substr);
421 Validator class for double value spin box
423 class QAD_SpinBoxDblValidator: public QDoubleValidator
426 QAD_SpinBoxDblValidator( QAD_SpinBoxDbl* sb, const char* name )
427 : QDoubleValidator( sb, name ),
430 State validate( QString& str, int& pos ) const;
433 QAD_SpinBoxDbl* spinBox;
437 Validates data entered
439 QValidator::State QAD_SpinBoxDblValidator::validate( QString& str, int& pos ) const
441 QString pref = spinBox->prefix();
442 QString suff = spinBox->suffix();
443 uint overhead = pref.length() + suff.length();
444 State state = Invalid;
446 ((QDoubleValidator *) this)->setRange( spinBox->minValue(),
447 spinBox->maxValue() );
448 if ( overhead == 0 ) {
449 state = QDoubleValidator::validate( str, pos );
451 if ( str.length() >= overhead &&
452 str.startsWith(pref) &&
453 endsWith(str, suff) ) {
454 QString core = str.mid( pref.length(), str.length() - overhead );
455 int corePos = pos - pref.length();
456 state = QDoubleValidator::validate( core, corePos );
457 pos = corePos + pref.length();
458 str.replace( pref.length(), str.length() - overhead, core );
460 state = QDoubleValidator::validate( str, pos );
461 if ( state == Invalid ) {
462 // stripWhiteSpace(), cf. QAD_SpinBoxDbl::interpretText()
463 QString special = spinBox->specialValueText().stripWhiteSpace();
464 QString candidate = str.stripWhiteSpace();
466 if ( special.startsWith(candidate) ) {
467 if ( candidate.length() == special.length() ) {
470 state = Intermediate;
480 Creates a spin box with min value 0.00, max value 99.99,
481 line step 0.1, precision 6, double precision 10e-6,
482 convertion flag 'g' and initial value 0.00.
484 QAD_SpinBoxDbl::QAD_SpinBoxDbl( QWidget* parent, const char* name )
485 : QFrame(parent, name),
493 Creates a spin box with min value <minValue>, max value <maxValue>,
494 line step <step>, precision <precision>, double precision <dblPrecision>,
495 convertion flag <cFlag> and initial value <minValue>
497 QAD_SpinBoxDbl::QAD_SpinBoxDbl( QWidget* parent,
505 : QFrame( parent, name ),
506 QDblRangeControl( minValue, maxValue, step, step, minValue, precision, dblPrecision, cFlag )
514 QAD_SpinBoxDbl::~QAD_SpinBoxDbl()
518 Internal initialization.
520 void QAD_SpinBoxDbl::initSpinBox()
524 butSymbols = UpDownArrows;
527 up = new QPushButton( this, "up" );
528 up->setFocusPolicy( QWidget::NoFocus );
529 up->setAutoDefault( FALSE );
530 up->setAutoRepeat( TRUE );
532 down = new QPushButton( this, "down" );
533 down->setFocusPolicy( QWidget::NoFocus );
534 down->setAutoDefault( FALSE );
535 down->setAutoRepeat( TRUE );
537 validate = new QAD_SpinBoxDblValidator( this, "validator" );
538 vi = new QLineEdit( this, "line editor" );
539 vi->setFrame( FALSE );
541 setFocusPolicy( StrongFocus );
542 vi->setValidator( validate );
543 vi->installEventFilter( this );
545 setFrameStyle( Panel | Sunken );
548 // setPalettePropagation( AllChildren );
549 // setFontPropagation( AllChildren );
551 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) );
554 connect( up, SIGNAL(pressed()), SLOT(stepUp()) );
555 connect( down, SIGNAL(pressed()), SLOT(stepDown()) );
556 connect( vi, SIGNAL(textChanged(const QString&)), SLOT(textChanged()) );
560 Returns the current text of the spin box, including any prefix() and suffix().
562 QString QAD_SpinBoxDbl::text() const
568 Returns a copy of the current text of the spin box with any prefix
569 and/or suffix and white space at the start and end removed.
571 QString QAD_SpinBoxDbl::cleanText() const
573 QString s = QString(text()).stripWhiteSpace();
574 if ( !prefix().isEmpty() ) {
575 QString px = QString(prefix()).stripWhiteSpace();
576 int len = px.length();
577 if ( len && s.left(len) == px ) // Remove _only_ if it is the prefix
580 if ( !suffix().isEmpty() ) {
581 QString sx = QString(suffix()).stripWhiteSpace();
582 int len = sx.length();
583 if ( len && s.right(len) == sx ) // Remove _only_ if it is the suffix
584 s.truncate( s.length() - len );
586 return s.stripWhiteSpace();
590 Sets the special-value text to text. If set, the spin box will
591 display this text instead of a numeric value whenever the current
592 value is equal to minVal(). Typically used for indicating that this
593 choice has a special (default) meaning.
595 void QAD_SpinBoxDbl::setSpecialValueText( const QString &text )
602 Returns the currently special-value text, or a null string if no
603 special-value text is currently set.
605 QString QAD_SpinBoxDbl::specialValueText() const
607 if ( specText.isEmpty() )
608 return QString::null;
614 Sets the prefix to <text>. The prefix is prepended to the start of
615 the displayed value. Typical use is to indicate the unit of
616 measurement to the user.
618 void QAD_SpinBoxDbl::setPrefix( const QString &text )
625 Sets the suffix to <text>. The suffix is appended to the end of the
626 displayed value. Typical use is to indicate the unit of measurement
629 void QAD_SpinBoxDbl::setSuffix( const QString &text )
636 Returns the currently set prefix, or a null string if no prefix is set.
638 QString QAD_SpinBoxDbl::prefix() const
640 if ( pfix.isEmpty() )
641 return QString::null;
647 Returns the currently set suffix, or a null string if no suffix is set.
649 QString QAD_SpinBoxDbl::suffix() const
651 if ( sfix.isEmpty() )
652 return QString::null;
658 Setting wrapping to TRUE will allow the value to be stepped from the
659 highest value to the lowest, and vice versa. By default, wrapping is
662 void QAD_SpinBoxDbl::setWrapping( bool on )
669 Returns the current setWrapping() value.
671 bool QAD_SpinBoxDbl::wrapping() const
679 QSize QAD_SpinBoxDbl::sizeHint() const
682 QFontMetrics fm = fontMetrics();
683 int h = vi->sizeHint().height();
684 if ( h < 12 ) // ensure enough space for the button pixmaps
686 int w = 35; // minimum width for the value
687 int wx = fm.width( ' ' )*2;
690 QAD_SpinBoxDbl* that = (QAD_SpinBoxDbl*)this;
691 s = prefix() + that->mapValueToText( that->minValue() ) + suffix();
692 w = QMAX( w, fm.width( s ) + wx);
693 s = prefix() + that->mapValueToText( that->maxValue() ) + suffix();
694 w = QMAX(w, fm.width( s ) + wx );
695 if ( !specialValueText().isEmpty() ) {
696 s = specialValueText();
697 w = QMAX( w, fm.width( s ) + wx );
699 QSize r( h * 8/5 // ~ buttons width
701 + frameWidth() * 2, // left/right frame
702 frameWidth() * 2 // top/bottom frame
705 return r.expandedTo( QApplication::globalStrut() );
709 Does the layout of the lineedit and the buttons
711 void QAD_SpinBoxDbl::arrangeWidgets()
713 if ( !up || !down ) // may happen if the application has a pointer error
716 QSize bs; // no, it's short for 'button size'
717 bs.setHeight( height()/2 - frameWidth() );
718 if ( bs.height() < 8 )
720 bs.setWidth( bs.height() * 8 / 5 ); // 1.6 - approximate golden mean
721 setFrameRect( QRect( 0, 0, 0, 0 ) );
723 if ( up->size() != bs || down->size() != bs ) {
726 updateButtonSymbols();
729 int y = frameWidth();
730 int x = width() - y - bs.width();
732 down->move( x, height() - y - up->height() );
733 vi->setGeometry( frameWidth(), frameWidth(),
734 x - frameWidth(), height() - 2*frameWidth() );
738 Sets the current value of the spin box to <value>. This is
739 QRangeControl::setValue() made available as a slot.
741 void QAD_SpinBoxDbl::setValue( double value )
743 QDblRangeControl::setValue( value );
747 Increases the current value one step, wrapping as necessary. This is
748 the same as clicking on the pointing-up button, and can be used for
749 e.g. keyboard accelerators.
751 void QAD_SpinBoxDbl::stepUp()
755 if ( wrapping() && ( value()+lineStep() > maxValue() ) )
756 setValue( minValue() );
762 Decreases the current value one step, wrapping as necessary. This is
763 the same as clicking on the pointing-down button, and can be used
764 for e.g. keyboard accelerators.
766 void QAD_SpinBoxDbl::stepDown()
770 if ( wrapping() && ( value()-lineStep() < minValue() ) )
771 setValue( maxValue() );
777 Intercepts and handles those events coming to the embedded QLineEdit
778 which have special meaning for the QAD_SpinBoxDbl.
780 bool QAD_SpinBoxDbl::eventFilter( QObject* obj, QEvent* ev )
785 if ( ev->type() == QEvent::KeyPress ) {
786 QKeyEvent* k = (QKeyEvent*)ev;
788 bool retval = FALSE; // workaround for MSVC++ optimization bug
789 if( (k->key() == Key_Tab) || (k->key() == Key_BackTab) ){
792 qApp->sendEvent( this, ev );
794 } if ( k->key() == Key_Up ) {
797 } else if ( k->key() == Key_Down ) {
800 } else if ( k->key() == Key_Return ) {
806 } else if ( ev->type() == QEvent::FocusOut || ev->type() == QEvent::Leave || ev->type() == QEvent::Hide ) {
818 void QAD_SpinBoxDbl::leaveEvent( QEvent* )
827 void QAD_SpinBoxDbl::resizeEvent( QResizeEvent* )
835 void QAD_SpinBoxDbl::wheelEvent( QWheelEvent * e )
838 static float offset = 0;
839 static QAD_SpinBoxDbl* offset_owner = 0;
840 if (offset_owner != this) {
844 offset += -e->delta()/120;
845 if (QABS(offset) < 1)
847 int ioff = int(offset);
849 for (i=0; i<QABS(ioff); i++)
850 offset > 0 ? stepDown() : stepUp();
855 This method gets called by QRangeControl whenever the value has changed.
856 Updates the display and emits the valueChanged() signals.
858 void QAD_SpinBoxDbl::valueChange()
863 emit valueChanged( value() );
864 emit valueChanged( currentValueText() );
868 This method gets called by QRangeControl whenever the range has
869 changed. It adjusts the default validator and updates the display.
871 void QAD_SpinBoxDbl::rangeChange()
877 Sets the validator to <v>. The validator controls what keyboard
878 input is accepted when the user is editing in the value field. The
879 default is to use a suitable QIntValidator.
881 void QAD_SpinBoxDbl::setValidator( const QValidator* v )
884 vi->setValidator( v );
887 Returns the validator which constrains editing for this spin box if
888 there is any, or else 0.
890 const QValidator* QAD_SpinBoxDbl::validator() const
892 return vi ? vi->validator() : 0;
896 Updates the contents of the embedded QLineEdit to reflect current
897 value, using mapValueToText(). Also enables/disables the push
900 void QAD_SpinBoxDbl::updateDisplay()
902 vi->setUpdatesEnabled( FALSE );
903 vi->setText( currentValueText() );
904 if ( selreq && isVisible() && ( hasFocus() || vi->hasFocus() ) ) {
907 if ( !suffix().isEmpty() &&
908 endsWith(vi->text(), suffix()) )
909 vi->setCursorPosition( vi->text().length() - suffix().length() );
911 vi->setUpdatesEnabled( TRUE );
912 vi->repaint( FALSE ); // immediate repaint needed for some reason
915 up->setEnabled( isEnabled() && (wrapping() || value() < maxValue()) );
916 down->setEnabled( isEnabled() && (wrapping() || value() > minValue()) );
917 vi->setEnabled( isEnabled() );
921 QAD_SpinBoxDbl calls this after the user has manually edited the contents
922 of the spin box (not using the up/down buttons/keys).
923 The default implementation of this function interprets the new text
924 using mapTextToValue(). If mapTextToValue() is successful, it
925 changes the spin box' value. If not the value if left unchanged.
927 void QAD_SpinBoxDbl::interpretText()
932 if ( !specialValueText().isEmpty() ) {
933 QString s = QString(text()).stripWhiteSpace();
934 QString t = QString(specialValueText()).stripWhiteSpace();
941 newVal = mapTextToValue( &ok );
944 updateDisplay(); // Sometimes redundant
948 Returns a pointer to the embedded 'up' button.
951 QPushButton* QAD_SpinBoxDbl::upButton() const
957 Returns a pointer to the embedded 'down' button.
959 QPushButton* QAD_SpinBoxDbl::downButton() const
965 Returns a pointer to the embedded QLineEdit.
967 QLineEdit* QAD_SpinBoxDbl::editor() const
973 This slot gets called whenever the user edits the text of the spin box.
975 void QAD_SpinBoxDbl::textChanged()
977 edited = TRUE; // This flag is cleared in updateDisplay()
981 This virtual function is used by the spin box whenever it needs to
982 display value <v>. The default implementation returns a string
983 containing <v> printed in the standard way.
986 QString QAD_SpinBoxDbl::mapValueToText( double v )
989 s.setNum( v, convertFlag(), precision() );
994 This virtual function is used by the spin box whenever it needs to
995 interpret the text entered by the user as a value. The default
996 implementation tries to interpret it as an integer in the standard
997 way, and returns the double value.
999 double QAD_SpinBoxDbl::mapTextToValue( bool* ok )
1002 double newVal = s.toDouble( ok );
1003 if ( !(*ok) && !( !prefix() && !suffix() ) ) {// Try removing any pre/suffix
1005 newVal = s.toDouble( ok );
1011 Returns the full text calculated from the current value, including any
1012 prefix, suffix or special-value text.
1014 QString QAD_SpinBoxDbl::currentValueText()
1017 if ( (value() <= minValue()) && !specialValueText().isEmpty() ) {
1018 s = specialValueText();
1021 s.append( mapValueToText( value() ) );
1022 s.append( suffix() );
1030 void QAD_SpinBoxDbl::setEnabled( bool on )
1032 bool b = isEnabled();
1033 QFrame::setEnabled( on );
1034 if ( isEnabled() != b ) {
1035 // ## enabledChange() might have been a better choice
1043 void QAD_SpinBoxDbl::styleChange( QStyle& old )
1045 setFrameStyle( Panel | Sunken );
1047 QWidget::styleChange( old );
1051 Sets the spin box to display <newSymbols> on its buttons.
1052 <newSymbols> can be either <UpDownArrows> (the default) or <PlusMinus>.
1054 void QAD_SpinBoxDbl::setButtonSymbols( ButtonSymbols newSymbols )
1056 if ( buttonSymbols() == newSymbols )
1058 butSymbols = newSymbols;
1059 updateButtonSymbols();
1063 Returns the current button symbol mode. The default is <UpDownArrows>
1065 QAD_SpinBoxDbl::ButtonSymbols QAD_SpinBoxDbl::buttonSymbols() const
1071 This function uses the pixmap cache for a Different Reason: the
1072 pixmap cache also preserves QPixmap::serialNumber(). by doing
1073 this, QButton::setPixmap() is able to avoid flicker e.g. when the
1074 spin box is resized in such a way that the height of the buttons
1075 does not change (common the default size policy).
1077 void QAD_SpinBoxDbl::updateButtonSymbols()
1079 QString key( QString::fromLatin1( "$qt$QAD_SpinBoxDbl$" ) );
1080 bool pmSym = buttonSymbols() == PlusMinus;
1081 key += QString::fromLatin1( pmSym ? "+-" : "^v" );
1082 key += QString::number( down->height() );
1083 QString upKey = key + QString::fromLatin1( "$up" );
1084 QString dnKey = key + QString::fromLatin1( "$down" );
1088 bool found = QPixmapCache::find( dnKey, dnBm )
1089 && QPixmapCache::find( upKey, upBm );
1094 int h = down->height()-4;
1099 else if ( (h > 6) && (h & 1) )
1101 h -= ( h / 8 ) * 2; // Empty border
1102 dnBm.resize( h, h );
1104 p.eraseRect( 0, 0, h, h );
1105 p.setBrush( color1 );
1107 p.drawLine( 0, c, h, c );
1109 p.drawLine( 0, c-1, h, c-1 );
1113 p.drawLine( c, 0, c, h );
1115 p.drawLine( c-1, 0, c-1, h );
1119 int w = down->width()-4;
1122 else if ( !(w & 1) )
1124 w -= ( w / 7 ) * 2; // Empty border
1125 int h = w/2 + 2; // Must have empty row at foot of arrow
1126 dnBm.resize( w, h );
1128 p.eraseRect( 0, 0, w, h );
1130 a.setPoints( 3, 0, 1, w-1, 1, h-2, h-1 );
1131 p.setBrush( color1 );
1134 #ifndef QT_NO_TRANSFORMATIONS
1137 upBm = dnBm.xForm( wm );
1139 upBm.resize( w, h );
1141 p.eraseRect( 0, 0, w, h );
1142 a.setPoints( 3, 0, h-2, w-1, h-2, h-2, 0 );
1143 p.setBrush( color1 );
1148 QPixmapCache::insert( dnKey, dnBm );
1149 QPixmapCache::insert( upKey, upBm );
1151 down->setPixmap( dnBm );
1152 up->setPixmap( upBm );
1156 Returns minimum value, reimplementaion
1158 double QAD_SpinBoxDbl::minValue()
1160 return QDblRangeControl::minValue();
1164 Returns maximum value, reimplementaion
1166 double QAD_SpinBoxDbl::maxValue()
1168 return QDblRangeControl::maxValue();
1172 Sets minimum value, reimplementaion
1174 void QAD_SpinBoxDbl::setMinValue( double minValue )
1176 QDblRangeControl::setMinValue( minValue );
1180 Sets maximum value, reimplementaion
1182 void QAD_SpinBoxDbl::setMaxValue( double maxValue )
1184 QDblRangeControl::setMaxValue( maxValue );
1188 Returns step size, reimplementaion
1190 double QAD_SpinBoxDbl::lineStep()
1192 return QDblRangeControl::lineStep();
1198 void QAD_SpinBoxDbl::setLineStep( double step )
1200 setSteps( step, pageStep() );
1204 Returns value of the spin box, reimplementaion
1206 double QAD_SpinBoxDbl::value()
1208 QAD_SpinBoxDbl* that = ( QAD_SpinBoxDbl* ) this;
1210 that->edited = FALSE; // avoid recursion
1211 that->interpretText();
1213 return QDblRangeControl::value();
1217 Selects all the text in the editor of the spinbox.
1219 void QAD_SpinBoxDbl::selectAll()
1221 int overhead = prefix().length() + suffix().length();
1222 if ( !overhead || currentValueText() == specialValueText() ) {
1225 vi->setSelection( prefix().length(), vi->text().length() - overhead );