Skip to content

Commit

Permalink
adapted system to support layouts sharing one file
Browse files Browse the repository at this point in the history
- added hashes for finding the corresponding file and description for one layout, instead of searching by tag
- adapted layout files to new description
  • Loading branch information
Johannes Bichler authored and AndreaRicchi committed Jun 21, 2024
1 parent 6fa5e08 commit 14509d3
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 21 deletions.
52 changes: 52 additions & 0 deletions src/DeclarativeInputEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
#include <QMetaEnum>
#include <QTimer>

#include "DeclarativeInputEngine.h"

/**
* Private data class
*/
struct DeclarativeInputEnginePrivate {
explicit DeclarativeInputEnginePrivate(DeclarativeInputEngine *_public);

struct LayoutData {
QString layoutFile;
QString description;
};

DeclarativeInputEngine *_this;
bool Animating;
QTimer *AnimatingFinishedTimer{nullptr};
Expand All @@ -20,6 +27,23 @@ struct DeclarativeInputEnginePrivate {

bool isUppercase{false};
bool symbolMode{false};
QHash<DeclarativeInputEngine::InputLayouts, LayoutData> layoutFiles = {
{DeclarativeInputEngine::En, {"EnLayout", "English"}},
{DeclarativeInputEngine::Fr, {"FrLayout", "Français"}},
{DeclarativeInputEngine::It, {"ItLayout", "Italiano"}},
{DeclarativeInputEngine::Es, {"EsLayout", "Español"}},
{DeclarativeInputEngine::De, {"DeLayout", "Deutsch"}},
{DeclarativeInputEngine::Nl, {"NlLayout", "Nederlands"}},
{DeclarativeInputEngine::Pt, {"PtLayout", "Português"}},
{DeclarativeInputEngine::Cs, {"CsLayout", "Čeština"}},
{DeclarativeInputEngine::El, {"ElLayout", "Ελληνικός"}},
{DeclarativeInputEngine::Pl, {"PlLayout", "Polski"}},
{DeclarativeInputEngine::Hr, {"LtSrHrBsLayout", "Hrvatski"}},
{DeclarativeInputEngine::CyBs, {"CySrBsLayout", "Босански"}},
{DeclarativeInputEngine::LtBs, {"LtSrHrBsLayout", "Bosanski"}},
{DeclarativeInputEngine::CySr, {"CySrBsLayout", "Српски"}},
{DeclarativeInputEngine::LtSr, {"LtSrHrBsLayout", "Srpski"}},
{DeclarativeInputEngine::Sv, {"SvLayout", "Svenska"}}};
};

DeclarativeInputEnginePrivate::DeclarativeInputEnginePrivate(
Expand Down Expand Up @@ -113,3 +137,31 @@ bool DeclarativeInputEngine::inputLayoutValid(const QString &layout) const {
<< "is not supported. Falling back to En!";
return false;
}

QString DeclarativeInputEngine::fileOfLayout(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, {}).layoutFile;
}

QString DeclarativeInputEngine::descriptionOfLayout(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, {}).description;
}
2 changes: 1 addition & 1 deletion src/qml/CsLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Čeština"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/DeLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Deutsch"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/ElLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Ελληνικός"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/EnLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "English"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/EsLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Español"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/FrLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Français"
btnDisplayedText: langDescription
}

Key {
Expand Down
25 changes: 15 additions & 10 deletions src/qml/InputPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ Item {
}

function loadLettersLayout() {
if (InputEngine.inputLayoutValid(languageLayout))
layoutLoader.setSource(languageLayout + "Layout.qml", {
"inputPanel": root
});
else
layoutLoader.setSource("EnLayout.qml", {
"inputPanel": root
});
}
var description = InputEngine.descriptionOfLayout(languageLayout);
var source = InputEngine.fileOfLayout(languageLayout);
if(description !== "" && source !== ""){
layoutLoader.langDescription = description
layoutLoader.setSource(source + ".qml", {
"inputPanel": root});
}
else{
layoutLoader.langDescription = "English"
layoutLoader.setSource("EnLayout.qml", {
"inputPanel": root});
}
}

objectName: "inputPanel"
width: parent.width
Expand Down Expand Up @@ -112,7 +116,8 @@ Item {

Loader {
id: layoutLoader

// lang description only needed for layouts that share a file
property string langDescription
anchors {
fill: parent
margins: 5
Expand Down
2 changes: 1 addition & 1 deletion src/qml/ItLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Italiano"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/NlLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Nederlands"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/PlLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Polski"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/PtLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Português"
btnDisplayedText: langDescription
}

Key {
Expand Down
2 changes: 1 addition & 1 deletion src/qml/SvLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ ColumnLayout {
SpaceKey {
weight: 1168
inputPanelRef: inputPanel
btnDisplayedText: "Svenska"
btnDisplayedText: langDescription
}

Key {
Expand Down

0 comments on commit 14509d3

Please sign in to comment.