libyui-qt  2.47.1.1
YQInputField.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQInputField.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQInputField_h
27 #define YQInputField_h
28 
29 #include <QFrame>
30 #include <qlineedit.h>
31 
32 #include <yui/YInputField.h>
33 
34 typedef union _XEvent XEvent;
35 class QString;
36 class QY2CharValidator;
37 class YQWidgetCaption;
38 class YQRawLineEdit;
39 
40 using std::string;
41 
42 
43 class YQInputField : public QFrame, public YInputField
44 {
45  Q_OBJECT
46 
47 public:
48  /**
49  * Constructor.
50  **/
51  YQInputField( YWidget * parent,
52  const std::string & label,
53  bool passwordMode = false );
54 
55  /**
56  * Get the current value (the text entered by the user or set from the
57  * outside) of this input field.
58  *
59  * Reimplemented from YInputField.
60  **/
61  virtual std::string value();
62 
63  /**
64  * Set the current value (the text entered by the user or set from the
65  * outside) of this input field.
66  *
67  * Reimplemented from YInputField.
68  **/
69  virtual void setValue( const std::string & text );
70 
71  /**
72  * Set the label (the caption above the input field).
73  *
74  * Reimplemented from YInputField.
75  **/
76  virtual void setLabel( const std::string & label );
77 
78  /**
79  * Set the valid input characters. No input validation is performed (i.e.,
80  * the user can enter anything) if this is empty.
81  *
82  * Reimplemented from YInputField.
83  **/
84  virtual void setValidChars( const std::string & validChars );
85 
86  /**
87  * Specify the amount of characters which can be inserted.
88  *
89  * Reimplemented from YInputField.
90  **/
91  virtual void setInputMaxLength( int numberOfChars );
92 
93  /**
94  * Returns 'true' if a given text is valid according to ValidChars.
95  **/
96  bool isValidText( const QString & text ) const;
97 
98  /**
99  * Set enabled/disabled state.
100  *
101  * Reimplemented from YWidget.
102  **/
103  virtual void setEnabled( bool enabled );
104 
105  /**
106  * Preferred width of the widget.
107  *
108  * Reimplemented from YWidget.
109  **/
110  virtual int preferredWidth();
111 
112  /**
113  * Preferred height of the widget.
114  *
115  * Reimplemented from YWidget.
116  **/
117  virtual int preferredHeight();
118 
119  /**
120  * Set the new size of the widget.
121  *
122  * Reimplemented from YWidget.
123  **/
124  virtual void setSize( int newWidth, int newHeight );
125 
126  /**
127  * Accept the keyboard focus.
128  *
129  * Reimplemented from YWidget.
130  **/
131  virtual bool setKeyboardFocus();
132 
133 
134 protected slots:
135  /**
136  * Triggered when the text in the InputField changes.
137  * This _may_ be of interest to the module.
138  **/
139  void changed( const QString & );
140 
141  /**
142  * Display a warning that CapsLock is active:
143  * Replace the label with "CapsLock!"
144  **/
145  void displayCapsLockWarning();
146 
147  /**
148  * Clear the CapsLock warning: Restore old label
149  **/
150  void clearCapsLockWarning();
151 
152 
153 protected:
154 
155  YQWidgetCaption * _caption;
156  YQRawLineEdit * _qt_lineEdit;
157  QY2CharValidator * _validator;
158  bool _shrinkable;
159  bool _displayingCapsLockWarning;
160 };
161 
162 
163 /**
164  * Helper class that can obtain the CapsLock status, too.
165  * For some reason, Qt does not propagate that information from X11.
166  **/
167 class YQRawLineEdit: public QLineEdit
168 {
169  Q_OBJECT
170 
171 public:
172 
173  /**
174  * Constructor
175  **/
176  YQRawLineEdit( QWidget * parent )
177  : QLineEdit( parent )
178  , _capsLockActive( false )
179  {}
180 
181  /**
182  * Destructor
183  **/
184  virtual ~YQRawLineEdit() {};
185 
186  /**
187  * Check if CapsLock is active
188  * (rather: was active at the time of the last key or focus event)
189  **/
190  bool isCapsLockActive() const { return _capsLockActive; }
191 
192 
193 signals:
194  void capsLockActivated();
195  void capsLockDeactivated();
196 
197 protected:
198 
199  /**
200  * X11 raw event handler. Propagates all events to the Qt event handlers,
201  * but updates _capsLockActive for key events.
202  *
203  * Reimplemented from QWidget.
204  **/
205  bool x11Event( XEvent * event ) ;
206 
207 private:
208 
209  bool _capsLockActive;
210 };
211 
212 #endif // YQInputField_h
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void setValue(const std::string &text)
Set the current value (the text entered by the user or set from the outside) of this input field...
YQInputField(YWidget *parent, const std::string &label, bool passwordMode=false)
Constructor.
Definition: YQInputField.cc:55
Helper class that can obtain the CapsLock status, too.
Definition: YQInputField.h:167
bool isValidText(const QString &text) const
Returns &#39;true&#39; if a given text is valid according to ValidChars.
YQRawLineEdit(QWidget *parent)
Constructor.
Definition: YQInputField.h:176
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
virtual void setInputMaxLength(int numberOfChars)
Specify the amount of characters which can be inserted.
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
virtual int preferredWidth()
Preferred width of the widget.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual ~YQRawLineEdit()
Destructor.
Definition: YQInputField.h:184
virtual void setValidChars(const std::string &validChars)
Set the valid input characters.
void displayCapsLockWarning()
Display a warning that CapsLock is active: Replace the label with "CapsLock!".
virtual int preferredHeight()
Preferred height of the widget.
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
bool isCapsLockActive() const
Check if CapsLock is active (rather: was active at the time of the last key or focus event) ...
Definition: YQInputField.h:190
void clearCapsLockWarning()
Clear the CapsLock warning: Restore old label.
virtual std::string value()
Get the current value (the text entered by the user or set from the outside) of this input field...
Definition: YQInputField.cc:97
void changed(const QString &)
Triggered when the text in the InputField changes.