| 1 | // Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDINPUTMETHODEVENTBUILDER_H |
| 5 | #define QWAYLANDINPUTMETHODEVENTBUILDER_H |
| 6 | |
| 7 | #include <QInputMethodEvent> |
| 8 | #include <private/qglobal_p.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | class QWaylandInputMethodEventBuilder |
| 13 | { |
| 14 | public: |
| 15 | QWaylandInputMethodEventBuilder() = default; |
| 16 | ~QWaylandInputMethodEventBuilder(); |
| 17 | |
| 18 | void reset(); |
| 19 | |
| 20 | void setCursorPosition(int32_t index, int32_t anchor); |
| 21 | void setDeleteSurroundingText(uint32_t beforeLength, uint32_t afterLength); |
| 22 | |
| 23 | void addPreeditStyling(uint32_t index, uint32_t length, uint32_t style); |
| 24 | void setPreeditCursor(int32_t index); |
| 25 | |
| 26 | QInputMethodEvent *buildCommit(const QString &text); |
| 27 | QInputMethodEvent *buildPreedit(const QString &text); |
| 28 | |
| 29 | static int indexFromWayland(const QString &text, int length, int base = 0); |
| 30 | static int indexToWayland(const QString &text, int length, int base = 0); |
| 31 | |
| 32 | static int trimmedIndexFromWayland(const QString &text, int length, int base = 0); |
| 33 | private: |
| 34 | QPair<int, int> replacementForDeleteSurrounding(); |
| 35 | |
| 36 | int32_t m_anchor = 0; |
| 37 | int32_t m_cursor = 0; |
| 38 | uint32_t m_deleteBefore = 0; |
| 39 | uint32_t m_deleteAfter = 0; |
| 40 | |
| 41 | int32_t m_preeditCursor = 0; |
| 42 | QList<QInputMethodEvent::Attribute> m_preeditStyles; |
| 43 | }; |
| 44 | |
| 45 | struct QWaylandInputMethodContentType { |
| 46 | uint32_t hint = 0; |
| 47 | uint32_t purpose = 0; |
| 48 | |
| 49 | static QWaylandInputMethodContentType convert(Qt::InputMethodHints hints); |
| 50 | static QWaylandInputMethodContentType convertV3(Qt::InputMethodHints hints); |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | QT_END_NAMESPACE |
| 55 | |
| 56 | #endif // QWAYLANDINPUTMETHODEVENTBUILDER_H |
| 57 | |