Skip to content

Commit

Permalink
Merge branch 'freaksdd-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaRicchi committed Sep 24, 2024
2 parents 53bdb0c + 7b96d76 commit 5af2d82
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/DeclarativeInputEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct DeclarativeInputEnginePrivate {
struct LayoutData {
QString layoutFile;
QString description;
QString spaceIdentifier = "Space";
};

DeclarativeInputEngine *_this;
Expand All @@ -32,7 +33,7 @@ struct DeclarativeInputEnginePrivate {
{DeclarativeInputEngine::Fr, {"FrLayout", "Français"}},
{DeclarativeInputEngine::It, {"ItLayout", "Italiano"}},
{DeclarativeInputEngine::Es, {"EsLayout", "Español"}},
{DeclarativeInputEngine::De, {"DeLayout", "Deutsch"}},
{DeclarativeInputEngine::De, {"DeLayout", "Deutsch", "Leerzeichen"}},
{DeclarativeInputEngine::Nl, {"NlLayout", "Nederlands"}},
{DeclarativeInputEngine::Pt, {"PtLayout", "Português"}},
{DeclarativeInputEngine::Cs, {"CsLayout", "Čeština"}},
Expand Down Expand Up @@ -165,3 +166,18 @@ QString DeclarativeInputEngine::descriptionOfLayout(QString layout) {
}
return d->layoutFiles.value(layoutVal, {}).description;
}

QString DeclarativeInputEngine::spaceIdentifierOfLayout(QString layout)
{
if (!inputLayoutValid(layout)) {
return "";
}
bool ok = false;
auto layoutVal = static_cast<InputLayouts>(
QMetaEnum::fromType<InputLayouts>().keyToValue(layout.toUtf8().data(),
&ok));
if (!ok) {
return "";
}
return d->layoutFiles.value(layoutVal, {}).spaceIdentifier;
}
8 changes: 6 additions & 2 deletions src/DeclarativeInputEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ class DeclarativeInputEngine : public QObject {
Q_INVOKABLE QString fileOfLayout(QString layout);

/**
* Use this function to get the correct layout file for each language
* (only needed for languages that share one file)
* Use this function to get the correct description for each language
*/
Q_INVOKABLE QString descriptionOfLayout(QString layout);

/**
* Use this function to get the correct 'space'-identifier for each language
*/
Q_INVOKABLE QString spaceIdentifierOfLayout(QString layout);

public slots:
/**
* Emits a key click event for the given key, text and modifiers.
Expand Down
37 changes: 37 additions & 0 deletions src/VirtualKeyboardInputContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <private/qquickflickable_p.h>

#include <QPropertyAnimation>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickwindow.h>

#include "DeclarativeInputEngine.h"
#include "EnterKeyAction.hpp"
Expand Down Expand Up @@ -70,6 +72,14 @@ bool VirtualKeyboardInputContext::focusItemHasEnterKeyAction(
qmlAttachedPropertiesObject<EnterKeyAction>(item, false);
}

void VirtualKeyboardInputContext::registerInputPanel(QObject *inputPanel)
{
Q_ASSERT(!this->inputPanel);
this->inputPanel = inputPanel;
if (QQuickItem *item = qobject_cast<QQuickItem *>(inputPanel))
item->setZ(std::numeric_limits<qreal>::max());
}

bool VirtualKeyboardInputContext::isValid() const { return true; }

QRectF VirtualKeyboardInputContext::keyboardRect() const { return QRectF(); }
Expand Down Expand Up @@ -108,9 +118,36 @@ void VirtualKeyboardInputContext::setFocusObject(QObject *object) {

bool AcceptsInput = d->FocusItem->inputMethodQuery(Qt::ImEnabled).toBool();
if (!AcceptsInput) {
hideInputPanel();
return;
}

// set the focusItem as parent of InputPanel
if (QObject *item = inputItem()) {
// ToDo: the InputPanel is set once, so cast can be done at register QQuickItem
if (QQuickItem *vkbPanel = qobject_cast<QQuickItem*>(inputPanel)) {
// ToDo: cast of inputItem is overflow ... use d->FocusItem
if (QQuickItem *quickItem = qobject_cast<QQuickItem*>(item)) {
const QVariant isRootItem = vkbPanel->property("__isRootItem");
/*
For integrated keyboards, make sure it's a sibling to the overlay. The
high z-order will make sure it gets events also during a modal session.
*/
if (isRootItem.isValid() && !isRootItem.toBool()) {
vkbPanel->setParentItem(quickItem->window()->contentItem());
vkbPanel->setProperty("__reparented", true);
}
}
}
}

