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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* innotek Qt extensions: QIWidgetValidator class declaration
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef __QIWidgetValidator_h__
#define __QIWidgetValidator_h__
#include <limits.h>
#include <qobject.h>
#include <qvalidator.h>
#include <qvaluelist.h>
class QIWidgetValidator : public QObject
{
Q_OBJECT
public:
QIWidgetValidator (QWidget *aWidget, QObject *aParent = 0,
const char *aName = 0);
QIWidgetValidator (const QString &aCaption,
QWidget *aWidget, QObject *aParent = 0,
const char *aName = 0);
~QIWidgetValidator();
QWidget *widget() const { return mWidget; }
bool isValid() const;
void rescan();
QString warningText() const;
void setOtherValid (bool aValid) { mOtherValid = aValid; }
bool isOtherValid() const { return mOtherValid; }
signals:
void validityChanged (const QIWidgetValidator *aValidator);
void isValidRequested (QIWidgetValidator *aValidator);
public slots:
void revalidate() { doRevalidate(); }
private:
QString mCaption;
QWidget *mWidget;
bool mOtherValid;
struct Watched
{
Watched()
: widget (NULL), buddy (NULL)
, state (QValidator::Acceptable) {}
QWidget *widget;
QWidget *buddy;
QValidator::State state;
};
QValueList <Watched> mWatched;
Watched mLastInvalid;
private slots:
void doRevalidate() { emit validityChanged (this); }
};
class QIULongValidator : public QValidator
{
public:
QIULongValidator (QObject *aParent, const char *aName = 0)
: QValidator (aParent, aName)
, mBottom (0), mTop (ULONG_MAX) {}
QIULongValidator (ulong aMinimum, ulong aMaximum,
QObject *aParent, const char *aName = 0)
: QValidator (aParent, aName)
, mBottom (aMinimum), mTop (aMaximum) {}
~QIULongValidator() {}
State validate (QString &aInput, int &aPos) const;
void setBottom (ulong aBottom) { setRange (aBottom, mTop); }
void setTop (ulong aTop) { setRange (mBottom, aTop); }
void setRange (ulong aBottom, ulong aTop) { mBottom = aBottom; mTop = aTop; }
ulong bottom() const { return mBottom; }
ulong top() const { return mTop; }
private:
ulong mBottom;
ulong mTop;
};
#endif // __QIWidgetValidator_h__
|