Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use QInputMethod instead of deprecated QInputPanel
Similarly deprecate Qt.application.inputPanel and
introduce replacement Qt.inputMethod.

Change-Id: Ie4fd467f93f75023c86b0a2d038d858fe5001146
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Sami Kananoja <sami.kananoja@nokia.com>
  • Loading branch information
Pekka Vuorela authored and Qt by Nokia committed Feb 10, 2012
1 parent 9634dc4 commit e761f5b
Show file tree
Hide file tree
Showing 19 changed files with 142 additions and 113 deletions.
2 changes: 1 addition & 1 deletion doc/src/declarative/righttoleft.qdoc
Expand Up @@ -58,7 +58,7 @@ When the horizontal alignment of a text item is not explicitly set, the text ele
automatically aligned to the natural reading direction of the text. By default left-to-right text
like English is aligned to the left side of the text area, and right-to-left text like Arabic is
aligned to the right side of the text area. The alignment of a text element with empty text takes
its alignment cue from \l QInputPanel::inputDirection(), which is based on the active
its alignment cue from \l QInputMethod::inputDirection(), which is based on the active
system locale.

This default locale-based alignment can be overriden by setting the \c horizontalAlignment
Expand Down
6 changes: 4 additions & 2 deletions src/declarative/qml/qdeclarativeapplication.cpp
Expand Up @@ -42,7 +42,8 @@
#include "qdeclarativeapplication_p.h"
#include <private/qobject_p.h>
#include <QtGui/QGuiApplication>
#include <QtGui/QInputPanel>
#include <QtGui/QInputMethod>
#include <QtCore/QDebug>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -85,7 +86,8 @@ Qt::LayoutDirection QDeclarativeApplication::layoutDirection() const

QObject *QDeclarativeApplication::inputPanel() const
{
return qApp ? qApp->inputPanel() : 0;
qWarning() << "Qt.application.inputPanel is deprecated, use Qt.inputMethod instead";
return qApp ? qApp->inputMethod() : 0;
}

bool QDeclarativeApplication::eventFilter(QObject *obj, QEvent *event)
Expand Down
2 changes: 1 addition & 1 deletion src/declarative/qml/qdeclarativeapplication_p.h
Expand Up @@ -64,7 +64,7 @@ class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeApplication : public QObject
virtual ~QDeclarativeApplication();
bool active() const;
Qt::LayoutDirection layoutDirection() const;
QObject *inputPanel() const;
QT_DEPRECATED QObject *inputPanel() const;

protected:
bool eventFilter(QObject *obj, QEvent *event);
Expand Down
8 changes: 7 additions & 1 deletion src/declarative/qml/qdeclarativeengine.cpp
Expand Up @@ -297,14 +297,20 @@ of their use.
\o
This read-only property allows access to application's QInputPanel object
and all its properties and slots. See the QInputPanel documentation for
further details.
further details. Deprecated in favor of Qt.InputMethod
\endtable
The following example uses the \c application object to indicate
whether the application is currently active:
\snippet doc/src/snippets/declarative/application.qml document
\qmlproperty object Qt::inputMethod
\since QtQuick 2.0
The \c inputMethod object allows access to application's QInputMethod object
and all its properties and slots. See the QInputMethod documentation for
further details.
*/


Expand Down
3 changes: 3 additions & 0 deletions src/declarative/qml/v8/qv8engine.cpp
Expand Up @@ -41,6 +41,8 @@

#include "qv8engine_p.h"

#include <QtGui/QGuiApplication>

#include "qv8contextwrapper_p.h"
#include "qv8valuetypewrapper_p.h"
#include "qv8sequencewrapper_p.h"
Expand Down Expand Up @@ -575,6 +577,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)

if (m_engine) {
qt->Set(v8::String::New("application"), newQObject(new QDeclarativeApplication(m_engine)));
qt->Set(v8::String::New("inputMethod"), newQObject(qGuiApp->inputMethod(), CppOwnership));
qt->Set(v8::String::New("lighter"), V8FUNCTION(lighter, this));
qt->Set(v8::String::New("darker"), V8FUNCTION(darker, this));
qt->Set(v8::String::New("tint"), V8FUNCTION(tint, this));
Expand Down
1 change: 0 additions & 1 deletion src/declarative/qml/v8/qv8engine_p.h
Expand Up @@ -253,7 +253,6 @@ class Q_DECLARATIVE_EXPORT QV8Engine
QV8Engine(QJSEngine* qq,QJSEngine::ContextOwnership ownership = QJSEngine::CreateNewContext);
virtual ~QV8Engine();

// ### TODO get rid of it, do we really need CppOwnership?
// This enum should be in sync with QDeclarativeEngine::ObjectOwnership
enum ObjectOwnership { CppOwnership, JavaScriptOwnership };

Expand Down
8 changes: 4 additions & 4 deletions src/quick/items/qquickcanvas.cpp
Expand Up @@ -54,7 +54,7 @@
#include <private/qquickwindowmanager_p.h>

#include <private/qguiapplication_p.h>
#include <QtGui/QInputPanel>
#include <QtGui/QInputMethod>

#include <private/qabstractanimation_p.h>

Expand All @@ -77,7 +77,7 @@ void QQuickCanvasPrivate::updateFocusItemTransform()
Q_Q(QQuickCanvas);
QQuickItem *focus = q->activeFocusItem();
if (focus && qApp->focusObject() == focus)
qApp->inputPanel()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform());
qApp->inputMethod()->setInputItemTransform(QQuickItemPrivate::get(focus)->itemToCanvasTransform());
}

