Line | |
---|
1 | #ifndef FACT_SpinBox4ns
|
---|
2 | #define FACT_SpinBox4ns
|
---|
3 |
|
---|
4 | #include <QtGui/QSpinBox>
|
---|
5 |
|
---|
6 | class SpinBox4ns : public QSpinBox
|
---|
7 | {
|
---|
8 | public:
|
---|
9 | SpinBox4ns(QWidget *p) : QSpinBox(p)
|
---|
10 | {
|
---|
11 | }
|
---|
12 |
|
---|
13 | QValidator::State validate(QString &input, int &p) const
|
---|
14 | {
|
---|
15 | const QValidator::State rc = QSpinBox::validate(input, p);
|
---|
16 | if (rc!=QValidator::Acceptable)
|
---|
17 | return rc;
|
---|
18 |
|
---|
19 | const int pf = prefix().length();
|
---|
20 | const int sf = suffix().length();
|
---|
21 | const int len = input.length();
|
---|
22 |
|
---|
23 | return input.mid(pf, len-sf-pf).toUInt()%4==0 ? QValidator::Acceptable : QValidator::Intermediate;
|
---|
24 | }
|
---|
25 |
|
---|
26 | void fixup(QString &input) const
|
---|
27 | {
|
---|
28 | const int pf = prefix().length();
|
---|
29 | const int sf = suffix().length();
|
---|
30 | const int len = input.length();
|
---|
31 |
|
---|
32 | const uint i = input.mid(pf, len-pf-sf).toUInt()+2;
|
---|
33 | input = QString::number((i/4)*4);
|
---|
34 | }
|
---|
35 | };
|
---|
36 |
|
---|
37 | #endif
|
---|
38 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.