Skip to content

Commit

Permalink
Add new setting for input method hints
Browse files Browse the repository at this point in the history
This property allows to set persistent input method hints.

[ChangeLog] Add new setting VirtualKeyboardSettings.inputMethodHints,
which allows the application to set persistent application wide
input method hints.

Change-Id: Iaa54a360d80c5def88f53aa8b8510c7cf041208c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
  • Loading branch information
jarkkokoivikko-code-q committed Jan 29, 2021
1 parent 5b81a28 commit e923b4f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void QVirtualKeyboardInputContextPrivate::update(Qt::InputMethodQueries queries)
Qt::ImQueryInput | Qt::ImInputItemClipRectangle));
platformInputContext->sendEvent(&imQueryEvent);
Qt::InputMethodHints inputMethodHints = Qt::InputMethodHints(imQueryEvent.value(Qt::ImHints).toInt());
inputMethodHints |= Settings::instance()->inputMethodHints();
const int cursorPosition = imQueryEvent.value(Qt::ImCursorPosition).toInt();
const int anchorPosition = imQueryEvent.value(Qt::ImAnchorPosition).toInt();
QRectF anchorRectangle;
Expand Down
16 changes: 16 additions & 0 deletions src/virtualkeyboard/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class SettingsPrivate : public QObjectPrivate
QString userDataPath;
int hwrTimeoutForAlphabetic;
int hwrTimeoutForCjk;
Qt::InputMethodHints inputMethodHints;
};

static QScopedPointer<Settings> s_settingsInstance;
Expand Down Expand Up @@ -300,5 +301,20 @@ void Settings::setHwrTimeoutForCjk(int hwrTimeoutForCjk)
}
}

Qt::InputMethodHints Settings::inputMethodHints() const
{
Q_D(const Settings);
return d->inputMethodHints;
}

void Settings::setInputMethodHints(const Qt::InputMethodHints &inputMethodHints)
{
Q_D(Settings);
if (d->inputMethodHints != inputMethodHints) {
d->inputMethodHints = inputMethodHints;
emit inputMethodHintsChanged();
}
}

} // namespace QtVirtualKeyboard
QT_END_NAMESPACE
4 changes: 4 additions & 0 deletions src/virtualkeyboard/settings_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class QVIRTUALKEYBOARD_EXPORT Settings : public QObject
int hwrTimeoutForCjk() const;
void setHwrTimeoutForCjk(int hwrTimeoutForCjk);

Qt::InputMethodHints inputMethodHints() const;
void setInputMethodHints(const Qt::InputMethodHints &inputMethodHints);

signals:
void styleChanged();
void styleNameChanged();
Expand All @@ -115,6 +118,7 @@ class QVIRTUALKEYBOARD_EXPORT Settings : public QObject
void userDataReset();
void hwrTimeoutForAlphabeticChanged();
void hwrTimeoutForCjkChanged();
void inputMethodHintsChanged();
};

} // namespace QtVirtualKeyboard
Expand Down
22 changes: 22 additions & 0 deletions src/virtualkeyboard/virtualkeyboardsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ VirtualKeyboardSettings::VirtualKeyboardSettings(QQmlEngine *engine) :
settings->connect(this, SIGNAL(userDataReset()), SIGNAL(userDataReset()));
connect(settings, SIGNAL(hwrTimeoutForAlphabeticChanged()), SIGNAL(hwrTimeoutForAlphabeticChanged()));
connect(settings, SIGNAL(hwrTimeoutForCjkChanged()), SIGNAL(hwrTimeoutForCjkChanged()));
connect(settings, SIGNAL(inputMethodHintsChanged()), SIGNAL(inputMethodHintsChanged()));
}

/*!
Expand Down Expand Up @@ -323,6 +324,16 @@ void VirtualKeyboardSettings::setHwrTimeoutForCjk(int hwrTimeoutForCjk)
return Settings::instance()->setHwrTimeoutForCjk(hwrTimeoutForCjk);
}

Qt::InputMethodHints VirtualKeyboardSettings::inputMethodHints() const
{
return Settings::instance()->inputMethodHints();
}

void VirtualKeyboardSettings::setInputMethodHints(const Qt::InputMethodHints &inputMethodHints)
{
Settings::instance()->setInputMethodHints(inputMethodHints);
}

void VirtualKeyboardSettings::resetStyle()
{
Q_D(VirtualKeyboardSettings);
Expand Down Expand Up @@ -462,6 +473,17 @@ void VirtualKeyboardSettings::resetStyle()
By default, the timeout is 500 millliseconds.
*/

/*!
\qmlproperty int VirtualKeyboardSettings::inputMethodHints
\since QtQuick.VirtualKeyboard.Settings 6.1

This property allows to set persistent input method hints.

The value of this property is combined with the input method
hints from the input control. For example, to disable predictive
text input, this property can be set to \c Qt::ImhNoPredictiveText.
*/

/*!
\since QtQuick.VirtualKeyboard.Settings 2.2
\qmlpropertygroup QtQuick.VirtualKeyboard::VirtualKeyboardSettings::wordCandidateList
Expand Down
5 changes: 5 additions & 0 deletions src/virtualkeyboard/virtualkeyboardsettings_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class QVIRTUALKEYBOARD_EXPORT VirtualKeyboardSettings : public QObject
Q_PROPERTY(QString userDataPath READ userDataPath WRITE setUserDataPath NOTIFY userDataPathChanged REVISION(6, 1))
Q_PROPERTY(int hwrTimeoutForAlphabetic READ hwrTimeoutForAlphabetic WRITE setHwrTimeoutForAlphabetic NOTIFY hwrTimeoutForAlphabeticChanged REVISION(6, 1))
Q_PROPERTY(int hwrTimeoutForCjk READ hwrTimeoutForCjk WRITE setHwrTimeoutForCjk NOTIFY hwrTimeoutForCjkChanged REVISION(6, 1))
Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged REVISION(6, 1))

public:
static QObject *registerSettingsModule(QQmlEngine *engine, QJSEngine *jsEngine);
Expand Down Expand Up @@ -101,6 +102,9 @@ class QVIRTUALKEYBOARD_EXPORT VirtualKeyboardSettings : public QObject
int hwrTimeoutForCjk() const;
void setHwrTimeoutForCjk(int hwrTimeoutForCjk);

Qt::InputMethodHints inputMethodHints() const;
void setInputMethodHints(const Qt::InputMethodHints &inputMethodHints);

signals:
void styleChanged();
void styleNameChanged();
Expand All @@ -113,6 +117,7 @@ class QVIRTUALKEYBOARD_EXPORT VirtualKeyboardSettings : public QObject
Q_REVISION(6, 1) void userDataReset();
Q_REVISION(6, 1) void hwrTimeoutForAlphabeticChanged();
Q_REVISION(6, 1) void hwrTimeoutForCjkChanged();
Q_REVISION(6, 1) void inputMethodHintsChanged();

private:
void resetStyle();
Expand Down

0 comments on commit e923b4f

Please sign in to comment.