aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/inputcontext.cpp
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-08-21 12:24:35 +0300
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-08-27 12:43:11 +0000
commitd16972ea958dcf47e9ccd8255d0d83861ba01aae (patch)
tree1216a6650ac1fba474ee06fe53521cff46576026 /src/virtualkeyboard/inputcontext.cpp
parent334116f863bd548532b51ed6f8d71617500fd7b0 (diff)
Trim InputContext API
The purpose of this change is to reduce the number of public API in the virtual keyboard. This change moves a lot of stuff from InputContext to ShiftHandler and InputContextPrivate and exposes the private API to QML through InputContext.priv property. Almost all the unrelevant APIs were moved away, except some properties and methods needed by selection control. These were left intact because moving them is not trivial. Change-Id: I1f23f5f54bc21c68996cb220a66d16d34b5d14ce Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src/virtualkeyboard/inputcontext.cpp')
-rw-r--r--src/virtualkeyboard/inputcontext.cpp749
1 files changed, 30 insertions, 719 deletions
diff --git a/src/virtualkeyboard/inputcontext.cpp b/src/virtualkeyboard/inputcontext.cpp
index 493f68e6..6c7774b0 100644
--- a/src/virtualkeyboard/inputcontext.cpp
+++ b/src/virtualkeyboard/inputcontext.cpp
@@ -28,27 +28,13 @@
****************************************************************************/
#include <QtVirtualKeyboard/inputcontext.h>
-#include <QtVirtualKeyboard/inputengine.h>
+#include <QtVirtualKeyboard/private/inputcontext_p.h>
#include <QtVirtualKeyboard/private/shifthandler_p.h>
#include <QtVirtualKeyboard/private/platforminputcontext_p.h>
-#include <QtVirtualKeyboard/private/shadowinputcontext_p.h>
#include <QtVirtualKeyboard/private/virtualkeyboarddebug_p.h>
-#include <QtVirtualKeyboard/private/enterkeyaction_p.h>
-#include <QtVirtualKeyboard/private/settings_p.h>
#include <QTextFormat>
#include <QGuiApplication>
-#include <QtCore/private/qobject_p.h>
-
-QT_BEGIN_NAMESPACE
-
-bool operator==(const QInputMethodEvent::Attribute &attribute1, const QInputMethodEvent::Attribute &attribute2)
-{
- return attribute1.start == attribute2.start &&
- attribute1.length == attribute2.length &&
- attribute1.type == attribute2.type &&
- attribute1.value == attribute2.value;
-}
/*!
\namespace QtVirtualKeyboard
@@ -57,86 +43,9 @@ bool operator==(const QInputMethodEvent::Attribute &attribute1, const QInputMeth
\brief Namespace for the Qt Virtual Keyboard C++ API.
*/
+QT_BEGIN_NAMESPACE
namespace QtVirtualKeyboard {
-class InputContextPrivate : public QObjectPrivate
-{
-public:
- enum StateFlag {
- ReselectEventState = 0x1,
- InputMethodEventState = 0x2,
- KeyEventState = 0x4,
- InputMethodClickState = 0x8,
- SyncShadowInputState = 0x10
- };
- Q_DECLARE_FLAGS(StateFlags, StateFlag)
-
- InputContextPrivate() :
- QObjectPrivate(),
- inputContext(nullptr),
- inputEngine(nullptr),
- shiftHandler(nullptr),
- keyboardRect(),
- previewRect(),
- previewVisible(false),
- animating(false),
- focus(false),
- shift(false),
- capsLock(false),
- cursorPosition(0),
- anchorPosition(0),
- forceAnchorPosition(-1),
- forceCursorPosition(-1),
- inputMethodHints(Qt::ImhNone),
- preeditText(),
- preeditTextAttributes(),
- surroundingText(),
- selectedText(),
- anchorRectangle(),
- cursorRectangle(),
- selectionControlVisible(false),
- anchorRectIntersectsClipRect(false),
- cursorRectIntersectsClipRect(false)
-#ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION
- , activeNavigationKeys()
-#endif
- {
- }
-
- PlatformInputContext *inputContext;
- InputEngine *inputEngine;
- ShiftHandler *shiftHandler;
- QRectF keyboardRect;
- QRectF previewRect;
- bool previewVisible;
- bool animating;
- bool focus;
- bool shift;
- bool capsLock;
- StateFlags stateFlags;
- int cursorPosition;
- int anchorPosition;
- int forceAnchorPosition;
- int forceCursorPosition;
- Qt::InputMethodHints inputMethodHints;
- QString preeditText;
- QList<QInputMethodEvent::Attribute> preeditTextAttributes;
- QString surroundingText;
- QString selectedText;
- QRectF anchorRectangle;
- QRectF cursorRectangle;
- bool selectionControlVisible;
- bool anchorRectIntersectsClipRect;
- bool cursorRectIntersectsClipRect;
-#ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION
- QSet<int> activeNavigationKeys;
-#endif
- QSet<quint32> activeKeys;
- ShadowInputContext shadow;
-};
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(InputContextPrivate::StateFlags)
-
/*!
\qmltype InputContext
\instantiates QtVirtualKeyboard::InputContext
@@ -159,17 +68,14 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(InputContextPrivate::StateFlags)
context.
*/
InputContext::InputContext(PlatformInputContext *parent) :
- QObject(*new InputContextPrivate(), parent)
+ d_ptr(new InputContextPrivate(this, parent))
{
Q_D(InputContext);
- d->inputContext = parent;
- d->shadow.setInputContext(this);
- if (d->inputContext) {
- d->inputContext->setInputContext(this);
- connect(d->inputContext, SIGNAL(focusObjectChanged()), SLOT(onInputItemChanged()));
- }
- d->inputEngine = new InputEngine(this);
- d->shiftHandler = new ShiftHandler(this);
+ d->init();
+ QObject::connect(d->_shiftHandler, &ShiftHandler::shiftChanged, this, &InputContext::shiftChanged);
+ QObject::connect(d->_shiftHandler, &ShiftHandler::capsLockChanged, this, &InputContext::capsLockChanged);
+ QObject::connect(d->_shiftHandler, &ShiftHandler::uppercaseChanged, this, &InputContext::uppercaseChanged);
+ QObject::connect(d, &InputContextPrivate::localeChanged, this, &InputContext::localeChanged);
}
/*!
@@ -180,50 +86,22 @@ InputContext::~InputContext()
{
}
-bool InputContext::focus() const
-{
- Q_D(const InputContext);
- return d->focus;
-}
-
bool InputContext::shift() const
{
Q_D(const InputContext);
- return d->shift;
-}
-
-void InputContext::setShift(bool enable)
-{
- Q_D(InputContext);
- if (d->shift != enable) {
- d->shift = enable;
- emit shiftChanged();
- if (!d->capsLock)
- emit uppercaseChanged();
- }
+ return d->_shiftHandler->shift();
}
bool InputContext::capsLock() const
{
Q_D(const InputContext);
- return d->capsLock;
-}
-
-void InputContext::setCapsLock(bool enable)
-{
- Q_D(InputContext);
- if (d->capsLock != enable) {
- d->capsLock = enable;
- emit capsLockChanged();
- if (!d->shift)
- emit uppercaseChanged();
- }
+ return d->_shiftHandler->capsLock();
}
bool InputContext::uppercase() const
{
Q_D(const InputContext);
- return d->shift || d->capsLock;
+ return d->_shiftHandler->uppercase();
}
int InputContext::anchorPosition() const
@@ -255,16 +133,16 @@ void InputContext::setPreeditText(const QString &text, QList<QInputMethodEvent::
Q_D(InputContext);
// Add default attributes
if (!text.isEmpty()) {
- if (!testAttribute(attributes, QInputMethodEvent::TextFormat)) {
+ if (!d->testAttribute(attributes, QInputMethodEvent::TextFormat)) {
QTextCharFormat textFormat;
textFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, text.length(), textFormat));
}
- } else if (d->forceCursorPosition != -1) {
- addSelectionAttribute(attributes);
+ } else if (d->_forceCursorPosition != -1) {
+ d->addSelectionAttribute(attributes);
}
- sendPreedit(text, attributes, replaceFrom, replaceLength);
+ d->sendPreedit(text, attributes, replaceFrom, replaceLength);
}
QList<QInputMethodEvent::Attribute> InputContext::preeditTextAttributes() const
@@ -297,52 +175,6 @@ QRectF InputContext::cursorRectangle() const
return d->cursorRectangle;
}
-QRectF InputContext::keyboardRectangle() const
-{
- Q_D(const InputContext);
- return d->keyboardRect;
-}
-
-void InputContext::setKeyboardRectangle(QRectF rectangle)
-{
- Q_D(InputContext);
- if (d->keyboardRect != rectangle) {
- d->keyboardRect = rectangle;
- emit keyboardRectangleChanged();
- d->inputContext->emitKeyboardRectChanged();
- }
-}
-
-QRectF InputContext::previewRectangle() const
-{
- Q_D(const InputContext);
- return d->previewRect;
-}
-
-void InputContext::setPreviewRectangle(QRectF rectangle)
-{
- Q_D(InputContext);
- if (d->previewRect != rectangle) {
- d->previewRect = rectangle;
- emit previewRectangleChanged();
- }
-}
-
-bool InputContext::previewVisible() const
-{
- Q_D(const InputContext);
- return d->previewVisible;
-}
-
-void InputContext::setPreviewVisible(bool visible)
-{
- Q_D(InputContext);
- if (d->previewVisible != visible) {
- d->previewVisible = visible;
- emit previewVisibleChanged();
- }
-}
-
bool InputContext::animating() const
{
Q_D(const InputContext);
@@ -356,49 +188,14 @@ void InputContext::setAnimating(bool animating)
VIRTUALKEYBOARD_DEBUG() << "InputContext::setAnimating():" << animating;
d->animating = animating;
emit animatingChanged();
- d->inputContext->emitAnimatingChanged();
+ d->platformInputContext->emitAnimatingChanged();
}
}
-
QString InputContext::locale() const
{
Q_D(const InputContext);
- return d->inputContext->locale().name();
-}
-
-void InputContext::setLocale(const QString &locale)
-{
- Q_D(InputContext);
- VIRTUALKEYBOARD_DEBUG() << "InputContext::setLocale():" << locale;
- QLocale newLocale(locale);
- if (newLocale != d->inputContext->locale()) {
- d->inputContext->setLocale(newLocale);
- d->inputContext->setInputDirection(newLocale.textDirection());
- emit localeChanged();
- }
-}
-
-/*!
- \internal
-*/
-void InputContext::updateAvailableLocales(const QStringList &availableLocales)
-{
- Settings *settings = Settings::instance();
- if (settings)
- settings->setAvailableLocales(availableLocales);
-}
-
-QObject *InputContext::inputItem() const
-{
- Q_D(const InputContext);
- return d->inputContext ? d->inputContext->focusObject() : nullptr;
-}
-
-ShiftHandler *InputContext::shiftHandler() const
-{
- Q_D(const InputContext);
- return d->shiftHandler;
+ return d->locale();
}
InputEngine *InputContext::inputEngine() const
@@ -408,26 +205,6 @@ InputEngine *InputContext::inputEngine() const
}
/*!
- \qmlmethod void InputContext::hideInputPanel()
-
- This method hides the input panel. This method should only be called
- when the user initiates the hide, e.g. by pressing a dedicated button
- on the keyboard.
-*/
-/*!
- \fn void QtVirtualKeyboard::InputContext::hideInputPanel()
-
- This method hides the input panel. This method should only be called
- when the user initiates the hide, e.g. by pressing a dedicated button
- on the keyboard.
-*/
-void InputContext::hideInputPanel()
-{
- Q_D(InputContext);
- d->inputContext->hideInputPanel();
-}
-
-/*!
\qmlmethod void InputContext::sendKeyClick(int key, string text, int modifiers = 0)
Sends a key click event with the given \a key, \a text and \a modifiers to
@@ -440,14 +217,14 @@ void InputContext::hideInputPanel()
void InputContext::sendKeyClick(int key, const QString &text, int modifiers)
{
Q_D(InputContext);
- if (d->focus && d->inputContext) {
+ if (d->_focus && d->platformInputContext) {
QKeyEvent pressEvent(QEvent::KeyPress, key, Qt::KeyboardModifiers(modifiers), text);
QKeyEvent releaseEvent(QEvent::KeyRelease, key, Qt::KeyboardModifiers(modifiers), text);
VIRTUALKEYBOARD_DEBUG() << "InputContext::sendKeyClick():" << key;
d->stateFlags |= InputContextPrivate::KeyEventState;
- d->inputContext->sendKeyEvent(&pressEvent);
- d->inputContext->sendKeyEvent(&releaseEvent);
+ d->platformInputContext->sendKeyEvent(&pressEvent);
+ d->platformInputContext->sendKeyEvent(&releaseEvent);
if (d->activeKeys.isEmpty())
d->stateFlags &= ~InputContextPrivate::KeyEventState;
} else {
@@ -495,15 +272,15 @@ void InputContext::commit(const QString &text, int replaceFrom, int replaceLengt
VIRTUALKEYBOARD_DEBUG() << "InputContext::commit():" << text << replaceFrom << replaceLength;
bool preeditChanged = !d->preeditText.isEmpty();
- if (d->inputContext) {
+ if (d->platformInputContext) {
QList<QInputMethodEvent::Attribute> attributes;
- addSelectionAttribute(attributes);
+ d->addSelectionAttribute(attributes);
d->preeditText.clear();
d->preeditTextAttributes.clear();
QInputMethodEvent inputEvent(QString(), attributes);
inputEvent.setCommitString(text, replaceFrom, replaceLength);
d->stateFlags |= InputContextPrivate::InputMethodEventState;
- d->inputContext->sendEvent(&inputEvent);
+ d->platformInputContext->sendEvent(&inputEvent);
d->stateFlags &= ~InputContextPrivate::InputMethodEventState;
} else {
d->preeditText.clear();
@@ -531,12 +308,12 @@ void InputContext::clear()
d->preeditText.clear();
d->preeditTextAttributes.clear();
- if (d->inputContext) {
+ if (d->platformInputContext) {
QList<QInputMethodEvent::Attribute> attributes;
- addSelectionAttribute(attributes);
+ d->addSelectionAttribute(attributes);
QInputMethodEvent event(QString(), attributes);
d->stateFlags |= InputContextPrivate::InputMethodEventState;
- d->inputContext->sendEvent(&event);
+ d->platformInputContext->sendEvent(&event);
d->stateFlags &= ~InputContextPrivate::InputMethodEventState;
}
@@ -547,69 +324,11 @@ void InputContext::clear()
/*!
\internal
*/
-bool InputContext::fileExists(const QUrl &fileUrl)
-{
- QString fileName;
- if (fileUrl.scheme() == QLatin1String("qrc")) {
- fileName = QLatin1Char(':') + fileUrl.path();
- } else {
- fileName = fileUrl.toLocalFile();
- }
- return !fileName.isEmpty() && QFile::exists(fileName);
-}
-
-/*!
- \internal
-*/
-bool InputContext::hasEnterKeyAction(QObject *item) const
-{
- return item != nullptr && qmlAttachedPropertiesObject<EnterKeyAction>(item, false);
-}
-
-/*!
- \internal
-*/
void InputContext::setSelectionOnFocusObject(const QPointF &anchorPos, const QPointF &cursorPos)
{
QPlatformInputContext::setSelectionOnFocusObject(anchorPos, cursorPos);
}
-/*!
- \internal
-*/
-void InputContext::forceCursorPosition(int anchorPosition, int cursorPosition)
-{
- Q_D(InputContext);
- if (!d->shadow.inputItem())
- return;
- if (!d->inputContext->m_visible)
- return;
- if (d->stateFlags.testFlag(InputContextPrivate::ReselectEventState))
- return;
- if (d->stateFlags.testFlag(InputContextPrivate::SyncShadowInputState))
- return;
-
- VIRTUALKEYBOARD_DEBUG() << "InputContext::forceCursorPosition():" << cursorPosition << "anchorPosition:" << anchorPosition;
- if (!d->preeditText.isEmpty()) {
- d->forceAnchorPosition = -1;
- d->forceCursorPosition = cursorPosition;
- if (cursorPosition > d->cursorPosition)
- d->forceCursorPosition += d->preeditText.length();
- d->inputEngine->update();
- } else {
- d->forceAnchorPosition = anchorPosition;
- d->forceCursorPosition = cursorPosition;
- setPreeditText("");
- if (!d->inputMethodHints.testFlag(Qt::ImhNoPredictiveText) &&
- cursorPosition > 0 && d->selectedText.isEmpty()) {
- d->stateFlags |= InputContextPrivate::ReselectEventState;
- if (d->inputEngine->reselect(cursorPosition, InputEngine::WordAtCursor))
- d->stateFlags |= InputContextPrivate::InputMethodClickState;
- d->stateFlags &= ~InputContextPrivate::ReselectEventState;
- }
- }
-}
-
bool InputContext::anchorRectIntersectsClipRect() const
{
Q_D(const InputContext);
@@ -628,334 +347,13 @@ bool InputContext::selectionControlVisible() const
return d->selectionControlVisible;
}
-ShadowInputContext *InputContext::shadow() const
+InputContextPrivate *InputContext::priv() const
{
Q_D(const InputContext);
- return const_cast<ShadowInputContext *>(&d->shadow);
-}
-
-void InputContext::onInputItemChanged()
-{
- Q_D(InputContext);
- if (!inputItem() && !d->activeKeys.isEmpty()) {
- // After losing keyboard focus it is impossible to track pressed keys
- d->activeKeys.clear();
- d->stateFlags &= ~InputContextPrivate::KeyEventState;
- }
- d->stateFlags &= ~InputContextPrivate::InputMethodClickState;
-
- emit inputItemChanged();
-}
-
-void InputContext::setFocus(bool enable)
-{
- Q_D(InputContext);
- if (d->focus != enable) {
- VIRTUALKEYBOARD_DEBUG() << "InputContext::setFocus():" << enable;
- d->focus = enable;
- emit focusChanged();
- }
- emit focusEditorChanged();
-}
-
-void InputContext::sendPreedit(const QString &text, const QList<QInputMethodEvent::Attribute> &attributes, int replaceFrom, int replaceLength)
-{
- Q_D(InputContext);
- VIRTUALKEYBOARD_DEBUG() << "InputContext::sendPreedit():" << text << replaceFrom << replaceLength;
-
- bool textChanged = d->preeditText != text;
- bool attributesChanged = d->preeditTextAttributes != attributes;
-
- if (textChanged || attributesChanged) {
- d->preeditText = text;
- d->preeditTextAttributes = attributes;
-
- if (d->inputContext) {
- QInputMethodEvent event(text, attributes);
- const bool replace = replaceFrom != 0 || replaceLength > 0;
- if (replace)
- event.setCommitString(QString(), replaceFrom, replaceLength);
- d->stateFlags |= InputContextPrivate::InputMethodEventState;
- d->inputContext->sendEvent(&event);
- d->stateFlags &= ~InputContextPrivate::InputMethodEventState;
-
- // Send also to shadow input if only attributes changed.
- // In this case the update() may not be called, so the shadow
- // input may be out of sync.
- if (d->shadow.inputItem() && !replace && !text.isEmpty() &&
- !textChanged && attributesChanged) {
- VIRTUALKEYBOARD_DEBUG() << "InputContext::sendPreedit(shadow):" << text << replaceFrom << replaceLength;
- event.setAccepted(true);
- QGuiApplication::sendEvent(d->shadow.inputItem(), &event);
- }
- }
-
- if (textChanged)
- emit preeditTextChanged();
- }
-
- if (d->preeditText.isEmpty())
- d->preeditTextAttributes.clear();
-}
-
-void InputContext::reset()
-{
- Q_D(InputContext);
- d->inputEngine->reset();
-}
-
-void InputContext::externalCommit()
-{
- Q_D(InputContext);
- d->inputEngine->update();
-}
-
-void InputContext::update(Qt::InputMethodQueries queries)
-{
- Q_D(InputContext);
-
- // No need to fetch input clip rectangle during animation
- if (!(queries & ~Qt::ImInputItemClipRectangle) && d->animating)
- return;
-
- // fetch
- QInputMethodQueryEvent imQueryEvent(Qt::InputMethodQueries(Qt::ImHints |
- Qt::ImQueryInput | Qt::ImInputItemClipRectangle));
- d->inputContext->sendEvent(&imQueryEvent);
- Qt::InputMethodHints inputMethodHints = Qt::InputMethodHints(imQueryEvent.value(Qt::ImHints).toInt());
- const int cursorPosition = imQueryEvent.value(Qt::ImCursorPosition).toInt();
- const int anchorPosition = imQueryEvent.value(Qt::ImAnchorPosition).toInt();
- QRectF anchorRectangle;
- QRectF cursorRectangle;
- if (const QGuiApplication *app = qApp) {
- anchorRectangle = app->inputMethod()->anchorRectangle();
- cursorRectangle = app->inputMethod()->cursorRectangle();
- } else {
- anchorRectangle = d->anchorRectangle;
- cursorRectangle = d->cursorRectangle;
- }
- QString surroundingText = imQueryEvent.value(Qt::ImSurroundingText).toString();
- QString selectedText = imQueryEvent.value(Qt::ImCurrentSelection).toString();
-
- // check against changes
- bool newInputMethodHints = inputMethodHints != d->inputMethodHints;
- bool newSurroundingText = surroundingText != d->surroundingText;
- bool newSelectedText = selectedText != d->selectedText;
- bool newAnchorPosition = anchorPosition != d->anchorPosition;
- bool newCursorPosition = cursorPosition != d->cursorPosition;
- bool newAnchorRectangle = anchorRectangle != d->anchorRectangle;
- bool newCursorRectangle = cursorRectangle != d->cursorRectangle;
- bool selectionControlVisible = d->inputContext->isInputPanelVisible() && (cursorPosition != anchorPosition) && !inputMethodHints.testFlag(Qt::ImhNoTextHandles);
- bool newSelectionControlVisible = selectionControlVisible != d->selectionControlVisible;
-
- QRectF inputItemClipRect = imQueryEvent.value(Qt::ImInputItemClipRectangle).toRectF();
- QRectF anchorRect = imQueryEvent.value(Qt::ImAnchorRectangle).toRectF();
- QRectF cursorRect = imQueryEvent.value(Qt::ImCursorRectangle).toRectF();
-
- bool anchorRectIntersectsClipRect = inputItemClipRect.intersects(anchorRect);
- bool newAnchorRectIntersectsClipRect = anchorRectIntersectsClipRect != d->anchorRectIntersectsClipRect;
-
- bool cursorRectIntersectsClipRect = inputItemClipRect.intersects(cursorRect);
- bool newCursorRectIntersectsClipRect = cursorRectIntersectsClipRect != d->cursorRectIntersectsClipRect;
-
- // update
- d->inputMethodHints = inputMethodHints;
- d->surroundingText = surroundingText;
- d->selectedText = selectedText;
- d->anchorPosition = anchorPosition;
- d->cursorPosition = cursorPosition;
- d->anchorRectangle = anchorRectangle;
- d->cursorRectangle = cursorRectangle;
- d->selectionControlVisible = selectionControlVisible;
- d->anchorRectIntersectsClipRect = anchorRectIntersectsClipRect;
- d->cursorRectIntersectsClipRect = cursorRectIntersectsClipRect;
-
- // update input engine
- if ((newSurroundingText || newCursorPosition) &&
- !d->stateFlags.testFlag(InputContextPrivate::InputMethodEventState)) {
- d->inputEngine->update();
- }
- if (newInputMethodHints) {
- d->inputEngine->reset();
- }
-
- // notify
- if (newInputMethodHints) {
- emit inputMethodHintsChanged();
- }
- if (newSurroundingText) {
- emit surroundingTextChanged();
- }
- if (newSelectedText) {
- emit selectedTextChanged();
- }
- if (newAnchorPosition) {
- emit anchorPositionChanged();
- }
- if (newCursorPosition) {
- emit cursorPositionChanged();
- }
- if (newAnchorRectangle) {
- emit anchorRectangleChanged();
- }
- if (newCursorRectangle) {
- emit cursorRectangleChanged();
- }
- if (newSelectionControlVisible) {
- emit selectionControlVisibleChanged();
- }
- if (newAnchorRectIntersectsClipRect) {
- emit anchorRectIntersectsClipRectChanged();
- }
- if (newCursorRectIntersectsClipRect) {
- emit cursorRectIntersectsClipRectChanged();
- }
-
- // word reselection
- if (newInputMethodHints || newSurroundingText || newSelectedText)
- d->stateFlags &= ~InputContextPrivate::InputMethodClickState;
- if ((newSurroundingText || newCursorPosition) && !newSelectedText && (int)d->stateFlags == 0 &&
- !d->inputMethodHints.testFlag(Qt::ImhNoPredictiveText) &&
- d->cursorPosition > 0 && d->selectedText.isEmpty()) {
- d->stateFlags |= InputContextPrivate::ReselectEventState;
- if (d->inputEngine->reselect(d->cursorPosition, InputEngine::WordAtCursor))
- d->stateFlags |= InputContextPrivate::InputMethodClickState;
- d->stateFlags &= ~InputContextPrivate::ReselectEventState;
- }
-
- if (!d->stateFlags.testFlag(InputContextPrivate::SyncShadowInputState)) {
- d->stateFlags |= InputContextPrivate::SyncShadowInputState;
- d->shadow.update(queries);
- d->stateFlags &= ~InputContextPrivate::SyncShadowInputState;
- }
-}
-
-void InputContext::invokeAction(QInputMethod::Action action, int cursorPosition)
-{
- Q_D(InputContext);
- switch (action) {
- case QInputMethod::Click:
- if ((int)d->stateFlags == 0) {
- if (d->inputEngine->clickPreeditText(cursorPosition))
- break;
-
- bool reselect = !d->inputMethodHints.testFlag(Qt::ImhNoPredictiveText) && d->selectedText.isEmpty() && cursorPosition < d->preeditText.length();
- if (reselect) {
- d->stateFlags |= InputContextPrivate::ReselectEventState;
- d->forceCursorPosition = d->cursorPosition + cursorPosition;
- d->inputEngine->update();
- d->inputEngine->reselect(d->cursorPosition, InputEngine::WordBeforeCursor);
- d->stateFlags &= ~InputContextPrivate::ReselectEventState;
- } else if (!d->preeditText.isEmpty() && cursorPosition == d->preeditText.length()) {
- d->inputEngine->update();
- }
- }
- d->stateFlags &= ~InputContextPrivate::InputMethodClickState;
- break;
-
- case QInputMethod::ContextMenu:
- break;
- }
-}
-
-bool InputContext::filterEvent(const QEvent *event)
-{
- QEvent::Type type = event->type();
- if (type == QEvent::KeyPress || type == QEvent::KeyRelease) {
- Q_D(InputContext);
- const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
-
- // Keep track of pressed keys update key event state
- if (type == QEvent::KeyPress)
- d->activeKeys += keyEvent->nativeScanCode();
- else if (type == QEvent::KeyRelease)
- d->activeKeys -= keyEvent->nativeScanCode();
-
- if (d->activeKeys.isEmpty())
- d->stateFlags &= ~InputContextPrivate::KeyEventState;
- else
- d->stateFlags |= InputContextPrivate::KeyEventState;
-
-#ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION
- int key = keyEvent->key();
- if ((key >= Qt::Key_Left && key <= Qt::Key_Down) || key == Qt::Key_Return) {
- if (type == QEvent::KeyPress && d->inputContext->isInputPanelVisible()) {
- d->activeNavigationKeys += key;
- emit navigationKeyPressed(key, keyEvent->isAutoRepeat());
- return true;
- } else if (type == QEvent::KeyRelease && d->activeNavigationKeys.contains(key)) {
- d->activeNavigationKeys -= key;
- emit navigationKeyReleased(key, keyEvent->isAutoRepeat());
- return true;
- }
- }
-#endif
-
- // Break composing text since the virtual keyboard does not support hard keyboard events
- if (!d->preeditText.isEmpty())
- d->inputEngine->update();
- }
- return false;
-}
-
-void InputContext::addSelectionAttribute(QList<QInputMethodEvent::Attribute> &attributes)
-{
- Q_D(InputContext);
- if (!testAttribute(attributes, QInputMethodEvent::Selection)) {
- // Convert Cursor attribute to Selection attribute.
- // In this case the cursor is set in pre-edit text, but
- // the cursor is not being forced to specific location.
- if (d->forceCursorPosition == -1) {
- int cursorAttributeIndex = findAttribute(d->preeditTextAttributes, QInputMethodEvent::Cursor);
- if (cursorAttributeIndex != -1 && d->preeditTextAttributes[cursorAttributeIndex].length > 0)
- d->forceCursorPosition = d->cursorPosition + d->preeditTextAttributes[cursorAttributeIndex].start;
- d->forceAnchorPosition = -1;
- }
-
- if (d->forceCursorPosition != -1) {
- if (d->forceAnchorPosition != -1)
- attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, d->forceAnchorPosition, d->forceCursorPosition - d->forceAnchorPosition, QVariant()));
- else
- attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, d->forceCursorPosition, 0, QVariant()));
- }
- }
- d->forceAnchorPosition = -1;
- d->forceCursorPosition = -1;
-}
-
-bool InputContext::testAttribute(const QList<QInputMethodEvent::Attribute> &attributes, QInputMethodEvent::AttributeType attributeType) const
-{
- for (const QInputMethodEvent::Attribute &attribute : qAsConst(attributes)) {
- if (attribute.type == attributeType)
- return true;
- }
- return false;
-}
-
-int InputContext::findAttribute(const QList<QInputMethodEvent::Attribute> &attributes, QInputMethodEvent::AttributeType attributeType) const
-{
- const int count = attributes.count();
- for (int i = 0; i < count; ++i) {
- if (attributes.at(i).type == attributeType)
- return i;
- }
- return -1;
+ return const_cast<InputContextPrivate *>(d);
}
/*!
- \qmlproperty bool InputContext::focus
-
- This property is changed when the input method receives or loses focus.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::focus
- \brief the focus status.
-
- This property is changed when the input method receives or loses focus.
-*/
-
-/*!
\qmlproperty bool InputContext::shift
This property is changed when the shift status changes.
@@ -1102,45 +500,6 @@ int InputContext::findAttribute(const QList<QInputMethodEvent::Attribute> &attri
*/
/*!
- \qmlproperty rect InputContext::keyboardRectangle
-
- Use this property to set the keyboard rectangle.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::keyboardRectangle
- \brief the keyboard rectangle.
-
- Use this property to set the keyboard rectangle.
-*/
-
-/*!
- \qmlproperty rect InputContext::previewRectangle
-
- Use this property to set the preview rectangle.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::previewRectangle
- \brief the preview rectangle.
-
- Use this property to set the preview rectangle.
-*/
-
-/*!
- \qmlproperty bool InputContext::previewVisible
-
- Use this property to set the visibility status of the preview.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::previewVisible
- \brief the animating status.
-
- Use this property to set the visibility status of the preview.
-*/
-
-/*!
\qmlproperty bool InputContext::animating
Use this property to set the animating status, for example
@@ -1158,40 +517,14 @@ int InputContext::findAttribute(const QList<QInputMethodEvent::Attribute> &attri
/*!
\qmlproperty string InputContext::locale
- Sets the locale for this input context.
+ This property is changed when the input locale changes.
*/
/*!
\property QtVirtualKeyboard::InputContext::locale
\brief the locale.
- Sets the locale for this input context.
-*/
-
-/*!
- \qmlproperty QtObject InputContext::inputItem
-
- This property is changed when the focused input item changes.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::inputItem
- \brief the focused input item.
-
- This property is changed when the focused input item changes.
-*/
-
-/*!
- \qmlproperty ShiftHandler InputContext::shiftHandler
-
- This property stores the shift handler.
-*/
-
-/*!
- \property QtVirtualKeyboard::InputContext::shiftHandler
- \brief the shift handler instance.
-
- This property stores the shift handler.
+ This property is changed when the input locale changes.
*/
/*!
@@ -1207,27 +540,5 @@ int InputContext::findAttribute(const QList<QInputMethodEvent::Attribute> &attri
This property stores the input engine.
*/
-/*!
- \qmlsignal InputContext::focusEditorChanged()
-
- This signal is emitted when the focus editor changes.
-*/
-
-/*!
- \fn void QtVirtualKeyboard::InputContext::focusEditorChanged()
-
- This signal is emitted when the focus editor changes.
-*/
-
-/*!
- \fn void QtVirtualKeyboard::InputContext::navigationKeyPressed(int key, bool isAutoRepeat)
- \internal
-*/
-
-/*!
- \fn void QtVirtualKeyboard::InputContext::navigationKeyReleased(int key, bool isAutoRepeat)
- \internal
-*/
-
} // namespace QtVirtualKeyboard
QT_END_NAMESPACE