aboutsummaryrefslogtreecommitdiff
path: root/src/qt/qvalidatedlineedit.cpp
diff options
context:
space:
mode:
authorPhilip Kaufmann <phil.kaufmann@t-online.de>2013-11-20 15:56:51 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2014-01-29 14:15:55 +0100
commitc78bd937017212c89c1c7aab07399cec5b6b3bdd (patch)
tree92129bb63c2b9bbb724c3a2b4ad643710484e3ea /src/qt/qvalidatedlineedit.cpp
parentaab8fc58c6e6dc6e0a104170bd2aa10dc1af5dea (diff)
[Qt] extend validate line edit and btc address validator
- remove btc address length from address validator - add an optional btc address check in validated line edit that defaults to off and is used in GUIUtil::setupAddressWidget() - an isAcceptable() check is added to validated line edit on focus out which only kicks in, when a validator is used with that widget - remove an isAcceptable() check from sendcoinsentry.cpp - remove obsolete attributes from ui files, which are set by calling GUIUtil::setupAddressWidget() - move some more things to GUIUtil::setupAddressWidget() and remove them from normal code e.g. placeholder text
Diffstat (limited to 'src/qt/qvalidatedlineedit.cpp')
-rw-r--r--src/qt/qvalidatedlineedit.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/qt/qvalidatedlineedit.cpp b/src/qt/qvalidatedlineedit.cpp
index 1e7596c9c1..c2567835c9 100644
--- a/src/qt/qvalidatedlineedit.cpp
+++ b/src/qt/qvalidatedlineedit.cpp
@@ -4,10 +4,13 @@
#include "qvalidatedlineedit.h"
+#include "bitcoinaddressvalidator.h"
#include "guiconstants.h"
QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
- QLineEdit(parent), valid(true)
+ QLineEdit(parent),
+ valid(true),
+ checkValidator(0)
{
connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
}
@@ -34,11 +37,20 @@ void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
{
// Clear invalid flag on focus
setValid(true);
+
QLineEdit::focusInEvent(evt);
}
+void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)
+{
+ checkValidity();
+
+ QLineEdit::focusOutEvent(evt);
+}
+
void QValidatedLineEdit::markValid()
{
+ // As long as a user is typing ensure we display state as valid
setValid(true);
}
@@ -47,3 +59,49 @@ void QValidatedLineEdit::clear()
setValid(true);
QLineEdit::clear();
}
+
+void QValidatedLineEdit::setEnabled(bool enabled)
+{
+ if (!enabled)
+ {
+ // A disabled QValidatedLineEdit should be marked valid
+ setValid(true);
+ }
+ else
+ {
+ // Recheck validity when QValidatedLineEdit gets enabled
+ checkValidity();
+ }
+
+ QLineEdit::setEnabled(enabled);
+}
+
+void QValidatedLineEdit::checkValidity()
+{
+ if (text().isEmpty())
+ {
+ setValid(true);
+ }
+ else if (hasAcceptableInput())
+ {
+ setValid(true);
+
+ // Check contents on focus out
+ if (checkValidator)
+ {
+ QString address = text();
+ int pos = 0;
+ if (checkValidator->validate(address, pos) == QValidator::Acceptable)
+ setValid(true);
+ else
+ setValid(false);
+ }
+ }
+ else
+ setValid(false);
+}
+
+void QValidatedLineEdit::setCheckValidator(const QValidator *v)
+{
+ checkValidator = v;
+}