Fabcoin Core  0.16.2
P2P Digital Currency
abiparamitem.cpp
Go to the documentation of this file.
1 #include <abiparamitem.h>
2 #include <contractabi.h>
3 #include <platformstyle.h>
4 
5 #include <QHBoxLayout>
6 #include <QRegularExpressionValidator>
7 
8 ABIParamItem::ABIParamItem(const PlatformStyle *platformStyle, const ParameterABI &param, QWidget *parent) :
9  QWidget(parent),
10  m_buttonAdd(new QToolButton(this)),
11  m_buttonRemove(new QToolButton(this)),
12  m_itemValue(new QValidatedLineEdit(this)),
13  m_isDeleted(false)
14 {
15  QHBoxLayout *mainLayout = new QHBoxLayout(this);
16  mainLayout->setSpacing(2);
17  mainLayout->setContentsMargins(0,0,0,0);
18 
19  m_buttonAdd->setIcon(platformStyle->MultiStatesIcon(":/icons/add", PlatformStyle::PushButton));
20  m_buttonRemove->setIcon(platformStyle->MultiStatesIcon(":/icons/remove", PlatformStyle::PushButton));
21 
22  m_buttonAdd->setFixedSize(30,30);
23  m_buttonRemove->setFixedSize(30,30);
24 
25  m_buttonAdd->setFocusPolicy(Qt::NoFocus);
26  m_buttonRemove->setFocusPolicy(Qt::NoFocus);
27 
28  QRegularExpression regEx;
30  {
31  QRegularExpressionValidator *validator = new QRegularExpressionValidator(m_itemValue);
32  validator->setRegularExpression(regEx);
34  m_itemValue->setCheckValidator(validator);
35  }
36 
37  mainLayout->addWidget(m_buttonAdd);
38  mainLayout->addWidget(m_buttonRemove);
39  mainLayout->addWidget(m_itemValue);
40  setLayout(mainLayout);
41 
42  connect(m_buttonAdd, SIGNAL(clicked(bool)), this, SLOT(on_addItemClicked()));
43  connect(m_buttonRemove, SIGNAL(clicked(bool)), this, SLOT(on_removeItemClicked()));
44 }
45 
47 {
48  return m_itemValue->text();
49 }
50 
51 void ABIParamItem::setFixed(bool isFixed)
52 {
53  m_buttonAdd->setVisible(!isFixed);
54  m_buttonRemove->setVisible(!isFixed);
55 }
56 
58 {
59  return m_position;
60 }
61 
62 void ABIParamItem::setPosition(int position)
63 {
64  m_position = position;
65 }
66 
68 {
69  Q_EMIT on_addItemClicked(m_position + 1);
70 }
71 
73 {
75 }
76 
78 {
79  return m_isDeleted;
80 }
81 
82 void ABIParamItem::setIsDeleted(bool isDeleted)
83 {
84  m_isDeleted= isDeleted;
85  if(isDeleted)
86  {
87  m_itemValue->setText("");
88  m_itemValue->setValid(true);
89  }
90  m_itemValue->setVisible(!isDeleted);
91  m_buttonRemove->setEnabled(!isDeleted);
92 }
93 
95 {
97  return m_itemValue->isValid();
98 }
QValidatedLineEdit * m_itemValue
Definition: abiparamitem.h:40
QToolButton * m_buttonAdd
Definition: abiparamitem.h:38
Line edit that can be marked as "invalid" to show input validation feedback.
bool getIsDeleted() const
QToolButton * m_buttonRemove
Definition: abiparamitem.h:39
void setEmptyIsValid(bool value)
int getPosition() const
ABIParamItem(const PlatformStyle *platformStyle, const ParameterABI &param, QWidget *parent=0)
Definition: abiparamitem.cpp:8
bool m_isDeleted
Definition: abiparamitem.h:42
QString getValue()
const ParameterType & decodeType() const
static bool getRegularExpession(const ParameterType &paramType, QRegularExpression &regEx)
QIcon MultiStatesIcon(const QString &resourcename, StateType type=NavBar, QColor color=Qt::white, QColor colorAlt=0x2d2d2d) const
Get multi-states icon.
void setFixed(bool isFixed)
void on_removeItemClicked()
void setCheckValidator(const QValidator *v)
void setIsDeleted(bool isLast)
void setValid(bool valid)
void setPosition(int position)
void on_addItemClicked()