Bind MnemonicLabel’s “plain” label to buddy’s Accessible.name

This is to give a default name to form controls by default, like <label>
does to <input> and <textarea> in HTML.

Had to add a “plain” version of the label, with neither the <u> tag used
in rich text or the ‘&’ in the “regular” label, otherwise orca would
spell out these symbols.
This commit is contained in:
jordi fita mas 2024-12-30 09:50:36 +01:00
parent f4affd9241
commit 9f181047ac
4 changed files with 29 additions and 0 deletions

View File

@ -22,6 +22,7 @@ Page {
}
}
Accessible.role: Accessible.Form
title: qsTr("Login")
ColumnLayout {

View File

@ -18,4 +18,10 @@ Label {
control.buddy.forceActiveFocus();
}
}
Binding {
property: "Accessible.name"
target: control.buddy
value: control.Mnemonic.plainLabel
}
}

View File

@ -61,6 +61,7 @@ private:
MnemonicAttached::MnemonicAttached(QObject *parent)
: QObject{parent}
, m_label{}
, m_plainLabel{}
, m_richTextLabel{}
, m_active{MnemonicEventFilter::instance().isAltPressed()}
{
@ -93,9 +94,15 @@ void MnemonicAttached::setLabel(const QString &label)
emit labelChanged();
emit sequenceChanged();
setPlainLabel(QString(m_label).remove('&'_L1));
updateRichText();
}
QString MnemonicAttached::plainLabel() const
{
return m_plainLabel;
}
QString MnemonicAttached::richTextLabel() const
{
return m_richTextLabel;
@ -124,6 +131,15 @@ void MnemonicAttached::onAltReleased()
updateRichText();
}
void MnemonicAttached::setPlainLabel(const QString &plain)
{
if (plain == m_plainLabel) {
return;
}
m_plainLabel = plain;
emit plainLabelChanged();
}
void MnemonicAttached::updateRichText()
{
QString richTextLabel;

View File

@ -11,6 +11,7 @@ class MnemonicAttached : public QObject
Q_OBJECT
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged FINAL)
Q_PROPERTY(QString plainLabel READ plainLabel NOTIFY plainLabelChanged FINAL)
Q_PROPERTY(QString richTextLabel READ richTextLabel NOTIFY richTextLabelChanged FINAL)
Q_PROPERTY(QKeySequence sequence READ sequence NOTIFY sequenceChanged FINAL)
@ -25,6 +26,8 @@ public:
QString label() const;
void setLabel(const QString &label);
QString plainLabel() const;
QString richTextLabel() const;
QKeySequence sequence() const;
@ -32,6 +35,7 @@ public:
signals:
void enabledChanged();
void labelChanged();
void plainLabelChanged();
void richTextLabelChanged();
void sequenceChanged();
@ -40,9 +44,11 @@ private slots:
void onAltReleased();
private:
void setPlainLabel(const QString &plain);
void updateRichText();
QString m_label;
QString m_plainLabel;
QString m_richTextLabel;
bool m_active;
};