QWidgets to use QGuiApplication focus object change notifications

Moving away from deprecated QInputPanel inputItem.

Small behavioral changes:
- On focus proxy widgets, disabling WA_InputMethodEnabled on
proxy will no longer disable input method for proxy target.
- setEnabled(false) on proxy widget will no longer disable
input method for target as a special case.

Change-Id: Ifb5b7144d29bd3aefdde7cf4a0bd396db06e67e2
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
This commit is contained in:
Pekka Vuorela 2012-01-23 13:09:14 +02:00 committed by Qt by Nokia
parent dd565d2d4c
commit 1166ad8603
4 changed files with 22 additions and 30 deletions

View File

@ -1981,7 +1981,6 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
|| (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled)
|| !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
qApp->inputPanel()->reset();
qApp->inputPanel()->setInputItem(0);
}
#endif //QT_NO_IM
@ -2005,13 +2004,6 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
QApplication::sendEvent(that->style(), &out);
}
if(focus && QApplicationPrivate::focus_widget == focus) {
#ifndef QT_NO_IM
if (focus->testAttribute(Qt::WA_InputMethodEnabled)
&& focus->testAttribute(Qt::WA_WState_Created)
&& focus->isEnabled()) {
qApp->inputPanel()->setInputItem(focus);
}
#endif //QT_NO_IM
QFocusEvent in(QEvent::FocusIn, reason);
QPointer<QWidget> that = focus;
QApplication::sendEvent(focus, &in);
@ -2019,6 +2011,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
QApplication::sendEvent(that->style(), &in);
}
emit qApp->focusChanged(prev, focus_widget);
emit qApp->focusObjectChanged(focus_widget);
}
}
}

View File

@ -172,7 +172,13 @@ QInputContext::~QInputContext()
*/
QWidget *QInputContext::focusWidget() const
{
return qobject_cast<QWidget *>(qApp->inputPanel()->inputItem());
bool enabled = false;
if (qApp->focusWidget()) {
QInputMethodQueryEvent query(Qt::ImEnabled);
QGuiApplication::sendEvent(qApp->focusWidget(), &query);
enabled = query.value(Qt::ImEnabled).toBool();
}
return enabled ? qobject_cast<QWidget *>(qApp->focusWidget()) : 0;
}
@ -186,7 +192,7 @@ QWidget *QInputContext::focusWidget() const
*/
void QInputContext::setFocusWidget(QWidget *widget)
{
qApp->inputPanel()->setInputItem(widget);
// not honored
}
/*!

View File

@ -355,7 +355,7 @@ void QWidgetPrivate::scrollChildren(int dx, int dy)
void QWidgetPrivate::updateWidgetTransform()
{
Q_Q(QWidget);
if (q == qApp->inputPanel()->inputItem()) {
if (q == qGuiApp->focusObject()) {
QTransform t;
QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0));
t.translate(p.x(), p.y());
@ -3125,10 +3125,10 @@ void QWidgetPrivate::setEnabled_helper(bool enable)
if (enable) {
if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
qApp->inputPanel()->setInputItem(focusWidget);
qApp->inputPanel()->update(Qt::ImEnabled);
} else {
qApp->inputPanel()->reset();
qApp->inputPanel()->setInputItem(0);
qApp->inputPanel()->update(Qt::ImEnabled);
}
}
#endif //QT_NO_IM
@ -10137,7 +10137,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
if (on && !internalWinId() && hasFocus()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
qApp->inputPanel()->reset();
qApp->inputPanel()->setInputItem(0);
qApp->inputPanel()->update(Qt::ImEnabled);
}
if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()
#ifdef Q_WS_MAC
@ -10151,7 +10151,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
d->createWinId();
if (isEnabled() && focusWidget->isEnabled()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
qApp->inputPanel()->setInputItem(focusWidget);
qApp->inputPanel()->update(Qt::ImEnabled);
}
#endif //QT_NO_IM
break;
@ -10184,13 +10184,10 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
break;
case Qt::WA_InputMethodEnabled: {
#ifndef QT_NO_IM
QWidget *focusWidget = d->effectiveFocusWidget();
if (on && hasFocus() && isEnabled()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
qApp->inputPanel()->setInputItem(focusWidget);
} else if (!on && qApp->inputPanel()->inputItem() == focusWidget) {
qApp->inputPanel()->reset();
qApp->inputPanel()->setInputItem(0);
if (qApp->focusObject() == this) {
if (!on)
qApp->inputPanel()->reset();
qApp->inputPanel()->update(Qt::ImEnabled);
}
#endif //QT_NO_IM
break;

View File

@ -8889,6 +8889,8 @@ void tst_QWidget::inputFocus_task257832()
QLineEdit *widget = new QLineEdit;
widget->setFocus();
widget->winId(); // make sure, widget has been created
widget->show();
QTRY_VERIFY(widget->hasFocus());
QCOMPARE(qApp->inputPanel()->inputItem(), static_cast<QWidget*>(widget));
widget->setReadOnly(true);
QVERIFY(!qApp->inputPanel()->inputItem());
@ -9028,16 +9030,10 @@ void tst_QWidget::focusProxyAndInputMethods()
// otherwise input method queries go to the wrong widget
QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
child->setAttribute(Qt::WA_InputMethodEnabled, false);
toplevel->setAttribute(Qt::WA_InputMethodEnabled, false);
QVERIFY(!qApp->inputPanel()->inputItem());
child->setAttribute(Qt::WA_InputMethodEnabled, true);
QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
child->setEnabled(false);
QVERIFY(!qApp->inputPanel()->inputItem());
child->setEnabled(true);
toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
QCOMPARE(qApp->inputPanel()->inputItem(), toplevel);
delete toplevel;