visibleConnection = std::make_shared<QMetaObject::Connection>(QObject::connect(d->FocusItem, &QQuickItem::visibleChanged, this, [&](){
if(!d->FocusItem->isVisible())
hideInputPanel();
else
showInputPanel();
}));

emit inputItemChanged();

Qt::InputMethodHints InputMethodHints(
Expand Down
11 changes: 11 additions & 0 deletions src/VirtualKeyboardInputContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <qpa/qplatforminputcontext.h>

#include <QRectF>
#include <QPointer>
#include <memory.h>

class QQmlEngine;
class QJSEngine;
Expand Down Expand Up @@ -96,6 +98,12 @@ class VirtualKeyboardInputContext : public QPlatformInputContext {
*/
Q_INVOKABLE bool focusItemHasEnterKeyAction(QObject *item) const;

/**
* This function register the InputPanel (QQucikItem) to the backend
* to handle the focusItem as parent
*/
Q_INVOKABLE void registerInputPanel(QObject *inputPanel);

protected:
/**
* Protected constructor - use instance function to get the one and only
Expand Down Expand Up @@ -135,7 +143,10 @@ class VirtualKeyboardInputContext : public QPlatformInputContext {
static QObject *inputContextProvider(QQmlEngine *engine,
QJSEngine *scriptEngine);

private:
VirtualKeyboardInputContextPrivate *d;
QPointer<QObject> inputPanel;
std::shared_ptr<QMetaObject::Connection> visibleConnection;
};

#endif // VIRTUALKEYBOARDINPUTCONTEXT_H
11 changes: 11 additions & 0 deletions src/qml/InputPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Item {
property string languageIcon: "qrc:/icons/language.png"
property var availableLanguageLayouts: ["En"]

/*! \internal */
readonly property bool __isRootItem: inputPanel.parent !== null && inputPanel.parent.parent === null

function showKeyPopup(keyButton) {
keyPopup.popup(keyButton, root);
}
Expand All @@ -34,14 +37,17 @@ Item {

function loadLettersLayout() {
var description = InputEngine.descriptionOfLayout(languageLayout);
var spaceIdentifier = InputEngine.spaceIdentifierOfLayout(languageLayout);
var source = InputEngine.fileOfLayout(languageLayout);
if (description !== "" && source !== "") {
layoutLoader.langDescription = description;
layoutLoader.spaceIdentifier = spaceIdentifier;
layoutLoader.setSource(source + ".qml", {
"inputPanel": root
});
} else {
layoutLoader.langDescription = "English";
layoutLoader.spaceIdentifier = "space";
layoutLoader.setSource("EnLayout.qml", {
"inputPanel": root
});
Expand All @@ -59,6 +65,9 @@ Item {
}
onLanguageLayoutChanged: loadLettersLayout()
Component.onCompleted: {

InputContext.registerInputPanel(root)

if (availableLanguageLayouts.length == 0)
availableLanguageLayouts = ["En"];

Expand Down Expand Up @@ -120,6 +129,8 @@ Item {

// lang description only needed for layouts that share a file
property string langDescription
// space identifier for the correct translation of the word "space"
property string spaceIdentifier

anchors {
fill: parent
Expand Down
1 change: 1 addition & 0 deletions src/qml/QwertyLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down
2 changes: 2 additions & 0 deletions src/qml/SymbolLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Item {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down Expand Up @@ -492,6 +493,7 @@ Item {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: spaceIdentifier
}

Key {
Expand Down

0 comments on commit 5af2d82

Please sign in to comment.