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:
parent
ad2df19c2a
commit
117148c381
@ -4187,7 +4187,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int tabwidth = mi->tabWidth;
|
|
||||||
const int maxpmw = mi->maxIconWidth;
|
const int maxpmw = mi->maxIconWidth;
|
||||||
const bool enabled = mi->state & State_Enabled;
|
const bool enabled = mi->state & State_Enabled;
|
||||||
|
|
||||||
@ -4245,21 +4244,37 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString s = mi->text;
|
QString s = mi->text;
|
||||||
if (!s.isEmpty()) {
|
const auto text_flags = Qt::AlignVCenter | Qt::TextHideMnemonic
|
||||||
int t = s.indexOf(QLatin1Char('\t'));
|
| Qt::TextSingleLine | Qt::AlignAbsolute;
|
||||||
int text_flags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextHideMnemonic
|
int yPos = mi->rect.y();
|
||||||
| Qt::TextSingleLine | Qt::AlignAbsolute;
|
if (widgetSize == QStyleHelper::SizeMini)
|
||||||
int yPos = mi->rect.y();
|
yPos += 1;
|
||||||
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 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;
|
const int xm = macItemFrame + maxpmw + macItemHMargin;
|
||||||
QFont myFont = mi->font;
|
QFont myFont = mi->font;
|
||||||
// myFont may not have any "hard" flags set. We override
|
// 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());
|
myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF());
|
||||||
p->setFont(myFont);
|
p->setFont(myFont);
|
||||||
p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
|
p->drawText(xpos, yPos, mi->rect.width() - xm - tabwidth + 1,
|
||||||
mi->rect.height(), text_flags ^ Qt::AlignRight, s);
|
mi->rect.height(), text_flags, s);
|
||||||
p->restore();
|
|
||||||
}
|
}
|
||||||
|
p->restore();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CE_MenuBarItem:
|
case CE_MenuBarItem:
|
||||||
@ -6364,8 +6379,8 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
|
|||||||
}
|
}
|
||||||
if (mi->text.contains(QLatin1Char('\t')))
|
if (mi->text.contains(QLatin1Char('\t')))
|
||||||
w += 12;
|
w += 12;
|
||||||
if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
|
else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
|
||||||
w += 20;
|
w += 35; // Not quite exactly as it seems to depend on other factors
|
||||||
if (maxpmw)
|
if (maxpmw)
|
||||||
w += maxpmw + 6;
|
w += maxpmw + 6;
|
||||||
// add space for a check. All items have place for a check too.
|
// add space for a check. All items have place for a check too.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user