]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQInputField.h
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / YQInputField.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQInputField.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQInputField_h
21 #define YQInputField_h
22
23 #include <QFrame>
24 #include <qlineedit.h>
25
26 #include "YInputField.h"
27
28 class QString;
29 class QY2CharValidator;
30 class YQWidgetCaption;
31 class YQRawLineEdit;
32
33 using std::string;
34
35
36 class YQInputField : public QFrame, public YInputField
37 {
38     Q_OBJECT
39
40 public:
41     /**
42      * Constructor.
43      **/
44     YQInputField( YWidget *             parent,
45                   const string &        label,
46                   bool                  passwordMode = false );
47
48     /**
49      * Get the current value (the text entered by the user or set from the
50      * outside) of this input field.
51      *
52      * Reimplemented from YInputField.
53      **/
54     virtual string value();
55
56     /**
57      * Set the current value (the text entered by the user or set from the
58      * outside) of this input field.
59      *
60      * Reimplemented from YInputField.
61      **/
62     virtual void setValue( const string & text );
63
64     /**
65      * Set the label (the caption above the input field).
66      *
67      * Reimplemented from YInputField.
68      **/
69     virtual void setLabel( const string & label );
70
71     /**
72      * Set the valid input characters. No input validation is performed (i.e.,
73      * the user can enter anything) if this is empty.
74      *
75      * Reimplemented from YInputField.
76      **/
77     virtual void setValidChars( const string & validChars );
78
79     /**
80      * Specify the amount of characters which can be inserted.
81      *
82      * Reimplemented from YInputField.
83      **/
84     virtual void setInputMaxLength( int numberOfChars );
85
86     /**
87      * Returns 'true' if a given text is valid according to ValidChars.
88      **/
89     bool isValidText( const QString & text ) const;
90
91     /**
92      * Set enabled/disabled state.
93      *
94      * Reimplemented from YWidget.
95      **/
96     virtual void setEnabled( bool enabled );
97
98     /**
99      * Preferred width of the widget.
100      *
101      * Reimplemented from YWidget.
102      **/
103     virtual int preferredWidth();
104
105     /**
106      * Preferred height of the widget.
107      *
108      * Reimplemented from YWidget.
109      **/
110     virtual int preferredHeight();
111
112     /**
113      * Set the new size of the widget.
114      *
115      * Reimplemented from YWidget.
116      **/
117     virtual void setSize( int newWidth, int newHeight );
118
119     /**
120      * Accept the keyboard focus.
121      *
122      * Reimplemented from YWidget.
123      **/
124     virtual bool setKeyboardFocus();
125
126
127 protected slots:
128     /**
129      * Triggered when the text in the InputField changes.
130      * This _may_ be of interest to the module.
131      **/
132     void changed( const QString & );
133
134     /**
135      * Display a warning that CapsLock is active:
136      * Replace the label with "CapsLock!"
137      **/
138     void displayCapsLockWarning();
139
140     /**
141      * Clear the CapsLock warning: Restore old label
142      **/
143     void clearCapsLockWarning();
144
145
146 protected:
147
148     YQWidgetCaption *   _caption;
149     YQRawLineEdit *     _qt_lineEdit;
150     QY2CharValidator *  _validator;
151     bool                _shrinkable;
152     bool                _displayingCapsLockWarning;
153 };
154
155
156 /**
157  * Helper class that can obtain the CapsLock status, too.
158  * For some reason, Qt does not propagate that information from X11.
159  **/
160 class YQRawLineEdit: public QLineEdit
161 {
162     Q_OBJECT
163
164 public:
165
166     /**
167      * Constructor
168      **/
169     YQRawLineEdit( QWidget * parent )
170         : QLineEdit( parent )
171         , _capsLockActive( false )
172         {}
173
174     /**
175      * Destructor
176      **/
177     virtual ~YQRawLineEdit() {};
178
179     /**
180      * Check if CapsLock is active
181      * (rather: was active at the time of the last key or focus event)
182      **/
183     bool isCapsLockActive() const { return _capsLockActive; }
184
185
186 signals:
187     void capsLockActivated();
188     void capsLockDeactivated();
189
190 protected:
191
192     /**
193      * X11 raw event handler. Propagates all events to the Qt event handlers,
194      * but updates _capsLockActive for key events.
195      *
196      * Reimplemented from QWidget.
197      **/
198     bool x11Event( XEvent * event ) ;
199
200 private:
201
202     bool _capsLockActive;
203 };
204
205 #endif // YQInputField_h