diff --git a/src/comm/HexSpinBox.cpp b/src/comm/HexSpinBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..878e9409e6ca56e11b27fcc3bb6e4bdc2350ff9e --- /dev/null +++ b/src/comm/HexSpinBox.cpp @@ -0,0 +1,35 @@ +#include "HexSpinBox.h" + +#include + +HexSpinBox::HexSpinBox(QWidget *parent) + : QSpinBox(parent), validator(NULL) +{ + setRange(0, 0x7fffffff); + validator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"), this); +} + +HexSpinBox::~HexSpinBox(void) +{ + if(this->validator) + { + delete this->validator; + this->validator = NULL; + } +} + +QValidator::State HexSpinBox::validate(QString &text, int &pos) const +{ + return validator->validate(text, pos); +} + +QString HexSpinBox::textFromValue(int value) const +{ + return QString::number(value, 16).toUpper(); +} + +int HexSpinBox::valueFromText(const QString &text) const +{ + bool ok; + return text.toInt(&ok, 16); +} \ No newline at end of file diff --git a/src/comm/HexSpinBox.h b/src/comm/HexSpinBox.h new file mode 100644 index 0000000000000000000000000000000000000000..84703c95c79e94c931a850a3e64c2bd1cc7a0060 --- /dev/null +++ b/src/comm/HexSpinBox.h @@ -0,0 +1,25 @@ +#ifndef HEXSPINBOX_H_ +#define HEXSPINBOX_H_ + +#include + +class QRegExpValidator; + +class HexSpinBox : public QSpinBox +{ + Q_OBJECT +public: + HexSpinBox(QWidget *parent = 0); + ~HexSpinBox(void); + +protected: + QValidator::State validate(QString &text, int &pos) const; + int valueFromText(const QString &text) const; + QString textFromValue(int value) const; + +private: + QRegExpValidator *validator; +}; + +#endif // HEXSPINBOX_H_ +