1a445343f6
-BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
123 lines
2.5 KiB
C++
123 lines
2.5 KiB
C++
// Copyright (c) 2011-2016 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <qt/qvalidatedlineedit.h>
|
|
|
|
#include <qt/bitcoinaddressvalidator.h>
|
|
#include <qt/guiconstants.h>
|
|
|
|
QValidatedLineEdit::QValidatedLineEdit(QWidget *parent) :
|
|
QLineEdit(parent),
|
|
valid(true),
|
|
checkValidator(0)
|
|
{
|
|
connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
|
|
}
|
|
|
|
void QValidatedLineEdit::setValid(bool _valid)
|
|
{
|
|
if(_valid == this->valid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(_valid)
|
|
{
|
|
setStyleSheet("");
|
|
}
|
|
else
|
|
{
|
|
setStyleSheet(STYLE_INVALID);
|
|
}
|
|
this->valid = _valid;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
|
|
Q_EMIT validationDidChange(this);
|
|
}
|
|
|
|
void QValidatedLineEdit::setCheckValidator(const QValidator *v)
|
|
{
|
|
checkValidator = v;
|
|
}
|
|
|
|
bool QValidatedLineEdit::isValid()
|
|
{
|
|
// use checkValidator in case the QValidatedLineEdit is disabled
|
|
if (checkValidator)
|
|
{
|
|
QString address = text();
|
|
int pos = 0;
|
|
if (checkValidator->validate(address, pos) == QValidator::Acceptable)
|
|
return true;
|
|
}
|
|
|
|
return valid;
|
|
}
|