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

Add an optional hint to the input fields

This replaces the less accessible tool tip with a hint text that is shown
between label and input field.

GnuPG-bug-id: 5916
parent 17662837
......@@ -93,25 +93,24 @@ public:
const auto regexp = config.readEntry("NAME_regex");
if (regexp.isEmpty()) {
ui.nameInput->setValidator(Validation::simpleName(Validation::Optional, q));
ui.nameInput->setToolTip(xi18n(
"<para>The name must not contain any of the following characters: &lt;, &gt;, @.</para>"));
ui.nameInput->setAccessibleDescription(i18nc("text for screen readers",
"The name must not contain any of the following characters: less-than sign, greater-than sign, at sign."));
ui.nameInput->setHint(i18n("Must not include &lt;, &gt;, and @."),
i18nc("text for screen readers",
"Must not include less-than sign, greater-than sign, and at sign."));
ui.nameInput->setInvalidEntryErrorMessage(i18n("Error: The entered name contains invalid characters."));
} else {
ui.nameInput->setValidator(Validation::simpleName(regexp, Validation::Optional, q));
ui.nameInput->setToolTip(xi18n(
"<para>The name must not contain any of the following characters: &lt;, &gt;, @. "
"Additionally, the name must follow the rules set by your organization.</para>"));
ui.nameInput->setAccessibleDescription(i18nc("text for screen readers",
"The name must not contain any of the following characters: less-than sign, greater-than sign, at sign. "
"Additionally, the name must follow the rules set by your organization."));
ui.nameInput->setHint(i18n("Must be in the format required by your organization and "
"must not include &lt;, &gt;, and @."),
i18nc("text for screen readers",
"Must be in the format required by your organization and "
"must not include less-than sign, greater-than sign, and at sign."));
ui.nameInput->setInvalidEntryErrorMessage(i18n(
"Error: The entered name contains invalid characters "
"or it does not follow your organization's rules."));
}
mainLayout->addWidget(ui.nameInput->label());
mainLayout->addWidget(ui.nameInput->hintLabel());
mainLayout->addWidget(ui.nameInput->errorLabel());
mainLayout->addWidget(ui.nameInput->widget());
}
......@@ -129,14 +128,15 @@ public:
ui.emailInput->setInvalidEntryErrorMessage(i18n("Error: The entered email address is not valid."));
} else {
ui.emailInput->setValidator(Validation::email(regexp, Validation::Optional, q));
ui.emailInput->setToolTip(xi18n(
"<para>If an email address is given, then it has to satisfy the rules set by your organization.</para>"));
ui.emailInput->setHint(i18n(
"Must be in the format required by your organization"));
ui.emailInput->setInvalidEntryErrorMessage(i18n(
"Error: The entered email address is not valid "
"or it does not follow your organization's rules."));
}
mainLayout->addWidget(ui.emailInput->label());
mainLayout->addWidget(ui.emailInput->hintLabel());
mainLayout->addWidget(ui.emailInput->errorLabel());
mainLayout->addWidget(ui.emailInput->widget());
}
......
......@@ -55,11 +55,13 @@ public:
{}
void updateLabel();
void setHint(const QString &text, const QString &accessibleDescription);
QString errorMessage(Error error) const;
void updateError();
void updateAccessibleNameAndDescription();
QPointer<QLabel> mLabel;
QPointer<QLabel> mHintLabel;
QPointer<QWidget> mWidget;
QPointer<ErrorLabel> mErrorLabel;
QPointer<const QValidator> mValidator;
......@@ -84,6 +86,17 @@ void FormTextInputBase::Private::updateLabel()
mLabel->setText(text);
}
void FormTextInputBase::Private::setHint(const QString &text, const QString &accessibleDescription)
{
if (!mHintLabel) {
return;
}
mHintLabel->setVisible(!text.isEmpty());
mHintLabel->setText(text);
mAccessibleDescription = accessibleDescription.isEmpty() ? text : accessibleDescription;
updateAccessibleNameAndDescription();
}
QString FormTextInputBase::Private::errorMessage(Error error) const
{
switch (error) {
......@@ -182,6 +195,11 @@ QLabel *FormTextInputBase::label() const
return d->mLabel;
}
QLabel *FormTextInputBase::hintLabel() const
{
return d->mHintLabel;
}
ErrorLabel *FormTextInputBase::errorLabel() const
{
return d->mErrorLabel;
......@@ -193,6 +211,11 @@ void FormTextInputBase::setLabelText(const QString &text)
d->updateLabel();
}
void FormTextInputBase::setHint(const QString &text, const QString &accessibleDescription)
{
d->setHint(text, accessibleDescription);
}
void FormTextInputBase::setIsRequired(bool required)
{
d->mRequired = required;
......@@ -243,12 +266,6 @@ void FormTextInputBase::setAccessibleName(const QString &name)
d->updateAccessibleNameAndDescription();
}
void FormTextInputBase::setAccessibleDescription(const QString &description)
{
d->mAccessibleDescription = description;
d->updateAccessibleNameAndDescription();
}
void FormTextInputBase::setWidget(QWidget *widget)
{
auto parent = widget ? widget->parentWidget() : nullptr;
......@@ -258,6 +275,8 @@ void FormTextInputBase::setWidget(QWidget *widget)
font.setBold(true);
d->mLabel->setFont(font);
d->mLabel->setBuddy(d->mWidget);
d->mHintLabel = new QLabel{parent};
d->mHintLabel->setVisible(false);
d->mErrorLabel = new ErrorLabel{parent};
d->mErrorLabel->setVisible(false);
connectWidget();
......
......@@ -8,11 +8,12 @@
*/
#pragma once
#include <QString>
#include <memory>
class QLabel;
class QLineEdit;
class QString;
class QValidator;
class QWidget;
......@@ -41,6 +42,11 @@ public:
*/
QLabel *label() const;
/**
* Returns the hint label associated to the controlled widget.
*/
QLabel *hintLabel() const;
/**
* Returns the error label associated to the controlled widget.
*/
......@@ -52,6 +58,13 @@ public:
*/
void setLabelText(const QString &text);
/**
* Sets \p text as hint text for this input field and \p accessibleDescription
* as alternative text for assistive tools. If \p accessibleDescription is
* empty, then \p text is used instead.
*/
void setHint(const QString &text, const QString &accessibleDescription = {});
/**
* Marks this input field as required.
*/
......@@ -94,13 +107,6 @@ public:
*/
void setAccessibleName(const QString &name);
/**
* Sets the accessible description of the controlled widget. Use this
* function instead of setting the accessible description directly on
* the controlled widget.
*/
void setAccessibleDescription(const QString &description);
/**
* Enables or disables the controlled widget and its associated label.
* If the widget is disables, then the error label is hidden. Otherwise,
......
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