7#include <QGuiApplication>
10#include <QTextCharFormat>
12#ifdef QT_BUILD_WAYLANDCOMPOSITOR_LIB
13#include <QtWaylandCompositor/private/qwayland-server-text-input-unstable-v2.h>
14#include <QtWaylandCompositor/private/qwayland-server-text-input-unstable-v3.h>
16#include <QtWaylandClient/private/qwayland-text-input-unstable-v2.h>
17#include <QtWaylandClient/private/qwayland-text-input-unstable-v3.h>
33 m_preeditStyles.
clear();
44 m_deleteBefore = beforeLength;
45 m_deleteAfter = afterLength;
53 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_NONE:
55 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_DEFAULT:
56 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_UNDERLINE:
61 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_ACTIVE:
62 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_INACTIVE:
64 format.setFontUnderline(
true);
68 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_HIGHLIGHT:
69 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_SELECTION:
71 format.setFontUnderline(
true);
79 case ZWP_TEXT_INPUT_V2_PREEDIT_STYLE_INCORRECT:
80 format.setFontUnderline(
true);
92 m_preeditCursor =
index;
97 QList<QInputMethodEvent::Attribute> attributes;
99 const QPair<int, int> replacement = replacementForDeleteSurrounding();
101 if (m_cursor != 0 || m_anchor != 0) {
107 const int absoluteOffset = absoluteCursor -
cursor;
110 surrounding.replace(
qMin(anchor,
cursor) + replacement.first,
114 indexFromWayland(surrounding, m_cursor, cursorAfterCommit) + absoluteOffset,
115 indexFromWayland(surrounding, m_anchor, cursorAfterCommit) + absoluteOffset,
120 event->setCommitString(
text, replacement.first, replacement.second);
127 QList<QInputMethodEvent::Attribute> attributes;
129 if (m_preeditCursor < 0) {
143 const QPair<int, int> replacement = replacementForDeleteSurrounding();
144 event->setCommitString(
QString(), replacement.first, replacement.second);
149QPair<int, int> QWaylandInputMethodEventBuilder::replacementForDeleteSurrounding()
151 if (m_deleteBefore == 0 && m_deleteAfter == 0)
152 return QPair<int, int>(0, 0);
158 const int selectionStart =
qMin(
cursor, anchor);
159 const int selectionEnd =
qMax(
cursor, anchor);
161 const int deleteBefore = selectionStart -
indexFromWayland(surrounding, -m_deleteBefore, selectionStart);
162 const int deleteAfter =
indexFromWayland(surrounding, m_deleteAfter, selectionEnd) - selectionEnd;
164 return QPair<int, int>(-deleteBefore, deleteBefore + deleteAfter);
169 uint32_t
hint = ZWP_TEXT_INPUT_V2_CONTENT_HINT_NONE;
170 uint32_t
purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_NORMAL;
173 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_HIDDEN_TEXT;
175 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_SENSITIVE_DATA;
177 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_CAPITALIZATION;
182 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_UPPERCASE;
184 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_LOWERCASE;
186 hint |= (ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_COMPLETION
187 | ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_CORRECTION);
191 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DATE;
193 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DATETIME;
195 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_TIME;
198 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_LATIN;
200 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_MULTILINE;
202 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DIGITS;
204 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_NUMBER;
206 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_UPPERCASE;
208 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_LOWERCASE;
210 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_PHONE;
212 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_EMAIL;
214 purpose = ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_URL;
216 hint |= ZWP_TEXT_INPUT_V2_CONTENT_HINT_LATIN;
223 uint32_t
hint = ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE;
224 uint32_t
purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL;
227 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_HIDDEN_TEXT;
229 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_SENSITIVE_DATA;
231 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_AUTO_CAPITALIZATION;
236 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE;
238 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE;
240 hint |= (ZWP_TEXT_INPUT_V3_CONTENT_HINT_COMPLETION
241 | ZWP_TEXT_INPUT_V3_CONTENT_HINT_SPELLCHECK);
245 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATE;
247 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DATETIME;
249 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TIME;
251 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LATIN;
253 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_MULTILINE;
255 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_DIGITS;
257 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER;
259 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_UPPERCASE;
261 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LOWERCASE;
263 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE;
265 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL;
267 purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL;
269 hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_LATIN;
300 for (
int i = 0;
i < 4;
i++) {
304 const unsigned char ch = utf8.at(
start +
i);
306 if (ch < 0x80 || ch > 0xbf)
316 for (
int i = 0;
i < 4;
i++) {
317 const unsigned char ch = utf8.at(
start -
i);
319 if (ch < 0x80 || ch > 0xbf)
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
The QColor class provides colors based on RGB, HSV or CMYK values.
void append(parameter_type t)
The QPalette class contains color groups for each widget state.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
QString mid(qsizetype position, qsizetype n=-1) const &
qsizetype size() const noexcept
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
qsizetype length() const noexcept
Returns the number of characters in this string.
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
Combined button and popup list for selecting options.
@ ImhFormattedNumbersOnly
@ ImhDialableCharactersOnly
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum format
static QWaylandInputMethodContentType convert(Qt::InputMethodHints hints)
static QWaylandInputMethodContentType convertV3(Qt::InputMethodHints hints)