libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YQInputField.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 00026 #ifndef YQInputField_h 00027 #define YQInputField_h 00028 00029 #include <QFrame> 00030 #include <qlineedit.h> 00031 00032 #include <yui/YInputField.h> 00033 00034 class QString; 00035 class QY2CharValidator; 00036 class YQWidgetCaption; 00037 class YQRawLineEdit; 00038 00039 using std::string; 00040 00041 00042 class YQInputField : public QFrame, public YInputField 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 /** 00048 * Constructor. 00049 **/ 00050 YQInputField( YWidget * parent, 00051 const std::string & label, 00052 bool passwordMode = false ); 00053 00054 /** 00055 * Get the current value (the text entered by the user or set from the 00056 * outside) of this input field. 00057 * 00058 * Reimplemented from YInputField. 00059 **/ 00060 virtual std::string value(); 00061 00062 /** 00063 * Set the current value (the text entered by the user or set from the 00064 * outside) of this input field. 00065 * 00066 * Reimplemented from YInputField. 00067 **/ 00068 virtual void setValue( const std::string & text ); 00069 00070 /** 00071 * Set the label (the caption above the input field). 00072 * 00073 * Reimplemented from YInputField. 00074 **/ 00075 virtual void setLabel( const std::string & label ); 00076 00077 /** 00078 * Set the valid input characters. No input validation is performed (i.e., 00079 * the user can enter anything) if this is empty. 00080 * 00081 * Reimplemented from YInputField. 00082 **/ 00083 virtual void setValidChars( const std::string & validChars ); 00084 00085 /** 00086 * Specify the amount of characters which can be inserted. 00087 * 00088 * Reimplemented from YInputField. 00089 **/ 00090 virtual void setInputMaxLength( int numberOfChars ); 00091 00092 /** 00093 * Returns 'true' if a given text is valid according to ValidChars. 00094 **/ 00095 bool isValidText( const QString & text ) const; 00096 00097 /** 00098 * Set enabled/disabled state. 00099 * 00100 * Reimplemented from YWidget. 00101 **/ 00102 virtual void setEnabled( bool enabled ); 00103 00104 /** 00105 * Preferred width of the widget. 00106 * 00107 * Reimplemented from YWidget. 00108 **/ 00109 virtual int preferredWidth(); 00110 00111 /** 00112 * Preferred height of the widget. 00113 * 00114 * Reimplemented from YWidget. 00115 **/ 00116 virtual int preferredHeight(); 00117 00118 /** 00119 * Set the new size of the widget. 00120 * 00121 * Reimplemented from YWidget. 00122 **/ 00123 virtual void setSize( int newWidth, int newHeight ); 00124 00125 /** 00126 * Accept the keyboard focus. 00127 * 00128 * Reimplemented from YWidget. 00129 **/ 00130 virtual bool setKeyboardFocus(); 00131 00132 00133 protected slots: 00134 /** 00135 * Triggered when the text in the InputField changes. 00136 * This _may_ be of interest to the module. 00137 **/ 00138 void changed( const QString & ); 00139 00140 /** 00141 * Display a warning that CapsLock is active: 00142 * Replace the label with "CapsLock!" 00143 **/ 00144 void displayCapsLockWarning(); 00145 00146 /** 00147 * Clear the CapsLock warning: Restore old label 00148 **/ 00149 void clearCapsLockWarning(); 00150 00151 00152 protected: 00153 00154 YQWidgetCaption * _caption; 00155 YQRawLineEdit * _qt_lineEdit; 00156 QY2CharValidator * _validator; 00157 bool _shrinkable; 00158 bool _displayingCapsLockWarning; 00159 }; 00160 00161 00162 /** 00163 * Helper class that can obtain the CapsLock status, too. 00164 * For some reason, Qt does not propagate that information from X11. 00165 **/ 00166 class YQRawLineEdit: public QLineEdit 00167 { 00168 Q_OBJECT 00169 00170 public: 00171 00172 /** 00173 * Constructor 00174 **/ 00175 YQRawLineEdit( QWidget * parent ) 00176 : QLineEdit( parent ) 00177 , _capsLockActive( false ) 00178 {} 00179 00180 /** 00181 * Destructor 00182 **/ 00183 virtual ~YQRawLineEdit() {}; 00184 00185 /** 00186 * Check if CapsLock is active 00187 * (rather: was active at the time of the last key or focus event) 00188 **/ 00189 bool isCapsLockActive() const { return _capsLockActive; } 00190 00191 00192 signals: 00193 void capsLockActivated(); 00194 void capsLockDeactivated(); 00195 00196 protected: 00197 00198 /** 00199 * X11 raw event handler. Propagates all events to the Qt event handlers, 00200 * but updates _capsLockActive for key events. 00201 * 00202 * Reimplemented from QWidget. 00203 **/ 00204 bool x11Event( XEvent * event ) ; 00205 00206 private: 00207 00208 bool _capsLockActive; 00209 }; 00210 00211 #endif // YQInputField_h