Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qibustypes.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qibustypes.h"
6
7
#
include
<
QHash
>
8
9
QT_BEGIN_NAMESPACE
10
11
Q_LOGGING_CATEGORY(qtQpaInputMethods,
"qt.qpa.input.methods"
)
12
Q_LOGGING_CATEGORY(qtQpaInputMethodsSerialize,
"qt.qpa.input.methods.serialize"
)
13
14
QIBusSerializable::QIBusSerializable()
15
{
16
}
17
18
void
QIBusSerializable::deserializeFrom(
const
QDBusArgument &argument)
19
{
20
argument >> name;
21
22
argument.beginMap();
23
while
(!argument.atEnd()) {
24
argument.beginMapEntry();
25
QString key;
26
QDBusVariant value;
27
argument >> key;
28
argument >> value;
29
argument.endMapEntry();
30
attachments[key] = qvariant_cast<QDBusArgument>(value.variant());
31
}
32
argument.endMap();
33
}
34
35
void
QIBusSerializable::serializeTo(QDBusArgument &argument)
const
36
{
37
argument << name;
38
39
argument.beginMap(qMetaTypeId<QString>(), qMetaTypeId<QDBusVariant>());
40
41
for
(
auto
i = attachments.begin(), end = attachments.end(); i != end; ++i) {
42
argument.beginMapEntry();
43
argument << i.key();
44
45
QDBusVariant variant(i.value().asVariant());
46
47
argument << variant;
48
argument.endMapEntry();
49
}
50
argument.endMap();
51
}
52
53
QIBusAttribute::QIBusAttribute()
54
: type(Invalid),
55
value(0),
56
start(0),
57
end(0)
58
{
59
name =
"IBusAttribute"
;
60
}
61
62
void
QIBusAttribute::serializeTo(QDBusArgument &argument)
const
63
{
64
argument.beginStructure();
65
66
QIBusSerializable::serializeTo(argument);
67
68
quint32 t = (quint32) type;
69
argument << t;
70
argument << value;
71
argument << start;
72
argument << end;
73
74
argument.endStructure();
75
}
76
77
void
QIBusAttribute::deserializeFrom(
const
QDBusArgument &argument)
78
{
79
argument.beginStructure();
80
81
QIBusSerializable::deserializeFrom(argument);
82
83
quint32 t;
84
argument >> t;
85
type = (QIBusAttribute::Type) t;
86
argument >> value;
87
argument >> start;
88
argument >> end;
89
90
argument.endStructure();
91
}
92
93
QTextCharFormat QIBusAttribute::format()
const
94
{
95
QTextCharFormat fmt;
96
switch
(type) {
97
case
Invalid:
98
break
;
99
case
Underline: {
100
QTextCharFormat::UnderlineStyle style = QTextCharFormat::NoUnderline;
101
102
switch
(value) {
103
case
UnderlineNone:
104
break
;
105
case
UnderlineSingle:
106
style = QTextCharFormat::SingleUnderline;
107
break
;
108
case
UnderlineDouble:
109
style = QTextCharFormat::DashUnderline;
110
break
;
111
case
UnderlineLow:
112
style = QTextCharFormat::DashDotLine;
113
break
;
114
case
UnderlineError:
115
style = QTextCharFormat::WaveUnderline;
116
fmt.setUnderlineColor(Qt::red);
117
break
;
118
}
119
120
fmt.setUnderlineStyle(style);
121
break
;
122
}
123
case
Foreground:
124
fmt.setForeground(QColor(value));
125
break
;
126
case
Background:
127
fmt.setBackground(QColor(value));
128
break
;
129
}
130
return
fmt;
131
}
132
133
QIBusAttributeList::QIBusAttributeList()
134
{
135
name =
"IBusAttrList"
;
136
}
137
138
void
QIBusAttributeList::serializeTo(QDBusArgument &argument)
const
139
{
140
argument.beginStructure();
141
142
QIBusSerializable::serializeTo(argument);
143
144
argument.beginArray(qMetaTypeId<QDBusVariant>());
145
for
(
int
i = 0; i < attributes.size(); ++i) {
146
QVariant variant;
147
variant.setValue(attributes.at(i));
148
argument << QDBusVariant (variant);
149
}
150
argument.endArray();
151
152
argument.endStructure();
153
}
154
155
void
QIBusAttributeList::deserializeFrom(
const
QDBusArgument &arg)
156
{
157
qCDebug(qtQpaInputMethodsSerialize) <<
"QIBusAttributeList::fromDBusArgument()"
<< arg.currentSignature();
158
159
arg.beginStructure();
160
161
QIBusSerializable::deserializeFrom(arg);
162
163
arg.beginArray();
164
while
(!arg.atEnd()) {
165
QDBusVariant var;
166
arg >> var;
167
168
QIBusAttribute attr;
169
qvariant_cast<QDBusArgument>(var.variant()) >> attr;
170
attributes.append(std::move(attr));
171
}
172
arg.endArray();
173
174
arg.endStructure();
175
}
176
177
QList<QInputMethodEvent::Attribute> QIBusAttributeList::imAttributes()
const
178
{
179
QHash<std::pair<
int
,
int
>, QTextCharFormat> rangeAttrs;
180
const
int
numAttributes = attributes.size();
181
182
// Merge text formats for identical ranges into a single QTextFormat.
183
for
(
int
i = 0; i < numAttributes; ++i) {
184
const
QIBusAttribute &attr = attributes.at(i);
185
const
QTextCharFormat &format = attr.format();
186
187
if
(format.isValid()) {
188
const
std::pair<
int
,
int
> range(attr.start, attr.end);
189
rangeAttrs[range].merge(format);
190
}
191
}
192
193
// Assemble list in original attribute order.
194
QList<QInputMethodEvent::Attribute> imAttrs;
195
imAttrs.reserve(numAttributes);
196
197
for
(
int
i = 0; i < numAttributes; ++i) {
198
const
QIBusAttribute &attr = attributes.at(i);
199
const
QTextFormat &format = attr.format();
200
201
imAttrs += QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
202
attr.start,
203
attr.end - attr.start,
204
format.isValid() ? rangeAttrs[std::pair<
int
,
int
>(attr.start, attr.end)] : format);
205
}
206
207
return
imAttrs;
208
}
209
210
QIBusText::QIBusText()
211
{
212
name =
"IBusText"
;
213
}
214
215
void
QIBusText::serializeTo(QDBusArgument &argument)
const
216
{
217
argument.beginStructure();
218
219
QIBusSerializable::serializeTo(argument);
220
221
argument << text << attributes;
222
argument.endStructure();
223
}
224
225
void
QIBusText::deserializeFrom(
const
QDBusArgument &argument)
226
{
227
qCDebug(qtQpaInputMethodsSerialize) <<
"QIBusText::fromDBusArgument()"
<< argument.currentSignature();
228
229
argument.beginStructure();
230
231
QIBusSerializable::deserializeFrom(argument);
232
233
argument >> text;
234
QDBusVariant variant;
235
argument >> variant;
236
qvariant_cast<QDBusArgument>(variant.variant()) >> attributes;
237
238
argument.endStructure();
239
}
240
241
QIBusEngineDesc::QIBusEngineDesc()
242
: rank(0)
243
{
244
name =
"IBusEngineDesc"
;
245
}
246
247
void
QIBusEngineDesc::serializeTo(QDBusArgument &argument)
const
248
{
249
argument.beginStructure();
250
251
QIBusSerializable::serializeTo(argument);
252
253
argument << engine_name;
254
argument << longname;
255
argument << description;
256
argument << language;
257
argument << license;
258
argument << author;
259
argument << icon;
260
argument << layout;
261
argument << rank;
262
argument << hotkeys;
263
argument << symbol;
264
argument << setup;
265
argument << layout_variant;
266
argument << layout_option;
267
argument << version;
268
argument << textdomain;
269
argument << iconpropkey;
270
271
argument.endStructure();
272
}
273
274
void
QIBusEngineDesc::deserializeFrom(
const
QDBusArgument &argument)
275
{
276
qCDebug(qtQpaInputMethodsSerialize) <<
"QIBusEngineDesc::fromDBusArgument()"
<< argument.currentSignature();
277
argument.beginStructure();
278
279
QIBusSerializable::deserializeFrom(argument);
280
281
argument >> engine_name;
282
argument >> longname;
283
argument >> description;
284
argument >> language;
285
argument >> license;
286
argument >> author;
287
argument >> icon;
288
argument >> layout;
289
argument >> rank;
290
argument >> hotkeys;
291
argument >> symbol;
292
argument >> setup;
293
// Previous IBusEngineDesc supports the arguments between engine_name
294
// and setup.
295
if
(argument.currentSignature() ==
""
)
296
goto
olderThanV2;
297
argument >> layout_variant;
298
argument >> layout_option;
299
// Previous IBusEngineDesc supports the arguments between engine_name
300
// and layout_option.
301
if
(argument.currentSignature() ==
""
)
302
goto
olderThanV3;
303
argument >> version;
304
if
(argument.currentSignature() ==
""
)
305
goto
olderThanV4;
306
argument >> textdomain;
307
if
(argument.currentSignature() ==
""
)
308
goto
olderThanV5;
309
argument >> iconpropkey;
310
// <-- insert new member streaming here (1/2)
311
goto
newest;
312
olderThanV2:
313
layout_variant.clear();
314
layout_option.clear();
315
olderThanV3:
316
version.clear();
317
olderThanV4:
318
textdomain.clear();
319
olderThanV5:
320
iconpropkey.clear();
321
// <-- insert new members here (2/2)
322
newest:
323
argument.endStructure();
324
}
325
326
QIBusPropTypeClientCommitPreedit::QIBusPropTypeClientCommitPreedit(
bool
inClientCommitPreedit)
327
: clientCommitPreedit(inClientCommitPreedit)
328
{
329
}
330
331
void
QIBusPropTypeClientCommitPreedit::serializeTo(QDBusArgument &argument)
const
332
{
333
argument.beginStructure();
334
argument << clientCommitPreedit;
335
argument.endStructure();
336
}
337
338
void
QIBusPropTypeClientCommitPreedit::deserializeFrom(
const
QDBusArgument &argument)
339
{
340
argument.beginStructure();
341
argument >> clientCommitPreedit;
342
argument.endStructure();
343
}
344
345
QIBusPropTypeContentType::QIBusPropTypeContentType(
unsigned
int
inPurpose,
unsigned
int
inHints)
346
: purpose(inPurpose)
347
, hints(inHints)
348
{
349
}
350
351
void
QIBusPropTypeContentType::serializeTo(QDBusArgument &argument)
const
352
{
353
argument.beginStructure();
354
argument << purpose << hints;
355
argument.endStructure();
356
}
357
358
void
QIBusPropTypeContentType::deserializeFrom(
const
QDBusArgument &argument)
359
{
360
argument.beginStructure();
361
argument >> purpose;
362
argument >> hints;
363
argument.endStructure();
364
}
365
366
QT_END_NAMESPACE
qtbase
src
plugins
platforminputcontexts
ibus
qibustypes.cpp
Generated on
for Qt by
1.18.0