aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cerence/xt9/xt9common/xt9kdbkey.h
blob: bd8e9a839e4dc9d68cad9b950c914649181eef09 (plain)
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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef XT9KDBKEY_H
#define XT9KDBKEY_H

#include "xt9kdbelement.h"
#include <QRect>
#include <QRectF>

QT_BEGIN_NAMESPACE
namespace QtVirtualKeyboard {

class Xt9KdbKey : public Xt9KdbElement
{
    Q_GADGET

public:
    enum class Type {
        regional,
        nonRegional,
        smartPunct,
        string,
        function
    };
    Q_ENUM(Type)

    // The names must match with et9kbdef.h.
    // The enum value must not be assigned.
    enum class Name {
        NONE,
        ET9KEY_BACK,
        ET9KEY_TAB,
        ET9KEY_NEW_LINE,
        ET9KEY_SPACE,
        ET9KEY_LEFT,
        ET9KEY_UP,
        ET9KEY_RIGHT,
        ET9KEY_DOWN,
        ET9KEY_SHIFT,
        ET9KEY_LANGUAGE,
    };
    Q_ENUM(Name)

    Xt9KdbKey();

    void serialize(QXmlStreamWriter &writer) const;

    QRect absolute;
    QRectF relative;
    Type type;
    Name name;
    QString label;
    QString labelShifted;
    QString codes;
    QString codesShifted;
    bool hackWriteDistinctKeysForAllCodes;

private:
    template<typename T>
    static QString joinCodeList(const T &codes);
};

template<typename T>
QString Xt9KdbKey::joinCodeList(const T &codes)
{
    static const QString HEX_VALUE = QStringLiteral("0x%1");

    QString result;
    bool first = true;

    for (const QChar &code : codes) {
        if (first)
            first = false;
        else
            result.append(QLatin1Char(','));

        result.append(HEX_VALUE.arg(code.unicode(), 0, 16));
    }

    return result;
}

} // namespace QtVirtualKeyboard
QT_END_NAMESPACE

#endif // XT9KDBKEY_H