12#include "nameandemailwidget.h"
14#include "formtextinput_p.h"
16#include "ui/errorlabel.h"
17#include "utils/validation.h"
19#include <KLocalizedString>
37 return QStringLiteral(
"%1 <%2>").arg(name, email);
42class NameAndEmailWidget::Private
48 std::unique_ptr<FormTextInput<QLineEdit>> nameInput;
49 std::unique_ptr<FormTextInput<QLineEdit>> emailInput;
58 ui.nameInput = FormTextInput<QLineEdit>::create(q);
59 ui.nameInput->setLabelText(
i18nc(
"@label",
"Name"));
60 ui.nameInput->setValueRequiredErrorMessage(
i18n(
"Enter a name."));
63 mainLayout->addWidget(ui.nameInput->label());
64 mainLayout->addWidget(ui.nameInput->hintLabel());
65 mainLayout->addWidget(ui.nameInput->widget());
66 mainLayout->addWidget(ui.nameInput->errorLabel());
70 Q_EMIT q->userIDChanged();
74 ui.emailInput = FormTextInput<QLineEdit>::create(q);
75 ui.emailInput->setLabelText(
i18nc(
"@label",
"Email address"));
76 ui.emailInput->setValueRequiredErrorMessage(
i18n(
"Enter an email address."));
79 mainLayout->addWidget(ui.emailInput->label());
80 mainLayout->addWidget(ui.emailInput->hintLabel());
81 mainLayout->addWidget(ui.emailInput->widget());
82 mainLayout->addWidget(ui.emailInput->errorLabel());
85 Q_EMIT q->userIDChanged();
89 void setNamePattern(
const QString ®exp)
92 ui.nameInput->setValidator(Validation::simpleName(Validation::Optional));
93 ui.nameInput->setInvalidEntryErrorMessage(
94 i18n(
"The name must not include <, >, and @."),
95 i18nc(
"text for screen readers",
"The name must not include less-than sign, greater-than sign, and at sign."));
97 ui.nameInput->setValidator(Validation::simpleName(regexp, Validation::Optional));
98 ui.nameInput->setInvalidEntryErrorMessage(
i18n(
"The name must be in the format required by your organization and "
99 "it must not include <, >, and @."),
100 i18nc(
"text for screen readers",
101 "The name must be in the format required by your organization and "
102 "it must not include less-than sign, greater-than sign, and at sign."));
106 void setEmailPattern(
const QString ®exp)
109 ui.emailInput->setValidator(Validation::email(Validation::Optional));
110 ui.emailInput->setInvalidEntryErrorMessage(
i18n(
"Enter an email address in the correct format, like name@example.com."));
112 ui.emailInput->setValidator(Validation::email(regexp, Validation::Optional));
113 ui.emailInput->setInvalidEntryErrorMessage(
i18n(
"Enter an email address in the correct format required by your organization."));
119 return ui.nameInput->widget()->text().trimmed();
124 return ui.emailInput->widget()->text().trimmed();
130 , d(new Private{this})
134NameAndEmailWidget::~NameAndEmailWidget() =
default;
136void NameAndEmailWidget::setName(
const QString &name)
138 d->ui.nameInput->widget()->setText(name);
141QString NameAndEmailWidget::name()
const
146void NameAndEmailWidget::setNameIsRequired(
bool required)
148 d->ui.nameInput->setIsRequired(required);
151bool NameAndEmailWidget::nameIsRequired()
const
153 return d->ui.nameInput->isRequired();
156void NameAndEmailWidget::setNameLabel(
const QString &label)
159 d->ui.nameInput->setLabelText(
i18nc(
"@label",
"Name"));
161 d->ui.nameInput->setLabelText(label);
165QString NameAndEmailWidget::nameLabel()
const
167 return d->ui.nameInput->label()->text();
170void NameAndEmailWidget::setNameHint(
const QString &hint)
172 d->ui.nameInput->setHint(hint);
175QString NameAndEmailWidget::nameHint()
const
177 return d->ui.nameInput->hintLabel()->text();
180void NameAndEmailWidget::setNamePattern(
const QString &pattern)
182 d->setNamePattern(pattern);
185QString NameAndEmailWidget::nameError()
const
187 return d->ui.nameInput->currentError();
190void NameAndEmailWidget::setEmail(
const QString &email)
192 d->ui.emailInput->widget()->setText(email);
195QString NameAndEmailWidget::email()
const
200void NameAndEmailWidget::setEmailIsRequired(
bool required)
202 d->ui.emailInput->setIsRequired(required);
205bool NameAndEmailWidget::emailIsRequired()
const
207 return d->ui.emailInput->isRequired();
210void NameAndEmailWidget::setEmailLabel(
const QString &label)
213 d->ui.emailInput->setLabelText(
i18nc(
"@label",
"Email address"));
215 d->ui.emailInput->setLabelText(label);
219QString NameAndEmailWidget::emailLabel()
const
221 return d->ui.emailInput->label()->text();
224void NameAndEmailWidget::setEmailHint(
const QString &hint)
226 d->ui.emailInput->setHint(hint);
229QString NameAndEmailWidget::emailHint()
const
231 return d->ui.emailInput->hintLabel()->text();
234void NameAndEmailWidget::setEmailPattern(
const QString &pattern)
236 d->setEmailPattern(pattern);
239QString NameAndEmailWidget::emailError()
const
241 return d->ui.emailInput->currentError();
246 return buildUserId(name(), email());
249#include "moc_nameandemailwidget.cpp"
constexpr bool isEmpty() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const=0