-
Notifications
You must be signed in to change notification settings - Fork 445
/
Copy pathUBPlatformUtils.h
244 lines (204 loc) · 6.67 KB
/
UBPlatformUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* Copyright (C) 2015-2022 Département de l'Instruction Publique (DIP-SEM)
*
* Copyright (C) 2013 Open Education Foundation
*
* Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
* l'Education Numérique en Afrique (GIP ENA)
*
* This file is part of OpenBoard.
*
* OpenBoard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License,
* with a specific linking exception for the OpenSSL project's
* "OpenSSL" library (or with modified versions of it that use the
* same license as the "OpenSSL" library).
*
* OpenBoard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBPLATFORMUTILS_H_
#define UBPLATFORMUTILS_H_
#include <QtCore>
#include <QIcon>
#include <QProcess>
class QMainWindow;
#define SYMBOL_KEYS_COUNT 47
/*
Declaration for single keycode (code, which will be sent to output after pressing of button)
Each button has several codes, associated with shift state and modifier
symbol - (Windows only) Unide symbol to send
code - (LINUX, MAC) - code of key to press. Phisical keycode on MAC, position in keys table on LINUX
modifier (LINUX) - offset in keys table
*/
struct KEYCODE{
KEYCODE()
:symbol(0)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol)
:symbol(_symbol)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol,
unsigned char _code,
int _modifier)
:symbol(_symbol)
,code(_code)
,modifier(_modifier)
{}
bool empty() const
{
return symbol == 0;
}
int symbol;
unsigned char code;
int modifier;
};
/*
Declaration of single button. Properties:
symbol1, symbol2 - symbols to display under obscreen keyboard on normal/shifted modes
capsLockSwitch - if true, CapsLock button switched keystate to "shifted"
modifier1/modifier2 - if >0 means modified symbol for next press (modifier * 2 + shiststate index in codes array)
If this code dedined (not empty), this symbol will sent to output. For French keyboard layout
codes[i] - code for pressed symbol.
code[0] - normal symbol
code[1] - shifted symbol
code[2] - modifier = 1, normal symbol
code[3] - modifier = 1, shifted symbol
...
*/
struct KEYBT
{
QChar symbol1;
QChar symbol2;
bool capsLockSwitch;
int modifier1;
int modifier2;
KEYCODE codes[8];
KEYBT( QChar _symbol1,
QChar _symbol2,
bool _capsLockSwitch,
int _modifier1,
int _modifier2,
KEYCODE c1 = 0,
KEYCODE c2 = 0,
KEYCODE c3 = 0,
KEYCODE c4 = 0,
KEYCODE c5 = 0,
KEYCODE c6 = 0,
KEYCODE c7 = 0,
KEYCODE c8 = 0)
:symbol1(_symbol1)
,symbol2(_symbol2)
,capsLockSwitch(_capsLockSwitch)
,modifier1(_modifier1)
,modifier2(_modifier2)
{
codes[0] = c1;
codes[1] = c2;
codes[2] = c3;
codes[3] = c4;
codes[4] = c5;
codes[5] = c6;
codes[6] = c7;
codes[7] = c8;
}
~KEYBT()
{}
};
class UBKeyboardLocale
{
public:
UBKeyboardLocale(const QString& _fullName,
const QString& _name,
const QString& _id,
QIcon* _icon,
KEYBT** _symbols)
:fullName(_fullName),name(_name), id(_id), icon(_icon),
constSymbols(NULL), varSymbols(_symbols)
{}
UBKeyboardLocale(const QString& _fullName,
const QString& _name,
const QString& _id,
QIcon* _icon,
KEYBT _symbols[])
:fullName(_fullName),name(_name), id(_id), icon(_icon),
constSymbols(_symbols), varSymbols(NULL)
{}
~UBKeyboardLocale();
const QString fullName;
const QString name;
const QString id;
QIcon* icon;
KEYBT* operator[] (int index) const
{
return (varSymbols==NULL)? constSymbols + index : varSymbols[index];
}
private:
KEYBT* constSymbols;
KEYBT** varSymbols;
};
class UBPlatformUtils
{
Q_DECLARE_TR_FUNCTIONS(UBPlatformUtils)
private:
UBPlatformUtils();
virtual ~UBPlatformUtils();
static void initializeKeyboardLayouts();
static void destroyKeyboardLayouts();
static int nKeyboardLayouts;
static UBKeyboardLocale** keyboardLayouts;
public:
static void init();
static void destroy();
static QString applicationResourcesDirectory();
static QString applicationEtcDirectory();
static QString applicationTemplateDirectory();
static void hideFile(const QString &filePath);
static void setFileType(const QString &filePath, unsigned long fileType);
static void fadeDisplayOut();
static void fadeDisplayIn();
static QString translationPath(QString pFilePrefix, QString pLanguage);
static QString systemLanguage();
static bool hasVirtualKeyboard();
static bool hasSystemOnScreenKeyboard();
static void bringPreviousProcessToFront();
static QString osUserLoginName();
static void hideMenuBarAndDock();
static void setWindowNonActivableFlag(QWidget* widget, bool nonAcivable);
static QString computerName();
static UBKeyboardLocale** getKeyboardLayouts(int& nCount);
static QString urlFromClipboard();
static QStringList availableTranslations();
static void setFrontProcess();
static void showFullScreen(QWidget * pWidget);
static void showOSK(bool show);
#ifdef Q_OS_OSX
static void SetMacLocaleByIdentifier(const QString& id);
static void toggleFinder(const bool on);
static bool errorOpeningVirtualKeyboard;
#endif
};
#ifdef Q_OS_LINUX
#include <QDBusConnection>
class OnboardListener : public QObject
{
Q_OBJECT
public:
OnboardListener(const QDBusConnection& connection, QObject* parent = nullptr);
public slots:
void onboardPropertiesChanged(QString interface, QMap<QString, QVariant> properties) const;
private:
QDBusConnection mConnection;
};
#endif
#endif /* UBPLATFORMUTILS_H_ */