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

pull/334/head
kirillpt 4 years ago
parent 4032f6e113
commit ac73f10eba
  1. 10
      src/LoginPage.cpp
  2. 14
      src/ui/TextField.cpp
  3. 3
      src/ui/TextField.h

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

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

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

Loading…
Cancel
Save