Adapted most QInputContext usage on widgets to QInputPanel

Including most of stuff excluding mouse event handling
which differs between the classes.

Change-Id: Iff1e56b9c50c3f84de2d1c43a3416a1952197a17
Reviewed-on: http://codereview.qt-project.org/5640
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Pekka Vuorela 2011-09-27 14:36:56 +03:00 committed by Qt by Nokia
parent 3d71266fea
commit 50f0aeee77
6 changed files with 35 additions and 66 deletions

View File

@ -78,10 +78,6 @@
#include <private/qt_x11_p.h>
#endif
#if defined(Q_WS_X11) || defined(Q_OS_SYMBIAN)
#include "qinputcontextfactory.h"
#endif
#include "qguiplatformplugin_p.h"
#include <qthread.h>
@ -2054,16 +2050,13 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
focus_widget = focus;
#ifndef QT_NO_IM
if (prev && ((reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
&& prev->testAttribute(Qt::WA_InputMethodEnabled))
// Do reset the input context, in case the new focus widget won't accept keyboard input
// or it is not created fully yet.
|| (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled)
|| !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
QInputContext *qic = prev->inputContext();
if(qic) {
qic->reset();
qic->setFocusWidget(0);
}
&& prev->testAttribute(Qt::WA_InputMethodEnabled))
// Do reset the input context, in case the new focus widget won't accept keyboard input
// or it is not created fully yet.
|| (focus_widget && (!focus_widget->testAttribute(Qt::WA_InputMethodEnabled)
|| !focus_widget->testAttribute(Qt::WA_WState_Created))))) {
qApp->inputPanel()->commit();
qApp->inputPanel()->setInputItem(0);
}
#endif //QT_NO_IM
@ -2092,11 +2085,10 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
}
if(focus && QApplicationPrivate::focus_widget == focus) {
#ifndef QT_NO_IM
if (focus->testAttribute(Qt::WA_InputMethodEnabled)) {
QInputContext *qic = focus->inputContext();
if (qic && focus->testAttribute(Qt::WA_WState_Created)
&& focus->isEnabled())
qic->setFocusWidget(focus);
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);

View File

@ -3186,13 +3186,13 @@ void QWidgetPrivate::setEnabled_helper(bool enable)
#ifndef QT_NO_IM
if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
QWidget *focusWidget = effectiveFocusWidget();
QInputContext *qic = focusWidget->d_func()->inputContext();
if (enable) {
if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
qic->setFocusWidget(focusWidget);
qApp->inputPanel()->setInputItem(focusWidget);
} else {
qic->reset();
qic->setFocusWidget(0);
qApp->inputPanel()->commit();
qApp->inputPanel()->setInputItem(0);
}
}
#endif //QT_NO_IM
@ -9017,12 +9017,7 @@ void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
#ifndef QT_NO_IM
Q_D(QWidget);
d->imHints = hints;
// Optimization to update input context only it has already been created.
if (d->ic || qApp->d_func()->inputContext) {
QInputContext *ic = inputContext();
if (ic)
ic->update();
}
qApp->inputPanel()->update(Qt::ImHints);
#endif //QT_NO_IM
}
@ -10320,14 +10315,10 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
#endif
#ifndef QT_NO_IM
QWidget *focusWidget = d->effectiveFocusWidget();
QInputContext *ic = 0;
if (on && !internalWinId() && hasFocus()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
ic = focusWidget->d_func()->inputContext();
if (ic) {
ic->reset();
ic->setFocusWidget(0);
}
qApp->inputPanel()->commit();
qApp->inputPanel()->setInputItem(0);
}
if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()
#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
@ -10339,9 +10330,9 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
parentWidget()->d_func()->enforceNativeChildren();
if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
d->createWinId();
if (ic && isEnabled() && focusWidget->isEnabled()
if (isEnabled() && focusWidget->isEnabled()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
ic->setFocusWidget(focusWidget);
qApp->inputPanel()->setInputItem(focusWidget);
}
#endif //QT_NO_IM
break;
@ -10375,15 +10366,12 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
case Qt::WA_InputMethodEnabled: {
#ifndef QT_NO_IM
QWidget *focusWidget = d->effectiveFocusWidget();
QInputContext *ic = qApp->inputContext();
if (ic) {
if (on && hasFocus() && ic->focusWidget() != focusWidget && isEnabled()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
ic->setFocusWidget(focusWidget);
} else if (!on && ic->focusWidget() == focusWidget) {
ic->reset();
ic->setFocusWidget(0);
}
if (on && hasFocus() && isEnabled()
&& focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
qApp->inputPanel()->setInputItem(focusWidget);
} else if (!on && qApp->inputPanel()->inputItem() == focusWidget) {
qApp->inputPanel()->commit();
qApp->inputPanel()->setInputItem(0);
}
#endif //QT_NO_IM
break;
@ -10845,6 +10833,7 @@ void QWidget::setShortcutAutoRepeat(int id, bool enable)
qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0);
}
#endif // QT_NO_SHORTCUT
/*!
Updates the widget's micro focus.
@ -10852,13 +10841,9 @@ void QWidget::setShortcutAutoRepeat(int id, bool enable)
*/
void QWidget::updateMicroFocus()
{
Q_D(QWidget);
// and optimization to update input context only it has already been created.
if (d->assignedInputContext() || qApp->d_func()->inputContext) {
QInputContext *ic = inputContext();
if (ic)
ic->update();
}
// updating everything since this is currently called for any kind of state change
qApp->inputPanel()->update(Qt::ImQueryAll);
#ifndef QT_NO_ACCESSIBILITY
if (isVisible()) {
// ##### is this correct

View File

@ -57,9 +57,6 @@
#include <qtreeview.h>
#include <qheaderview.h>
#include <qmath.h>
#ifndef QT_NO_IM
#include "qinputcontext.h"
#endif
#include <private/qapplication_p.h>
#include <private/qcombobox_p.h>
#include <private/qabstractitemmodel_p.h>
@ -2489,10 +2486,10 @@ void QComboBox::showPopup()
listRect.moveBottomLeft(above);
}
#ifndef QT_NO_IM
if (QInputContext *qic = inputContext())
qic->reset();
#endif
if (qApp) {
qApp->inputPanel()->reset();
}
QScrollBar *sb = view()->horizontalScrollBar();
Qt::ScrollBarPolicy policy = view()->horizontalScrollBarPolicy();
bool needHorizontalScrollBar = (policy == Qt::ScrollBarAsNeeded || policy == Qt::ScrollBarAlwaysOn)

View File

@ -64,7 +64,6 @@
#include <limits.h>
#include <qtexttable.h>
#include <qvariant.h>
#include <qinputcontext.h>
#ifndef QT_NO_TEXTEDIT

View File

@ -67,7 +67,6 @@
#include <qtexttable.h>
#include <qvariant.h>
#include <qinputcontext.h>
#endif
QT_BEGIN_NAMESPACE

View File

@ -48,10 +48,7 @@
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
#endif
#ifndef QT_NO_IM
#include "qinputcontext.h"
#include "qlist.h"
#endif
#include "qapplication.h"
#ifndef QT_NO_GRAPHICSVIEW
#include "qgraphicssceneevent.h"