Skip to content

Commit

Permalink
[maliit] Forward arbitrary extension properties to QML input methods.…
Browse files Browse the repository at this point in the history
… Contributes to JB#45133
  • Loading branch information
adenexter committed May 22, 2019
1 parent 391e821 commit 8ba39f3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
10 changes: 10 additions & 0 deletions maliit-framework/input-context/minputcontext.cpp
Expand Up @@ -688,8 +688,18 @@ void MInputContext::setDetectableAutoRepeat(bool enabled)

QMap<QString, QVariant> MInputContext::getStateInformation() const
{
QObject * const focusObject = QGuiApplication::focusObject();

QMap<QString, QVariant> stateInformation;

if (focusObject) {
stateInformation = focusObject->property("__inputMethodExtensions").toMap();
stateInformation.remove(QStringLiteral("enterKeyIconSource"));
stateInformation.remove(QStringLiteral("enterKeyText"));
stateInformation.remove(QStringLiteral("enterKeyEnabled"));
stateInformation.remove(QStringLiteral("enterKeyHighlighted"));
}

stateInformation["focusState"] = inputMethodAccepted();

if (!inputMethodAccepted() || !qGuiApp->focusObject()) {
Expand Down
9 changes: 8 additions & 1 deletion maliit-framework/src/mimpluginmanager.cpp
Expand Up @@ -1479,7 +1479,14 @@ void MIMPluginManager::handleWidgetStateChanged(unsigned int clientId,
if (oldState.value(iter.key()) != iter.value()) {
changedProperties.append(iter.key());
}

}
for (QMap<QString, QVariant>::const_iterator iter = oldState.constBegin();
iter != oldState.constEnd();
++iter)
{
if (!newState.contains(iter.key())) {
changedProperties.append(iter.key());
}
}

variant = newState[FocusStateAttribute];
Expand Down
30 changes: 30 additions & 0 deletions maliit-framework/src/quick/inputmethodquick.cpp
Expand Up @@ -19,6 +19,7 @@

#include <maliit/plugins/abstractinputmethodhost.h>
#include <maliit/plugins/keyoverride.h>
#include <maliit/plugins/updateevent.h>

#include "abstractplatform.h"

Expand All @@ -28,6 +29,7 @@
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickView>
#include <QQmlPropertyMap>

namespace Maliit
{
Expand Down Expand Up @@ -85,6 +87,7 @@ class InputMethodQuickPrivate
bool m_autoCapitalizationEnabled;
bool m_hiddenText;
QSharedPointer<Maliit::AbstractPlatform> m_platform;
QScopedPointer<QQmlPropertyMap> m_extensions;

InputMethodQuickPrivate(MAbstractInputMethodHost *host,
InputMethodQuick *im,
Expand Down Expand Up @@ -546,6 +549,24 @@ QList<MAbstractInputMethod::MInputMethodSubView> InputMethodQuick::subViews(Mali
return sub_views;
}

bool InputMethodQuick::imExtensionEvent(MImExtensionEvent *event)
{
Q_D(InputMethodQuick);

if (event->type() == MImExtensionEvent::Update && d->m_extensions) {
const QStringList keys = d->m_extensions->keys();
MImUpdateEvent * const update = static_cast<MImUpdateEvent *>(event);
for (const QString &property : update->propertiesChanged()) {
d->m_extensions->insert(property, update->value(property));
}

if (d->m_extensions->keys() != keys) {
Q_EMIT extensionsChanged();
}
}
return false;
}

void InputMethodQuick::onSentActionKeyAttributesChanged(const QString &, const MKeyOverride::KeyOverrideAttributes changedAttributes)
{
Q_D(InputMethodQuick);
Expand Down Expand Up @@ -641,4 +662,13 @@ bool InputMethodQuick::hiddenText()
return d->m_hiddenText;
}

QObject *InputMethodQuick::extensions()
{
Q_D(InputMethodQuick);
if (!d->m_extensions) {
d->m_extensions.reset(new QQmlPropertyMap);
}
return d->m_extensions.data();
}

} // namespace Maliit
6 changes: 5 additions & 1 deletion maliit-framework/src/quick/inputmethodquick.h
Expand Up @@ -73,7 +73,7 @@ class InputMethodQuick
Q_PROPERTY(bool predictionEnabled READ predictionEnabled NOTIFY predictionEnabledChanged)
Q_PROPERTY(bool autoCapitalizationEnabled READ autoCapitalizationEnabled NOTIFY autoCapitalizationChanged)
Q_PROPERTY(bool hiddenText READ hiddenText NOTIFY hiddenTextChanged)

Q_PROPERTY(QObject *extensions READ extensions NOTIFY extensionsChanged)
public:
//! Constructor
//! \param host serves as communication link to framework and application. Managed by framework.
Expand All @@ -97,6 +97,7 @@ class InputMethodQuick
virtual void setKeyOverrides(const QMap<QString, QSharedPointer<MKeyOverride> > &overrides);
virtual void handleFocusChange(bool focusIn);
QList<MAbstractInputMethod::MInputMethodSubView> subViews(Maliit::HandlerState state) const;
bool imExtensionEvent(MImExtensionEvent *event);
//! \reimp_end

//! Propagates screen size to QML components.
Expand Down Expand Up @@ -142,6 +143,8 @@ class InputMethodQuick
bool autoCapitalizationEnabled();
bool hiddenText();

QObject *extensions();

Q_SIGNALS:
//! Emitted when screen height changes.
void screenHeightChanged(int height);
Expand Down Expand Up @@ -178,6 +181,7 @@ class InputMethodQuick
void predictionEnabledChanged();
void autoCapitalizationChanged();
void hiddenTextChanged();
void extensionsChanged();

public Q_SLOTS:
//! Sends preedit string. Called by QML components. See also MAbstractInputMethodHost::sendPreeditString()
Expand Down

0 comments on commit 8ba39f3

Please sign in to comment.