UBPlatformUtils.h 6.08 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
2
 * Copyright (C) 2015-2018 Département de l'Instruction Publique (DIP-SEM)
Craig Watson's avatar
Craig Watson committed
3
 *
Claudio Valerio's avatar
Claudio Valerio committed
4
 * Copyright (C) 2013 Open Education Foundation
Claudio Valerio's avatar
Claudio Valerio committed
5
 *
Claudio Valerio's avatar
Claudio Valerio committed
6 7
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8
 *
Claudio Valerio's avatar
Claudio Valerio committed
9 10 11
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
14 15 16 17
 * 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).
 *
Claudio Valerio's avatar
Claudio Valerio committed
18
 * OpenBoard is distributed in the hope that it will be useful,
Claudio Valerio's avatar
Claudio Valerio committed
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Claudio Valerio's avatar
Claudio Valerio committed
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Claudio Valerio's avatar
Claudio Valerio committed
21
 * GNU General Public License for more details.
Claudio Valerio's avatar
Claudio Valerio committed
22
 *
Claudio Valerio's avatar
Claudio Valerio committed
23
 * You should have received a copy of the GNU General Public License
Claudio Valerio's avatar
Claudio Valerio committed
24
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
25
 */
26

27

Claudio Valerio's avatar
Claudio Valerio committed
28

Claudio Valerio's avatar
Claudio Valerio committed
29

30 31 32 33 34
#ifndef UBPLATFORMUTILS_H_
#define UBPLATFORMUTILS_H_

#include <QtCore>
#include <QIcon>
35
#include <QProcess>
36 37 38 39 40

class QMainWindow;

#define SYMBOL_KEYS_COUNT 47

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
41 42 43 44 45 46 47 48 49 50

/*
    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
*/

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
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;
};

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
83 84 85 86 87 88 89 90 91 92 93 94 95
/*
    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
        ...
*/
96 97
struct KEYBT
{
98
    QChar symbol1;
Claudio Valerio's avatar
Claudio Valerio committed
99
    QChar symbol2;
100 101 102 103 104 105
    bool capsLockSwitch;
    int modifier1;
    int modifier2;
    KEYCODE codes[8];

    KEYBT(  QChar _symbol1,
Claudio Valerio's avatar
Claudio Valerio committed
106
            QChar _symbol2,
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
            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()
    {}
};
Claudio Valerio's avatar
Claudio Valerio committed
137 138


139

Claudio Valerio's avatar
Claudio Valerio committed
140 141 142 143 144 145 146 147 148
    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),
149
                        constSymbols(NULL), varSymbols(_symbols)
Claudio Valerio's avatar
Claudio Valerio committed
150 151 152 153 154
        {}
        UBKeyboardLocale(const QString& _fullName,
            const QString& _name,
            const QString& _id,
            QIcon* _icon,
155
            KEYBT _symbols[])
Claudio Valerio's avatar
Claudio Valerio committed
156
            :fullName(_fullName),name(_name),  id(_id), icon(_icon),
157
                        constSymbols(_symbols), varSymbols(NULL)
Claudio Valerio's avatar
Claudio Valerio committed
158
        {}
159

Claudio Valerio's avatar
Claudio Valerio committed
160
        ~UBKeyboardLocale();
161

Claudio Valerio's avatar
Claudio Valerio committed
162 163 164 165
        const QString fullName;
        const QString name;
        const QString id;
        QIcon* icon;
166
        KEYBT* operator[] (int index) const
Claudio Valerio's avatar
Claudio Valerio committed
167 168 169 170
        {
            return (varSymbols==NULL)? constSymbols + index : varSymbols[index];
        }
    private:
171
        KEYBT* constSymbols;
Claudio Valerio's avatar
Claudio Valerio committed
172 173
        KEYBT** varSymbols;
    };
174 175 176 177


class UBPlatformUtils
{
178 179
    Q_DECLARE_TR_FUNCTIONS(UBPlatformUtils)

180 181 182 183 184 185 186 187 188
    private:
        UBPlatformUtils();
        virtual ~UBPlatformUtils();

        static void initializeKeyboardLayouts();
        static void destroyKeyboardLayouts();
        static int nKeyboardLayouts;
        static UBKeyboardLocale** keyboardLayouts;

189

190
public:
191 192 193 194 195 196 197
        static void init();
        static void destroy();
        static QString applicationResourcesDirectory();
        static void hideFile(const QString &filePath);
        static void setFileType(const QString &filePath, unsigned long fileType);
        static void fadeDisplayOut();
        static void fadeDisplayIn();
198 199
        static QString translationPath(QString pFilePrefix, QString pLanguage);
        static QString systemLanguage();
200 201 202 203 204 205 206 207
        static bool hasVirtualKeyboard();
        static void bringPreviousProcessToFront();
        static QString osUserLoginName();
        static void setDesktopMode(bool desktop);
        static void setWindowNonActivableFlag(QWidget* widget, bool nonAcivable);
        static QString computerName();
        static UBKeyboardLocale** getKeyboardLayouts(int& nCount);
        static QString urlFromClipboard();
208
        static QStringList availableTranslations();
209
        static void setFrontProcess();
210
        static void showFullScreen(QWidget * pWidget);
211
        static void showOSK(bool show);
212

213
#ifdef Q_OS_OSX
214 215
        static void SetMacLocaleByIdentifier(const QString& id);
#endif
216 217 218 219 220
};



#endif /* UBPLATFORMUTILS_H_ */