Commit 689e2e16 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Visually indicate required input fields

To indicate required input fields the text " (required)" is appended
to the label. We do not add "required" to the accessible name anymore.
In the Add User ID dialog we remove the colon at the end of the labels
texts and we do not need to set an alternative accessible name anymore.

GnuPG-bug-id: 5916
parent df9b9fe6
......@@ -88,8 +88,7 @@ public:
{
ui.nameInput = FormTextInput<QLineEdit>::create(q);
ui.nameInput->label()->setText(i18nc("@label", "Name:"));
ui.nameInput->setAccessibleName(i18nc("@label without colon for assistive tools", "Name"));
ui.nameInput->setLabelText(i18nc("@label", "Name"));
ui.nameInput->setIsRequired(nameIsRequired);
ui.nameInput->setValueRequiredErrorMessage(i18n("Error: The name is required."));
const auto regexp = config.readEntry("NAME_regex");
......@@ -124,8 +123,7 @@ public:
{
ui.emailInput = FormTextInput<QLineEdit>::create(q);
ui.emailInput->label()->setText(i18nc("@label", "Email:"));
ui.emailInput->setAccessibleName(i18nc("@label without colon for assistive tools", "Email"));
ui.emailInput->setLabelText(i18nc("@label", "Email address"));
ui.emailInput->setIsRequired(emailIsRequired);
ui.emailInput->setValueRequiredErrorMessage(i18n("Error: The email address is required."));
const auto regexp = config.readEntry(QLatin1String("EMAIL_regex"));
......
......@@ -54,6 +54,7 @@ public:
, mInvalidEntryErrorMessage{defaultInvalidEntryErrorMessage()}
{}
void updateLabel();
QString errorMessage(Error error) const;
void updateError();
void updateAccessibleNameAndDescription();
......@@ -62,6 +63,7 @@ public:
QPointer<QWidget> mWidget;
QPointer<ErrorLabel> mErrorLabel;
QPointer<const QValidator> mValidator;
QString mLabelText;
QString mAccessibleName;
QString mAccessibleDescription;
QString mValueRequiredErrorMessage;
......@@ -71,6 +73,17 @@ public:
bool mEditingInProgress = false;
};
void FormTextInputBase::Private::updateLabel()
{
if (!mLabel) {
return;
}
const auto text = mRequired
? i18nc("@label label text (required)", "%1 (required)", mLabelText)
: mLabelText;
mLabel->setText(text);
}
QString FormTextInputBase::Private::errorMessage(Error error) const
{
switch (error) {
......@@ -141,9 +154,6 @@ void FormTextInputBase::Private::updateAccessibleNameAndDescription()
// emulate this by adding "invalid entry" to the accessible name of the input field
// and its label
QString name = mAccessibleName;
if (mRequired) {
name += QLatin1String{", "} + requiredText();
}
if (errorShown) {
name += QLatin1String{", "} + invalidEntryText();
};
......@@ -177,9 +187,16 @@ ErrorLabel *FormTextInputBase::errorLabel() const
return d->mErrorLabel;
}
void FormTextInputBase::setLabelText(const QString &text)
{
d->mLabelText = text;
d->updateLabel();
}
void FormTextInputBase::setIsRequired(bool required)
{
d->mRequired = required;
d->updateLabel();
}
bool FormTextInputBase::isRequired() const
......
......@@ -35,7 +35,9 @@ public:
FormTextInputBase& operator=(FormTextInputBase&&) = delete;
/**
* Returns the label associated to the controlled widget.
* Returns the label associated to the controlled widget. Use it to add
* the label to a layout, but do not use it to set properties of the label
* for which this class provides setters.
*/
QLabel *label() const;
......@@ -44,6 +46,12 @@ public:
*/
ErrorLabel *errorLabel() const;
/**
* Sets the text of the label. Do not add a colon at the end of the text.
* If input is required, then the label is marked appropriately.
*/
void setLabelText(const QString &text);
/**
* Marks this input field as required.
*/
......
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