Gui: fix action title processing
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
# include <QMenuBar>
|
||||
#endif
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Tools.h>
|
||||
@@ -214,16 +216,30 @@ void Action::setToolTip(const QString & s, const QString & title)
|
||||
this));
|
||||
}
|
||||
|
||||
static QString & actionTitle(QString & title)
|
||||
{
|
||||
// Deal with QAction title mnemonic
|
||||
static QRegularExpression re(QStringLiteral("&(.)"));
|
||||
title.replace(re, QStringLiteral("\\1"));
|
||||
// Trim line ending punctuation
|
||||
static QRegularExpression rePunct(QStringLiteral("[[:punct:]]+$"));
|
||||
title.replace(rePunct, QString());
|
||||
return title;
|
||||
}
|
||||
|
||||
static inline QString actionTitle(const QString &title)
|
||||
{
|
||||
QString text(title);
|
||||
return actionTitle(text);
|
||||
}
|
||||
|
||||
QString Action::createToolTip(QString _tooltip,
|
||||
const QString & title,
|
||||
const QFont &font,
|
||||
const QString &sc,
|
||||
Action *act)
|
||||
{
|
||||
QString text = title;
|
||||
text.remove(QLatin1Char('&'));;
|
||||
while(text.size() && text[text.size()-1].isPunct())
|
||||
text.resize(text.size()-1);
|
||||
QString text = actionTitle(title);
|
||||
|
||||
if (text.isEmpty())
|
||||
return _tooltip;
|
||||
@@ -1406,14 +1422,10 @@ public:
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
if (info.text.isEmpty()) {
|
||||
#if QT_VERSION>=QT_VERSION_CHECK(5,2,0)
|
||||
info.text = QString::fromLatin1("%2 (%1)").arg(
|
||||
info.text = QStringLiteral("%2 (%1)").arg(
|
||||
QString::fromLatin1(info.cmd->getName()),
|
||||
qApp->translate(info.cmd->className(), info.cmd->getMenuText()));
|
||||
#else
|
||||
info.text = qApp->translate(info.cmd->className(), info.cmd->getMenuText());
|
||||
#endif
|
||||
info.text.replace(QLatin1Char('&'), QString());
|
||||
actionTitle(info.text);
|
||||
if (info.text.isEmpty())
|
||||
info.text = QString::fromLatin1(info.cmd->getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user