Commit f93af913 authored by Bhushan Shah's avatar Bhushan Shah 📱 Committed by Bhushan Shah
Browse files

virtualkeyboard: remove unused event overrides

Previously qtvirtualkeyboard was integrated weirdly so that it was
acting as the focus object and proxy for input methods, however now that
we support proper input methods, this code is totally unused and it is
confusing to have it here, so just drop it

See: f26f2fe1 for the reference of the
code deleted.
parent 97c0270c
......@@ -358,174 +358,4 @@ void VirtualKeyboard::updateInputPanelState()
t->setInputPanelState(m_inputClient && m_inputClient->isShown(false), QRect(0, 0, 0, 0));
}
bool VirtualKeyboard::event(QEvent *e)
{
if (e->type() == QEvent::InputMethod) {
QInputMethodEvent *event = static_cast<QInputMethodEvent*>(e);
if (m_enabled && waylandServer()) {
bool isPreedit = false;
for (auto attribute : event->attributes()) {
switch (attribute.type) {
case QInputMethodEvent::TextFormat:
case QInputMethodEvent::Cursor:
case QInputMethodEvent::Language:
case QInputMethodEvent::Ruby:
isPreedit = true;
break;
default:
break;
}
}
TextInputInterface *ti = waylandServer()->seat()->focusedTextInput();
if (ti && ti->isEnabled()) {
if (!isPreedit && event->preeditString().isEmpty() && !event->commitString().isEmpty()) {
ti->commit(event->commitString().toUtf8());
} else {
ti->preEdit(event->preeditString().toUtf8(), event->commitString().toUtf8());
}
}
}
}
if (e->type() == QEvent::InputMethodQuery) {
auto event = static_cast<QInputMethodQueryEvent*>(e);
TextInputInterface *ti = nullptr;
if (waylandServer() && m_enabled) {
ti = waylandServer()->seat()->focusedTextInput();
}
if (event->queries().testFlag(Qt::ImEnabled)) {
event->setValue(Qt::ImEnabled, QVariant(ti != nullptr && ti->isEnabled()));
}
if (event->queries().testFlag(Qt::ImCursorRectangle)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImFont)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImCursorPosition)) {
// the virtual keyboard doesn't send us the cursor position in the preedit
// this would break text input, thus we ignore it
// see https://bugreports.qt.io/browse/QTBUG-53517
#if 0
event->setValue(Qt::ImCursorPosition, QString::fromUtf8(ti->surroundingText().left(ti->surroundingTextCursorPosition())).size());
#else
event->setValue(Qt::ImCursorPosition, 0);
#endif
}
if (event->queries().testFlag(Qt::ImSurroundingText)) {
// the virtual keyboard doesn't send us the cursor position in the preedit
// this would break text input, thus we ignore it
// see https://bugreports.qt.io/browse/QTBUG-53517
#if 0
event->setValue(Qt::ImSurroundingText, QString::fromUtf8(ti->surroundingText()));
#else
event->setValue(Qt::ImSurroundingText, QString());
#endif
}
if (event->queries().testFlag(Qt::ImCurrentSelection)) {
// TODO: should be text between cursor and anchor, but might be dangerous
}
if (event->queries().testFlag(Qt::ImMaximumTextLength)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImAnchorPosition)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImHints)) {
if (ti && ti->isEnabled()) {
Qt::InputMethodHints hints;
const auto contentHints = ti->contentHints();
if (!contentHints.testFlag(TextInputInterface::ContentHint::AutoCompletion)) {
hints |= Qt::ImhNoPredictiveText;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::AutoCorrection)) {
// no mapping in Qt
}
if (!contentHints.testFlag(TextInputInterface::ContentHint::AutoCapitalization)) {
hints |= Qt::ImhNoAutoUppercase;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::LowerCase)) {
hints |= Qt::ImhPreferLowercase;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::UpperCase)) {
hints |= Qt::ImhPreferUppercase;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::TitleCase)) {
// no mapping in Qt
}
if (contentHints.testFlag(TextInputInterface::ContentHint::HiddenText)) {
hints |= Qt::ImhHiddenText;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::SensitiveData)) {
hints |= Qt::ImhSensitiveData;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::Latin)) {
hints |= Qt::ImhPreferLatin;
}
if (contentHints.testFlag(TextInputInterface::ContentHint::MultiLine)) {
hints |= Qt::ImhMultiLine;
}
switch (ti->contentPurpose()) {
case TextInputInterface::ContentPurpose::Digits:
hints |= Qt::ImhDigitsOnly;
break;
case TextInputInterface::ContentPurpose::Number:
hints |= Qt::ImhFormattedNumbersOnly;
break;
case TextInputInterface::ContentPurpose::Phone:
hints |= Qt::ImhDialableCharactersOnly;
break;
case TextInputInterface::ContentPurpose::Url:
hints |= Qt::ImhUrlCharactersOnly;
break;
case TextInputInterface::ContentPurpose::Email:
hints |= Qt::ImhEmailCharactersOnly;
break;
case TextInputInterface::ContentPurpose::Date:
hints |= Qt::ImhDate;
break;
case TextInputInterface::ContentPurpose::Time:
hints |= Qt::ImhTime;
break;
case TextInputInterface::ContentPurpose::DateTime:
hints |= Qt::ImhDate;
hints |= Qt::ImhTime;
break;
case TextInputInterface::ContentPurpose::Name:
// no mapping in Qt
case TextInputInterface::ContentPurpose::Password:
// no mapping in Qt
case TextInputInterface::ContentPurpose::Terminal:
// no mapping in Qt
case TextInputInterface::ContentPurpose::Normal:
// that's the default
case TextInputInterface::ContentPurpose::Alpha:
// no mapping in Qt
break;
}
event->setValue(Qt::ImHints, QVariant(int(hints)));
} else {
event->setValue(Qt::ImHints, Qt::ImhNone);
}
}
if (event->queries().testFlag(Qt::ImPreferredLanguage)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImPlatformData)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImAbsolutePosition)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImTextBeforeCursor)) {
// not used by virtual keyboard
}
if (event->queries().testFlag(Qt::ImTextAfterCursor)) {
// not used by virtual keyboard
}
event->accept();
return true;
}
return QObject::event(e);
}
}
......@@ -31,8 +31,6 @@ public:
~VirtualKeyboard() override;
void init();
bool event(QEvent *e) override;
void hide();
void show();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment