void StereoCam::placeRight() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixf(pmr().getPtr()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixf(vm().getPtr()); setupRight(); }
/*! \reimp */ void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &g, SFlags flags, const QStyleOption& opt ) { switch ( element ) { case CE_PopupMenuItem: { if (! widget || opt.isDefault()) break; const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = !(flags & Style_Enabled); bool checkable = popupmenu->isCheckable(); bool act = flags & Style_Active; int x, y, w, h; r.rect( &x, &y, &w, &h ); QColorGroup itemg = g; if ( checkable ) maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks int checkcol = maxpmw; if ( mi && mi->isSeparator() ) { // draw separator p->setPen( g.dark() ); p->drawLine( x, y, x+w, y ); p->setPen( g.light() ); p->drawLine( x, y+1, x+w, y+1 ); return; } QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x, y, w, h, fill); if ( !mi ) return; if ( mi->isChecked() ) { if ( act && !dis ) { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Button ) ); } else { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); } } else if ( !act ) { p->fillRect(x, y, checkcol , h, g.brush( QColorGroup::Button )); } if ( mi->iconSet() ) { // draw iconset QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; if (act && !dis ) mode = QIconSet::Active; QPixmap pixmap; if ( checkable && mi->isChecked() ) pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On ); else pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); int pixw = pixmap.width(); int pixh = pixmap.height(); if ( act && !dis ) { if ( !mi->isChecked() ) qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); } QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); } else if ( checkable ) { // just "checking"... int mw = checkcol + motifItemFrame; int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { SFlags cflags = Style_Default; if (! dis) cflags |= Style_Enabled; if (act) cflags |= Style_On; drawPrimitive( PE_CheckMark, p, QRect(x + motifItemFrame + 2, y + motifItemFrame, mw, mh), itemg, cflags, opt ); } } p->setPen( act ? g.highlightedText() : g.buttonText() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = motifItemFrame + checkcol + motifItemHMargin; if ( mi->custom() ) { int m = motifItemVMargin; p->save(); if ( dis && !act ) { p->setPen( g.light() ); mi->custom()->paint( p, itemg, act, !dis, x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); p->setPen( discol ); } mi->custom()->paint( p, itemg, act, !dis, x+xm, y+m, w-xm-tab+1, h-2*m ); p->restore(); } QString s = mi->text(); if ( !s.isNull() ) { // draw text int t = s.find( '\t' ); int m = motifItemVMargin; const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; if ( t >= 0 ) { // draw tab text if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); p->setPen( discol ); } p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); s = s.left( t ); } if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); p->setPen( discol ); } p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); } else if ( mi->pixmap() ) { // draw pixmap QPixmap *pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } if ( mi->popup() ) { // draw sub menu arrow int dim = (h-2*motifItemFrame) / 2; if ( act ) { if ( !dis ) discol = white; QColorGroup g2( discol, g.highlight(), white, white, dis ? discol : white, discol, white ); drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g2, Style_Enabled); } else { drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim), g, !dis ? Style_Enabled : Style_Default); } } } break; default: QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt ); break; } }
void QGIPiece::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget ) { if(0) { // for me this only works in GL mode QPen linePen(Qt::red, 4, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin); paintLinesToChildren( this, painter, linePen ); } /** Using a pixmap cache for the rendering saves a lot of repainting, but it causes rounding errors because QPixmap is int-based. The borders don't show up properly (off-by-one errors) at certain sizes and scales. */ QRectF bounds( this->boundingRect().normalized() ); #define AMSG if(0) qDebug() << "QGIPixmap::paint():" if( #if QGIPiece_USE_PIXCACHE impl->pixcache.isNull() #else 1 #endif ) { ++impl->countRepaint; QPainter * cp = 0; #if QGIPiece_USE_PIXCACHE QPixmap captcha( bounds.size().toSize() ); AMSG << "bounds="<<bounds<<", pixcache.size ="<<captcha.size(); captcha.fill( Qt::transparent ); QPainter _cp( &captcha ); cp = &_cp; #else cp = painter; #endif if( 1 ) // Background color { QColor col = impl->pen.color(); if( col.isValid() ) { cp->fillRect( bounds, col ); } } const qreal bs = impl->penB.widthF(); qreal xl = bs / 2.0; if( ! impl->pixmap.isNull() ) // Draw pixmap { // Weird: if i use impl->pixmap.rect() i get (0.5,0.5,W,H) QRectF pmr( QPointF(0,0), impl->pixmap.size() ); //QRectF pmr( impl->pixmap.rect() ); AMSG << "drawPixmap("<<pmr<<"...)"; cp->drawPixmap(pmr, impl->pixmap, impl->pixmap.rect() ); } if( bs && impl->penB.color().isValid() ) // Draw border { QRectF br( bounds ); br.adjust( xl, xl, -xl, -xl ); #if QGIPiece_USE_PIXCACHE if( (int(bs+0.49) % 2) == 1 ) { // kludge to avoid some off-by-one unsightlyness qreal fudge = 0.5; br.adjust( -fudge, -fudge, -fudge, -fudge ); } #endif cp->save(); cp->setPen( impl->penB ); AMSG << "drawRect("<<br<<"...) bs ="<<bs<<", xl ="<<xl;; cp->drawRect( br ); cp->restore(); } #if QGIPiece_USE_PIXCACHE impl->pixcache = captcha; #endif } else { ++impl->countPaintCache; if(0) AMSG << "using cached image."; } #if QGIPiece_USE_PIXCACHE painter->drawPixmap( bounds, impl->pixcache, bounds ); #endif // Let parent draw selection borders and such: this->QGraphicsPixmapItem::paint(painter,option,widget); #undef AMSG }
void FreshStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, const QPalette& pal, bool act, bool enabled, int x, int y, int w, int h) { #ifndef QT_NO_MENUDATA const QColorGroup & g = pal.active(); bool dis = !enabled; QColorGroup itemg = dis ? pal.disabled() : pal.active(); if ( checkable ) maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks int checkcol = maxpmw; if ( mi && mi->isSeparator() ) { // draw separator p->setPen( g.dark() ); p->drawLine( x, y, x+w, y ); p->setPen( g.light() ); p->drawLine( x, y+1, x+w, y+1 ); return; } QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x, y, w, h, fill); if ( !mi ) return; if ( mi->isChecked() ) { if ( act && !dis ) { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Button ) ); } else { qDrawShadePanel( p, x, y, checkcol, h, g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); } } else if ( !act ) { p->fillRect(x, y, checkcol , h, g.brush( QColorGroup::Button )); } if ( mi->iconSet() ) { // draw iconset QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; if (act && !dis ) mode = QIconSet::Active; QPixmap pixmap; if ( mode == QIconSet::Disabled ) pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode ); else pixmap = mi->iconSet()->pixmap(); int pixw = pixmap.width(); int pixh = pixmap.height(); if ( act && !dis ) { if ( !mi->isChecked() ) qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); } QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( cr.center() ); p->setPen( itemg.text() ); p->drawPixmap( pmr.topLeft(), pixmap ); QBrush fill = act? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Button ); p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); } else if ( checkable ) { // just "checking"... int mw = checkcol + motifItemFrame; int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { drawCheckMark( p, x + motifItemFrame + 2, y+motifItemFrame, mw, mh, itemg, act, dis ); } } p->setPen( act ? g.highlightedText() : g.buttonText() ); QColor discol; if ( dis ) { discol = itemg.text(); p->setPen( discol ); } int xm = motifItemFrame + checkcol + motifItemHMargin; if ( mi->custom() ) { int m = motifItemVMargin; p->save(); if ( dis && !act ) { p->setPen( g.light() ); mi->custom()->paint( p, itemg, act, enabled, x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); p->setPen( discol ); } mi->custom()->paint( p, itemg, act, enabled, x+xm, y+m, w-xm-tab+1, h-2*m ); p->restore(); } QString s = mi->text(); if ( !s.isNull() ) { // draw text int t = s.find( '\t' ); int m = motifItemVMargin; const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; if ( t >= 0 ) { // draw tab text if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); p->setPen( discol ); } p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); } if ( dis && !act ) { p->setPen( g.light() ); p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); p->setPen( discol ); } p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); } else if ( mi->pixmap() ) { // draw pixmap QPixmap *pixmap = mi->pixmap(); if ( pixmap->depth() == 1 ) p->setBackgroundMode( OpaqueMode ); p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); if ( pixmap->depth() == 1 ) p->setBackgroundMode( TransparentMode ); } if ( mi->popup() ) { // draw sub menu arrow int dim = (h-2*motifItemFrame) / 2; if ( act ) { if ( !dis ) discol = white; QColorGroup g2( discol, g.highlight(), white, white, dis ? discol : white, discol, white ); drawArrow( p, RightArrow, FALSE, x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, dim, dim, g2, TRUE ); } else { drawArrow( p, RightArrow, FALSE, x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, dim, dim, g, mi->isEnabled() ); } } #endif }
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(); }
void MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { #if !defined(Q_OS_OSX) case CE_Splitter: break; #endif case CE_MenuBarItem:{ const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option); const bool act = somi->state & (State_Sunken | State_Selected); QPalette palette = QApplication::palette(); QBrush brush; if (act) { painter->setPen(palette.highlight().color()); brush = palette.highlight().color().lighter(); painter->setBrush(brush); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); } else { brush = palette.window(); painter->fillRect(option->rect, palette.window()); } uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, somi, widget)) { alignment |= Qt::TextHideMnemonic; } if (somi->state.testFlag(QStyle::State_Enabled)) { if (SettingsPrivate::instance()->isCustomTextColorOverriden()) { if (act) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } else { if (qAbs(palette.text().color().value() - brush.color().value()) < 128) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } } /*else if (act) { painter->setPen(palette.mid().color()); }*/ painter->drawText(option->rect, alignment, somi->text); break; } case CE_MenuItem: if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance()); qreal checkcol = 25 / app->devicePixelRatio(); qreal gutterWidth = 3 / app->devicePixelRatio(); QRect rect = option->rect; //draw vertical menu line if (option->direction == Qt::LeftToRight) checkcol += rect.x(); int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); int tab = menuitem->tabWidth; bool dis = !(menuitem->state & State_Enabled); bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable ? menuitem->checked : false; bool act = menuitem->state & State_Selected; QPalette palette = QApplication::palette(); if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) { int yoff = y - 1 + h / 2; qreal separatorSize = 6 / app->devicePixelRatio(); QPoint p1 = QPoint(x + checkcol, yoff); QPoint p2 = QPoint(x + w + separatorSize, yoff); painter->save(); painter->fillRect(menuitem->rect, palette.window()); painter->setPen(palette.mid().color()); painter->drawLine(p1, p2); painter->restore(); return; } QString s = menuitem->text; QBrush fill; if (act) { fill = palette.highlight().color().lighter(); } else { fill = palette.window(); } painter->fillRect(menuitem->rect, fill); QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height())); if (checked) { QStyleOptionMenuItem newMi = *menuitem; int windowsItemFrame = 2; newMi.rect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame, checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2 * windowsItemFrame) ); painter->setRenderHint(QPainter::Antialiasing, true); proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, painter, widget); painter->setRenderHint(QPainter::Antialiasing, false); } if (!menuitem->icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) { mode = QIcon::Active; } QPixmap pixmap; if (checked) { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On); } else { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode); } const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); painter->setPen(palette.text().color()); painter->drawPixmap(pmr.topLeft(), pixmap); } //painter->setPen(palette.buttonText().color()); QColor textColor = palette.text().color(); if (dis) { textColor = palette.mid().color(); painter->setPen(textColor); } else if (act && SettingsPrivate::instance()->isCustomTextColorOverriden()) { textColor = palette.highlightedText().color(); painter->setPen(textColor); } int xm = checkcol + 2 + (gutterWidth - menuitem->rect.x()) - 1; int xpos = menuitem->rect.x() + xm; /// int windowsItemVMargin = 3, windowsRightBorder = 3; QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect); if (!s.isEmpty()) { // draw text painter->save(); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget)) { text_flags |= Qt::TextHideMnemonic; } text_flags |= Qt::AlignLeft; if (t >= 0) { QRect vShortcutRect = visualRect(option->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); painter->drawText(vShortcutRect, text_flags, s.mid(t + 1)); s = s.left(t); } QFont font = menuitem->font; if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) { font.setBold(true); } painter->setFont(font); painter->setPen(textColor); painter->drawText(vTextRect, text_flags, s.left(t)); painter->restore(); } if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow int dim = (h - 2 * 5) / 2; PrimitiveElement arrow; arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; xpos = x + w - 2 - 2 - dim; QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); QStyleOptionMenuItem newMI = *menuitem; newMI.rect = vSubMenuRect; newMI.state = dis ? State_None : State_Enabled; proxy()->drawPrimitive(arrow, &newMI, painter, widget); } } break; case CE_MenuBarEmptyArea:{ painter->fillRect(option->rect, QApplication::palette().window()); break; } default: QProxyStyle::drawControl(element, option, painter, widget); } }