source: branches/testFACT++branch/gui/SpinBox4ns.h@ 20115

Last change on this file since 20115 was 10659, checked in by tbretz, 14 years ago
Added or improved documentation.
File size: 1.1 KB
Line 
1#ifndef FACT_SpinBox4ns
2#define FACT_SpinBox4ns
3
4#include <QSpinBox>
5
6class SpinBox4ns : public QSpinBox
7{
8public:
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
39// **************************************************************************
40/** @class SpinBox4ns
41
42@brief A QSpinBox which only accepts values dividable by 4
43
44*/
45// **************************************************************************
Note: See TracBrowser for help on using the repository browser.