move error_matrixid label below matrixid input, made hide/show for the label, made red underline for invalid input, add to TextField class isValid() setValid() for custom validation

This commit is contained in:
kirillpt 2020-11-23 23:33:53 +03:00
parent 4032f6e113
commit ac73f10eba
3 changed files with 25 additions and 2 deletions

View file

@ -137,12 +137,14 @@ LoginPage::LoginPage(QWidget *parent)
serverLayout_ = new QHBoxLayout();
serverLayout_->addWidget(serverInput_, 0, Qt::AlignVCenter);
form_layout_->addLayout(matrixid_error_layout_);
form_layout_->addLayout(matrixidLayout_);
form_layout_->addLayout(matrixid_error_layout_);
form_layout_->addWidget(password_input_);
form_layout_->addWidget(deviceName_, Qt::AlignHCenter);
form_layout_->addLayout(serverLayout_);
error_matrixid_label_->hide();
button_layout_ = new QHBoxLayout();
button_layout_->setSpacing(0);
button_layout_->setContentsMargins(0, 0, 0, 30);
@ -194,7 +196,9 @@ LoginPage::loginError(const QString &msg)
void
LoginPage::matrixIdError(const QString &msg)
{
error_matrixid_label_->show();
error_matrixid_label_->setText(msg);
matrixid_input_->setValid(false);
}
bool
@ -218,6 +222,8 @@ LoginPage::onMatrixIdEntered()
return;
} else {
error_matrixid_label_->setText("");
error_matrixid_label_->hide();
matrixid_input_->setValid(true);
}
try {
@ -377,6 +383,8 @@ LoginPage::onLoginButtonClicked()
return;
} else {
error_matrixid_label_->setText("");
error_matrixid_label_->hide();
matrixid_input_->setValid(true);
}
try {

View file

@ -69,6 +69,18 @@ TextField::hasLabel() const
return show_label_;
}
bool
TextField::isValid() const
{
return is_valid_;
}
void
TextField::setValid(bool valid)
{
is_valid_ = valid;
}
void
TextField::setLabelFontSize(qreal size)
{
@ -147,7 +159,7 @@ QColor
TextField::underlineColor() const
{
if (!underline_color_.isValid()) {
if (hasAcceptableInput() || !isModified())
if (TextField::isValid() || !isModified())
return QPalette().color(QPalette::Highlight);
else
return Qt::red;

View file

@ -30,6 +30,7 @@ public:
void setLabelFontSize(qreal size);
void setShowLabel(bool value);
void setUnderlineColor(const QColor &color);
void setValid(bool valid);
QColor inkColor() const;
QColor labelColor() const;
@ -37,6 +38,7 @@ public:
QColor backgroundColor() const;
QString label() const;
bool hasLabel() const;
bool isValid() const;
qreal labelFontSize() const;
protected:
@ -54,6 +56,7 @@ private:
TextFieldLabel *label_;
TextFieldStateMachine *state_machine_;
bool show_label_;
bool is_valid_;
qreal label_font_size_;
};