Improve accelerator stripping in accessible widgets

When we strip the & we should also report the hotkey.
In addition only strip labels when they are buddys and try not to remove
ampersands from all kinds of random text.

This fixes https://bugs.kde.org/show_bug.cgi?id=338282

Change-Id: I401281cd9ff43b23a3923ad9909ca9c469b59506
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Frederik Gladhorn 2014-08-20 14:32:29 +02:00
parent 52f859604d
commit 68206db907
3 changed files with 14 additions and 7 deletions

View File

@ -294,8 +294,7 @@ QString QAccessibleMenuItem::text(QAccessible::Text t) const
QString str;
switch (t) {
case QAccessible::Name:
str = m_action->text();
str = qt_accStripAmp(str);
str = qt_accStripAmp(m_action->text());
break;
case QAccessible::Accelerator: {
#ifndef QT_NO_SHORTCUT

View File

@ -73,6 +73,7 @@
QT_BEGIN_NAMESPACE
QString qt_accStripAmp(const QString &text);
QString qt_accHotKey(const QString &text);
QList<QWidget*> childWidgets(const QWidget *widget)
{
@ -636,6 +637,8 @@ QString QAccessibleDockWidget::text(QAccessible::Text t) const
{
if (t == QAccessible::Name) {
return qt_accStripAmp(dockWidget()->windowTitle());
} else if (t == QAccessible::Accelerator) {
return qt_accHotKey(dockWidget()->windowTitle());
}
return QString();
}

View File

@ -121,14 +121,14 @@ QString QAccessibleButton::text(QAccessible::Text t) const
case QAccessible::Name:
str = widget()->accessibleName();
if (str.isEmpty())
str = button()->text();
str = qt_accStripAmp(button()->text());
break;
default:
break;
}
if (str.isEmpty())
str = QAccessibleWidget::text(t);
return qt_accStripAmp(str);
return str;
}
QAccessible::State QAccessibleButton::state() const
@ -395,6 +395,8 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const
doc.setHtml(str);
str = doc.toPlainText();
}
if (label->buddy())
str = qt_accStripAmp(str);
#ifndef QT_NO_LCDNUMBER
} else if (qobject_cast<QLCDNumber*>(object())) {
QLCDNumber *l = qobject_cast<QLCDNumber*>(object());
@ -419,7 +421,7 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const
}
if (str.isEmpty())
str = QAccessibleWidget::text(t);
return qt_accStripAmp(str);
return str;
}
/*! \reimp */
@ -508,7 +510,10 @@ QString QAccessibleGroupBox::text(QAccessible::Text t) const
txt = qt_accStripAmp(groupBox()->title());
break;
case QAccessible::Description:
txt = qt_accStripAmp(groupBox()->toolTip());
txt = groupBox()->toolTip();
break;
case QAccessible::Accelerator:
txt = qt_accHotKey(groupBox()->title());
break;
default:
break;
@ -611,7 +616,7 @@ QString QAccessibleLineEdit::text(QAccessible::Text t) const
}
if (str.isEmpty())
str = QAccessibleWidget::text(t);
return qt_accStripAmp(str);
return str;
}
void QAccessibleLineEdit::setText(QAccessible::Text t, const QString &text)