Commit 7bfd7829 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add helper for storing/retrieving the accessible name of a QAction

Qt only supports setting accessible names for widgets. Therefore, we
change to existing helpers getAccessibleName/getAccessibleDescription
to accept only QWidget instead of QObject. Additionally, we add
setAccessibleName/getAccessibleName helpers which store the accessible
name of a QAction as custom property of the action.

GnuPG-bug-id: 6046
parent 8fdb244e
......@@ -35,7 +35,7 @@
#include "commands/genrevokecommand.h"
#include "commands/detailscommand.h"
#include "commands/dumpcertificatecommand.h"
#include "utils/accessibility.h"
#include "utils/keys.h"
#include "utils/tags.h"
......@@ -85,8 +85,6 @@ Q_DECLARE_METATYPE(GpgME::UserID)
using namespace Kleo;
static const char *accessibleNameProperty = "_kleo_accessibleName";
class InfoField {
public:
InfoField(const QString &label, QWidget *parent);
......@@ -172,7 +170,7 @@ void InfoField::setAction(const QAction *action)
onActionChanged();
});
onActionChanged();
mButton->setAccessibleName(mAction->property(accessibleNameProperty).toString());
mButton->setAccessibleName(getAccessibleName(mAction));
mButton->setVisible(true);
} else {
mButton->setVisible(false);
......@@ -413,7 +411,7 @@ private:
changeExpirationAction = new QAction{parent};
changeExpirationAction->setIcon(QIcon::fromTheme(QStringLiteral("editor")));
changeExpirationAction->setToolTip(i18nc("@info:tooltip", "Change the end of the validity period"));
changeExpirationAction->setProperty(accessibleNameProperty, i18nc("@action:button", "Change Validity"));
Kleo::setAccessibleName(changeExpirationAction, i18nc("@action:button", "Change Validity"));
expiresField->setAction(changeExpirationAction);
gridLayout->addWidget(expiresField->label(), row, 0);
gridLayout->addLayout(expiresField->layout(), row, 1);
......@@ -424,7 +422,7 @@ private:
copyFingerprintAction = new QAction{parent};
copyFingerprintAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
copyFingerprintAction->setToolTip(i18nc("@info:tooltip", "Copy the fingerprint to the clipboard"));
copyFingerprintAction->setProperty(accessibleNameProperty, i18nc("@action:button", "Copy fingerprint"));
Kleo::setAccessibleName(copyFingerprintAction, i18nc("@action:button", "Copy fingerprint"));
fingerprintField->setAction(copyFingerprintAction);
}
gridLayout->addWidget(fingerprintField->label(), row, 0);
......@@ -435,7 +433,7 @@ private:
showIssuerCertificateAction = new QAction{parent};
showIssuerCertificateAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-information")));
showIssuerCertificateAction->setToolTip(i18nc("@info:tooltip", "Show the issuer certificate"));
showIssuerCertificateAction->setProperty(accessibleNameProperty, i18nc("@action:button", "Show certificate"));
Kleo::setAccessibleName(showIssuerCertificateAction, i18nc("@action:button", "Show certificate"));
smimeIssuerField->setAction(showIssuerCertificateAction);
gridLayout->addWidget(smimeIssuerField->label(), row, 0);
gridLayout->addLayout(smimeIssuerField->layout(), row, 1);
......
......@@ -13,6 +13,7 @@
#include <KLocalizedString>
#include <QAction>
#ifdef Q_OS_WIN32
#include <QApplication>
#include <QDesktopWidget>
......@@ -29,26 +30,38 @@
using namespace Kleo;
static const char *accessibleNameProperty = "_kleo_accessibleName";
namespace
{
QString getAccessibleText(QObject *object, QAccessible::Text t)
QString getAccessibleText(QWidget *widget, QAccessible::Text t)
{
QString name;
if (const auto *const iface = QAccessible::queryAccessibleInterface(object)) {
if (const auto *const iface = QAccessible::queryAccessibleInterface(widget)) {
name = iface->text(t);
}
return name;
}
}
QString Kleo::getAccessibleName(QObject *object)
QString Kleo::getAccessibleName(QWidget *widget)
{
return getAccessibleText(widget, QAccessible::Name);
}
QString Kleo::getAccessibleDescription(QWidget *widget)
{
return getAccessibleText(widget, QAccessible::Description);
}
void Kleo::setAccessibleName(QAction *action, const QString &name)
{
return getAccessibleText(object, QAccessible::Name);
action->setProperty(accessibleNameProperty, name);
}
QString Kleo::getAccessibleDescription(QObject *object)
QString Kleo::getAccessibleName(const QAction *action)
{
return getAccessibleText(object, QAccessible::Description);
return action->property(accessibleNameProperty).toString();
}
QString Kleo::invalidEntryText()
......
......@@ -11,14 +11,30 @@
#include <QAccessible>
#include <QPointer>
class QAction;
class QLabel;
class QObject;
class QString;
namespace Kleo
{
QString getAccessibleName(QObject *object);
QString getAccessibleDescription(QObject *object);
QString getAccessibleName(QWidget *widget);
QString getAccessibleDescription(QWidget *widget);
/**
* Sets the accessible name of the action \p action.
*
* \note Qt does not provide an accessible object for a QAction. Therefore,
* we store the accessible name as custom property of the action.
* \sa getAccessibleName
*/
void setAccessibleName(QAction *action, const QString &name);
/**
* Returns the accessible name of the action \p action.
* \sa setAccessibleName
*/
QString getAccessibleName(const QAction *action);
QString invalidEntryText();
QString requiredText();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment