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

📄 qdrawutil.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    QPolygon a;                                // arrow polygon    switch (type) {    case Qt::UpArrow:        a.setPoints(7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2);        break;    case Qt::DownArrow:        a.setPoints(7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2);        break;    case Qt::LeftArrow:        a.setPoints(7, 1,-3, 1,3, 0,-2, 0,2, -1,-1, -1,1, -2,0);        break;    case Qt::RightArrow:        a.setPoints(7, -1,-3, -1,3, 0,-2, 0,2, 1,-1, 1,1, 2,0);        break;    default:        break;    }    if (a.isEmpty())        return;    if (down) {        x++;        y++;    }    QPen savePen = p->pen();                        // save current pen    if (down)        p->setBrushOrigin(p->brushOrigin() + QPoint(1,1));    p->fillRect(x, y, w, h, pal.brush(QPalette::Button));    if (down)        p->setBrushOrigin(p->brushOrigin() - QPoint(1,1));    if (enabled) {        a.translate(x+w/2, y+h/2);        p->setPen(pal.foreground().color());        p->drawLine(a.at(0), a.at(1));        p->drawLine(a.at(2), a.at(2));        p->drawPoint(a[6]);    } else {        a.translate(x+w/2+1, y+h/2+1);        p->setPen(pal.light().color());        p->drawLine(a.at(0), a.at(1));        p->drawLine(a.at(2), a.at(2));        p->drawPoint(a[6]);        a.translate(-1, -1);        p->setPen(pal.mid().color());        p->drawLine(a.at(0), a.at(1));        p->drawLine(a.at(2), a.at(2));        p->drawPoint(a[6]);    }    p->setPen(savePen);                        // restore pen}#endif // QT3_SUPPORT#if defined(Q_CC_MSVC)#pragma warning(disable: 4244)#endif#ifdef QT3_SUPPORT#ifndef QT_NO_STYLE_MOTIF// motif arrows look the same whether they are used or not// is this correct?static void qDrawMotifArrow(QPainter *p, Qt::ArrowType type, bool down,                             int x, int y, int w, int h,                             const QPalette &pal, bool){    QPolygon bFill;                                // fill polygon    QPolygon bTop;                                // top shadow.    QPolygon bBot;                                // bottom shadow.    QPolygon bLeft;                                // left shadow.    QMatrix        matrix;                                // xform matrix    bool vertical = type == Qt::UpArrow || type == Qt::DownArrow;    bool horizontal = !vertical;    int         dim = w < h ? w : h;    int         colspec = 0x0000;                        // color specification array    if (dim < 2)                                // too small arrow        return;    if (dim > 3) {        if (dim > 6)            bFill.resize(dim & 1 ? 3 : 4);        bTop.resize((dim/2)*2);        bBot.resize(dim & 1 ? dim + 1 : dim);        bLeft.resize(dim > 4 ? 4 : 2);        bLeft.putPoints(0, 2, 0,0, 0,dim-1);        if (dim > 4)            bLeft.putPoints(2, 2, 1,2, 1,dim-3);        bTop.putPoints(0, 4, 1,0, 1,1, 2,1, 3,1);        bBot.putPoints(0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2);        for(int i=0; i<dim/2-2 ; i++) {            bTop.putPoints(i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i);            bBot.putPoints(i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i);        }        if (dim & 1)                                // odd number size: extra line            bBot.putPoints(dim-1, 2, dim-3,dim/2, dim-1,dim/2);        if (dim > 6) {                        // dim>6: must fill interior            bFill.putPoints(0, 2, 1,dim-3, 1,2);            if (dim & 1)                        // if size is an odd number                bFill.setPoint(2, dim - 3, dim / 2);            else                bFill.putPoints(2, 2, dim-4,dim/2-1, dim-4,dim/2);        }    }    else {        if (dim == 3) {                        // 3x3 arrow pattern            bLeft.setPoints(4, 0,0, 0,2, 1,1, 1,1);            bTop .setPoints(2, 1,0, 1,0);            bBot .setPoints(2, 1,2, 2,1);        }        else {                                        // 2x2 arrow pattern            bLeft.setPoints(2, 0,0, 0,1);            bTop .setPoints(2, 1,0, 1,0);            bBot .setPoints(2, 1,1, 1,1);        }    }    if (type == Qt::UpArrow || type == Qt::LeftArrow) {        matrix.translate(x, y);        if (vertical) {            matrix.translate(0, h - 1);            matrix.rotate(-90);        } else {            matrix.translate(w - 1, h - 1);            matrix.rotate(180);        }        if (down)            colspec = horizontal ? 0x2334 : 0x2343;        else            colspec = horizontal ? 0x1443 : 0x1434;    }    else if (type == Qt::DownArrow || type == Qt::RightArrow) {        matrix.translate(x, y);        if (vertical) {            matrix.translate(w-1, 0);            matrix.rotate(90);        }        if (down)            colspec = horizontal ? 0x2443 : 0x2434;        else            colspec = horizontal ? 0x1334 : 0x1343;    }    const QColor *cols[5];    cols[0] = 0;    cols[1] = &pal.button().color();    cols[2] = &pal.mid().color();    cols[3] = &pal.light().color();    cols[4] = &pal.dark().color();#define CMID        *cols[(colspec>>12) & 0xf]#define CLEFT        *cols[(colspec>>8) & 0xf]#define CTOP        *cols[(colspec>>4) & 0xf]#define CBOT        *cols[colspec & 0xf]    QPen     savePen   = p->pen();                // save current pen    QBrush   saveBrush = p->brush();                // save current brush    QMatrix wxm = p->matrix();    QPen     pen(Qt::NoPen);    const QBrush &brush = pal.brush(QPalette::Button);    p->setPen(pen);    p->setBrush(brush);    p->setMatrix(matrix, true);                // set transformation matrix    p->drawPolygon(bFill);                        // fill arrow    p->setBrush(Qt::NoBrush);                        // don't fill    p->setPen(CLEFT);    p->drawLines(bLeft);    p->setPen(CTOP);    p->drawLines(bTop);    p->setPen(CBOT);    p->drawLines(bBot);    p->setMatrix(wxm);    p->setBrush(saveBrush);                        // restore brush    p->setPen(savePen);                        // restore pen#undef CMID#undef CLEFT#undef CTOP#undef CBOT}#endif // QT_NO_STYLE_MOTIFQRect qItemRect(QPainter *p, Qt::GUIStyle gs,                int x, int y, int w, int h,                int flags,                bool enabled,                const QPixmap *pixmap,                const QString& text, int len){    QRect result;    if (pixmap) {        if ((flags & Qt::AlignVCenter) == Qt::AlignVCenter)            y += h/2 - pixmap->height()/2;        else if ((flags & Qt::AlignBottom) == Qt::AlignBottom)            y += h - pixmap->height();        if ((flags & Qt::AlignRight) == Qt::AlignRight)            x += w - pixmap->width();        else if ((flags & Qt::AlignHCenter) == Qt::AlignHCenter)            x += w/2 - pixmap->width()/2;        else if ((flags & Qt::AlignLeft) != Qt::AlignLeft && QApplication::isRightToLeft())            x += w - pixmap->width();        result = QRect(x, y, pixmap->width(), pixmap->height());    } else if (!text.isNull() && p) {        result = p->boundingRect(QRect(x, y, w, h), flags, text.left(len));        if (gs == Qt::WindowsStyle && !enabled) {            result.setWidth(result.width()+1);            result.setHeight(result.height()+1);        }    } else {        result = QRect(x, y, w, h);    }    return result;}void qDrawArrow(QPainter *p, Qt::ArrowType type, Qt::GUIStyle style, bool down,                 int x, int y, int w, int h,                 const QPalette &pal, bool enabled){    switch (style) {        case Qt::WindowsStyle:            qDrawWinArrow(p, type, down, x, y, w, h, pal, enabled);            break;#ifndef QT_NO_STYLE_MOTIF        case Qt::MotifStyle:            qDrawMotifArrow(p, type, down, x, y, w, h, pal, enabled);            break;#endif        default:            qWarning("qDrawArrow: Requested GUI style not supported");    }}void qDrawItem(QPainter *p, Qt::GUIStyle gs,                int x, int y, int w, int h,                int flags,                const QPalette &pal, bool enabled,                const QPixmap *pixmap,                const QString& text, int len , const QColor* penColor){    p->setPen(penColor?*penColor:pal.foreground().color());    if (pixmap) {        QPixmap  pm(*pixmap);        bool clip = (flags & Qt::TextDontClip) == 0;        if (clip) {            if (pm.width() < w && pm.height() < h)                clip = false;            else                p->setClipRect(x, y, w, h);        }        if ((flags & Qt::AlignVCenter) == Qt::AlignVCenter)            y += h/2 - pm.height()/2;        else if ((flags & Qt::AlignBottom) == Qt::AlignBottom)            y += h - pm.height();        if ((flags & Qt::AlignRight) == Qt::AlignRight)            x += w - pm.width();        else if ((flags & Qt::AlignHCenter) == Qt::AlignHCenter)            x += w/2 - pm.width()/2;        else if (((flags & Qt::AlignLeft) != Qt::AlignLeft) && QApplication::isRightToLeft()) // Qt::AlignAuto && rightToLeft            x += w - pm.width();        if (!enabled) {            if (pm.hasAlphaChannel()) {                        // pixmap with a mask                pm = pm.mask();            } else if (pm.depth() == 1) {        // monochrome pixmap, no mask                ;#ifndef QT_NO_IMAGE_HEURISTIC_MASK            } else {                                // color pixmap, no mask                QString k;                k.sprintf("$qt-drawitem-%x", pm.serialNumber());                if (!QPixmapCache::find(k, pm)) {                    pm = pm.createHeuristicMask();                    pm.setMask((QBitmap&)pm);                    QPixmapCache::insert(k, pm);                }#endif            }            if (gs == Qt::WindowsStyle) {                p->setPen(pal.light().color());                p->drawPixmap(x+1, y+1, pm);                p->setPen(pal.text().color());            }        }        p->drawPixmap(x, y, pm);        if (clip)            p->setClipping(false);    } else if (!text.isNull()) {        if (gs == Qt::WindowsStyle && !enabled) {            p->setPen(pal.light().color());            p->drawText(x+1, y+1, w, h, flags, text.left(len));            p->setPen(pal.text().color());        }        p->drawText(x, y, w, h, flags, text.left(len));    }}#endif

⌨️ 快捷键说明

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