Fabcoin Core  0.16.2
P2P Digital Currency
qvalidatedtextedit.cpp
Go to the documentation of this file.
1 #include <qvalidatedtextedit.h>
2 #include <styleSheet.h>
3 
4 #include <QValidator>
5 
7  QTextEdit(parent),
8  valid(true),
9  checkValidator(0),
10  emptyIsValid(true),
11  isValidManually(false)
12 {
13  connect(this, SIGNAL(textChanged()), this, SLOT(markValid()));
14  setStyleSheet("");
15 }
16 
18 {
19  setValid(true);
20  QTextEdit::clear();
21 }
22 
23 void QValidatedTextEdit::setCheckValidator(const QValidator *v)
24 {
25  checkValidator = v;
26 }
27 
29 {
30  // use checkValidator in case the QValidatedTextEdit is disabled
31  if (checkValidator)
32  {
33  QString address = toPlainText();
34  int pos = 0;
35  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
36  return true;
37  }
38 
39  return valid;
40 }
41 
43 {
44  if(_valid == this->valid)
45  {
46  return;
47  }
48 
49  if(_valid)
50  {
51  setStyleSheet("");
52  }
53  else
54  {
55  SetObjectStyleSheet(this, StyleSheetNames::Invalid);
56  }
57  this->valid = _valid;
58 }
59 
61 {
62  if (!enabled)
63  {
64  // A disabled QValidatedLineEdit should be marked valid
65  setValid(true);
66  }
67  else
68  {
69  // Recheck validity when QValidatedLineEdit gets enabled
70  checkValidity();
71  }
72 
73  QTextEdit::setEnabled(enabled);
74 }
75 
77 {
78  if (emptyIsValid && toPlainText().isEmpty())
79  {
80  setValid(true);
81  }
82  else if(isValidManually)
83  {
84  setValid(true);
85  }
86  else if (checkValidator)
87  {
88  QString address = toPlainText();
89  int pos = 0;
90  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
91  setValid(true);
92  else
93  setValid(false);
94  }
95  else
96  setValid(false);
97 }
98 
100 {
101  // As long as a user is typing ensure we display state as valid
102  setValid(true);
103 }
104 
105 void QValidatedTextEdit::focusInEvent(QFocusEvent *event)
106 {
107  setValid(true);
108  QTextEdit::focusInEvent(event);
109 }
110 
111 void QValidatedTextEdit::focusOutEvent(QFocusEvent *event)
112 {
113  checkValidity();
114  QTextEdit::focusOutEvent(event);
115 }
116 
118 {
119  return isValidManually;
120 }
121 
123 {
124  isValidManually = value;
125 }
126 
128 {
129  return emptyIsValid;
130 }
131 
133 {
134  emptyIsValid = value;
135 }
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
void setIsValidManually(bool value)
void setValid(bool valid)
const QValidator * checkValidator
void setEnabled(bool enabled)
void focusInEvent(QFocusEvent *event)
QValidatedTextEdit(QWidget *parent)
void focusOutEvent(QFocusEvent *event)
void setEmptyIsValid(bool value)
void setCheckValidator(const QValidator *v)
bool getIsValidManually() const
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
bool getEmptyIsValid() const