src/gui/widgets/qlcdnumber.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    83 
    83 
    84     There are also slots to change the base with setMode() and the
    84     There are also slots to change the base with setMode() and the
    85     decimal point with setSmallDecimalPoint().
    85     decimal point with setSmallDecimalPoint().
    86 
    86 
    87     QLCDNumber emits the overflow() signal when it is asked to display
    87     QLCDNumber emits the overflow() signal when it is asked to display
    88     something beyond its range. The range is set by setNumDigits(),
    88     something beyond its range. The range is set by setDigitCount(),
    89     but setSmallDecimalPoint() also influences it. If the display is
    89     but setSmallDecimalPoint() also influences it. If the display is
    90     set to hexadecimal, octal or binary, the integer equivalent of the
    90     set to hexadecimal, octal or binary, the integer equivalent of the
    91     value is displayed.
    91     value is displayed.
    92 
    92 
    93     These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S,
    93     These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S,
   158     \fn void QLCDNumber::overflow()
   158     \fn void QLCDNumber::overflow()
   159 
   159 
   160     This signal is emitted whenever the QLCDNumber is asked to display
   160     This signal is emitted whenever the QLCDNumber is asked to display
   161     a too-large number or a too-long string.
   161     a too-large number or a too-long string.
   162 
   162 
   163     It is never emitted by setNumDigits().
   163     It is never emitted by setDigitCount().
   164 */
   164 */
   165 
   165 
   166 
   166 
   167 static QString int2string(int num, int base, int ndigits, bool *oflow)
   167 static QString int2string(int num, int base, int ndigits, bool *oflow)
   168 {
   168 {
   343     to a raised box. The segmentStyle() is set to \c Outline.
   343     to a raised box. The segmentStyle() is set to \c Outline.
   344 
   344 
   345     The \a parent and \a name arguments are passed to the QFrame
   345     The \a parent and \a name arguments are passed to the QFrame
   346     constructor.
   346     constructor.
   347 
   347 
   348     \sa setNumDigits(), setSmallDecimalPoint()
   348     \sa setDigitCount(), setSmallDecimalPoint()
   349 */
   349 */
   350 
   350 
   351 QLCDNumber::QLCDNumber(QWidget *parent, const char *name)
   351 QLCDNumber::QLCDNumber(QWidget *parent, const char *name)
   352         : QFrame(*new QLCDNumberPrivate, parent)
   352         : QFrame(*new QLCDNumberPrivate, parent)
   353 {
   353 {
   365     \c Outline.
   365     \c Outline.
   366 
   366 
   367     The \a parent and \a name arguments are passed to the QFrame
   367     The \a parent and \a name arguments are passed to the QFrame
   368     constructor.
   368     constructor.
   369 
   369 
   370     \sa setNumDigits(), setSmallDecimalPoint()
   370     \sa setDigitCount(), setSmallDecimalPoint()
   371 */
   371 */
   372 
   372 
   373 QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name)
   373 QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name)
   374         : QFrame(*new QLCDNumberPrivate, parent)
   374         : QFrame(*new QLCDNumberPrivate, parent)
   375 {
   375 {
   385     to decimal, the decimal point mode to 'small' and the frame style
   385     to decimal, the decimal point mode to 'small' and the frame style
   386     to a raised box. The segmentStyle() is set to \c Outline.
   386     to a raised box. The segmentStyle() is set to \c Outline.
   387 
   387 
   388     The \a parent argument is passed to the QFrame constructor.
   388     The \a parent argument is passed to the QFrame constructor.
   389 
   389 
   390     \sa setNumDigits(), setSmallDecimalPoint()
   390     \sa setDigitCount(), setSmallDecimalPoint()
   391 */
   391 */
   392 
   392 
   393 QLCDNumber::QLCDNumber(QWidget *parent)
   393 QLCDNumber::QLCDNumber(QWidget *parent)
   394         : QFrame(*new QLCDNumberPrivate, parent)
   394         : QFrame(*new QLCDNumberPrivate, parent)
   395 {
   395 {
   405     and the frame style to a raised box. The segmentStyle() is set to
   405     and the frame style to a raised box. The segmentStyle() is set to
   406     \c Filled.
   406     \c Filled.
   407 
   407 
   408     The \a parent argument is passed to the QFrame constructor.
   408     The \a parent argument is passed to the QFrame constructor.
   409 
   409 
   410     \sa setNumDigits(), setSmallDecimalPoint()
   410     \sa setDigitCount(), setSmallDecimalPoint()
   411 */
   411 */
   412 
   412 
   413 QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent)
   413 QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent)
   414         : QFrame(*new QLCDNumberPrivate, parent)
   414         : QFrame(*new QLCDNumberPrivate, parent)
   415 {
   415 {
   424 
   424 
   425     q->setFrameStyle(QFrame::Box | QFrame::Raised);
   425     q->setFrameStyle(QFrame::Box | QFrame::Raised);
   426     val        = 0;
   426     val        = 0;
   427     base       = QLCDNumber::Dec;
   427     base       = QLCDNumber::Dec;
   428     smallPoint = false;
   428     smallPoint = false;
   429     q->setNumDigits(ndigits);
   429     q->setDigitCount(ndigits);
   430     q->setSegmentStyle(QLCDNumber::Filled);
   430     q->setSegmentStyle(QLCDNumber::Filled);
   431     q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
   431     q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
   432 }
   432 }
   433 
   433 
   434 /*!
   434 /*!
   439 {
   439 {
   440 }
   440 }
   441 
   441 
   442 
   442 
   443 /*!
   443 /*!
       
   444     \deprecated
   444     \property QLCDNumber::numDigits
   445     \property QLCDNumber::numDigits
       
   446     \brief the current number of digits displayed
       
   447     \sa digitCount
       
   448 */
       
   449 
       
   450 void QLCDNumber::setNumDigits(int numDigits)
       
   451 {
       
   452     setDigitCount(numDigits);
       
   453 }
       
   454 
       
   455 /*!
       
   456     \since 4.6
       
   457     \property QLCDNumber::digitCount
   445     \brief the current number of digits displayed
   458     \brief the current number of digits displayed
   446 
   459 
   447     Corresponds to the current number of digits. If \l
   460     Corresponds to the current number of digits. If \l
   448     QLCDNumber::smallDecimalPoint is false, the decimal point occupies
   461     QLCDNumber::smallDecimalPoint is false, the decimal point occupies
   449     one digit position.
   462     one digit position.
   451     By default, this property contains a value of 5.
   464     By default, this property contains a value of 5.
   452 
   465 
   453     \sa smallDecimalPoint
   466     \sa smallDecimalPoint
   454 */
   467 */
   455 
   468 
   456 void QLCDNumber::setNumDigits(int numDigits)
   469 /*!
       
   470   Sets the current number of digits to \a numDigits. Must
       
   471   be in the range 0..99.
       
   472  */
       
   473 void QLCDNumber::setDigitCount(int numDigits)
   457 {
   474 {
   458     Q_D(QLCDNumber);
   475     Q_D(QLCDNumber);
   459     if (numDigits > 99) {
   476     if (numDigits > 99) {
   460         qWarning("QLCDNumber::setNumDigits: (%s) Max 99 digits allowed",
   477         qWarning("QLCDNumber::setNumDigits: (%s) Max 99 digits allowed",
   461                  objectName().toLocal8Bit().constData());
   478                  objectName().toLocal8Bit().constData());
   468     }
   485     }
   469     if (d->digitStr.isNull()) {                  // from constructor
   486     if (d->digitStr.isNull()) {                  // from constructor
   470         d->ndigits = numDigits;
   487         d->ndigits = numDigits;
   471         d->digitStr.fill(QLatin1Char(' '), d->ndigits);
   488         d->digitStr.fill(QLatin1Char(' '), d->ndigits);
   472         d->points.fill(0, d->ndigits);
   489         d->points.fill(0, d->ndigits);
   473         d->digitStr[d->ndigits - 1] = QLatin1Char('0');            // "0" is the default number
   490         d->digitStr[d->ndigits - 1] = QLatin1Char('0'); // "0" is the default number
   474     } else {
   491     } else {
   475         bool doDisplay = d->ndigits == 0;
   492         bool doDisplay = d->ndigits == 0;
   476         if (numDigits == d->ndigits)             // no change
   493         if (numDigits == d->ndigits)             // no change
   477             return;
   494             return;
   478         register int i;
   495         register int i;
   507     Q_D(const QLCDNumber);
   524     Q_D(const QLCDNumber);
   508     return d->ndigits;
   525     return d->ndigits;
   509 }
   526 }
   510 
   527 
   511 /*!
   528 /*!
       
   529   Returns the current number of digits.
       
   530  */
       
   531 int QLCDNumber::digitCount() const
       
   532 {
       
   533     Q_D(const QLCDNumber);
       
   534     return d->ndigits;
       
   535 }
       
   536 
       
   537 /*!
   512     \overload
   538     \overload
   513 
   539 
   514     Returns true if \a num is too big to be displayed in its entirety;
   540     Returns true if \a num is too big to be displayed in its entirety;
   515     otherwise returns false.
   541     otherwise returns false.
   516 
   542 
   517     \sa display(), numDigits(), smallDecimalPoint()
   543     \sa display(), digitCount(), smallDecimalPoint()
   518 */
   544 */
   519 
   545 
   520 bool QLCDNumber::checkOverflow(int num) const
   546 bool QLCDNumber::checkOverflow(int num) const
   521 {
   547 {
   522     Q_D(const QLCDNumber);
   548     Q_D(const QLCDNumber);
   528 
   554 
   529 /*!
   555 /*!
   530     Returns true if \a num is too big to be displayed in its entirety;
   556     Returns true if \a num is too big to be displayed in its entirety;
   531     otherwise returns false.
   557     otherwise returns false.
   532 
   558 
   533     \sa display(), numDigits(), smallDecimalPoint()
   559     \sa display(), digitCount(), smallDecimalPoint()
   534 */
   560 */
   535 
   561 
   536 bool QLCDNumber::checkOverflow(double num) const
   562 bool QLCDNumber::checkOverflow(double num) const
   537 {
   563 {
   538     Q_D(const QLCDNumber);
   564     Q_D(const QLCDNumber);
  1254 
  1280 
  1255 /*!\reimp
  1281 /*!\reimp
  1256 */
  1282 */
  1257 QSize QLCDNumber::sizeHint() const
  1283 QSize QLCDNumber::sizeHint() const
  1258 {
  1284 {
  1259     return QSize(10 + 9 * (numDigits() + (smallDecimalPoint() ? 0 : 1)), 23);
  1285     return QSize(10 + 9 * (digitCount() + (smallDecimalPoint() ? 0 : 1)), 23);
  1260 }
  1286 }
  1261 
  1287 
  1262 /*! \reimp */
  1288 /*! \reimp */
  1263 bool QLCDNumber::event(QEvent *e)
  1289 bool QLCDNumber::event(QEvent *e)
  1264 {
  1290 {