Gui: Improved tooltips

Improved tooltips showing:
- the command name as an <h3> title,
- the tooltip text,
- the (What's this).

the title is build from translated getMenuText() and can contain a "&" character. This commit search and remove the "&" characters. It should be better not to use the "&" character in the command name, but if it is necessary it has to be done with "&&".

ref forum discussion: https://forum.freecadweb.org/viewtopic.php?f=34&t=58747
.
This commit is contained in:
carlopav
2021-08-19 10:24:00 +02:00
parent ea9a4ef93f
commit b5a5a6cd70

View File

@@ -856,8 +856,22 @@ void Command::applyCommandData(const char* context, Action* action)
{
action->setText(QCoreApplication::translate(
context, getMenuText()));
action->setToolTip(QCoreApplication::translate(
context, getToolTipText()));
// build the tooltip
QString tooltip;
tooltip.append(QString::fromLatin1("<h3>"));
tooltip.append(QCoreApplication::translate(
context, getMenuText()));
tooltip.append(QString::fromLatin1("</h3>"));
QRegularExpression re(QString::fromLatin1("([^&])&([^&])"));
tooltip.replace(re, QString::fromLatin1("\\1\\2"));
tooltip.replace(QString::fromLatin1("&&"), QString::fromLatin1("&"));
tooltip.append(QCoreApplication::translate(
context, getToolTipText()));
tooltip.append(QString::fromLatin1("<br><i>("));
tooltip.append(QCoreApplication::translate(
context, getWhatsThis()));
tooltip.append(QString::fromLatin1(")</i> "));
action->setToolTip(tooltip);
action->setWhatsThis(QCoreApplication::translate(
context, getWhatsThis()));
if (sStatusTip)