a11y: Port qt_accHotKey() to QKeySequence::mnemonic()
QKeySequence::mnemonic() contains additional input sanitization logic and in combination with the toString() function, it provides a platform agnostic way to get the shortcut text for the mnemonic. tst_QAccessibility was adjusted because mnemonics don't work by default on macOS. See qt_set_sequence_auto_mnemonic(). Change-Id: I96842a6c18140a559aeaeb8f687e32011e5e2e77 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
da799c20d7
commit
d612dcd249
@ -107,9 +107,7 @@ QString qt_accStripAmp(const QString &text)
|
||||
QString qt_accHotKey(const QString &text)
|
||||
{
|
||||
#ifndef QT_NO_SHORTCUT
|
||||
qsizetype ampIndex = qt_accAmpIndex(text);
|
||||
if (ampIndex != -1)
|
||||
return QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + text.at(ampIndex + 1);
|
||||
return QKeySequence::mnemonic(text).toString(QKeySequence::NativeText);
|
||||
#else
|
||||
Q_UNUSED(text);
|
||||
#endif
|
||||
|
@ -3984,8 +3984,21 @@ void tst_QAccessibility::labelTest()
|
||||
QTestAccessibility::clearEvents();
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MACOS)
|
||||
QT_BEGIN_NAMESPACE
|
||||
extern void qt_set_sequence_auto_mnemonic(bool);
|
||||
QT_END_NAMESPACE
|
||||
#endif
|
||||
|
||||
void tst_QAccessibility::accelerators()
|
||||
{
|
||||
#if defined(Q_OS_MACOS)
|
||||
qt_set_sequence_auto_mnemonic(true);
|
||||
const auto resetAutoMnemonic = qScopeGuard([] {
|
||||
qt_set_sequence_auto_mnemonic(false);
|
||||
});
|
||||
#endif
|
||||
|
||||
auto windowHolder = std::make_unique<QWidget>();
|
||||
auto window = windowHolder.get();
|
||||
QHBoxLayout *lay = new QHBoxLayout(window);
|
||||
@ -4011,7 +4024,7 @@ void tst_QAccessibility::accelerators()
|
||||
label->setText(tr("Q &&A"));
|
||||
QCOMPARE(accLineEdit->text(QAccessible::Accelerator), QString());
|
||||
|
||||
#if !defined(QT_NO_DEBUG) && !defined(Q_OS_MAC)
|
||||
#if !defined(QT_NO_DEBUG)
|
||||
QTest::ignoreMessage(QtWarningMsg, "QKeySequence::mnemonic: \"Q &A&B\" contains multiple occurrences of '&'");
|
||||
#endif
|
||||
label->setText(tr("Q &A&B"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user