-
Notifications
You must be signed in to change notification settings - Fork 0
/
asciispinbox.cpp
executable file
·70 lines (54 loc) · 1.35 KB
/
asciispinbox.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "asciispinbox.h"
#include "asciiwidget.h"
#include <QTextCodec>
AsciiSpinBox::AsciiSpinBox(QWidget *parent):QSpinBox(parent)
{
setRange(0, 255);
QFont font;
font.setFamily("arial");
font.setBold(false);
font.setPointSize(12);
this->setFont(font);
}
AsciiSpinBox::~AsciiSpinBox()
{
}
void AsciiSpinBox::focusInEvent ( QFocusEvent * event )
{
}
QString AsciiSpinBox::textFromValue(int value) const
{
char asciiLetter[2];
asciiLetter[0] = value;
asciiLetter[1] = '\0';
QTextCodec* codec = QTextCodec::codecForName("IBM 850");
QString str = codec->toUnicode(asciiLetter);
if( ( value >= 0 && value <= 31 ) || value == 127)
{
return AsciiWidget::asciiControlCharacters(value);
}
else
{
return str;
}
}
int AsciiSpinBox::valueFromText(const QString &text) const
{
for (int i = 0 ; i < 256 ; i++)
{
char asciiLetter[2];
asciiLetter[0] = i;
asciiLetter[1] = '\0';
QTextCodec* codec = QTextCodec::codecForName("IBM 850");
QString str = codec->toUnicode(asciiLetter);
if ( text == str)
{
return i;
}
}
return 0;
}
QValidator::State AsciiSpinBox::validate(QString &text, int &pos) const
{
return QValidator::Acceptable;
}