28 #include <qlineedit.h> 29 #define YUILogComponent "qt-ui" 30 #include <yui/YUILog.h> 36 #include <yui/YEvent.h> 37 #include "QY2CharValidator.h" 38 #include "YQInputField.h" 40 #include "YQSignalBlocker.h" 41 #include "YQWidgetCaption.h" 42 #include <QVBoxLayout> 49 #include <X11/keysym.h> 56 const std::string & label,
58 : QFrame( (QWidget *) parent->widgetRep() )
59 , YInputField( parent, label, passwordMode )
61 , _displayingCapsLockWarning( false )
63 QVBoxLayout* layout =
new QVBoxLayout(
this );
68 layout->setSpacing( YQWidgetSpacing );
69 layout->setMargin( YQWidgetMargin );
72 YUI_CHECK_NEW( _caption );
73 layout->addWidget( _caption );
76 YUI_CHECK_NEW( _qt_lineEdit );
77 layout->addWidget( _qt_lineEdit );
79 _caption->setBuddy( _qt_lineEdit );
81 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::textChanged,
86 _qt_lineEdit->setEchoMode( QLineEdit::Password );
88 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockActivated,
91 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockDeactivated,
99 return toUTF8( _qt_lineEdit->text() );
105 QString text = fromUTF8( newText );
110 _qt_lineEdit->setText( text );
114 yuiError() <<
this <<
": Rejecting invalid value \"" << newText <<
"\"" << std::endl;
121 _qt_lineEdit->setEnabled( enabled );
122 _caption->setEnabled( enabled );
123 YWidget::setEnabled( enabled );
129 int minSize = shrinkable() ? 30 : 200;
130 int hintWidth = !_caption->isHidden()
131 ? _caption->sizeHint().width() + 2 * YQWidgetMargin
134 return max( minSize, hintWidth );
140 return sizeHint().height();
146 resize( newWidth, newHeight );
153 YInputField::setLabel( label );
165 return _validator->
validate( text, pos ) == QValidator::Acceptable;
178 _qt_lineEdit->setValidator( _validator );
186 yuiError() <<
this <<
": Old value \"" << _qt_lineEdit->text()
187 <<
"\" invalid according to new ValidChars \"" << newValidChars
191 _qt_lineEdit->setText(
"" );
194 YInputField::setValidChars( newValidChars );
199 _qt_lineEdit->setMaxLength( len );
200 YInputField::setInputMaxLength( len );
205 _qt_lineEdit->setFocus();
206 _qt_lineEdit->selectAll();
221 yuiMilestone() <<
"warning" << std::endl;
222 if ( _displayingCapsLockWarning )
225 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
238 _caption->
setText( _(
"CapsLock!" ) );
239 _displayingCapsLockWarning =
true;
245 yuiMilestone() <<
"warning off " << std::endl;
246 if ( ! _displayingCapsLockWarning )
249 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
253 _displayingCapsLockWarning =
false;
269 bool oldCapsLockActive = _capsLockActive;
271 switch ( event->type )
274 _capsLockActive = (bool) ( event->xkey.state & LockMask );
279 _capsLockActive = (bool) ( event->xkey.state & LockMask );
281 if ( _capsLockActive && oldCapsLockActive )
283 KeySym key = XLookupKeysym( &(event->xkey), 0 );
285 if ( key == XK_Caps_Lock ||
286 key == XK_Shift_Lock )
288 yuiMilestone() <<
"CapsLock released" << std::endl;
289 _capsLockActive =
false;
293 if ( _capsLockActive )
294 yuiDebug() <<
"Key event; caps lock: " 295 << std::boolalpha << _capsLockActive << std::noboolalpha
301 _capsLockActive = (bool) ( event->xbutton.state & LockMask );
305 _capsLockActive = (bool) ( event->xcrossing.state & LockMask );
310 _capsLockActive =
false;
311 emit capsLockDeactivated();
318 if ( oldCapsLockActive != _capsLockActive )
320 yuiMilestone() <<
"Emitting warning" << std::endl;
322 if ( _capsLockActive )
323 emit capsLockActivated();
325 emit capsLockDeactivated();
333 #include "YQInputField.moc" 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.