1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VirtualBox Qt extensions: QIWidgetValidator class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef __QIWidgetValidator_h__
|
---|
24 | #define __QIWidgetValidator_h__
|
---|
25 |
|
---|
26 | #include <limits.h>
|
---|
27 |
|
---|
28 | /* Qt includes */
|
---|
29 | #include <QObject>
|
---|
30 | #include <QValidator>
|
---|
31 | #include <QList>
|
---|
32 |
|
---|
33 | class QIWidgetValidator : public QObject
|
---|
34 | {
|
---|
35 | Q_OBJECT
|
---|
36 |
|
---|
37 | public:
|
---|
38 |
|
---|
39 | QIWidgetValidator (QWidget *aWidget, QObject *aParent = 0);
|
---|
40 | QIWidgetValidator (const QString &aCaption,
|
---|
41 | QWidget *aWidget, QObject *aParent = 0);
|
---|
42 | ~QIWidgetValidator();
|
---|
43 |
|
---|
44 | QWidget *widget() const { return mWidget; }
|
---|
45 | bool isValid() const;
|
---|
46 | void rescan();
|
---|
47 |
|
---|
48 | void setCaption (const QString& aCaption) { mCaption = aCaption; }
|
---|
49 | QString caption() const { return mCaption; }
|
---|
50 |
|
---|
51 | QString warningText() const;
|
---|
52 |
|
---|
53 | void setOtherValid (bool aValid) { mOtherValid = aValid; }
|
---|
54 | bool isOtherValid() const { return mOtherValid; }
|
---|
55 |
|
---|
56 | signals:
|
---|
57 |
|
---|
58 | void validityChanged (const QIWidgetValidator *aValidator);
|
---|
59 | void isValidRequested (QIWidgetValidator *aValidator);
|
---|
60 |
|
---|
61 | public slots:
|
---|
62 |
|
---|
63 | void revalidate() { doRevalidate(); }
|
---|
64 |
|
---|
65 | private:
|
---|
66 |
|
---|
67 | QString mCaption;
|
---|
68 | QWidget *mWidget;
|
---|
69 | bool mOtherValid;
|
---|
70 |
|
---|
71 | struct Watched
|
---|
72 | {
|
---|
73 | Watched()
|
---|
74 | : widget (NULL), buddy (NULL)
|
---|
75 | , state (QValidator::Acceptable) {}
|
---|
76 |
|
---|
77 | QWidget *widget;
|
---|
78 | QWidget *buddy;
|
---|
79 | QValidator::State state;
|
---|
80 | };
|
---|
81 |
|
---|
82 | QList <Watched> mWatched;
|
---|
83 | Watched mLastInvalid;
|
---|
84 |
|
---|
85 | private slots:
|
---|
86 |
|
---|
87 | void doRevalidate() { emit validityChanged (this); }
|
---|
88 | };
|
---|
89 |
|
---|
90 | class QIULongValidator : public QValidator
|
---|
91 | {
|
---|
92 | public:
|
---|
93 |
|
---|
94 | QIULongValidator (QObject *aParent)
|
---|
95 | : QValidator (aParent)
|
---|
96 | , mBottom (0), mTop (ULONG_MAX) {}
|
---|
97 |
|
---|
98 | QIULongValidator (ulong aMinimum, ulong aMaximum,
|
---|
99 | QObject *aParent)
|
---|
100 | : QValidator (aParent)
|
---|
101 | , mBottom (aMinimum), mTop (aMaximum) {}
|
---|
102 |
|
---|
103 | ~QIULongValidator() {}
|
---|
104 |
|
---|
105 | State validate (QString &aInput, int &aPos) const;
|
---|
106 | void setBottom (ulong aBottom) { setRange (aBottom, mTop); }
|
---|
107 | void setTop (ulong aTop) { setRange (mBottom, aTop); }
|
---|
108 | void setRange (ulong aBottom, ulong aTop) { mBottom = aBottom; mTop = aTop; }
|
---|
109 | ulong bottom() const { return mBottom; }
|
---|
110 | ulong top() const { return mTop; }
|
---|
111 |
|
---|
112 | private:
|
---|
113 |
|
---|
114 | ulong mBottom;
|
---|
115 | ulong mTop;
|
---|
116 | };
|
---|
117 |
|
---|
118 | #endif // __QIWidgetValidator_h__
|
---|
119 |
|
---|