[go: up one dir, main page]

Menu

[735b18]: / floatedit.cpp  Maximize  Restore  History

Download this file

41 lines (36 with data), 741 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "floatedit.h"
#include "validators.h"
#include "types.h"
#include <QDebug>
FloatEdit::FloatEdit()
: QLineEdit()
{
val = new FloatValidator;
setValidator(val);
setToolTip(tr("Enter an float value or 0xDEADBEEF (8 hex nibbles)"));
}
bool FloatEdit::isValid()
{
QString t=text();
int pos=0;
return val->validate(t,pos) == QValidator::Acceptable;
}
int FloatEdit::value()
{
bool ok;
QString t = text();
AllTypes x;
x.i8 = 0;
if ( t.left(2) == "0x" || t.left(2) == "0X" ) {
x.i8 = t.mid(2).toLong(&ok,16);
} else {
x.f4 = t.toFloat();
}
return x.i4;
}
void FloatEdit::setValue(int n)
{
QString number;
number.sprintf("0x%08x",n);
setText(number);
}