From ac73f10eba557588a78a5e9c24a3874c287c5db8 Mon Sep 17 00:00:00 2001 From: kirillpt Date: Mon, 23 Nov 2020 23:33:53 +0300 Subject: [PATCH] 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 --- src/LoginPage.cpp | 10 +++++++++- src/ui/TextField.cpp | 14 +++++++++++++- src/ui/TextField.h | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 1d5b6911..e02aa9c6 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -137,11 +137,13 @@ 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); @@ -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 { diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 27584693..c3eed734 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -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; diff --git a/src/ui/TextField.h b/src/ui/TextField.h index 85d5036d..966155f4 100644 --- a/src/ui/TextField.h +++ b/src/ui/TextField.h @@ -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_; };