summary refs log tree commit diff
path: root/src/ui/TextField.cpp
diff options
context:
space:
mode:
authorKirillpt <kirp@dismail.de>2020-12-01 01:30:33 +0300
committerGitHub <noreply@github.com>2020-11-30 22:30:33 +0000
commit68b2f6cb4f05d427e037760b6124531211de2095 (patch)
tree13beececf6fcd0fb95c586db3d873a022a180055 /src/ui/TextField.cpp
parentMerge pull request #347 from kamathmanu/avatarFullViewSupport (diff)
downloadnheko-68b2f6cb4f05d427e037760b6124531211de2095.tar.xz
Improve Register page (#346)
* add username error label, add word wrapping for error labels

* make lint

* last commits

* remove font, and remove some lambdas

* add QRegularExpression for regex

* improve review things

* add isModified() for checkFields()

* add check isModified() for  all fields in checkFields

* Update src/RegisterPage.cpp

Co-authored-by: DeepBlueV7.X <nicolas.werner@hotmail.de>

* remove emit call for showError

Co-authored-by: DeepBlueV7.X <nicolas.werner@hotmail.de>
Diffstat (limited to 'src/ui/TextField.cpp')
-rw-r--r--src/ui/TextField.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp

index 941d00a3..055fe73b 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp
@@ -6,6 +6,7 @@ #include <QPaintEvent> #include <QPainter> #include <QPropertyAnimation> +#include <QRegularExpressionValidator> TextField::TextField(QWidget *parent) : QLineEdit(parent) @@ -70,18 +71,24 @@ TextField::hasLabel() const return show_label_; } -bool -TextField::isValid() const -{ - return is_valid_; -} - void TextField::setValid(bool valid) { is_valid_ = valid; } +bool +TextField::isValid() const +{ + QString s = text(); + int pos = 0; + if (regexp_.pattern().isEmpty()) { + return is_valid_; + } + QRegularExpressionValidator v(QRegularExpression(regexp_), 0); + return v.validate(s, pos) == QValidator::Acceptable; +} + void TextField::setLabelFontSize(qreal size) { @@ -156,6 +163,12 @@ TextField::setUnderlineColor(const QColor &color) update(); } +void +TextField::setRegexp(const QRegularExpression &regexp) +{ + regexp_ = regexp; +} + QColor TextField::underlineColor() const {