28 #include <qlineedit.h> 29 #define YUILogComponent "qt-ui" 30 #include <yui/YUILog.h> 34 #include <yui/YEvent.h> 35 #include "QY2CharValidator.h" 36 #include "YQInputField.h" 38 #include "YQSignalBlocker.h" 39 #include "YQWidgetCaption.h" 40 #include <QVBoxLayout> 47 #include <X11/keysym.h> 56 : QFrame( (QWidget *) parent->widgetRep() )
57 , YInputField( parent, label, passwordMode )
59 , _displayingCapsLockWarning( false )
61 QVBoxLayout* layout =
new QVBoxLayout(
this );
66 layout->setSpacing( YQWidgetSpacing );
67 layout->setMargin( YQWidgetMargin );
70 YUI_CHECK_NEW( _caption );
71 layout->addWidget( _caption );
74 YUI_CHECK_NEW( _qt_lineEdit );
75 layout->addWidget( _qt_lineEdit );
77 _caption->setBuddy( _qt_lineEdit );
79 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::textChanged,
84 _qt_lineEdit->setEchoMode( QLineEdit::Password );
86 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockActivated,
89 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockDeactivated,
97 return toUTF8( _qt_lineEdit->text() );
103 QString text = fromUTF8( newText );
108 _qt_lineEdit->setText( text );
112 yuiError() <<
this <<
": Rejecting invalid value \"" << newText <<
"\"" << endl;
119 _qt_lineEdit->setEnabled( enabled );
120 _caption->setEnabled( enabled );
121 YWidget::setEnabled( enabled );
127 int minSize = shrinkable() ? 30 : 200;
128 int hintWidth = !_caption->isHidden()
129 ? _caption->sizeHint().width() + 2 * YQWidgetMargin
132 return std::max( minSize, hintWidth );
138 return sizeHint().height();
144 resize( newWidth, newHeight );
151 YInputField::setLabel( label );
163 return _validator->
validate( text, pos ) == QValidator::Acceptable;
176 _qt_lineEdit->setValidator( _validator );
184 yuiError() <<
this <<
": Old value \"" << _qt_lineEdit->text()
185 <<
"\" invalid according to new ValidChars \"" << newValidChars
189 _qt_lineEdit->setText(
"" );
192 YInputField::setValidChars( newValidChars );
197 _qt_lineEdit->setMaxLength( len );
198 YInputField::setInputMaxLength( len );
203 _qt_lineEdit->setFocus();
204 _qt_lineEdit->selectAll();
219 yuiMilestone() <<
"warning" << endl;
220 if ( _displayingCapsLockWarning )
223 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
236 _caption->
setText( _(
"CapsLock!" ) );
237 _displayingCapsLockWarning =
true;
243 yuiMilestone() <<
"warning off " << endl;
244 if ( ! _displayingCapsLockWarning )
247 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
251 _displayingCapsLockWarning =
false;
267 bool oldCapsLockActive = _capsLockActive;
269 switch ( event->type )
272 _capsLockActive = (bool) ( event->xkey.state & LockMask );
277 _capsLockActive = (bool) ( event->xkey.state & LockMask );
279 if ( _capsLockActive && oldCapsLockActive )
281 KeySym key = XLookupKeysym( &(event->xkey), 0 );
283 if ( key == XK_Caps_Lock ||
284 key == XK_Shift_Lock )
286 yuiMilestone() <<
"CapsLock released" << endl;
287 _capsLockActive =
false;
291 if ( _capsLockActive )
292 yuiDebug() <<
"Key event; caps lock: " 293 << std::boolalpha << _capsLockActive << std::noboolalpha
299 _capsLockActive = (bool) ( event->xbutton.state & LockMask );
303 _capsLockActive = (bool) ( event->xcrossing.state & LockMask );
308 _capsLockActive =
false;
309 emit capsLockDeactivated();
316 if ( oldCapsLockActive != _capsLockActive )
318 yuiMilestone() <<
"Emitting warning" << endl;
320 if ( _capsLockActive )
321 emit capsLockActivated();
323 emit capsLockDeactivated();
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
Helper class that can obtain the CapsLock status, too.
bool x11Event(XEvent *event)
X11 raw event handler.
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
void setValidChars(const QString &newValidChars)
Set the valid input characters.
virtual State validate(QString &input, int &pos) const
Check user input.
static YQUI * ui()
Access the global Qt-UI.