Interfaces introduced and deprecated during Qt5 development.
Change-Id: I804a02df8c4a03ed6558f4a86375f97d09513d5c
Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
QInputMethod::QInputMethod()
: QObject(*new QInputMethodPrivate)
{
- // might be instantiated before QGuiApplication is fully done, need to connect later
- QTimer::singleShot(0, this, SLOT(_q_connectFocusObject()));
}
/*!
*/
/*!
- \property QInputMethod::inputItem
- \brief Focused item that accepts text input
- \obsolete
-
- Input item is set and unset by the focused window. In QML Scene Graph this is done by
- QQuickCanvas and the input item is either TextInput or TextEdit element. Any QObject can
- behave as an input item as long as it responds to QInputMethodQueryEvent and QInputMethodEvent
- events sent by the input methods.
-
- \sa inputItemTransform, inputWindow, QInputMethodQueryEvent, QInputMethodEvent
-*/
-QObject *QInputMethod::inputItem() const
-{
- Q_D(const QInputMethod);
- return d->inputItem.data();
-}
-
-void QInputMethod::setInputItem(QObject *inputItem)
-{
- Q_D(QInputMethod);
- d->setInputItem(inputItem);
-}
-
-/*!
- Returns the currently focused window containing the input item.
-
- \obsolete
-*/
-QWindow *QInputMethod::inputWindow() const
-{
- return qApp->focusWindow();
-}
-
-/*!
Returns the transformation from input item coordinates to the window coordinates.
*/
QTransform QInputMethod::inputItemTransform() const
{
Q_D(const QInputMethod);
- if (!d->inputItem)
+ QObject *focusObject = qGuiApp->focusObject();
+ if (!focusObject)
return QRectF();
QInputMethodQueryEvent query(Qt::ImCursorRectangle);
- QGuiApplication::sendEvent(d->inputItem.data(), &query);
+ QGuiApplication::sendEvent(focusObject, &query);
QRectF r = query.value(Qt::ImCursorRectangle).toRectF();
if (!r.isValid())
return QRectF();
if (queries & Qt::ImEnabled) {
QObject *focus = qApp->focusObject();
bool enabled = d->objectAcceptsInputMethod(focus);
- d->setInputItem(enabled ? focus : 0);
QPlatformInputContextPrivate::setInputMethodAccepted(enabled);
}
ic->invokeAction(a, cursorPosition);
}
-// temporary handlers for updating focus item based on application focus
-void QInputMethodPrivate::_q_connectFocusObject()
-{
- Q_Q(QInputMethod);
- QObject::connect(qApp, SIGNAL(focusObjectChanged(QObject*)),
- q, SLOT(_q_checkFocusObject(QObject*)));
- _q_checkFocusObject(qApp->focusObject());
-}
-
-void QInputMethodPrivate::_q_checkFocusObject(QObject *object)
-{
- bool enabled = objectAcceptsInputMethod(object);
- setInputItem(enabled ? object : 0);
-}
-
bool QInputMethodPrivate::objectAcceptsInputMethod(QObject *object)
{
bool enabled = false;
{
Q_OBJECT
Q_DECLARE_PRIVATE(QInputMethod)
- Q_PROPERTY(QObject *inputItem READ inputItem WRITE setInputItem NOTIFY inputItemChanged)
Q_PROPERTY(QRectF cursorRectangle READ cursorRectangle NOTIFY cursorRectangleChanged)
Q_PROPERTY(QRectF keyboardRectangle READ keyboardRectangle NOTIFY keyboardRectangleChanged)
Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
Q_ENUMS(Action)
public:
-#ifdef QT_DEPRECATED
- QT_DEPRECATED QObject *inputItem() const;
- QT_DEPRECATED void setInputItem(QObject *inputItemChanged);
-
- // the window containing the editor
- QT_DEPRECATED QWindow *inputWindow() const;
-#endif
-
QTransform inputItemTransform() const;
void setInputItemTransform(const QTransform &transform);
void invokeAction(Action a, int cursorPosition);
Q_SIGNALS:
- void inputItemChanged();
void cursorRectangleChanged();
void keyboardRectangleChanged();
void visibleChanged();
friend class QPlatformInputContext;
QInputMethod();
~QInputMethod();
-
- Q_PRIVATE_SLOT(d_func(), void _q_connectFocusObject())
- Q_PRIVATE_SLOT(d_func(), void _q_checkFocusObject(QObject* object))
-
};
QT_END_NAMESPACE
{
return inputMethod->d_func();
}
- inline void setInputItem(QObject *item)
- {
- Q_Q(QInputMethod);
-
- if (inputItem.data() == item)
- return;
-
- inputItem = item;
- emit q->inputItemChanged();
- }
void _q_connectFocusObject();
void _q_checkFocusObject(QObject *object);
bool objectAcceptsInputMethod(QObject *object);
QTransform inputItemTransform;
- QPointer<QObject> inputItem;
QPlatformInputContext *testContext;
};
void isVisible();
void animating();
void keyboarRectangle();
- void inputItem();
void inputItemTransform();
void cursorRectangle();
void invokeAction();
QCOMPARE(spy.count(), 1);
}
-void tst_qinputmethod::inputItem()
-{
- QVERIFY(!qApp->inputMethod()->inputItem());
- QSignalSpy spy(qApp->inputMethod(), SIGNAL(inputItemChanged()));
-
- qApp->inputMethod()->setInputItem(&m_inputItem);
-
- QCOMPARE(qApp->inputMethod()->inputItem(), &m_inputItem);
- QCOMPARE(spy.count(), 1);
-
- // reset
- qApp->inputMethod()->setInputItem(0);
-}
-
void tst_qinputmethod::inputItemTransform()
{
QCOMPARE(qApp->inputMethod()->inputItemTransform(), QTransform());
{
QCOMPARE(qApp->inputMethod()->cursorRectangle(), QRectF());
+ DummyWindow window;
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ window.requestActivateWindow();
+ QTRY_COMPARE(qApp->focusWindow(), &window);
+ window.setFocusObject(&m_inputItem);
+
QTransform transform;
transform.translate(10, 10);
transform.scale(2, 2);
transform.shear(2, 2);
qApp->inputMethod()->setInputItemTransform(transform);
- qApp->inputMethod()->setInputItem(&m_inputItem);
-
QCOMPARE(qApp->inputMethod()->cursorRectangle(), transform.mapRect(QRectF(1, 2, 3, 4)));
m_inputItem.cursorRectangle = QRectF(1.5, 2, 1, 8);
// reset
m_inputItem.cursorRectangle = QRectF(1, 2, 3, 4);
- qApp->inputMethod()->setInputItem(0);
qApp->inputMethod()->setInputItemTransform(QTransform());
}
QCOMPARE(int(m_platformInputContext.m_lastQueries), int(Qt::ImQueryAll));
QCOMPARE(qApp->inputMethod()->keyboardRectangle(), QRectF(10, 20, 30, 40));
-
- // reset
- qApp->inputMethod()->setInputItem(0);
}
void tst_qinputmethod::query()
void initialPosForDontShowOnScreenWidgets();
void updateOnDestroyedSignal();
void toplevelLineEditFocus();
- void inputFocus_task257832();
void focusWidget_task254563();
#ifndef Q_OS_WINCE_WM
}
#endif
-void tst_QWidget::inputFocus_task257832()
-{
- QScopedPointer<QLineEdit> widget(new QLineEdit);
- widget->setFocus();
- widget->winId(); // make sure, widget has been created
- widget->show();
- QTRY_VERIFY(widget->hasFocus());
- QCOMPARE(qApp->inputMethod()->inputItem(), widget.data());
- widget->setReadOnly(true);
- QVERIFY(!qApp->inputMethod()->inputItem());
-}
-
void tst_QWidget::setGraphicsEffect()
{
// Check that we don't have any effect by default.
QVERIFY(QTest::qWaitForWindowActive(toplevel.data()));
QVERIFY(toplevel->hasFocus());
QVERIFY(child->hasFocus());
-
- // verify that toggling input methods on the child widget
- // correctly propagate to the focus proxy's input method
- // and that the input method gets the focus proxy passed
- // as the focus widget instead of the child widget.
- // otherwise input method queries go to the wrong widget
- QCOMPARE(qApp->inputMethod()->inputItem(), toplevel.data());
-
- toplevel->setAttribute(Qt::WA_InputMethodEnabled, false);
- QVERIFY(!qApp->inputMethod()->inputItem());
-
- toplevel->setAttribute(Qt::WA_InputMethodEnabled, true);
- QCOMPARE(qApp->inputMethod()->inputItem(), toplevel.data());
+ QCOMPARE(qApp->focusObject(), toplevel.data());
}
#ifdef QT_BUILD_INTERNAL