Exemplo n.º 1
0
static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option,
                                     const QRect &rect, Qt::Orientation orientation,
                                     const QWidget *widget)
{
    QColor borderColor = option->palette.background().color().darker(178);
    QColor alphaCornerColor;
    if (widget) {
        // ### backgroundrole/foregroundrole should be part of the style option
        alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
    } else {
        alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
    }
	
    QImage handle(qt_simple_toolbarhandle);
    handle.setColor(1, alphaCornerColor.rgba());
    handle.setColor(2, mergedColors(alphaCornerColor, option->palette.base().color()).rgba());
    handle.setColor(3, option->palette.base().color().rgba());
	
    const int spacing = 2;
	
    if (orientation == Qt::Vertical) {
        int nchunks = rect.width() / (handle.width() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle);
    } else {
        int nchunks = rect.height() / (handle.height() + spacing);
        for (int i = 0; i < nchunks; ++i)
            painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle);
    }
}
Exemplo n.º 2
0
void StyleHelper::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect)
{
    QString key;
    key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(),
                                             clipRect.height(), StyleHelper::baseColor().rgb());;
    QPixmap pixmap;
    QPainter *p = painter;
    QRect rect = clipRect;
    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        pixmap = QPixmap(clipRect.size());
        p = new QPainter(&pixmap);
        rect = QRect(0, 0, clipRect.width(), clipRect.height());
    }

    QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft());
    QColor menuColor = mergedColors(StyleHelper::baseColor(), QColor(240, 240, 240), 25);
    grad.setColorAt(0, menuColor.lighter(112));
    grad.setColorAt(1, menuColor);
    p->fillRect(rect, grad);

    if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
        painter->drawPixmap(clipRect.topLeft(), pixmap);
        p->end();
        delete p;
        QPixmapCache::insert(key, pixmap);
    }
}
Exemplo n.º 3
0
void CustomStyle::drawHoverRect(QPainter *painter, const QRect &rect) const
{
/*    double h = r.height();
double h2 = r.height() / 2.0;
QPainterPath path;
path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height());
path.addEllipse(r.x(), r.y(), h, h);
path.addEllipse(r.x() + r.width() - h, r.y(), h, h);
path.setFillRule(Qt::WindingFill);
painter->setPen(Qt::NoPen);
painter->setBrush(QColor(191, 215, 191));
painter->setRenderHint(QPainter::Antialiasing);
    painter->drawPath(path);*/
    int radius = qMin(rect.width(), rect.height()) / 2;
    int diam = 2 * radius;

    int x1, y1, x2, y2;
    rect.getCoords(&x1, &y1, &x2, &y2);
    QPainterPath path;
    QColor color;
    color = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
    QPen pen(color, 4);
    painter->setPen(pen);
    path.moveTo(x2, y1 + radius);
    path.arcTo(QRect(x2 - diam, y1, diam, diam), 0.0, +90.0);
    path.lineTo(x1 + radius, y1);
    path.arcTo(QRect(x1, y1, diam, diam), 90.0, +90.0);
    path.lineTo(x1, y2 - radius);
    path.arcTo(QRect(x1, y2 - diam, diam, diam), 180.0, +90.0);
    path.lineTo(x1 + radius, y2);
    path.arcTo(QRect(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0);
    painter->drawPath(path);
}
Exemplo n.º 4
0
void CustomStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                    QPainter *painter, const QWidget *widget) const
{
   QColor borderColor;
   QPen oldPen(2);
   QPainterPath path;
   int x1, x2, y1, y2;

   switch (control) {

#ifndef QT_NO_COMBOBOX
   case CC_ComboBox:
       if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {

           painter->save();
//            backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole());
           bool isEnabled = (comboBox->state & State_Enabled);
           bool focus = isEnabled && (comboBox->state & State_HasFocus);

           oldPen = painter->pen();
           painter->setPen(Qt::black);
           if(!focus)
               borderColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
           else
               borderColor = QColor(255, 255, 0);
           oldPen.setColor(borderColor);
           painter->setPen(oldPen);
//			painter->setBrush(Qt::transparent);

           painter->fillRect(option->rect, option->palette.brush(QPalette::Base));
           option->rect.getCoords(&x1, &y1, &x2, &y2);
           path.moveTo(x1+0, y1);
           path.lineTo(x2-0, y1);
           path.lineTo(x2, y1+0);
           path.lineTo(x2, y2-0);
           path.lineTo(x2-0, y2);
           path.lineTo(x1+0, y2);
           path.lineTo(x1, y2-0);
           path.lineTo(x1, y1+0);
           path.lineTo(x1+0, y1);
           painter->drawPath(path);

           QRect downArrowRect = subControlRect(CC_ComboBox, comboBox,
               SC_ComboBoxArrow, widget);

           if (comboBox->subControls & SC_ComboBoxArrow) {
               QStyleOptionButton buttonOption;

               buttonOption.QStyleOption::operator=(*comboBox);
               QRect arrowRect(option->rect.right() - downArrowRect.width(),
                   option->rect.top(),
                   downArrowRect.width(),
                   downArrowRect.height());

               buttonOption.rect = arrowRect;
               if(!focus)
                   buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
               else
                   buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
//				drawControl(CE_PushButtonBevel, &buttonOption, painter, widget);

               buttonOption.rect = downArrowRect;
               if(!focus)
                   buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
               else
                   buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
//				drawControl(CE_PushButtonBevel, &buttonOption, painter, widget);

               QImage imgLeftArrow(qt_scrollbar_button_arrow_left);
               QImage imgRightArrow(qt_scrollbar_button_arrow_right);
               //downArrow.setColor(1, comboBox->palette.foreground().color().rgba());
//				int offset = comboBox->direction == Qt::RightToLeft ? -2 : 2;
               if(!focus)
               {
                   imgRightArrow.setColor(1,qRgb(48,255,0));
                   imgLeftArrow.setColor(1,qRgb(48,255,0));
               }
               else
               {
                   imgRightArrow.setColor(1,qRgb(255,255,0));
                   imgLeftArrow.setColor(1,qRgb(255,255,0));
               }
               painter->drawImage(downArrowRect.center().x() - imgLeftArrow.width() / 2,// + offset,
                   downArrowRect.center().y() - imgLeftArrow.height() / 2 + 1, imgLeftArrow);
               painter->drawImage(arrowRect.center().x() - imgRightArrow.width() / 2,// + offset,
                   arrowRect.center().y() - imgRightArrow.height() / 2 + 1, imgRightArrow);


           }

           QRect editFieldRect = subControlRect(CC_ComboBox, comboBox,
               SC_ComboBoxEditField, widget);
           if (comboBox->subControls & SC_ComboBoxEditField) {
// 				QStyleOptionButton buttonOption;
// 				buttonOption.rect = editFieldRect;
// 				if(!focus)
// 					buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver);
// 				else
// 					buttonOption.state = comboBox->state & (State_Enabled | State_MouseOver | State_HasFocus);
// 				drawPrimitive(PE_FrameLineEdit, &buttonOption, painter, widget);

           }
           painter->restore();
       }
       break;
#endif // QT_NO_COMBOBOX
   default:
       QWindowsStyle::drawComplexControl(control, option, painter, widget);
       break;
   }
}
Exemplo n.º 5
0
void CustomStyle::drawControl(ControlElement element,
                             const QStyleOption *option,
                             QPainter *painter,
                             const QWidget *widget) const
{
   QColor backgroundColor;
   QPen oldPen(2);
   QPainterPath path;
   int x1, x2, y1, y2;

   switch (element)
   {
   case CE_PushButtonBevel:

       if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option))
       {
           bool hover = (button->state & State_HasFocus);
// 			if (hover)
// 				drawHoverRect(painter, widget->rect());

           QColor slightlyOpaqueBlack(0, 0, 0, 63);
           int x, y, width, height;

           option->rect.getRect(&x, &y, &width, &height);

           QPainterPath roundRect = roundRectPath(option->rect);
//			int radius = qMin(width, height) / 2;

           QBrush brush;
           bool darker;

           const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option);
           if (buttonOption && (buttonOption->features & QStyleOptionButton::Flat))
           {
               brush = option->palette.mid();
               darker = (option->state & (State_Sunken | State_On));
           }
           else
           {
               if (option->state & (State_Sunken | State_On))
               {
                   brush = option->palette.mid();
                   darker = !(option->state & State_Sunken);
               }
               else
               {
                   brush = option->palette.button();
                   darker = false;
               }
           }

           painter->save();
           painter->setRenderHint(QPainter::Antialiasing, true);
           painter->fillPath(roundRect, brush); // Draw Image ...
           if (darker)
               painter->fillPath(roundRect, slightlyOpaqueBlack);

           QBrush normalBrush(QBrush(QColor(145, 116, 255)));
           painter->fillPath(roundRect, normalBrush);



           if (!hover)
           {
               QBrush highlightBrush(QBrush(QColor(142, 163, 133)));
               painter->fillPath(roundRect, highlightBrush);
           /*	x1 =x;x2 =x+width;y1=y;y2=y+height;
               QLineF line1(x1+2, y1, x2-2, y1);
               QLineF line2(x2-2,y1,x2,y2+2);
               QLineF line3(x2,y2+2,x2,y2-2);
               QLineF line4(x2,y2-2,x2-2,y2);
               QLineF line5(x2-2,y2,x1,y2-2);
               QLineF line6(x1,y2-2,x1,y2-2);
               QLineF line7(x1,y2-2,x1,y1+2);
               QLineF line8(x1,y1+2,x1+2,y1);
               QPen linePen(QPen(QColor(92,135,75)));
               painter->drawLine(line1);
               painter->drawLine(line8);
               painter->drawLine(line7);

               linePen.setColor(QColor(34,63,22));
               painter->drawLine(line8);
               painter->drawLine(line8);
               painter->drawLine(line8);
               painter->drawLine(line8);
               painter->drawLine(line8);*/

           }
       /*	else
           {
               QPen myPen(QPen(QColor(145, 116, 255)));
               painter->setPen(myPen);
               painter->drawRect(option->rect);
               QBrush normalBrush1(QBrush(QColor(145, 116, 255)));
               painter->fillRect(option->rect, normalBrush1);
           }*/
           /*
           int penWidth;
           if (radius < 10)
           penWidth = 1;
           else if (radius < 20)
           penWidth = 1;
           else
           penWidth = 1;

           int delta = (option->state & State_MouseOver) ? 64 : 0;
           QColor semiTransparentWhite(255, 255, 255, 127 + delta);
           QColor semiTransparentBlack(0, 0, 0, 127 - delta);
           QColor semiFocusTop(255, 0, 0, 127 + delta);
           QColor semiFocusDown(200, 0, 100, 127 - delta);
           QPen topPen((hover ? semiFocusTop:semiTransparentWhite), penWidth);
           QPen bottomPen((hover ? semiFocusDown:semiTransparentBlack), penWidth);

           if (option->state & (State_Sunken | State_On))
           qSwap(topPen, bottomPen);
           int x1 = x;
           int x2 = x + radius;
           int x3 = x + width - radius;
           int x4 = x + width;

           if (option->direction == Qt::RightToLeft) {
           qSwap(x1, x4);
           qSwap(x2, x3);
           }

           QPolygon topHalf;
           topHalf << QPoint(x1, y)
           << QPoint(x4, y)
           << QPoint(x3, y + radius)
           << QPoint(x2, y + height - radius)
           << QPoint(x1, y + height);

           painter->setClipPath(roundRect);
           painter->setClipRegion(topHalf, Qt::IntersectClip);
           painter->setPen(topPen);
           painter->drawPath(roundRect); // Border draw ...

           QPolygon bottomHalf = topHalf;
           bottomHalf[0] = QPoint(x4, y + height);

           painter->setClipPath(roundRect);
           painter->setClipRegion(bottomHalf, Qt::IntersectClip);
           painter->setPen(bottomPen);
           painter->drawPath(roundRect);

           painter->setPen(option->palette.foreground().color());
           painter->setClipping(false);
           painter->drawPath(roundRect);
           */
           painter->restore();
       }

       break;
   case CE_PushButtonLabel:
       {
           QStyleOptionButton myButtonOption;
           const QStyleOptionButton *buttonOption =
               qstyleoption_cast<const QStyleOptionButton *>(option);
           if (buttonOption) {
               myButtonOption = *buttonOption;
               if (myButtonOption.palette.currentColorGroup()
                   != QPalette::Disabled) {
                       if (myButtonOption.state & (State_Sunken | State_On)) {
                           myButtonOption.palette.setBrush(QPalette::ButtonText,
                               myButtonOption.palette.brightText());
                       }
               }
           }
           QWindowsStyle::drawControl(element, &myButtonOption, painter, widget);
       }
       break;
