1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "qvalidatedlineedit.h"
7 #include "bitcoinaddressvalidator.h"
8 #include "guiconstants.h"
10 QValidatedLineEdit::QValidatedLineEdit(QWidget
*parent
) :
15 connect(this, SIGNAL(textChanged(QString
)), this, SLOT(markValid()));
18 void QValidatedLineEdit::setValid(bool _valid
)
20 if(_valid
== this->valid
)
31 setStyleSheet(STYLE_INVALID
);
36 void QValidatedLineEdit::focusInEvent(QFocusEvent
*evt
)
38 // Clear invalid flag on focus
41 QLineEdit::focusInEvent(evt
);
44 void QValidatedLineEdit::focusOutEvent(QFocusEvent
*evt
)
48 QLineEdit::focusOutEvent(evt
);
51 void QValidatedLineEdit::markValid()
53 // As long as a user is typing ensure we display state as valid
57 void QValidatedLineEdit::clear()
63 void QValidatedLineEdit::setEnabled(bool enabled
)
67 // A disabled QValidatedLineEdit should be marked valid
72 // Recheck validity when QValidatedLineEdit gets enabled
76 QLineEdit::setEnabled(enabled
);
79 void QValidatedLineEdit::checkValidity()
85 else if (hasAcceptableInput())
89 // Check contents on focus out
92 QString address
= text();
94 if (checkValidator
->validate(address
, pos
) == QValidator::Acceptable
)
103 Q_EMIT
validationDidChange(this);
106 void QValidatedLineEdit::setCheckValidator(const QValidator
*v
)
111 bool QValidatedLineEdit::isValid()
113 // use checkValidator in case the QValidatedLineEdit is disabled
116 QString address
= text();
118 if (checkValidator
->validate(address
, pos
) == QValidator::Acceptable
)