Open-Typer
Open source typewriting tutor program
Loading...
Searching...
No Matches
KeyboardLayout.h
1/*
2 * KeyboardLayout.h
3 * This file is part of Open-Typer
4 *
5 * Copyright (C) 2023 - adazem009
6 *
7 * Open-Typer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * Open-Typer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Open-Typer. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KEYBOARDLAYOUT_H
22#define KEYBOARDLAYOUT_H
23
24#include <QObject>
25#include <QVariant>
26#include <QPoint>
27#include "Key.h"
28
30class Q_DECL_EXPORT KeyboardLayout : public QObject
31{
32 Q_OBJECT
33 Q_PROPERTY(QString layoutId READ layoutId WRITE setLayoutId NOTIFY layoutIdChanged)
34 Q_PROPERTY(QString variant READ variant WRITE setVariant NOTIFY variantChanged)
35#if QT_VERSION > QT_VERSION_CHECK(5, 15, 0)
36 Q_PROPERTY(KeyboardRow rowB READ rowB NOTIFY rowBChanged)
37 Q_PROPERTY(KeyboardRow rowC READ rowC NOTIFY rowCChanged)
38 Q_PROPERTY(KeyboardRow rowD READ rowD NOTIFY rowDChanged)
39 Q_PROPERTY(KeyboardRow rowE READ rowE NOTIFY rowEChanged)
40#else
41 Q_PROPERTY(QVariantList rowB READ rowB NOTIFY rowBChanged)
42 Q_PROPERTY(QVariantList rowC READ rowC NOTIFY rowCChanged)
43 Q_PROPERTY(QVariantList rowD READ rowD NOTIFY rowDChanged)
44 Q_PROPERTY(QVariantList rowE READ rowE NOTIFY rowEChanged)
45#endif
46 public:
47 enum Hand
48 {
49 Hand_Invalid = 0,
50 Hand_Left = -1,
51 Hand_Right = 1
52 };
53 Q_ENUM(Hand)
54
55 enum Finger
56 {
57 Finger_Invalid = 0,
58 Finger_LeftLittle = -5,
59 Finger_LeftRing = -4,
60 Finger_LeftMiddle = -3,
61 Finger_LeftIndex = -2,
62 Finger_LeftThumb = -1,
63 Finger_RightThumb = 1,
64 Finger_RightIndex = 2,
65 Finger_RightMiddle = 3,
66 Finger_RightRing = 4,
67 Finger_RightLittle = 5
68 };
69 Q_ENUM(Finger)
70
71 enum Row
72 {
73 Row_A = 0,
74 Row_B = 1,
75 Row_C = 2,
76 Row_D = 3,
77 Row_E = 4
78 };
79 Q_ENUM(Row)
80
81 explicit KeyboardLayout(QObject *parent = nullptr);
82 KeyboardLayout(QString id, QObject *parent = nullptr);
83 QString layoutId(void);
84 void setLayoutId(QString id);
85 QString variant(void);
86 void setVariant(QString variant);
87#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
88 KeyboardRow rowB(void);
89 KeyboardRow rowC(void);
90 KeyboardRow rowD(void);
91 KeyboardRow rowE(void);
92#else
93 QVariantList rowB(void);
94 QVariantList rowC(void);
95 QVariantList rowD(void);
96 QVariantList rowE(void);
97#endif
98 Q_INVOKABLE Finger keyFinger(Row row, int id);
99 Q_INVOKABLE Hand fingerHand(Finger finger);
100#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
101 Q_INVOKABLE KeyboardRow characterKeys(QChar character);
102#else
103 Q_INVOKABLE QVariantList characterKeys(QChar character);
104#endif
105
106 private:
107 void init(void);
108 void loadLayout(QString rawData, QString variantName);
109 QVariantList parse(QString data);
110 QString nestedData(int *pos, QString data, QString startToken, QString endToken);
111 QPair<QString, QString> keyText(QString id, bool *isDead = nullptr);
112 QPoint keyPos(QString keyId, KeyboardUtils::KeyType *type = nullptr);
113 void addKey(Key key, int x, int y);
114 Key findKeyInRow(QChar character, KeyboardRow row, int *id = nullptr, bool *isShifted = nullptr, bool *ok = nullptr);
115 Key findKey(QChar character, Row *row = nullptr, int *id = nullptr, bool *isShifted = nullptr, bool *ok = nullptr);
116 KeyboardUtils::KeyType getShiftKey(Row row, int id);
117 QString m_layoutId;
118 QString m_variant;
119 KeyboardRow m_rowB;
120 KeyboardRow m_rowC;
121 KeyboardRow m_rowD;
122 KeyboardRow m_rowE;
123
124 signals:
125 void layoutIdChanged(QString id);
126 void variantChanged(QString variant);
127 void rowBChanged(KeyboardRow row);
128 void rowCChanged(KeyboardRow row);
129 void rowDChanged(KeyboardRow row);
130 void rowEChanged(KeyboardRow row);
131};
132
133#endif // KEYBOARDLAYOUT_H
The Key class is used for the keys on the on screen keyboard.
Definition Key.h:30
The KeyboardLayout class provides information about a keyboard layout.
Definition KeyboardLayout.h:31