#ifndef QT_NO_PROGRESSBAR
   case CE_ProgressBarGroove:
       if (/*const QStyleOptionProgressBar *bar = */qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
           painter->save();
//          backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole());
           oldPen = painter->pen();
           painter->setPen(Qt::black);
           backgroundColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
           oldPen.setColor(backgroundColor);
           painter->setPen(oldPen);

           option->rect.getCoords(&x1, &y1, &x2, &y2);
           path.moveTo(x1, y1);
           path.lineTo(x2, y1);
           path.lineTo(x2, y2);
           path.lineTo(x1, y2);
           path.lineTo(x1, y1);
           painter->drawPath(path);
           painter->restore();

       }
       break;
#endif
   default:
       QWindowsStyle::drawControl(element, option, painter, widget);
   }
}
Exemplo n.º 6
0
void CustomStyle::drawPrimitive(PrimitiveElement element,
                                       const QStyleOption *option,
                                       QPainter *painter,
                                       const QWidget *widget) const
{
//	QColor borderColor = option->palette.background().color().dark(178);
//        QColor alphaCornerColor;
       QColor backgroundColor;
       QPen oldPen(2);
       QPainterPath path;

       int x1, x2, y1, y2;

    switch (element) {
   case PE_Frame:
       if (widget && widget->parent()) {
           painter->save();
           backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole());
           oldPen = painter->pen();
           painter->setPen(Qt::black);
           backgroundColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
           oldPen.setColor(backgroundColor);
           painter->setPen(oldPen);

           option->rect.getCoords(&x1, &y1, &x2, &y2);
/*            painter->drawPoint(option->rect.topLeft());
           painter->drawPoint(option->rect.topRight());
           painter->drawPoint(option->rect.bottomLeft());
           painter->drawPoint(option->rect.bottomRight());*/
           path.moveTo(x1, y1);
           path.lineTo(x2, y1);
           path.lineTo(x2, y2);
           path.lineTo(x1, y2);
           path.lineTo(x1, y1);
           painter->drawPath(path);
           painter->restore();
//            painter->setPen(oldPen);
//            alphaCornerColor = mergedColors(backgroundColor, borderColor);
       }

       break;

#ifndef QT_NO_LINEEDIT
//    case PE_FrameLineEdit:
//	if (widget) {
//    	    alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
//	} else {
//    	    alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
//	}
/*        if (widget && widget->parent()) {
           painter->save();
           backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole());
           oldPen = painter->pen();
           painter->setPen(Qt::black);
           backgroundColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6));
           oldPen.setColor(backgroundColor);
           painter->setPen(oldPen);

           option->rect.getCoords(&x1, &y1, &x2, &y2);*/
/*            painter->drawPoint(option->rect.topLeft());
           painter->drawPoint(option->rect.topRight());
           painter->drawPoint(option->rect.bottomLeft());
           painter->drawPoint(option->rect.bottomRight());*/
/*			path.moveTo(x1, y1);
           path.lineTo(x2, y1);
           path.lineTo(x2, y2);
           path.lineTo(x1, y2);
           path.lineTo(x1, y1);
           painter->drawPath(path);
           painter->restore();
//            painter->setPen(oldPen);
//            alphaCornerColor = mergedColors(backgroundColor, borderColor);
       }
   break;*/
       // fall through
#endif // QT_NO_LINEEDIT

    case PE_FrameFocusRect:
/*        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
           bool hover = (button->state & State_Enabled);
           painter->save();
           if (hover)
           drawHoverRect(painter, widget->rect());
           painter->restore();
   }*/
/*        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
           QColor bg = fropt->backgroundColor;
           QPen oldPen = painter->pen();
           if (bg.isValid()) {
               int h, s, v;
               bg.getHsv(&h, &s, &v);
               if (v >= 128)
                   painter->setPen(Qt::white);
               else
                   painter->setPen(Qt::white);
           } else {
               painter->setPen(option->palette.foreground().color());
           }
           QRect focusRect = option->rect.adjusted(1, 1, -1, -1);
           painter->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
           painter->setPen(oldPen);
       }
*/       break;
/*     case PE_PanelButtonCommand:
        {
            int delta = (option->state & State_MouseOver) ? 64 : 0;
            QColor slightlyOpaqueBlack(0, 0, 0, 63);
            QColor semiTransparentWhite(255, 255, 255, 127 + delta);
            QColor semiTransparentBlack(0, 0, 0, 127 - delta);

            int x, y, width, height;
            option->rect.getRect(&x, &y, &width, &height);

            QPainterPath roundRect = roundRectPath(option->rect);
            int radius = qMin(width, height) / 2;

            QBrush brush;
            bool darker;

            const QStyleOptionButton *buttonOption =
                    qstyleoption_cast<const QStyleOptionButton *>(option);
            if (buttonOption
                    && (buttonOption->features & QStyleOptionButton::Flat)) {
                brush = option->palette.background();
                darker = (option->state & (State_Sunken | State_On));
            } else {
                if (option->state & (State_Sunken | State_On)) {
                    brush = option->palette.mid();
                    darker = !(option->state & State_Sunken);
                } else {
                    brush = option->palette.button();
                    darker = false;
                }
            }

            painter->save();
            painter->setRenderHint(QPainter::Antialiasing, true);
            painter->fillPath(roundRect, brush); // Draw Image ...
            if (darker)
                painter->fillPath(roundRect, slightlyOpaqueBlack);

            int penWidth;
            if (radius < 10)
                penWidth = 3;
            else if (radius < 20)
                penWidth = 5;
            else
                penWidth = 7;

            QPen topPen(semiTransparentWhite, penWidth);
            QPen bottomPen(semiTransparentBlack, penWidth);

            if (option->state & (State_Sunken | State_On))
                qSwap(topPen, bottomPen);
            int x1 = x;
            int x2 = x + radius;
            int x3 = x + width - radius;
            int x4 = x + width;

            if (option->direction == Qt::RightToLeft) {
                qSwap(x1, x4);
                qSwap(x2, x3);
            }

            QPolygon topHalf;
            topHalf << QPoint(x1, y)
                    << QPoint(x4, y)
                    << QPoint(x3, y + radius)
                    << QPoint(x2, y + height - radius)
                    << QPoint(x1, y + height);

            painter->setClipPath(roundRect);
            painter->setClipRegion(topHalf, Qt::IntersectClip);
            painter->setPen(topPen);
            painter->drawPath(roundRect); // Boader draw ...

            QPolygon bottomHalf = topHalf;
            bottomHalf[0] = QPoint(x4, y + height);

            painter->setClipPath(roundRect);
            painter->setClipRegion(bottomHalf, Qt::IntersectClip);
            painter->setPen(bottomPen);
            painter->drawPath(roundRect);

            painter->setPen(option->palette.foreground().color());
            painter->setClipping(false);
            painter->drawPath(roundRect);

            painter->restore();
        }
        break;
*/
    default:
        QWindowsStyle::drawPrimitive(element, option, painter, widget);
    }
}
Exemplo n.º 7
0
void CCustomStyle::drawMenuItem(const QStyleOption *option, QPainter *painter, const QWidget *widget ) const
{
    painter->save();

    if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
    {
        // 先绘制一层背景(否则在透明情况下, 会直接透过去);
        painter->setPen(colItemBg);
        painter->setBrush(colItemBg);
        painter->drawRect(option->rect);

        if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
        {
            int w = 0;

            if (!menuItem->text.isEmpty())
            {
                // 绘制分隔符文字
                painter->setFont(menuItem->font);
                proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
                                      menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
                                      QPalette::Text);
                w = menuItem->fontMetrics.width(menuItem->text) + 5;
            }
            painter->setPen(colSeparator);
            bool reverse = menuItem->direction == Qt::RightToLeft;
            painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
                              menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
            painter->restore();
            return;
        }

        bool selected = menuItem->state & State_Selected && menuItem->state & State_Enabled;

        if (selected)
        {
            QRect r = option->rect;
            painter->fillRect(r, colItemHighlight);
        }

        bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
        bool checked = menuItem->checked;
        bool sunken = menuItem->state & State_Sunken;
        bool enabled = menuItem->state & State_Enabled;

        bool ignoreCheckMark = false;
        int checkcol = qMax(menuItem->maxIconWidth, 20);

        if (qobject_cast<const QComboBox*>(widget))
        {
            ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate
        }

        if (!ignoreCheckMark)
        {
            // Check
            QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 14, 14);
            checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
            if (checkable)
            {
                if (menuItem->checkType & QStyleOptionMenuItem::Exclusive)
                {
                    // Radio button 未实现
                    if (checked || sunken)
                    {
                        /*	painter->setRenderHint(QPainter::Antialiasing);
                        painter->setPen(Qt::NoPen);

                        QPalette::ColorRole textRole = !enabled ? QPalette::Text:
                            selected ? QPalette::HighlightedText : QPalette::ButtonText;
                        painter->setBrush(option->palette.brush( option->palette.currentColorGroup(), textRole));
                        painter->drawEllipse(checkRect.adjusted(4, 4, -4, -4));
                        */
                    }
                }
                else
                {
                    // Check box
                    if (menuItem->icon.isNull())
                    {
                        QStyleOptionButton box;
                        box.QStyleOption::operator=(*option);
                        box.rect = checkRect;

                        if (checked)
                        {
                            box.state |= State_On;
                        }

                        proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, painter, widget);
                    }
                }
            }
        }
        else
        {
            //ignore checkmark
            if (menuItem->icon.isNull())
            {
                checkcol = 0;
            }
            else
            {
                checkcol = menuItem->maxIconWidth;
            }
        }

        // Text and icon, ripped from windows style
        bool dis = !(menuItem->state & State_Enabled);
        bool act = menuItem->state & State_Selected;
        const QStyleOption *opt = option;
        const QStyleOptionMenuItem *menuitem = menuItem;

        QPainter *p = painter;
        QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + 4, 
			                          menuitem->rect.y(), checkcol, menuitem->rect.height()));

        if (!menuItem->icon.isNull())
        {
            QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;

            if (act && !dis)
            {
                mode = QIcon::Active;
            }

            QPixmap pixmap;

            int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
            QSize iconSize(smallIconSize, smallIconSize);

            if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget))
            {
                iconSize = combo->iconSize();
            }

            if (checked)
            {
                pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On);
            }
            else
            {
                pixmap = menuItem->icon.pixmap(iconSize, mode);
            }

            int pixw = pixmap.width();
            int pixh = pixmap.height();

            QRect pmr(0, 0, pixw, pixh);
            pmr.moveCenter(vCheckRect.center());
            painter->setPen(colText);//menuItem->palette.text().color()

            if (checkable && checked)
            {
                QStyleOption opt = *option;
                if (act)
                {
                    QColor activeColor = mergedColors(
                                colItemBg, //option->palette.background().color(),
                                colItemHighlight // option->palette.highlight().color());
                                );
                    opt.palette.setBrush(QPalette::Button, activeColor);
                }
                opt.state |= State_Sunken;
                opt.rect = vCheckRect;
                proxy()->drawPrimitive(PE_PanelButtonCommand, &opt, painter, widget);
            }

            painter->drawPixmap(pmr.topLeft(), pixmap);
        }

        if (selected)
        {
            painter->setPen(colText);//menuItem->palette.highlightedText().color()
        }
        else
        {
            painter->setPen(colText); //menuItem->palette.text().color()
        }

        int x, y, w, h;
        menuitem->rect.getRect(&x, &y, &w, &h);
        int tab = menuitem->tabWidth;
        QColor discol;

        if (dis)
        {
            discol = colDisText; //menuitem->palette.text().color()
            p->setPen(discol);
        }

        int xm = windowsItemFrame + checkcol + windowsItemHMargin + 2;
        int xpos = menuitem->rect.x() + xm; //modify text position(if we don't add xm, we can make text left-aligned)

        QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
        QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
        QString s = menuitem->text;

        if (!s.isEmpty())
        {
            // draw text
            p->save();
            int t = s.indexOf(QLatin1Char('\t'));
            int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;

            if (!QProxyStyle::styleHint(SH_UnderlineShortcut, menuitem, widget))
            {
                text_flags |= Qt::TextHideMnemonic;
            }

            text_flags |= Qt::AlignLeft;

            if (t >= 0)
            {
                QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
                                                 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));

                if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget))
                {
                    p->setPen(colText);//menuitem->palette.light().color()
                    p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, s.mid(t + 1));
                    p->setPen(discol);
                }

                p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
                s = s.left(t);
            }

            QFont font = menuitem->font;
            // font may not have any "hard" flags set. We override
            // the point size so that when it is resolved against the device, this font will win.
            // This is mainly to handle cases where someone sets the font on the window
            // and then the combo inherits it and passes it onward. At that point the resolve mask
            // is very, very weak. This makes it stonger.
            font.setPointSizeF(QFontInfo(menuItem->font).pointSizeF());

            if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
            {
                font.setBold(true);
            }

            p->setFont(font);

            if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, option, widget))
            {
                p->setPen(menuitem->palette.light().color());
                p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, s.left(t));
                p->setPen(discol);
            }

            p->drawText(vTextRect, text_flags, s.left(t));
            p->restore();
        }

        // Arrow 绘制子菜单指示符
        if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu)
        {
            // draw sub menu arrow
            int dim = (menuItem->rect.height() - 4) / 2;
            PrimitiveElement arrow;
            arrow = option->direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
            int xpos = menuItem->rect.left() + menuItem->rect.width() - 3 - dim;
            QRect  vSubMenuRect = visualRect(option->direction, menuItem->rect,
                                             QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
            QStyleOptionMenuItem newMI = *menuItem;
            newMI.rect = vSubMenuRect;
            newMI.state = !enabled ? State_None : State_Enabled;

            if (selected)
            {
                newMI.palette.setColor(QPalette::ButtonText,// 此处futionstyle 有误, QPalette::Foreground改为ButtonText
                                       colIndicatorArrow);  //newMI.palette.highlightedText().color()
            }
            else
            {
                newMI.palette.setColor(QPalette::ButtonText, colIndicatorArrow);
            }

            proxy()->drawPrimitive(arrow, &newMI, painter, widget);
        }
    }

    painter->restore();
}