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> 57 : QFrame( (QWidget *) parent->widgetRep() )
58 , YInputField( parent, label, passwordMode )
60 , _displayingCapsLockWarning( false )
62 QVBoxLayout* layout =
new QVBoxLayout(
this );
67 layout->setSpacing( YQWidgetSpacing );
68 layout->setMargin( YQWidgetMargin );
71 YUI_CHECK_NEW( _caption );
72 layout->addWidget( _caption );
75 YUI_CHECK_NEW( _qt_lineEdit );
76 layout->addWidget( _qt_lineEdit );
78 _caption->setBuddy( _qt_lineEdit );
80 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::textChanged,
85 _qt_lineEdit->setEchoMode( QLineEdit::Password );
87 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockActivated,
90 connect( _qt_lineEdit, &pclass(_qt_lineEdit)::capsLockDeactivated,
98 return toUTF8( _qt_lineEdit->text() );
104 QString text = fromUTF8( newText );
109 _qt_lineEdit->setText( text );
113 yuiError() <<
this <<
": Rejecting invalid value \"" << newText <<
"\"" << endl;
120 _qt_lineEdit->setEnabled( enabled );
121 _caption->setEnabled( enabled );
122 YWidget::setEnabled( enabled );
128 int minSize = shrinkable() ? 30 : 200;
129 int hintWidth = !_caption->isHidden()
130 ? _caption->sizeHint().width() + 2 * YQWidgetMargin
133 return std::max( minSize, hintWidth );
139 return sizeHint().height();
145 resize( newWidth, newHeight );
152 YInputField::setLabel( label );
164 return _validator->
validate( text, pos ) == QValidator::Acceptable;
177 _qt_lineEdit->setValidator( _validator );
185 yuiError() <<
this <<
": Old value \"" << _qt_lineEdit->text()
186 <<
"\" invalid according to new ValidChars \"" << newValidChars
190 _qt_lineEdit->setText(
"" );
193 YInputField::setValidChars( newValidChars );
198 _qt_lineEdit->setMaxLength( len );
199 YInputField::setInputMaxLength( len );
204 _qt_lineEdit->setFocus();
205 _qt_lineEdit->selectAll();
220 yuiMilestone() <<
"warning" << endl;
221 if ( _displayingCapsLockWarning )
224 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
237 _caption->
setText( _(
"CapsLock!" ) );
238 _displayingCapsLockWarning =
true;
244 yuiMilestone() <<
"warning off " << endl;
245 if ( ! _displayingCapsLockWarning )
248 if ( _qt_lineEdit->echoMode() == QLineEdit::Normal )
252 _displayingCapsLockWarning =
false;
268 bool oldCapsLockActive = _capsLockActive;
270 switch ( event->type )
273 _capsLockActive = (bool) ( event->xkey.state & LockMask );
278 _capsLockActive = (bool) ( event->xkey.state & LockMask );
280 if ( _capsLockActive && oldCapsLockActive )
282 KeySym key = XLookupKeysym( &(event->xkey), 0 );
284 if ( key == XK_Caps_Lock ||
285 key == XK_Shift_Lock )
287 yuiMilestone() <<
"CapsLock released" << endl;
288 _capsLockActive =
false;
292 if ( _capsLockActive )
293 yuiDebug() <<
"Key event; caps lock: " 294 << std::boolalpha << _capsLockActive << std::noboolalpha
300 _capsLockActive = (bool) ( event->xbutton.state & LockMask );
304 _capsLockActive = (bool) ( event->xcrossing.state & LockMask );
309 _capsLockActive =
false;
310 emit capsLockDeactivated();
317 if ( oldCapsLockActive != _capsLockActive )
319 yuiMilestone() <<
"Emitting warning" << endl;
321 if ( _capsLockActive )
322 emit capsLockActivated();
324 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.