Fabcoin Core  0.16.2
P2P Digital Currency
qvalidatedlineedit.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2017 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.
4 
5 #include <qvalidatedlineedit.h>
6 
8 #include <styleSheet.h>
9 
11  QLineEdit(parent),
12  valid(true),
13  checkValidator(0),
14  emptyIsValid(true)
15 {
16  connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
17 }
18 
20 {
21  if(_valid == this->valid)
22  {
23  return;
24  }
25 
26  if(_valid)
27  {
28  QWidget *widget = this->parentWidget();
29  if(widget && widget->inherits("QComboBox"))
30  {
31  widget->setStyleSheet("");
32  }
33  else
34  {
35  setStyleSheet("");
36  }
37  }
38  else
39  {
40  QWidget *widget = this->parentWidget();
41  if(widget && widget->inherits("QComboBox"))
42  {
43  SetObjectStyleSheet(widget, StyleSheetNames::Invalid);
44  }
45  else
46  {
47  SetObjectStyleSheet(this, StyleSheetNames::Invalid);
48  }
49  }
50  this->valid = _valid;
51 }
52 
53 void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
54 {
55  // Clear invalid flag on focus
56  setValid(true);
57 
58  QLineEdit::focusInEvent(evt);
59 }
60 
61 void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)
62 {
63  checkValidity();
64 
65  QLineEdit::focusOutEvent(evt);
66 }
67 
69 {
70  return emptyIsValid;
71 }
72 
74 {
75  emptyIsValid = value;
76 }
77 
79 {
80  // As long as a user is typing ensure we display state as valid
81  setValid(true);
82 }
83 
85 {
86  setValid(true);
87  QLineEdit::clear();
88 }
89 
91 {
92  if (!enabled)
93  {
94  // A disabled QValidatedLineEdit should be marked valid
95  setValid(true);
96  }
97  else
98  {
99  // Recheck validity when QValidatedLineEdit gets enabled
100  checkValidity();
101  }
102 
103  QLineEdit::setEnabled(enabled);
104 }
105 
107 {
108  if (emptyIsValid && text().isEmpty())
109  {
110  setValid(true);
111  }
112  else if (hasAcceptableInput())
113  {
114  setValid(true);
115 
116  // Check contents on focus out
117  if (checkValidator)
118  {
119  QString address = text();
120  int pos = 0;
121  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
122  setValid(true);
123  else
124  setValid(false);
125  }
126  }
127  else
128  setValid(false);
129 
130  Q_EMIT validationDidChange(this);
131 }
132 
133 void QValidatedLineEdit::setCheckValidator(const QValidator *v)
134 {
135  checkValidator = v;
136 }
137 
139 {
140  // use checkValidator in case the QValidatedLineEdit is disabled
141  if (checkValidator)
142  {
143  QString address = text();
144  int pos = 0;
145  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
146  return true;
147  }
148 
149  return valid;
150 }
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
void setEmptyIsValid(bool value)
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
void focusInEvent(QFocusEvent *evt)
bool getEmptyIsValid() const
QValidatedLineEdit(QWidget *parent)
const QValidator * checkValidator
void focusOutEvent(QFocusEvent *evt)
void setCheckValidator(const QValidator *v)
void setEnabled(bool enabled)
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
void setValid(bool valid)