1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #ifndef YQInputField_h
21 #define YQInputField_h
24 #include <qlineedit.h>
26 #include "YInputField.h"
29 class QY2CharValidator;
30 class YQWidgetCaption;
36 class YQInputField : public QFrame, public YInputField
44 YQInputField( YWidget * parent,
46 bool passwordMode = false );
49 * Get the current value (the text entered by the user or set from the
50 * outside) of this input field.
52 * Reimplemented from YInputField.
54 virtual string value();
57 * Set the current value (the text entered by the user or set from the
58 * outside) of this input field.
60 * Reimplemented from YInputField.
62 virtual void setValue( const string & text );
65 * Set the label (the caption above the input field).
67 * Reimplemented from YInputField.
69 virtual void setLabel( const string & label );
72 * Set the valid input characters. No input validation is performed (i.e.,
73 * the user can enter anything) if this is empty.
75 * Reimplemented from YInputField.
77 virtual void setValidChars( const string & validChars );
80 * Specify the amount of characters which can be inserted.
82 * Reimplemented from YInputField.
84 virtual void setInputMaxLength( int numberOfChars );
87 * Returns 'true' if a given text is valid according to ValidChars.
89 bool isValidText( const QString & text ) const;
92 * Set enabled/disabled state.
94 * Reimplemented from YWidget.
96 virtual void setEnabled( bool enabled );
99 * Preferred width of the widget.
101 * Reimplemented from YWidget.
103 virtual int preferredWidth();
106 * Preferred height of the widget.
108 * Reimplemented from YWidget.
110 virtual int preferredHeight();
113 * Set the new size of the widget.
115 * Reimplemented from YWidget.
117 virtual void setSize( int newWidth, int newHeight );
120 * Accept the keyboard focus.
122 * Reimplemented from YWidget.
124 virtual bool setKeyboardFocus();
129 * Triggered when the text in the InputField changes.
130 * This _may_ be of interest to the module.
132 void changed( const QString & );
135 * Display a warning that CapsLock is active:
136 * Replace the label with "CapsLock!"
138 void displayCapsLockWarning();
141 * Clear the CapsLock warning: Restore old label
143 void clearCapsLockWarning();
148 YQWidgetCaption * _caption;
149 YQRawLineEdit * _qt_lineEdit;
150 QY2CharValidator * _validator;
152 bool _displayingCapsLockWarning;
157 * Helper class that can obtain the CapsLock status, too.
158 * For some reason, Qt does not propagate that information from X11.
160 class YQRawLineEdit: public QLineEdit
169 YQRawLineEdit( QWidget * parent )
170 : QLineEdit( parent )
171 , _capsLockActive( false )
177 virtual ~YQRawLineEdit() {};
180 * Check if CapsLock is active
181 * (rather: was active at the time of the last key or focus event)
183 bool isCapsLockActive() const { return _capsLockActive; }
187 void capsLockActivated();
188 void capsLockDeactivated();
193 * X11 raw event handler. Propagates all events to the Qt event handlers,
194 * but updates _capsLockActive for key events.
196 * Reimplemented from QWidget.
198 bool x11Event( XEvent * event ) ;
202 bool _capsLockActive;
205 #endif // YQInputField_h