summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qstylesheetstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/styles/qstylesheetstyle.cpp')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 94509f621e..8340ac086a 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -1041,7 +1041,7 @@ QRenderRule::QRenderRule(const QVector<Declaration> &declarations, const QObject
if (const QWidget *widget = qobject_cast<const QWidget *>(object)) {
QStyleSheetStyle *style = const_cast<QStyleSheetStyle *>(globalStyleSheetStyle);
if (!style)
- style = qobject_cast<QStyleSheetStyle *>(widget->style());
+ style = qt_styleSheet(widget->style());
if (style)
fixupBorder(style->nativeFrameWidth(widget));
}
@@ -1502,7 +1502,7 @@ public:
return className;
} else if (name == QLatin1String("style")) {
QWidget *w = qobject_cast<QWidget *>(obj);
- QStyleSheetStyle *proxy = w ? qobject_cast<QStyleSheetStyle *>(w->style()) : 0;
+ QStyleSheetStyle *proxy = w ? qt_styleSheet(w->style()) : 0;
if (proxy) {
QString styleName = QString::fromLatin1(proxy->baseStyle()->metaObject()->className());
cache[name] = styleName;
@@ -2734,7 +2734,7 @@ QStyle *QStyleSheetStyle::baseStyle() const
{
if (base)
return base;
- if (QStyleSheetStyle *me = qobject_cast<QStyleSheetStyle *>(QApplication::style()))
+ if (QStyleSheetStyle *me = qt_styleSheet(QApplication::style()))
return me->base;
return QApplication::style();
}
@@ -3673,6 +3673,17 @@ 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);
+ checkableOffset = newMi.rect.width();
+ if (subSubRule.hasDrawable() || checked)
+ drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
+ }
+
+ int iconOffset = 0;
if (!mi.icon.isNull()) {
QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
if (act && !dis)
@@ -3692,20 +3703,22 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
iconRule.geo->height = pixh;
}
QRect iconRect = positionRect(w, subRule, iconRule, PseudoElement_MenuIcon, opt->rect, opt->direction);
+ if (opt->direction == Qt::LeftToRight)
+ iconRect.moveLeft(iconRect.left() + checkableOffset);
+ else
+ iconRect.moveRight(iconRect.right() - checkableOffset);
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;
- newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction);
- drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w);
- }
+ iconOffset = iconRule.geo->width;
}
QRect textRect = subRule.contentsRect(opt->rect);
+ if (opt->direction == Qt::LeftToRight)
+ textRect.setLeft(textRect.left() + checkableOffset + iconOffset);
+ else
+ textRect.setRight(textRect.right() - checkableOffset - iconOffset);
textRect.setWidth(textRect.width() - mi.tabWidth);
QStringRef s(&mi.text);
p->setPen(mi.palette.buttonText().color());
@@ -5051,6 +5064,16 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
int width = csz.width();
if (mi->text.contains(QLatin1Char('\t')))
width += 12; //as in QCommonStyle
+ bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable;
+ if (checkable) {
+ QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark);
+ QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction);
+ width += checkmarkRect.width();
+ }
+ if (!mi->icon.isNull()) {
+ QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize));
+ width += pixmap.width();
+ }
return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
}
}