class QQuickCanvasIncubationController : public QObject, public QDeclarativeIncubationController
Expand Down Expand Up @@ -498,7 +498,7 @@ void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F

if (oldActiveFocusItem) {
#ifndef QT_NO_IM
qApp->inputPanel()->reset();
qApp->inputMethod()->reset();
#endif

activeFocusItem = 0;
Expand Down Expand Up @@ -605,7 +605,7 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
Q_ASSERT(oldActiveFocusItem);

#ifndef QT_NO_IM
qApp->inputPanel()->reset();
qApp->inputMethod()->reset();
#endif

activeFocusItem = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/quick/items/qquickitem.cpp
Expand Up @@ -54,7 +54,7 @@
#include <QtGui/qpen.h>
#include <QtGui/qcursor.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qinputpanel.h>
#include <QtGui/qinputmethod.h>
#include <QtCore/qdebug.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/qnumeric.h>
Expand Down Expand Up @@ -3128,7 +3128,7 @@ void QQuickItem::setInputMethodHints(Qt::InputMethodHints hints)
return;

if (qApp->focusObject() == this)
qApp->inputPanel()->update(Qt::ImHints);
qApp->inputMethod()->update(Qt::ImHints);
}

QVariant QQuickItem::inputMethodQuery(Qt::InputMethodQuery query) const
Expand Down Expand Up @@ -3671,7 +3671,7 @@ void QQuickItem::itemChange(ItemChange change, const ItemChangeData &value)
void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
{
if (hasActiveFocus())
qApp->inputPanel()->update(queries);
qApp->inputMethod()->update(queries);
}

/*! \internal */
Expand Down
4 changes: 2 additions & 2 deletions src/quick/items/qquicktext.cpp
Expand Up @@ -56,7 +56,7 @@
#include <QtGui/qtextobject.h>
#include <QtGui/qtextcursor.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qinputpanel.h>
#include <QtGui/qinputmethod.h>

