AddressLineEdit.hpp
1 #pragma once
2 #include "AddressValidator.hpp"
3 
4 #include <State/MessageListSerialization.hpp>
5 #include <State/Widgets/AddressValidator.hpp>
6 
7 #include <QDropEvent>
8 #include <QLineEdit>
9 #include <QPalette>
10 #include <QValidator>
11 
12 namespace State
13 {
19 template <class Validator_T, class Parent_T>
20 class AddressLineEditBase : public QLineEdit
21 {
22 public:
23  explicit AddressLineEditBase(Parent_T* parent)
24  : QLineEdit{parent}
25  {
26  setAcceptDrops(true);
27  setMinimumHeight(24);
28  connect(this, &QLineEdit::textChanged, this, [&](const QString& str) {
29  QString s = str;
30  int i = 0;
31  QPalette palette{this->palette()};
32  if(m_validator.validate(s, i) == QValidator::State::Acceptable)
33  {
34  palette.setColor(QPalette::Base, QColor{"#161514"});
35  palette.setColor(QPalette::Light, QColor{"#c58014"});
36  palette.setColor(QPalette::Midlight, QColor{"#161514"});
37  }
38  else
39  {
40  palette.setColor(QPalette::Base, QColor{"#300000"});
41  palette.setColor(QPalette::Light, QColor{"#660000"});
42  palette.setColor(QPalette::Midlight, QColor{"#500000"});
43  }
44  this->setPalette(palette);
45  });
46  }
47 
48 private:
49  void dragEnterEvent(QDragEnterEvent* ev) override
50  {
51  static_cast<Parent_T*>(parent())->dragEnterEvent(ev);
52  }
53  void dropEvent(QDropEvent* ev) override
54  {
55  static_cast<Parent_T*>(parent())->dropEvent(ev);
56  }
57 
58  Validator_T m_validator;
59 };
60 
61 template <typename Parent_T>
62 class AddressLineEdit final : public AddressLineEditBase<AddressValidator, Parent_T>
63 {
64 public:
66 };
67 
68 template <typename Parent_T>
70  : public AddressLineEditBase<AddressAccessorValidator, Parent_T>
71 {
72 public:
74 };
75 }
Definition: AddressLineEdit.hpp:71
The AddressLineEdit class.
Definition: AddressLineEdit.hpp:21
Definition: AddressLineEdit.hpp:63
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33