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

📄 qlcdnumber.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        digitStr.truncate(ndigits);        if (newPoints)            points = *newPoints;    }}/*!  \internal*/void QLCDNumberPrivate::drawDigit(const QPoint &pos, QPainter &p, int segLen,                                  char newCh, char oldCh){// Draws and/or erases segments to change display of a single digit// from oldCh to newCh    char updates[18][2];        // can hold 2 times number of segments, only                                // first 9 used if segment table is correct    int  nErases;    int  nUpdates;    const char *segs;    int  i,j;    const char erase      = 0;    const char draw       = 1;    const char leaveAlone = 2;    segs = getSegments(oldCh);    for (nErases=0; segs[nErases] != 99; nErases++) {        updates[nErases][0] = erase;            // get segments to erase to        updates[nErases][1] = segs[nErases];    // remove old char    }    nUpdates = nErases;    segs = getSegments(newCh);    for(i = 0 ; segs[i] != 99 ; i++) {        for (j=0;  j<nErases; j++)            if (segs[i] == updates[j][1]) {   // same segment ?                updates[j][0] = leaveAlone;     // yes, already on screen                break;            }        if (j == nErases) {                   // if not already on screen            updates[nUpdates][0] = draw;            updates[nUpdates][1] = segs[i];            nUpdates++;        }    }    for (i=0; i<nUpdates; i++) {        if (updates[i][0] == draw)            drawSegment(pos, updates[i][1], p, segLen);        if (updates[i][0] == erase)            drawSegment(pos, updates[i][1], p, segLen, true);    }}static void addPoint(QPolygon &a, const QPoint &p){    uint n = a.size();    a.resize(n + 1);    a.setPoint(n, p);}/*!  \internal*/void QLCDNumberPrivate::drawSegment(const QPoint &pos, char segmentNo, QPainter &p,                                    int segLen, bool erase){    Q_Q(QLCDNumber);    QPoint ppt;    QPoint pt = pos;    int width = segLen/5;    const QPalette &pal = q->palette();    QColor lightColor,darkColor,fgColor;    if (erase){        lightColor = pal.color(q->backgroundRole());        darkColor  = lightColor;        fgColor    = lightColor;    } else {        lightColor = pal.light().color();        darkColor  = pal.dark().color();        fgColor    = pal.color(q->foregroundRole());    }#define LINETO(X,Y) addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y)))#define LIGHT#define DARK    if (fill) {        QPolygon a(0);        //The following is an exact copy of the switch below.        //don't make any changes here        switch (segmentNo) {        case 0 :            ppt = pt;            LIGHT;            LINETO(segLen - 1,0);            DARK;            LINETO(segLen - width - 1,width);            LINETO(width,width);            LINETO(0,0);            break;        case 1 :            pt += QPoint(0 , 1);            ppt = pt;            LIGHT;            LINETO(width,width);            DARK;            LINETO(width,segLen - width/2 - 2);            LINETO(0,segLen - 2);            LIGHT;            LINETO(0,0);            break;        case 2 :            pt += QPoint(segLen - 1 , 1);            ppt = pt;            DARK;            LINETO(0,segLen - 2);            LINETO(-width,segLen - width/2 - 2);            LIGHT;            LINETO(-width,width);            LINETO(0,0);            break;        case 3 :            pt += QPoint(0 , segLen);            ppt = pt;            LIGHT;            LINETO(width,-width/2);            LINETO(segLen - width - 1,-width/2);            LINETO(segLen - 1,0);            DARK;            if (width & 1) {            // adjust for integer division error                LINETO(segLen - width - 3,width/2 + 1);                LINETO(width + 2,width/2 + 1);            } else {                LINETO(segLen - width - 1,width/2);                LINETO(width,width/2);            }            LINETO(0,0);            break;        case 4 :            pt += QPoint(0 , segLen + 1);            ppt = pt;            LIGHT;            LINETO(width,width/2);            DARK;            LINETO(width,segLen - width - 2);            LINETO(0,segLen - 2);            LIGHT;            LINETO(0,0);            break;        case 5 :            pt += QPoint(segLen - 1 , segLen + 1);            ppt = pt;            DARK;            LINETO(0,segLen - 2);            LINETO(-width,segLen - width - 2);            LIGHT;            LINETO(-width,width/2);            LINETO(0,0);            break;        case 6 :            pt += QPoint(0 , segLen*2);            ppt = pt;            LIGHT;            LINETO(width,-width);            LINETO(segLen - width - 1,-width);            LINETO(segLen - 1,0);            DARK;            LINETO(0,0);            break;        case 7 :            if (smallPoint)   // if smallpoint place'.' between other digits                pt += QPoint(segLen + width/2 , segLen*2);            else                pt += QPoint(segLen/2 , segLen*2);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        case 8 :            pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        case 9 :            pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        default :            qWarning("QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",                     q->objectName().toLocal8Bit().constData(), segmentNo);        }        // End exact copy        p.setPen(fgColor);        p.setBrush(fgColor);        p.drawPolygon(a);        p.setBrush(Qt::NoBrush);        pt = pos;    }#undef LINETO#undef LIGHT#undef DARK#define LINETO(X,Y) p.drawLine(ppt.x(), ppt.y(), pt.x()+(X), pt.y()+(Y)); \                    ppt = QPoint(pt.x()+(X), pt.y()+(Y))#define LIGHT p.setPen(lightColor)#define DARK  p.setPen(darkColor)    if (shadow)        switch (segmentNo) {        case 0 :            ppt = pt;            LIGHT;            LINETO(segLen - 1,0);            DARK;            LINETO(segLen - width - 1,width);            LINETO(width,width);            LINETO(0,0);            break;        case 1 :            pt += QPoint(0,1);            ppt = pt;            LIGHT;            LINETO(width,width);            DARK;            LINETO(width,segLen - width/2 - 2);            LINETO(0,segLen - 2);            LIGHT;            LINETO(0,0);            break;        case 2 :            pt += QPoint(segLen - 1 , 1);            ppt = pt;            DARK;            LINETO(0,segLen - 2);            LINETO(-width,segLen - width/2 - 2);            LIGHT;            LINETO(-width,width);            LINETO(0,0);            break;        case 3 :            pt += QPoint(0 , segLen);            ppt = pt;            LIGHT;            LINETO(width,-width/2);            LINETO(segLen - width - 1,-width/2);            LINETO(segLen - 1,0);            DARK;            if (width & 1) {            // adjust for integer division error                LINETO(segLen - width - 3,width/2 + 1);                LINETO(width + 2,width/2 + 1);            } else {                LINETO(segLen - width - 1,width/2);                LINETO(width,width/2);            }            LINETO(0,0);            break;        case 4 :            pt += QPoint(0 , segLen + 1);            ppt = pt;            LIGHT;            LINETO(width,width/2);            DARK;            LINETO(width,segLen - width - 2);            LINETO(0,segLen - 2);            LIGHT;            LINETO(0,0);            break;        case 5 :            pt += QPoint(segLen - 1 , segLen + 1);            ppt = pt;            DARK;            LINETO(0,segLen - 2);            LINETO(-width,segLen - width - 2);            LIGHT;            LINETO(-width,width/2);            LINETO(0,0);            break;        case 6 :            pt += QPoint(0 , segLen*2);            ppt = pt;            LIGHT;            LINETO(width,-width);            LINETO(segLen - width - 1,-width);            LINETO(segLen - 1,0);            DARK;            LINETO(0,0);            break;        case 7 :            if (smallPoint)   // if smallpoint place'.' between other digits                pt += QPoint(segLen + width/2 , segLen*2);            else                pt += QPoint(segLen/2 , segLen*2);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        case 8 :            pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        case 9 :            pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width);            ppt = pt;            DARK;            LINETO(width,0);            LINETO(width,-width);            LIGHT;            LINETO(0,-width);            LINETO(0,0);            break;        default :            qWarning("QLCDNumber::drawSegment: (%s) Illegal segment id: %d\n",                     q->objectName().toLocal8Bit().constData(), segmentNo);        }#undef LINETO#undef LIGHT#undef DARK}/*!    \property QLCDNumber::segmentStyle    \brief the style of the LCDNumber    \table    \header \i Style \i Result    \row \i \c Outline         \i Produces raised segments filled with the background color            (this is the default).    \row \i \c Filled         \i Produces raised segments filled with the foreground color.    \row \i \c Flat         \i Produces flat segments filled with the foreground color.    \endtable    \c Outline and \c Filled will additionally use    QPalette::light() and QPalette::dark() for shadow effects.*/void QLCDNumber::setSegmentStyle(SegmentStyle s){    Q_D(QLCDNumber);    d->fill = (s == Flat || s == Filled);    d->shadow = (s == Outline || s == Filled);    update();}QLCDNumber::SegmentStyle QLCDNumber::segmentStyle() const{    Q_D(const QLCDNumber);    Q_ASSERT(d->fill || d->shadow);    if (!d->fill && d->shadow)        return Outline;    if (d->fill && d->shadow)        return Filled;    return Flat;}/*!\reimp*/QSize QLCDNumber::sizeHint() const{    return QSize(10 + 9 * (numDigits() + (smallDecimalPoint() ? 0 : 1)), 23);}/*! \reimp */bool QLCDNumber::event(QEvent *e){    return QFrame::event(e);}/*!    \fn void QLCDNumber::setMargin(int margin)    Sets the width of the margin around the contents of the widget to \a margin.        Use QWidget::setContentsMargins() instead.    \sa margin(), QWidget::setContentsMargins()*//*!    \fn int QLCDNumber::margin() const    Returns the with of the the margin around the contents of the widget.        Use QWidget::getContentsMargins() instead.    \sa setMargin(), QWidget::getContentsMargins()*/#endif // QT_NO_LCDNUMBER

⌨️ 快捷键说明

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