#include <private/qtextengine_p.h>
#include <private/qdeclarativestyledtext_p.h>
Expand Down Expand Up @@ -1470,7 +1470,7 @@ bool QQuickTextPrivate::setHAlign(QQuickText::HAlignment alignment, bool forceAl
bool QQuickTextPrivate::determineHorizontalAlignment()
{
if (hAlignImplicit) {
bool alignToRight = text.isEmpty() ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft : rightToLeftText;
bool alignToRight = text.isEmpty() ? qApp->inputMethod()->inputDirection() == Qt::RightToLeft : rightToLeftText;
return setHAlign(alignToRight ? QQuickText::AlignRight : QQuickText::AlignLeft);
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/quick/items/qquicktextcontrol.cpp
Expand Up @@ -51,7 +51,7 @@
#include <qdrag.h>
#include <qclipboard.h>
#include <qtimer.h>
#include <qinputpanel.h>
#include <qinputmethod.h>
#include "private/qtextdocumentlayout_p.h"
#include "private/qabstracttextdocumentlayout_p.h"
#include "qtextdocument.h"
Expand Down Expand Up @@ -1310,7 +1310,7 @@ void QQuickTextControlPrivate::mouseMoveEvent(QMouseEvent *e, const QPointF &mou
emit q->cursorPositionChanged();
_q_updateCurrentCharFormatAndSelection();
if (qGuiApp)
qGuiApp->inputPanel()->update(Qt::ImQueryInput);
qGuiApp->inputMethod()->update(Qt::ImQueryInput);
} else if (cursor.position() != oldCursorPos) {
emit q->cursorPositionChanged();
}
Expand Down Expand Up @@ -1424,7 +1424,7 @@ bool QQuickTextControlPrivate::sendMouseEventToInputContext(QMouseEvent *e, cons

if (cursorPos >= 0 && cursorPos <= layout->preeditAreaText().length()) {
if (e->type() == QEvent::MouseButtonRelease) {
qApp->inputPanel()->invokeAction(QInputPanel::Click, cursorPos);
qApp->inputMethod()->invokeAction(QInputMethod::Click, cursorPos);
}

return true;
Expand Down Expand Up @@ -1859,7 +1859,7 @@ void QQuickTextControlPrivate::commitPreedit()
return;

cursor.beginEditBlock();
qApp->inputPanel()->reset();
qApp->inputMethod()->reset();

if (!tentativeCommit.isEmpty()) {
cursor.insertText(tentativeCommit);
Expand Down
10 changes: 5 additions & 5 deletions src/quick/items/qquicktextedit.cpp
Expand Up @@ -560,7 +560,7 @@ bool QQuickTextEditPrivate::determineHorizontalAlignment()
if (document->isEmpty()) {
const QString preeditText = control->textCursor().block().layout()->preeditAreaText();
alignToRight = preeditText.isEmpty()
? qApp->inputPanel()->inputDirection() == Qt::RightToLeft
? qApp->inputMethod()->inputDirection() == Qt::RightToLeft
: preeditText.isRightToLeft();
} else {
alignToRight = rightToLeftText;
Expand Down Expand Up @@ -1545,10 +1545,10 @@ void QQuickTextEdit::itemChange(ItemChange change, const ItemChangeData &value)

if (value.boolValue) {
q_updateAlignment();
connect(qApp->inputPanel(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
connect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
this, SLOT(q_updateAlignment()));
} else {
disconnect(qApp->inputPanel(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
disconnect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
this, SLOT(q_updateAlignment()));
}
}
Expand Down Expand Up @@ -2099,7 +2099,7 @@ void QQuickTextEditPrivate::updateDefaultTextOption()
void QQuickTextEdit::openSoftwareInputPanel()
{
if (qGuiApp)
qGuiApp->inputPanel()->show();
qGuiApp->inputMethod()->show();
}

/*!
Expand Down Expand Up @@ -2142,7 +2142,7 @@ void QQuickTextEdit::openSoftwareInputPanel()
void QQuickTextEdit::closeSoftwareInputPanel()
{
if (qGuiApp)
qGuiApp->inputPanel()->hide();
qGuiApp->inputMethod()->hide();
}

void QQuickTextEdit::focusInEvent(QFocusEvent *event)
Expand Down
18 changes: 9 additions & 9 deletions src/quick/items/qquicktextinput.cpp
Expand Up @@ -52,7 +52,7 @@
#include <QtQuick/qsgsimplerectnode.h>

#include <QtGui/qstylehints.h>
#include <QtGui/qinputpanel.h>
#include <QtGui/qinputmethod.h>

#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
Expand Down Expand Up @@ -131,7 +131,7 @@ void QQuickTextInput::setText(const QString &s)
if (s == text())
return;
if (d->composeMode())
qApp->inputPanel()->reset();
qApp->inputMethod()->reset();
d->m_tentativeCommit.clear();
d->internalSetText(s, -1, false);
}
Expand Down Expand Up @@ -482,7 +482,7 @@ bool QQuickTextInputPrivate::determineHorizontalAlignment()
QString text = q_func()->text();
if (text.isEmpty())
text = m_textLayout.preeditAreaText();
bool isRightToLeft = text.isEmpty() ? qApp->inputPanel()->inputDirection() == Qt::RightToLeft
bool isRightToLeft = text.isEmpty() ? qApp->inputMethod()->inputDirection() == Qt::RightToLeft
: text.isRightToLeft();
return setHAlign(isRightToLeft ? QQuickTextInput::AlignRight : QQuickTextInput::AlignLeft);
}
Expand Down Expand Up @@ -1529,7 +1529,7 @@ bool QQuickTextInputPrivate::sendMouseEventToInputContext(QMouseEvent *event)
int mousePos = tmp_cursor - m_cursor;
if (mousePos >= 0 && mousePos <= m_textLayout.preeditAreaText().length()) {
if (event->type() == QEvent::MouseButtonRelease) {
qApp->inputPanel()->invokeAction(QInputPanel::Click, mousePos);
qApp->inputMethod()->invokeAction(QInputMethod::Click, mousePos);
}
return true;
}
Expand Down Expand Up @@ -2417,7 +2417,7 @@ void QQuickTextInput::moveCursorSelection(int pos, SelectionMode mode)
void QQuickTextInput::openSoftwareInputPanel()
{
if (qGuiApp)
qGuiApp->inputPanel()->show();
qGuiApp->inputMethod()->show();
}

/*!
Expand Down Expand Up @@ -2460,7 +2460,7 @@ void QQuickTextInput::openSoftwareInputPanel()
void QQuickTextInput::closeSoftwareInputPanel()
{
if (qGuiApp)
qGuiApp->inputPanel()->hide();
qGuiApp->inputMethod()->hide();
}

void QQuickTextInput::focusInEvent(QFocusEvent *event)
Expand Down Expand Up @@ -2490,11 +2490,11 @@ void QQuickTextInput::itemChange(ItemChange change, const ItemChangeData &value)
d->commitPreedit();
if (!d->persistentSelection)
d->deselect();
disconnect(qApp->inputPanel(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
disconnect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
this, SLOT(q_updateAlignment()));
} else {
q_updateAlignment();
connect(qApp->inputPanel(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
connect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
this, SLOT(q_updateAlignment()));
}
}
Expand Down Expand Up @@ -2790,7 +2790,7 @@ void QQuickTextInputPrivate::commitPreedit()
if (!composeMode())
return;

qApp->inputPanel()->reset();
qApp->inputMethod()->reset();

if (!m_tentativeCommit.isEmpty()) {
internalInsert(m_tentativeCommit);
Expand Down
2 changes: 1 addition & 1 deletion src/quick/items/qquicktextinput_p_p.h
Expand Up @@ -395,7 +395,7 @@ class Q_AUTOTEST_EXPORT QQuickTextInputPrivate : public QQuickImplicitSizeItemPr
Qt::LayoutDirection layoutDirection() const {
if (m_layoutDirection == Qt::LayoutDirectionAuto) {
if (m_text.isEmpty())
return qApp->inputPanel()->inputDirection();
return qApp->inputMethod()->inputDirection();
return m_text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
}
return m_layoutDirection;
Expand Down
7 changes: 5 additions & 2 deletions src/quick/util/qdeclarativeutilmodule.cpp
Expand Up @@ -61,11 +61,14 @@
#include <private/qdeclarativetypenotavailable_p.h>
#include <private/qdeclarativeanimationcontroller_p.h>
#include <QtCore/qcoreapplication.h>
#include <QtGui/QInputPanel>
#include <QtGui/QInputMethod>

void QDeclarativeUtilModule::defineModule()
{
qmlRegisterUncreatableType<QInputPanel>("QtQuick",2,0,"InputPanel", QInputPanel::tr("InputPanel is an abstract class"));
qmlRegisterUncreatableType<QInputMethod>("QtQuick",2,0,"InputPanel",
QInputMethod::tr("InputPanel is an abstract class")); // deprecated
qmlRegisterUncreatableType<QInputMethod>("QtQuick",2,0,"InputMethod",
QInputMethod::tr("InputMethod is an abstract class"));
qmlRegisterUncreatableType<QDeclarativeAbstractAnimation>("QtQuick",2,0,"Animation",QDeclarativeAbstractAnimation::tr("Animation is an abstract class"));

qmlRegisterType<QDeclarativeBehavior>("QtQuick",2,0,"Behavior");
Expand Down
Expand Up @@ -44,7 +44,7 @@
#include <QtDeclarative/qdeclarativeengine.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <QtGui/qinputpanel.h>
#include <QtGui/qinputmethod.h>

class tst_qdeclarativeapplication : public QObject
{
Expand All @@ -56,6 +56,7 @@ private slots:
void active();
void layoutDirection();
void inputPanel();
void inputMethod();

private:
QDeclarativeEngine engine;
Expand Down Expand Up @@ -135,9 +136,24 @@ void tst_qdeclarativeapplication::inputPanel()
item->setParentItem(view.rootObject());

// check that the inputPanel property maches with application's input panel
QCOMPARE(qvariant_cast<QObject*>(item->property("inputPanel")), qApp->inputPanel());
QCOMPARE(qvariant_cast<QObject*>(item->property("inputPanel")), qApp->inputMethod());
}

void tst_qdeclarativeapplication::inputMethod()
{
// technically not in QDeclarativeApplication, but testing anyway here
QDeclarativeComponent component(&engine);
component.setData("import QtQuick 2.0; Item { property variant inputMethod: Qt.inputMethod }", QUrl::fromLocalFile(""));
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
QVERIFY(item);
QQuickView view;
item->setParentItem(view.rootObject());

// check that the inputMethod property maches with application's input method
QCOMPARE(qvariant_cast<QObject*>(item->property("inputMethod")), qApp->inputMethod());
}


QTEST_MAIN(tst_qdeclarativeapplication)

#include "tst_qdeclarativeapplication.moc"

0 comments on commit e761f5b

Please sign in to comment.