Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

qvalidatedlineedit.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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 
6 
8 #include <qt/guiutil.h>
9 
11  QLineEdit(parent),
12  valid(true),
13  checkValidator(0)
14 {
15  connect(this, SIGNAL(textChanged(QString)), this, SLOT(markValid()));
16 }
17 
19 {
20  if(_valid == this->valid)
21  {
22  return;
23  }
24 
25  if(_valid)
26  {
27  setStyleSheet("");
28  }
29  else
30  {
32  }
33  this->valid = _valid;
34 }
35 
36 void QValidatedLineEdit::focusInEvent(QFocusEvent *evt)
37 {
38  // Clear invalid flag on focus
39  setValid(true);
40 
41  QLineEdit::focusInEvent(evt);
42 }
43 
44 void QValidatedLineEdit::focusOutEvent(QFocusEvent *evt)
45 {
46  checkValidity();
47 
48  QLineEdit::focusOutEvent(evt);
49 }
50 
52 {
53  // As long as a user is typing ensure we display state as valid
54  setValid(true);
55 }
56 
58 {
59  setValid(true);
60  QLineEdit::clear();
61 }
62 
64 {
65  if (!enabled)
66  {
67  // A disabled QValidatedLineEdit should be marked valid
68  setValid(true);
69  }
70  else
71  {
72  // Recheck validity when QValidatedLineEdit gets enabled
73  checkValidity();
74  }
75 
76  QLineEdit::setEnabled(enabled);
77 }
78 
80 {
81  if (text().isEmpty())
82  {
83  setValid(true);
84  }
85  else if (hasAcceptableInput())
86  {
87  setValid(true);
88 
89  // Check contents on focus out
90  if (checkValidator)
91  {
92  QString address = text();
93  int pos = 0;
94  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
95  setValid(true);
96  else
97  setValid(false);
98  }
99  }
100  else
101  setValid(false);
102 
103  Q_EMIT validationDidChange(this);
104 }
105 
106 void QValidatedLineEdit::setCheckValidator(const QValidator *v)
107 {
108  checkValidator = v;
109 }
110 
112 {
113  // use checkValidator in case the QValidatedLineEdit is disabled
114  if (checkValidator)
115  {
116  QString address = text();
117  int pos = 0;
118  if (checkValidator->validate(address, pos) == QValidator::Acceptable)
119  return true;
120  }
121 
122  return valid;
123 }
false true true true
Definition: bls_dkg.cpp:176
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
void focusInEvent(QFocusEvent *evt)
QString getThemedStyleQString(ThemedStyle style)
Helper to get css style strings which are injected into rich text through qt.
Definition: guiutil.cpp:210
QValidatedLineEdit(QWidget *parent)
const QValidator * checkValidator
void focusOutEvent(QFocusEvent *evt)
void setCheckValidator(const QValidator *v)
void setEnabled(bool enabled)
void setValid(bool valid)
Released under the MIT license