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

📄 qmotifstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    QPolygon r(a.size());    for (int i = 0; i < (int)a.size(); i++) {        switch (n) {        case 1: r.setPoint(i,-a[i].y(),a[i].x()); break;        case 2: r.setPoint(i,-a[i].x(),-a[i].y()); break;        case 3: r.setPoint(i,a[i].y(),-a[i].x()); break;        }    }    a = r;}/*!  \reimp*/void QMotifStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,                                const QWidget *w) const{    switch(pe) {    case PE_Q3CheckListExclusiveIndicator:        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {            if (lv->items.isEmpty())                return;            if (lv->state & State_Enabled)                p->setPen(QPen(opt->palette.text().color()));            else                p->setPen(QPen(lv->palette.color(QPalette::Disabled, QPalette::Text)));            QPolygon a;            int cx = opt->rect.width()/2 - 1;            int cy = opt->rect.height()/2;            int e = opt->rect.width()/2 - 1;            for (int i = 0; i < 3; i++) { //penWidth 2 doesn't quite work                a.setPoints(4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e);                p->drawPolygon(a);                e--;            }            if (opt->state & State_On) {                if (lv->state & State_Enabled)                    p->setPen(QPen(opt->palette.text().color()));                else                    p->setPen(QPen(lv->palette.color(QPalette::Disabled,                                                     QPalette::Text)));                QBrush saveBrush = p->brush();                p->setBrush(opt->palette.text());                e = e - 2;                a.setPoints(4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e);                p->drawPolygon(a);                p->setBrush(saveBrush);            }        }        break;    case PE_FrameTabWidget:    case PE_FrameWindow:        qDrawShadePanel(p, opt->rect, opt->palette, QStyle::State_None, pixelMetric(PM_DefaultFrameWidth));        break;    case PE_FrameFocusRect:        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {            if ((fropt->state & State_HasFocus) && focus && focus->isVisible()                    && !(fropt->state & QStyle::State_Item))                break;            QCommonStyle::drawPrimitive(pe, opt, p, w);        }        break;    case PE_IndicatorToolBarHandle: {        p->save();        p->translate(opt->rect.x(), opt->rect.y());        QColor dark(opt->palette.dark().color());        QColor light(opt->palette.light().color());        int i;        if (opt->state & State_Horizontal) {            int h = opt->rect.height();            if (h > 6) {                if (opt->state & State_On)                    p->fillRect(1, 1, 8, h - 2, opt->palette.highlight());                QPolygon a(2 * ((h-6)/3));                int y = 3 + (h%3)/2;                p->setPen(dark);                p->drawLine(8, 1, 8, h-2);                for (i=0; 2*i < a.size(); ++i) {                    a.setPoint(2*i, 5, y+1+3*i);                    a.setPoint(2*i+1, 2, y+2+3*i);                }                p->drawPoints(a);                p->setPen(light);                p->drawLine(9, 1, 9, h-2);                for (i=0; 2*i < a.size(); i++) {                    a.setPoint(2*i, 4, y+3*i);                    a.setPoint(2*i+1, 1, y+1+3*i);                }                p->drawPoints(a);                // if (drawBorder) {                // p->setPen(QPen(Qt::darkGray));                // p->drawLine(0, opt->rect.height() - 1,                // tbExtent, opt->rect.height() - 1);                // }            }        } else {            int w = opt->rect.width();            if (w > 6) {                if (opt->state & State_On)                    p->fillRect(1, 1, w - 2, 9, opt->palette.highlight());                QPolygon a(2 * ((w-6)/3));                int x = 3 + (w%3)/2;                p->setPen(dark);                p->drawLine(1, 8, w-2, 8);                for (i=0; 2*i < a.size(); ++i) {                    a.setPoint(2*i, x+1+3*i, 6);                    a.setPoint(2*i+1, x+2+3*i, 3);                }                p->drawPoints(a);                p->setPen(light);                p->drawLine(1, 9, w-2, 9);                for (i=0; 2*i < a.size(); ++i) {                    a.setPoint(2*i, x+3*i, 5);                    a.setPoint(2*i+1, x+1+3*i, 2);                }                p->drawPoints(a);                // if (drawBorder) {                // p->setPen(QPen(Qt::darkGray));                // p->drawLine(opt->rect.width() - 1, 0,                // opt->rect.width() - 1, tbExtent);                // }            }        }        p->restore();        break; }    case PE_PanelButtonCommand:    case PE_PanelButtonBevel:    case PE_PanelButtonTool: {        QBrush fill;        if (opt->state & State_Sunken)            fill = opt->palette.brush(QPalette::Mid);        else if ((opt->state & State_On) && (opt->state & State_Enabled))            fill = QBrush(opt->palette.mid().color(), Qt::Dense4Pattern);        else            fill = opt->palette.brush(QPalette::Button);         if ((opt->state & State_Enabled) || !(opt->state & State_AutoRaise))             qDrawShadePanel(p, opt->rect, opt->palette, bool(opt->state & (State_Sunken | State_On)),                             pixelMetric(PM_DefaultFrameWidth), &fill);        break; }    case PE_IndicatorCheckBox: {        bool on = opt->state & State_On;        bool down = opt->state & State_Sunken;        bool showUp = !(down ^ on);        QBrush fill = opt->palette.brush((showUp || opt->state & State_NoChange) ?QPalette::Button : QPalette::Mid);        if (opt->state & State_NoChange) {            qDrawPlainRect(p, opt->rect, opt->palette.text().color(),                           1, &fill);            p->drawLine(opt->rect.x() + opt->rect.width() - 1, opt->rect.y(),                        opt->rect.x(), opt->rect.y() + opt->rect.height() - 1);        } else {            qDrawShadePanel(p, opt->rect, opt->palette, !showUp,                            pixelMetric(PM_DefaultFrameWidth), &fill);        }        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));        break; }    case PE_IndicatorRadioButton: {#define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)        int inner_pts[] = { // used for filling diamond            2,opt->rect.height()/2,            opt->rect.width()/2,2,            opt->rect.width()-3,opt->rect.height()/2,            opt->rect.width()/2,opt->rect.height()-3        };        int top_pts[] = { // top (^) of diamond            0,opt->rect.height()/2,            opt->rect.width()/2,0,            opt->rect.width()-2,opt->rect.height()/2-1,            opt->rect.width()-3,opt->rect.height()/2-1,            opt->rect.width()/2,1,            1,opt->rect.height()/2,            2,opt->rect.height()/2,            opt->rect.width()/2,2,            opt->rect.width()-4,opt->rect.height()/2-1        };        int bottom_pts[] = { // bottom (v) of diamond            1,opt->rect.height()/2+1,            opt->rect.width()/2,opt->rect.height()-1,            opt->rect.width()-1,opt->rect.height()/2,            opt->rect.width()-2,opt->rect.height()/2,            opt->rect.width()/2,opt->rect.height()-2,            2,opt->rect.height()/2+1,            3,opt->rect.height()/2+1,            opt->rect.width()/2,opt->rect.height()-3,            opt->rect.width()-3,opt->rect.height()/2        };        bool on = opt->state & State_On;        bool down = opt->state & State_Sunken;        bool showUp = !(down ^ on);        QPen oldPen = p->pen();        QBrush oldBrush = p->brush();        QPolygon a(INTARRLEN(inner_pts), inner_pts);        p->setPen(Qt::NoPen);        p->setBrush(opt->palette.brush(showUp ? QPalette::Button : QPalette::Mid));        a.translate(opt->rect.x(), opt->rect.y());        p->drawPolygon(a);        p->setPen(showUp ? opt->palette.light().color() : opt->palette.dark().color());        p->setBrush(Qt::NoBrush);        a.setPoints(INTARRLEN(top_pts), top_pts);        a.translate(opt->rect.x(), opt->rect.y());        p->drawPolyline(a);        p->setPen(showUp ? opt->palette.dark().color() : opt->palette.light().color());        a.setPoints(INTARRLEN(bottom_pts), bottom_pts);        a.translate(opt->rect.x(), opt->rect.y());        p->drawPolyline(a);        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));        p->setPen(oldPen);        p->setBrush(oldBrush);        break; }    case PE_IndicatorSpinUp:    case PE_IndicatorSpinPlus:    case PE_IndicatorSpinDown:    case PE_IndicatorSpinMinus:    case PE_IndicatorArrowUp:    case PE_IndicatorArrowDown:    case PE_IndicatorArrowRight:    case PE_IndicatorArrowLeft: {        QRect rect = opt->rect;        QPolygon bFill;        QPolygon bTop;        QPolygon bBot;        QPolygon bLeft;        if (pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinUp)            pe = PE_IndicatorArrowUp;        else if (pe == PE_IndicatorSpinMinus || pe == PE_IndicatorSpinDown)            pe = PE_IndicatorArrowDown;        bool vertical = pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown;        bool horizontal = !vertical;        int dim = rect.width() < rect.height() ? rect.width() : rect.height();        int colspec = 0x0000;        if (!(opt->state & State_Enabled))            dim -= 2;        if(dim < 2)           break;        // adjust size and center (to fix rotation below)        if (rect.width() > dim) {            rect.setX(rect.x() + ((rect.width() - dim) / 2));            rect.setWidth(dim);        }        if (rect.height() > dim) {            rect.setY(rect.y() + ((rect.height() - dim) / 2));            rect.setHeight(dim);        }        if (dim > 3) {            if (pixelMetric(PM_DefaultFrameWidth) < 2) { // thin style                bFill.resize( dim & 1 ? 3 : 4 );                bTop.resize( 2 );                bBot.resize( 2 );                bLeft.resize( 2 );                bLeft.putPoints( 0, 2, 0, 0, 0, dim-1 );                bTop.putPoints( 0, 2, 1, 0, dim-1, dim/2 );                bBot.putPoints( 0, 2, 1, dim-1, dim-1, dim/2 );                if ( dim > 6 ) {                        // dim>6: must fill interior                    bFill.putPoints( 0, 2, 0, dim-1, 0, 0 );                    if ( dim & 1 )                      // if size is an odd number                        bFill.setPoint( 2, dim - 1, dim / 2 );                    else                        bFill.putPoints( 2, 2, dim-1, dim/2-1, dim-1, dim/2 );                }            } else {                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);            }        }        // We use rot() and translate() as it is more efficient that        // matrix transformations on the painter, and because it still        // works with QT_NO_TRANSFORMATIONS defined.

⌨️ 快捷键说明

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