⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlcdnumber.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qlcdnumber.h"#ifndef QT_NO_LCDNUMBER#include "qbitarray.h"#include "qpainter.h"#include "private/qframe_p.h"class QLCDNumberPrivate : public QFramePrivate{    Q_DECLARE_PUBLIC(QLCDNumber)public:    void init();    void internalSetString(const QString& s);    void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true);    //void drawString(const QString &, QPainter &, QBitArray * = 0) const;    void drawDigit(const QPoint &, QPainter &, int, char, char = ' ');    void drawSegment(const QPoint &, char, QPainter &, int, bool = false);    int ndigits;    double val;    uint base : 2;    uint smallPoint : 1;    uint fill : 1;    uint shadow : 1;    QString digitStr;    QBitArray points;};/*!    \class QLCDNumber    \brief The QLCDNumber widget displays a number with LCD-like digits.    \ingroup basicwidgets    \mainclass    It can display a number in just about any size. It can display    decimal, hexadecimal, octal or binary numbers. It is easy to    connect to data sources using the display() slot, which is    overloaded to take any of five argument types.    There are also slots to change the base with setMode() and the    decimal point with setSmallDecimalPoint().    QLCDNumber emits the overflow() signal when it is asked to display    something beyond its range. The range is set by setNumDigits(),    but setSmallDecimalPoint() also influences it. If the display is    set to hexadecimal, octal or binary, the integer equivalent of the    value is displayed.    These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S,    6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o,    P, r, u, U, Y, colon, degree sign (which is specified as single    quote in the string) and space. QLCDNumber substitutes spaces for    illegal characters.    It is not possible to retrieve the contents of a QLCDNumber    object, although you can retrieve the numeric value with value().    If you really need the text, we recommend that you connect the    signals that feed the display() slot to another slot as well and    store the value there.    Incidentally, QLCDNumber is the very oldest part of Qt, tracing    its roots back to a BASIC program on the \link    http://www.nvg.ntnu.no/sinclair/computers/zxspectrum/zxspectrum.htm    Sinclair Spectrum\endlink.    \table    \row \o \inlineimage motif-lcdnumber.png Screenshot of a Motif style LCD number widget    \inlineimage cde-lcdnumber.png Screenshot of a CDE style LCD number widget    \inlineimage windows-lcdnumber.png Screenshot of a Windows style LCD number widget    \inlineimage windowsxp-lcdnumber.png Screenshot of a Windows XP style LCD number widget    \inlineimage macintosh-lcdnumber.png Screenshot of a Macintosh style LCD number widget    \inlineimage plastique-lcdnumber.png Screenshot of a Plastique style LCD number widget    \row \o LCD number widgets shown in various widget styles (from left to right):    \l{Motif Style Widget Gallery}{Motif}, \l{CDE Style Widget Gallery}{CDE},    \l{Windows Style Widget Gallery}{Windows}, \l{Windows XP Style Widget Gallery}{Windows XP},    \l{Macintosh Style Widget Gallery}{Macintosh}, \l{Plastique Style Widget Gallery}{Plastique}.    \endtable    \sa QLabel, QFrame, {Digital Clock Example}, {Tetrix Example}*//*!    \enum QLCDNumber::Mode    This type determines how numbers are shown.    \value Hex  Hexadecimal    \value Dec  Decimal    \value Oct  Octal    \value Bin  Binary    \omitvalue HEX    \omitvalue DEC    \omitvalue OCT    \omitvalue BIN    If the display is set to hexadecimal, octal or binary, the integer    equivalent of the value is displayed.*//*!    \enum QLCDNumber::SegmentStyle    This type determines the visual appearance of the QLCDNumber    widget.    \value Outline gives raised segments filled with the background color.    \value Filled gives raised segments filled with the windowText color.    \value Flat gives flat segments filled with the windowText color.*//*!    \fn void QLCDNumber::overflow()    This signal is emitted whenever the QLCDNumber is asked to display    a too-large number or a too-long string.    It is never emitted by setNumDigits().*/static QString int2string(int num, int base, int ndigits, bool *oflow){    QString s;    bool negative;    if (num < 0) {        negative = true;        num      = -num;    } else {        negative = false;    }    switch(base) {        case QLCDNumber::Hex:            s.sprintf("%*x", ndigits, num);            break;        case QLCDNumber::Dec:            s.sprintf("%*i", ndigits, num);            break;        case QLCDNumber::Oct:            s.sprintf("%*o", ndigits, num);            break;        case QLCDNumber::Bin:            {                char buf[42];                char *p = &buf[41];                uint n = num;                int len = 0;                *p = '\0';                do {                    *--p = (char)((n&1)+'0');                    n >>= 1;                    len++;                } while (n != 0);                len = ndigits - len;                if (len > 0)                s.fill(QLatin1Char(' '), len);                s += QString::fromLatin1(p);            }            break;    }    if (negative) {        for (int i=0; i<(int)s.length(); i++) {            if (s[i] != QLatin1Char(' ')) {                if (i != 0) {                    s[i-1] = QLatin1Char('-');                } else {                    s.insert(0, QLatin1Char('-'));                }                break;            }        }    }    if (oflow)        *oflow = (int)s.length() > ndigits;    return s;}static QString double2string(double num, int base, int ndigits, bool *oflow){    QString s;    if (base != QLCDNumber::Dec) {        bool of = num >= 2147483648.0 || num < -2147483648.0;        if (of) {                             // oops, integer overflow            if (oflow)                *oflow = true;            return s;        }        s = int2string((int)num, base, ndigits, 0);    } else {                                    // decimal base        int nd = ndigits;        do {            s.sprintf("%*.*g", ndigits, nd, num);            int i = s.indexOf(QLatin1Char('e'));            if (i > 0 && s[i+1]==QLatin1Char('+')) {                s[i] = QLatin1Char(' ');                s[i+1] = QLatin1Char('e');            }        } while (nd-- && (int)s.length() > ndigits);    }    if (oflow)        *oflow = (int)s.length() > ndigits;    return s;}static const char *getSegments(char ch)               // gets list of segments for ch{    static const char segments[30][8] =       { { 0, 1, 2, 4, 5, 6,99, 0},             // 0    0 / O         { 2, 5,99, 0, 0, 0, 0, 0},             // 1    1         { 0, 2, 3, 4, 6,99, 0, 0},             // 2    2         { 0, 2, 3, 5, 6,99, 0, 0},             // 3    3         { 1, 2, 3, 5,99, 0, 0, 0},             // 4    4         { 0, 1, 3, 5, 6,99, 0, 0},             // 5    5 / S         { 0, 1, 3, 4, 5, 6,99, 0},             // 6    6         { 0, 2, 5,99, 0, 0, 0, 0},             // 7    7         { 0, 1, 2, 3, 4, 5, 6,99},             // 8    8         { 0, 1, 2, 3, 5, 6,99, 0},             // 9    9 / g         { 3,99, 0, 0, 0, 0, 0, 0},             // 10   -         { 7,99, 0, 0, 0, 0, 0, 0},             // 11   .         { 0, 1, 2, 3, 4, 5,99, 0},             // 12   A         { 1, 3, 4, 5, 6,99, 0, 0},             // 13   B         { 0, 1, 4, 6,99, 0, 0, 0},             // 14   C         { 2, 3, 4, 5, 6,99, 0, 0},             // 15   D         { 0, 1, 3, 4, 6,99, 0, 0},             // 16   E         { 0, 1, 3, 4,99, 0, 0, 0},             // 17   F         { 1, 3, 4, 5,99, 0, 0, 0},             // 18   h         { 1, 2, 3, 4, 5,99, 0, 0},             // 19   H         { 1, 4, 6,99, 0, 0, 0, 0},             // 20   L         { 3, 4, 5, 6,99, 0, 0, 0},             // 21   o         { 0, 1, 2, 3, 4,99, 0, 0},             // 22   P         { 3, 4,99, 0, 0, 0, 0, 0},             // 23   r         { 4, 5, 6,99, 0, 0, 0, 0},             // 24   u         { 1, 2, 4, 5, 6,99, 0, 0},             // 25   U         { 1, 2, 3, 5, 6,99, 0, 0},             // 26   Y         { 8, 9,99, 0, 0, 0, 0, 0},             // 27   :         { 0, 1, 2, 3,99, 0, 0, 0},             // 28   '         {99, 0, 0, 0, 0, 0, 0, 0} };           // 29   empty    if (ch >= '0' && ch <= '9')        return segments[ch - '0'];    if (ch >= 'A' && ch <= 'F')        return segments[ch - 'A' + 12];    if (ch >= 'a' && ch <= 'f')        return segments[ch - 'a' + 12];    int n;    switch (ch) {        case '-':            n = 10;  break;        case 'O':            n = 0;   break;        case 'g':            n = 9;   break;        case '.':            n = 11;  break;        case 'h':            n = 18;  break;        case 'H':            n = 19;  break;        case 'l':        case 'L':            n = 20;  break;        case 'o':            n = 21;  break;        case 'p':        case 'P':            n = 22;  break;        case 'r':        case 'R':            n = 23;  break;        case 's':        case 'S':            n = 5;   break;        case 'u':            n = 24;  break;        case 'U':            n = 25;  break;        case 'y':        case 'Y':            n = 26;  break;        case ':':            n = 27;  break;        case '\'':            n = 28;  break;        default:            n = 29;  break;    }    return segments[n];}#ifdef QT3_SUPPORT/*! \obsolete    Constructs an LCD number, sets the number of digits to 5, the base    to decimal, the decimal point mode to 'small' and the frame style    to a raised box. The segmentStyle() is set to \c Outline.    The \a parent and \a name arguments are passed to the QFrame    constructor.    \sa setNumDigits(), setSmallDecimalPoint()*/QLCDNumber::QLCDNumber(QWidget *parent, const char *name)        : QFrame(*new QLCDNumberPrivate, parent){    setObjectName(QString::fromAscii(name));    Q_D(QLCDNumber);    d->ndigits = 5;    d->init();}/*! \obsolete    Constructs an LCD number, sets the number of digits to \a    numDigits, the base to decimal, the decimal point mode to 'small'    and the frame style to a raised box. The segmentStyle() is set to    \c Outline.    The \a parent and \a name arguments are passed to the QFrame    constructor.    \sa setNumDigits(), setSmallDecimalPoint()*/QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent, const char *name)        : QFrame(*new QLCDNumberPrivate, parent){    setObjectName(QString::fromAscii(name));    Q_D(QLCDNumber);    d->ndigits = numDigits;    d->init();}#endif //QT3_SUPPORT/*!    Constructs an LCD number, sets the number of digits to 5, the base    to decimal, the decimal point mode to 'small' and the frame style    to a raised box. The segmentStyle() is set to \c Outline.    The \a parent argument is passed to the QFrame constructor.    \sa setNumDigits(), setSmallDecimalPoint()*/QLCDNumber::QLCDNumber(QWidget *parent)        : QFrame(*new QLCDNumberPrivate, parent){    Q_D(QLCDNumber);    d->ndigits = 5;    d->init();}/*!    Constructs an LCD number, sets the number of digits to \a    numDigits, the base to decimal, the decimal point mode to 'small'    and the frame style to a raised box. The segmentStyle() is set to    \c Outline.    The \a parent argument is passed to the QFrame constructor.    \sa setNumDigits(), setSmallDecimalPoint()*/QLCDNumber::QLCDNumber(uint numDigits, QWidget *parent)        : QFrame(*new QLCDNumberPrivate, parent){    Q_D(QLCDNumber);    d->ndigits = numDigits;    d->init();}void QLCDNumberPrivate::init(){    Q_Q(QLCDNumber);    q->setFrameStyle(QFrame::Box | QFrame::Raised);    val        = 0;    base       = QLCDNumber::Dec;    smallPoint = false;    q->setNumDigits(ndigits);    q->setSegmentStyle(QLCDNumber::Outline);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -