QMacStyle: Bring back submenu indicator

This one fell off the truck while we were removing
HITheme calls. We add it back by simply rendering a
BLACK RIGHT-POINTING TRIANGLE character.

We also fix smaller issues, such as not displaying
any shortcut related to a submenu action — this is
simply not a thing. The spacing between the menu
item's text and the submenu indicator has also been
slightly improved.

Change-Id: I6c768a5506a5eb9528b0dd76acd52b561266d67b
Task-number: QTBUG-64405
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
This commit is contained in:
Gabriel de Dietrich 2017-12-20 10:34:56 -08:00 committed by Liang Qi
parent ad2df19c2a
commit 117148c381

View File

@ -4187,7 +4187,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
break;
}
const int tabwidth = mi->tabWidth;
const int maxpmw = mi->maxIconWidth;
const bool enabled = mi->state & State_Enabled;
@ -4245,21 +4244,37 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
}
QString s = mi->text;
if (!s.isEmpty()) {
int t = s.indexOf(QLatin1Char('\t'));
int text_flags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextHideMnemonic
| Qt::TextSingleLine | Qt::AlignAbsolute;
int yPos = mi->rect.y();
if (widgetSize == QStyleHelper::SizeMini)
yPos += 1;
p->save();
if (t >= 0) {
p->setFont(qt_app_fonts_hash()->value("QMenuItem", p->font()));
int xp = mi->rect.right() - tabwidth - macRightBorder - macItemHMargin - macItemFrame + 1;
p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags, s.mid(t + 1));
s = s.left(t);
}
const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
| Qt::TextSingleLine | Qt::AlignAbsolute;
int yPos = mi->rect.y();
if (widgetSize == QStyleHelper::SizeMini)
yPos += 1;
const bool isSubMenu = mi->menuItemType == QStyleOptionMenuItem::SubMenu;
const int tabwidth = isSubMenu ? 9 : mi->tabWidth;
QString rightMarginText;
if (isSubMenu)
rightMarginText = QStringLiteral("\u25b6\ufe0e"); // U+25B6 U+FE0E: BLACK RIGHT-POINTING TRIANGLE
// If present, save and remove embedded shorcut from text
const int tabIndex = s.indexOf(QLatin1Char('\t'));
if (tabIndex >= 0) {
if (!isSubMenu) // ... but ignore it if it's a submenu.
rightMarginText = s.mid(tabIndex + 1);
s = s.left(tabIndex);
}
p->save();
if (!rightMarginText.isEmpty()) {
p->setFont(qt_app_fonts_hash()->value("QMenuItem", p->font()));
int xp = mi->rect.right() - tabwidth - macRightBorder + 2;
if (!isSubMenu)
xp -= macItemHMargin + macItemFrame + 3; // Adjust for shortcut
p->drawText(xp, yPos, tabwidth, mi->rect.height(), text_flags | Qt::AlignRight, rightMarginText);
}
if (!s.isEmpty()) {
const int xm = macItemFrame + maxpmw + macItemHMargin;
QFont myFont = mi->font;
// myFont may not have any "hard" flags set. We override
@ -4270,9 +4285,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
p->setFont(myFont);
p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
mi->rect.height(), text_flags ^ Qt::AlignRight, s);
p->restore();
mi->rect.height(), text_flags, s);
}
p->restore();
}
break;
case CE_MenuBarItem:
@ -6364,8 +6379,8 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
}
if (mi->text.contains(QLatin1Char('\t')))
w += 12;
if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
w += 20;
else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
w += 35; // Not quite exactly as it seems to depend on other factors
if (maxpmw)
w += maxpmw + 6;
// add space for a check. All items have place for a check too.