diff options
Diffstat (limited to 'src/widgets/styles/qstylesheetstyle.cpp')
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 025e1e0044..c1f498cd0c 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3706,17 +3706,6 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q bool dis = !(opt->state & QStyle::State_Enabled), act = opt->state & QStyle::State_Selected; - int checkableOffset = 0; - if (checkable) { - QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); - QStyleOptionMenuItem newMi = mi; - newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - // align with icons if there are some - checkableOffset = std::max(m->maxIconWidth, newMi.rect.width()); - if (subSubRule.hasDrawable() || checked) - drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); - } - if (!mi.icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) @@ -3733,24 +3722,28 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } QRect iconRect = positionRect(w, subRule, iconRule, PseudoElement_MenuIcon, opt->rect, opt->direction); if (opt->direction == Qt::LeftToRight) - iconRect.moveLeft(iconRect.left() + checkableOffset); + iconRect.moveLeft(iconRect.left()); else - iconRect.moveRight(iconRect.right() - checkableOffset); + iconRect.moveRight(iconRect.right()); iconRule.drawRule(p, iconRect); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(iconRect.center()); p->drawPixmap(pmr.topLeft(), pixmap); + } else if (checkable) { + QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); + if (subSubRule.hasDrawable() || checked) { + QStyleOptionMenuItem newMi = mi; + if (!dis) + newMi.state |= State_Enabled; + if (act) + newMi.state |= State_On; + newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); + drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); + } } - int textOffset = 0; - // padding overrules it all - if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { - textOffset = checkableOffset; - if (!m->icon.isNull() || !checkable) - textOffset += m->maxIconWidth; - } QRect textRect = subRule.contentsRect(opt->rect); - textRect.setLeft(textRect.left() + textOffset); + textRect.setLeft(textRect.left() + m->maxIconWidth); textRect.setWidth(textRect.width() - mi.tabWidth); const QRect vTextRect = visualRect(opt->direction, m->rect, textRect); @@ -5106,27 +5099,20 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op if (mi->text.contains(QLatin1Char('\t'))) sz.rwidth() += 12; //as in QCommonStyle bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; - int checkableWidth = 0; - if (checkable) { + if (!mi->icon.isNull()) { + const int pmSmall = pixelMetric(PM_SmallIconSize); + const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall)); + sz.rwidth() += pmSize.width() + 4; + } else if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - checkableWidth = std::max(mi->maxIconWidth, checkmarkRect.width()); - } - if (!mi->icon.isNull()) { - QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize)); - sz.rwidth() += pixmap.width(); + sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4; } if (subRule.hasFont) { QFontMetrics fm(subRule.font); const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); sz = sz.expandedTo(r.size()); } - // padding overrules it all - if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { - sz.rwidth() += checkableWidth; - if (!mi->icon.isNull() || !checkable) - sz.rwidth() += mi->maxIconWidth; - } return subRule.boxSize(subRule.adjustSize(sz)); } } |