![]() |
Mixxx
|
00001 #include <qvalidator.h> 00002 00003 #include "hexspinbox.h" 00004 00005 HexSpinBox::HexSpinBox(QWidget *parent) 00006 : QSpinBox(parent) 00007 { 00008 00009 setRange(0, 255); 00010 } 00011 00012 QString HexSpinBox::textFromValue(int value) const 00013 { 00014 //Construct a hex string formatted like 0x0f. 00015 return QString("0x") + QString("%1").arg(value, 00016 2, //Field width (makes "F" become "0F") 00017 16, 00018 QLatin1Char('0')).toUpper(); 00019 } 00020 00021 int HexSpinBox::valueFromText(const QString& text) const 00022 { 00023 bool ok; 00024 return text.toInt(&ok, 16); 00025 } 00026 00027 QValidator::State HexSpinBox::validate ( QString & input, int & pos ) const 00028 { 00029 const QRegExp regExp("^0(x|X)[0-9A-Fa-f]+"); 00030 QRegExpValidator validator(regExp, NULL); 00031 return validator.validate(input, pos); 00032 }