Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtextformat.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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
4#include "qtextformat.h"
5#include "qtextformat_p.h"
6
7#include <qvariant.h>
8#include <qdatastream.h>
9#include <qdebug.h>
10#include <qmap.h>
11#include <qhashfunctions.h>
12
14
109QTextLength::operator QVariant() const
110{
111 return QVariant::fromValue(*this);
112}
113
114#ifndef QT_NO_DATASTREAM
116{
117 return stream << qint32(length.lengthType) << double(length.fixedValueOrPercentage);
118}
119
121{
122 qint32 type;
123 double fixedValueOrPercentage;
124 stream >> type >> fixedValueOrPercentage;
125 length.fixedValueOrPercentage = fixedValueOrPercentage;
126 length.lengthType = QTextLength::Type(type);
127 return stream;
128}
129#endif // QT_NO_DATASTREAM
130
131namespace {
132struct Property
133{
134 inline Property(qint32 k, const QVariant &v) : key(k), value(v) {}
135 inline Property() {}
136
137 qint32 key = -1;
139
140 inline bool operator==(const Property &other) const
141 { return key == other.key && value == other.value; }
142};
143}
145
147{
148public:
149 QTextFormatPrivate() : hashDirty(true), fontDirty(true), hashValue(0) {}
150
151 inline size_t hash() const
152 {
153 if (!hashDirty)
154 return hashValue;
155 return recalcHash();
156 }
157
158 inline bool operator==(const QTextFormatPrivate &rhs) const {
159 if (hash() != rhs.hash())
160 return false;
161
162 return props == rhs.props;
163 }
164
166 {
167 hashDirty = true;
169 fontDirty = true;
170
171 for (int i = 0; i < props.size(); ++i)
172 if (props.at(i).key == key) {
173 props[i].value = value;
174 return;
175 }
176 props.append(Property(key, value));
177 }
178
180 {
181 for (int i = 0; i < props.size(); ++i)
182 if (props.at(i).key == key) {
183 hashDirty = true;
185 fontDirty = true;
186 props.remove(i);
187 return;
188 }
189 }
190
191 inline int propertyIndex(qint32 key) const
192 {
193 for (int i = 0; i < props.size(); ++i)
194 if (props.at(i).key == key)
195 return i;
196 return -1;
197 }
198
200 {
201 const int idx = propertyIndex(key);
202 if (idx < 0)
203 return QVariant();
204 return props.at(idx).value;
205 }
206
207 inline bool hasProperty(qint32 key) const
208 { return propertyIndex(key) != -1; }
209
210 void resolveFont(const QFont &defaultFont);
211
212 inline const QFont &font() const {
213 if (fontDirty)
214 recalcFont();
215 return fnt;
216 }
217
218 QList<Property> props;
219private:
220
221 size_t recalcHash() const;
222 void recalcFont() const;
223
224 mutable bool hashDirty;
225 mutable bool fontDirty;
226 mutable size_t hashValue;
227 mutable QFont fnt;
228
229 friend QDataStream &operator<<(QDataStream &, const QTextFormat &);
231};
232
233static inline size_t hash(const QColor &color)
234{
235 return (color.isValid()) ? color.rgba() : 0x234109;
236}
237
238static inline size_t hash(const QPen &pen)
239{
240 return hash(pen.color()) + qHash(pen.widthF());
241}
242
243static inline size_t hash(const QBrush &brush)
244{
245 return hash(brush.color()) + (brush.style() << 3);
246}
247
248static inline size_t variantHash(const QVariant &variant)
249{
250 // simple and fast hash functions to differentiate between type and value
251 switch (variant.userType()) { // sorted by occurrence frequency
252 case QMetaType::QString: return qHash(variant.toString());
253 case QMetaType::Double: return qHash(variant.toDouble());
254 case QMetaType::Int: return 0x811890U + variant.toInt();
255 case QMetaType::QBrush:
256 return 0x01010101 + hash(qvariant_cast<QBrush>(variant));
257 case QMetaType::Bool: return 0x371818 + variant.toBool();
258 case QMetaType::QPen: return 0x02020202 + hash(qvariant_cast<QPen>(variant));
259 case QMetaType::QVariantList:
260 return 0x8377U + qvariant_cast<QVariantList>(variant).size();
261 case QMetaType::QColor: return hash(qvariant_cast<QColor>(variant));
262 case QMetaType::QTextLength:
263 return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
264 case QMetaType::Float: return qHash(variant.toFloat());
265 case QMetaType::UnknownType: return 0;
266 default: break;
267 }
268 return qHash(variant.typeName());
269}
270
271static inline size_t getHash(const QTextFormatPrivate *d, int format)
272{
273 return (d ? d->hash() : 0) + format;
274}
275
276size_t QTextFormatPrivate::recalcHash() const
277{
278 hashValue = 0;
279 const auto end = props.constEnd();
280 for (auto it = props.constBegin(); it != end; ++it)
281 hashValue += (static_cast<quint32>(it->key) << 16) + variantHash(it->value);
282
283 hashDirty = false;
284
285 return hashValue;
286}
287
289{
290 recalcFont();
291 const uint oldMask = fnt.resolveMask();
292 fnt = fnt.resolve(defaultFont);
293
295 const qreal scaleFactors[7] = {qreal(0.7), qreal(0.8), qreal(1.0), qreal(1.2), qreal(1.5), qreal(2), qreal(2.4)};
296
297 const int htmlFontSize = qBound(0, property(QTextFormat::FontSizeAdjustment).toInt() + 3 - 1, 6);
298
299
300 if (defaultFont.pointSize() <= 0) {
301 qreal pixelSize = scaleFactors[htmlFontSize] * defaultFont.pixelSize();
302 fnt.setPixelSize(qRound(pixelSize));
303 } else {
304 qreal pointSize = scaleFactors[htmlFontSize] * defaultFont.pointSizeF();
305 fnt.setPointSizeF(pointSize);
306 }
307 }
308
309 fnt.setResolveMask(oldMask);
310}
311
312void QTextFormatPrivate::recalcFont() const
313{
314 // update cached font as well
315 QFont f;
316
317 bool hasSpacingInformation = false;
319 qreal letterSpacing = 0.0;
320
321 for (int i = 0; i < props.size(); ++i) {
322 switch (props.at(i).key) {
324 f.setFamilies(props.at(i).value.toStringList());
325 break;
327 f.setStyleName(props.at(i).value.toString());
328 break;
330 f.setPointSizeF(props.at(i).value.toReal());
331 break;
333 f.setPixelSize(props.at(i).value.toInt());
334 break;
336 const QVariant weightValue = props.at(i).value;
337 int weight = weightValue.toInt();
338 if (weight >= 0 && weightValue.isValid())
339 f.setWeight(QFont::Weight(weight));
340 break; }
342 f.setItalic(props.at(i).value.toBool());
343 break;
345 if (! hasProperty(QTextFormat::TextUnderlineStyle)) // don't use the old one if the new one is there.
346 f.setUnderline(props.at(i).value.toBool());
347 break;
349 f.setUnderline(static_cast<QTextCharFormat::UnderlineStyle>(props.at(i).value.toInt()) == QTextCharFormat::SingleUnderline);
350 break;
352 f.setOverline(props.at(i).value.toBool());
353 break;
355 f.setStrikeOut(props.at(i).value.toBool());
356 break;
358 spacingType = static_cast<QFont::SpacingType>(props.at(i).value.toInt());
359 hasSpacingInformation = true;
360 break;
362 letterSpacing = props.at(i).value.toReal();
363 hasSpacingInformation = true;
364 break;
366 f.setWordSpacing(props.at(i).value.toReal());
367 break;
369 f.setCapitalization(static_cast<QFont::Capitalization> (props.at(i).value.toInt()));
370 break;
372 const bool value = props.at(i).value.toBool();
373 if (f.fixedPitch() != value)
374 f.setFixedPitch(value);
375 break; }
377 f.setStretch(props.at(i).value.toInt());
378 break;
380 f.setStyleHint(static_cast<QFont::StyleHint>(props.at(i).value.toInt()), f.styleStrategy());
381 break;
383 f.setHintingPreference(static_cast<QFont::HintingPreference>(props.at(i).value.toInt()));
384 break;
386 f.setStyleStrategy(static_cast<QFont::StyleStrategy>(props.at(i).value.toInt()));
387 break;
389 f.setKerning(props.at(i).value.toBool());
390 break;
391 default:
392 break;
393 }
394 }
395
396 if (hasSpacingInformation)
397 f.setLetterSpacing(spacingType, letterSpacing);
398
399 fnt = f;
400 fontDirty = false;
401}
402
403#ifndef QT_NO_DATASTREAM
405{
406 QMap<int, QVariant> properties = fmt.properties();
407 if (stream.version() < QDataStream::Qt_6_0) {
409 if (it != properties.cend()) {
411 properties.erase(it);
412 }
413
415 if (it != properties.cend()) {
417 properties.erase(it);
418 }
419
421 if (it != properties.cend()) {
423 properties.erase(it);
424 }
425
427 if (it != properties.cend()) {
428 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().constFirst());
429 properties.erase(it);
430 }
431 }
432
433 stream << fmt.format_type << properties;
434 return stream;
435}
436
438{
439 QMap<qint32, QVariant> properties;
440 stream >> fmt.format_type >> properties;
441
442 // QTextFormat's default constructor doesn't allocate the private structure, so
443 // we have to do this, in case fmt is a default constructed value.
444 if (!fmt.d)
445 fmt.d = new QTextFormatPrivate();
446
448 it != properties.constEnd(); ++it) {
449 qint32 key = it.key();
458 fmt.d->insertProperty(key, it.value());
459 }
460
461 return stream;
462}
463
465{
466 return stream << static_cast<const QTextFormat &>(fmt);
467}
468
470{
471 return stream >> static_cast<QTextFormat &>(fmt);
472}
473
475{
476 return stream << static_cast<const QTextFormat &>(fmt);
477}
478
480{
481 return stream >> static_cast<QTextFormat &>(fmt);
482}
483
485{
486 return stream << static_cast<const QTextFormat &>(fmt);
487}
488
490{
491 return stream >> static_cast<QTextFormat &>(fmt);
492}
493
495{
496 return stream << static_cast<const QTextFormat &>(fmt);
497}
498
500{
501 return stream >> static_cast<QTextFormat &>(fmt);
502}
503
505{
506 return stream << static_cast<const QTextFormat &>(fmt);
507}
508
510{
511 return stream >> static_cast<QTextFormat &>(fmt);
512}
513#endif // QT_NO_DATASTREAM
514
873 : format_type(InvalidFormat)
874{
875}
876
883 : format_type(type)
884{
885}
886
887
895 : d(rhs.d), format_type(rhs.format_type)
896{
897}
898
906{
907 d = rhs.d;
908 format_type = rhs.format_type;
909 return *this;
910}
911
926
927
931QTextFormat::operator QVariant() const
932{
933 return QVariant::fromValue(*this);
934}
935
941{
942 if (format_type != other.format_type)
943 return;
944
945 if (!d) {
946 d = other.d;
947 return;
948 }
949
950 if (!other.d)
951 return;
952
954
955 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
956 p->props.reserve(p->props.size() + otherProps.size());
957 for (int i = 0; i < otherProps.size(); ++i) {
958 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
959 if (prop.value.isValid()) {
960 p->insertProperty(prop.key, prop.value);
961 } else {
962 p->clearProperty(prop.key);
963 }
964 }
965}
966
973{
974 return format_type;
975}
976
984
989{
990 return QTextCharFormat(*this);
991}
992
997{
998 return QTextListFormat(*this);
999}
1000
1005{
1006 return QTextTableFormat(*this);
1007}
1008
1013{
1014 return QTextFrameFormat(*this);
1015}
1016
1021{
1022 return QTextImageFormat(*this);
1023}
1024
1034
1042bool QTextFormat::boolProperty(int propertyId) const
1043{
1044 if (!d)
1045 return false;
1046 const QVariant prop = d->property(propertyId);
1047 if (prop.userType() != QMetaType::Bool)
1048 return false;
1049 return prop.toBool();
1050}
1051
1059int QTextFormat::intProperty(int propertyId) const
1060{
1061 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
1062 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
1063
1064 if (!d)
1065 return def;
1066 const QVariant prop = d->property(propertyId);
1067 if (prop.userType() != QMetaType::Int)
1068 return def;
1069 return prop.toInt();
1070}
1071
1081{
1082 if (!d)
1083 return 0.;
1084 const QVariant prop = d->property(propertyId);
1085 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1086 return 0.;
1087 return qvariant_cast<qreal>(prop);
1088}
1089
1099{
1100 if (!d)
1101 return QString();
1102 const QVariant prop = d->property(propertyId);
1103 if (prop.userType() != QMetaType::QString)
1104 return QString();
1105 return prop.toString();
1106}
1107
1117{
1118 if (!d)
1119 return QColor();
1120 const QVariant prop = d->property(propertyId);
1121 if (prop.userType() != QMetaType::QColor)
1122 return QColor();
1123 return qvariant_cast<QColor>(prop);
1124}
1125
1134QPen QTextFormat::penProperty(int propertyId) const
1135{
1136 if (!d)
1137 return QPen(Qt::NoPen);
1138 const QVariant prop = d->property(propertyId);
1139 if (prop.userType() != QMetaType::QPen)
1140 return QPen(Qt::NoPen);
1141 return qvariant_cast<QPen>(prop);
1142}
1143
1153{
1154 if (!d)
1155 return QBrush(Qt::NoBrush);
1156 const QVariant prop = d->property(propertyId);
1157 if (prop.userType() != QMetaType::QBrush)
1158 return QBrush(Qt::NoBrush);
1159 return qvariant_cast<QBrush>(prop);
1160}
1161
1169{
1170 if (!d)
1171 return QTextLength();
1172 return qvariant_cast<QTextLength>(d->property(propertyId));
1173}
1174
1183QList<QTextLength> QTextFormat::lengthVectorProperty(int propertyId) const
1184{
1185 QList<QTextLength> list;
1186 if (!d)
1187 return list;
1188 const QVariant prop = d->property(propertyId);
1189 if (prop.userType() != QMetaType::QVariantList)
1190 return list;
1191
1192 const QList<QVariant> propertyList = prop.toList();
1193 for (const auto &var : propertyList) {
1194 if (var.userType() == QMetaType::QTextLength)
1195 list.append(qvariant_cast<QTextLength>(var));
1196 }
1197
1198 return list;
1199}
1200
1206QVariant QTextFormat::property(int propertyId) const
1207{
1208 return d ? d->property(propertyId) : QVariant();
1209}
1210
1216void QTextFormat::setProperty(int propertyId, const QVariant &value)
1217{
1218 if (!d)
1219 d = new QTextFormatPrivate;
1220
1221 d->insertProperty(propertyId, value);
1222}
1223
1229void QTextFormat::setProperty(int propertyId, const QList<QTextLength> &value)
1230{
1231 if (!d)
1232 d = new QTextFormatPrivate;
1234 const int numValues = value.size();
1235 list.reserve(numValues);
1236 for (int i = 0; i < numValues; ++i)
1237 list << value.at(i);
1238 d->insertProperty(propertyId, list);
1239}
1240
1246void QTextFormat::clearProperty(int propertyId)
1247{
1248 if (!d)
1249 return;
1250 d->clearProperty(propertyId);
1251}
1252
1253
1278{
1279 if (!d)
1280 return -1;
1281 const QVariant prop = d->property(ObjectIndex);
1282 if (prop.userType() != QMetaType::Int) // ####
1283 return -1;
1284 return prop.toInt();
1285}
1286
1295{
1296 if (o == -1) {
1297 if (d.constData())
1299 } else {
1300 if (!d.constData())
1301 d = new QTextFormatPrivate;
1302 // ### type
1304 }
1305}
1306
1313bool QTextFormat::hasProperty(int propertyId) const
1314{
1315 return d ? d->hasProperty(propertyId) : false;
1316}
1317
1318/*
1319 Returns the property type for the given \a propertyId.
1320
1321 \sa hasProperty(), allPropertyIds(), Property
1322*/
1323
1327QMap<int, QVariant> QTextFormat::properties() const
1328{
1329 QMap<int, QVariant> map;
1330 if (d) {
1331 for (int i = 0; i < d->props.size(); ++i)
1332 map.insert(d->props.at(i).key, d->props.at(i).value);
1333 }
1334 return map;
1335}
1336
1342{
1343 return d ? d->props.size() : 0;
1344}
1345
1361{
1362 if (format_type != rhs.format_type)
1363 return false;
1364
1365 if (d == rhs.d)
1366 return true;
1367
1368 if (d && d->props.isEmpty() && !rhs.d)
1369 return true;
1370
1371 if (!d && rhs.d && rhs.d->props.isEmpty())
1372 return true;
1373
1374 if (!d || !rhs.d)
1375 return false;
1376
1377 return *d == *rhs.d;
1378}
1379
1457
1469
1506#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1519#else
1520/* // Qt 7 documents this function
1521 \fn QStringList QTextCharFormat::fontFamilies() const
1522 \since 5.13
1523
1524 Returns the text format's font families.
1525
1526 \sa font()
1527*/
1528#endif
1529
1539#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1552#else
1553/* // Qt 7 documents this function
1554 \fn QStringList QTextCharFormat::fontStyleName() const
1555 \since 5.13
1556
1557 Returns the text format's font style name.
1558
1559 \sa font(), QFont::styleName()
1560*/
1561#endif
1562
1643
1658{
1660 // for compatibility
1662}
1663
1988{
1990 if (prop.userType() == QMetaType::QStringList)
1991 return prop.toStringList();
1992 else if (prop.userType() != QMetaType::QString)
1993 return QStringList();
1994 return QStringList(prop.toString());
1995}
1996
1997
2098{
2100 : font.resolveMask();
2101
2106
2107 if (mask & QFont::SizeResolved) {
2108 const qreal pointSize = font.pointSizeF();
2109 if (pointSize > 0) {
2110 setFontPointSize(pointSize);
2111 } else {
2112 const int pixelSize = font.pixelSize();
2113 if (pixelSize > 0)
2115 }
2116 }
2117
2137 }
2148}
2149
2154{
2155 return d ? d->font() : QFont();
2156}
2157
2222
2234
2242void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)
2243{
2244 QList<QVariant> list;
2245 list.reserve(tabs.size());
2246 for (const auto &e : tabs)
2249}
2250
2257QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const
2258{
2260 if (variant.isNull())
2261 return QList<QTextOption::Tab>();
2262 QList<QTextOption::Tab> answer;
2263 const QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2264 answer.reserve(variantsList.size());
2265 for (const auto &e: variantsList)
2266 answer.append(qvariant_cast<QTextOption::Tab>(e));
2267 return answer;
2268}
2269
2645 : QTextFormat(ListFormat)
2646{
2647 setIndent(1);
2648 setStart(1);
2649}
2650
2662
2856
2868
2937{
2938 setProperty(FrameMargin, amargin);
2939 setProperty(FrameTopMargin, amargin);
2941 setProperty(FrameLeftMargin, amargin);
2942 setProperty(FrameRightMargin, amargin);
2943}
2944
2945
2966{
2968 return margin();
2970}
2971
2991
3006{
3008 return margin();
3010}
3011
3026{
3028 return margin();
3030}
3031
3164
3176
3386
3398
3924
3936
3959// ------------------------------------------------------
3960
3964
3966{
3967 formats.clear();
3968 objFormats.clear();
3969 hashes.clear();
3970}
3971
3973{
3974 size_t hash = getHash(format.d, format.format_type);
3975 auto i = hashes.constFind(hash);
3976 while (i != hashes.constEnd() && i.key() == hash) {
3977 if (formats.value(i.value()) == format) {
3978 return i.value();
3979 }
3980 ++i;
3981 }
3982
3983 int idx = formats.size();
3984 formats.append(format);
3985
3986 QT_TRY{
3987 QTextFormat &f = formats.last();
3988 if (!f.d)
3989 f.d = new QTextFormatPrivate;
3990 f.d->resolveFont(defaultFnt);
3991
3992 hashes.insert(hash, idx);
3993
3994 } QT_CATCH(...) {
3995 formats.pop_back();
3996 QT_RETHROW;
3997 }
3998 return idx;
3999}
4000
4002{
4003 size_t hash = getHash(format.d, format.format_type);
4004 auto i = hashes.constFind(hash);
4005 while (i != hashes.constEnd() && i.key() == hash) {
4006 if (formats.value(i.value()) == format) {
4007 return true;
4008 }
4009 ++i;
4010 }
4011 return false;
4012}
4013
4015{
4016 if (objectIndex == -1 || objectIndex >= objFormats.size())
4017 return -1;
4018 return objFormats.at(objectIndex);
4019}
4020
4021void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
4022{
4023 objFormats[objectIndex] = formatIndex;
4024}
4025
4027{
4028 const int objectIndex = objFormats.size();
4030 return objectIndex;
4031}
4032
4034{
4035 if (idx < 0 || idx >= formats.size())
4036 return QTextFormat();
4037
4038 return formats.at(idx);
4039}
4040
4042{
4043 defaultFnt = f;
4044 for (int i = 0; i < formats.size(); ++i)
4045 if (formats.at(i).d)
4046 formats[i].d->resolveFont(defaultFnt);
4047}
4048
4049#ifndef QT_NO_DEBUG_STREAM
4051{
4052 QDebugStateSaver saver(dbg);
4053 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
4054 return dbg;
4055}
4056
4058{
4059 QDebugStateSaver saver(dbg);
4060 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";
4061 return dbg;
4062}
4063
4064#endif
4065
4067
4068#include "moc_qtextformat.cpp"
\inmodule QtGui
Definition qbrush.h:30
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
\reentrant
Definition qfont.h:22
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:25
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition qfont.cpp:1394
QString styleName() const
Definition qfont.cpp:849
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition qfont.cpp:1074
StyleHint styleHint() const
Returns the StyleHint.
Definition qfont.cpp:1407
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition qfont.cpp:1304
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition qfont.cpp:1251
Capitalization
Definition qfont.h:97
void setFamilies(const QStringList &)
Definition qfont.cpp:2721
qreal letterSpacing() const
Definition qfont.cpp:1621
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition qfont.cpp:1893
HintingPreference hintingPreference() const
Definition qfont.cpp:974
SpacingType
Definition qfont.h:106
@ PercentageSpacing
Definition qfont.h:107
Capitalization capitalization() const
Definition qfont.cpp:1743
QStringList families() const
Definition qfont.cpp:2699
Weight weight() const
Returns the weight of the font, using the same scale as the \l{QFont::Weight} enumeration.
Definition qfont.cpp:1133
@ StretchResolved
Definition qfont.h:124
@ LetterSpacingResolved
Definition qfont.h:127
@ SizeResolved
Definition qfont.h:115
@ OverlineResolved
Definition qfont.h:121
@ UnderlineResolved
Definition qfont.h:120
@ StyleHintResolved
Definition qfont.h:116
@ StyleNameResolved
Definition qfont.h:130
@ AllPropertiesResolved
Definition qfont.h:134
@ StrikeOutResolved
Definition qfont.h:122
@ KerningResolved
Definition qfont.h:125
@ WeightResolved
Definition qfont.h:118
@ CapitalizationResolved
Definition qfont.h:126
@ HintingPreferenceResolved
Definition qfont.h:129
@ FixedPitchResolved
Definition qfont.h:123
@ WordSpacingResolved
Definition qfont.h:128
@ StyleStrategyResolved
Definition qfont.h:117
@ StyleResolved
Definition qfont.h:119
@ FamiliesResolved
Definition qfont.h:131
qreal wordSpacing() const
Definition qfont.cpp:1671
int pointSize() const
Returns the point size of the font.
Definition qfont.cpp:884
int stretch() const
Returns the stretch factor for the font.
Definition qfont.cpp:1564
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
Definition qfont.cpp:1359
void setPixelSize(int)
Sets the font size to pixelSize pixels, with a maxiumum size of an unsigned 16-bit integer.
Definition qfont.cpp:1049
bool fixedPitch() const
Returns true if fixed pitch has been set; otherwise returns false.
Definition qfont.cpp:1331
HintingPreference
Definition qfont.h:55
void setResolveMask(uint mask)
Definition qfont.h:313
uint resolveMask() const
Definition qfont.h:312
qreal pointSizeF() const
Returns the point size of the font.
Definition qfont.cpp:1034
SpacingType letterSpacingType() const
Definition qfont.cpp:1660
Style style() const
Returns the style of the font.
Definition qfont.cpp:1105
StyleStrategy
The style strategy tells the \l{QFont}{font matching} algorithm what type of fonts should be used to ...
Definition qfont.h:38
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition qfont.cpp:1010
Weight
Qt uses a weighting scale from 1 to 1000 compatible with OpenType.
Definition qfont.h:63
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition qfont.cpp:1278
@ StyleNormal
Definition qfont.h:77
Definition qlist.h:75
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void reserve(qsizetype size)
Definition qlist.h:753
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
iterator insert(const Key &key, const T &value)
Definition qmap.h:688
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
Definition qhash.h:1925
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:2034
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:1588
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:2025
\inmodule QtGui
Definition qpen.h:28
qreal widthF() const
Returns the pen width with floating point precision.
Definition qpen.cpp:572
QColor color() const
Returns the color of this pen's brush.
Definition qpen.cpp:692
const_iterator constBegin() const noexcept
Definition qset.h:139
const T * constData() const noexcept
Returns a const pointer to the shared data object.
Definition qshareddata.h:51
T * data()
Returns a pointer to the shared data object.
Definition qshareddata.h:47
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QList< QTextOption::Tab > tabPositions() const
QTextBlockFormat()
Constructs a new QTextBlockFormat.
void setTabPositions(const QList< QTextOption::Tab > &tabs)
QStringList anchorNames() const
void setFontFamilies(const QStringList &families)
void setUnderlineStyle(UnderlineStyle style)
UnderlineStyle underlineStyle() const
void setFontWordSpacing(qreal spacing)
QTextCharFormat()
Constructs a new character format object.
void setFontPointSize(qreal size)
Sets the text format's font size.
UnderlineStyle
This enum describes the different ways drawing underlined text.
QFont font() const
Returns the font for this character format.
void setFontKerning(bool enable)
void setFontStyleHint(QFont::StyleHint hint, QFont::StyleStrategy strategy=QFont::PreferDefault)
void setFontFixedPitch(bool fixedPitch)
If fixedPitch is true, sets the text format's font to be fixed pitch; otherwise a non-fixed pitch fon...
void setFontLetterSpacing(qreal spacing)
void setFontStyleStrategy(QFont::StyleStrategy strategy)
void setFontStrikeOut(bool strikeOut)
If strikeOut is true, sets the text format's font with strike-out enabled (with a horizontal line thr...
void setFontHintingPreference(QFont::HintingPreference hintingPreference)
void setFontStretch(int factor)
bool fontUnderline() const
Returns true if the text format's font is underlined; otherwise returns false.
void setFontOverline(bool overline)
If overline is true, sets the text format's font to be overlined; otherwise the font is displayed non...
void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
void setFontStyleName(const QString &styleName)
void setFontItalic(bool italic)
If italic is true, sets the text format's font to be italic; otherwise the font will be non-italic.
void setFontWeight(int weight)
Sets the text format's font weight to weight.
void setFontCapitalization(QFont::Capitalization capitalization)
void setFont(const QFont &font, FontPropertiesInheritanceBehavior behavior=FontPropertiesAll)
int indexForFormat(const QTextFormat &f)
QMultiHash< size_t, int > hashes
QList< qint32 > objFormats
int createObjectIndex(const QTextFormat &f)
int objectFormatIndex(int objectIndex) const
void setObjectFormatIndex(int objectIndex, int formatIndex)
QTextFormat format(int idx) const
bool hasFormatCached(const QTextFormat &format) const
void setDefaultFont(const QFont &f)
const QFont & font() const
QList< Property > props
friend QDataStream & operator<<(QDataStream &, const QTextFormat &)
friend QDataStream & operator>>(QDataStream &, QTextFormat &)
bool hasProperty(qint32 key) const
bool operator==(const QTextFormatPrivate &rhs) const
size_t hash() const
void resolveFont(const QFont &defaultFont)
void insertProperty(qint32 key, const QVariant &value)
QVariant property(qint32 key) const
int propertyIndex(qint32 key) const
void clearProperty(qint32 key)
\reentrant
Definition qtextformat.h:90
QTextCharFormat toCharFormat() const
Returns this format as a character format.
QString stringProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QString ty...
QTextBlockFormat toBlockFormat() const
Returns this format as a block format.
@ OldTextUnderlineColor
@ FontLetterSpacingType
@ OldFontLetterSpacingType
@ FontHintingPreference
QTextLength lengthProperty(int propertyId) const
Returns the value of the property given by propertyId.
int intProperty(int propertyId) const
Returns the value of the property specified by propertyId.
int objectIndex() const
Returns the index of the format object, or -1 if the format object is invalid.
QColor colorProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QColor typ...
bool boolProperty(int propertyId) const
Returns the value of the property specified by propertyId.
QTextFormat & operator=(const QTextFormat &rhs)
Assigns the other text format to this text format, and returns a reference to this text format.
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
friend class QTextCharFormat
QTextFormat()
Creates a new text format with an InvalidFormat.
QBrush brushProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QBrush typ...
QTextTableFormat toTableFormat() const
Returns this format as a table format.
QTextImageFormat toImageFormat() const
Returns this format as an image format.
void setObjectType(int type)
Sets the text format's object type to type.
~QTextFormat()
Destroys this text format.
QMap< int, QVariant > properties() const
Returns a map with all properties of this text format.
QTextTableCellFormat toTableCellFormat() const
int propertyCount() const
QTextListFormat toListFormat() const
Returns this format as a list format.
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false.
QPen penProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QPen type,...
void setObjectIndex(int object)
Sets the format object's object index.
bool operator==(const QTextFormat &rhs) const
Returns true if this text format is the same as the other text format.
QTextFrameFormat toFrameFormat() const
Returns this format as a frame format.
int type() const
Returns the type of this format.
void clearProperty(int propertyId)
Clears the value of the property given by propertyId.
void merge(const QTextFormat &other)
Merges the other format with this format; where there are conflicts the other format takes precedence...
QList< QTextLength > lengthVectorProperty(int propertyId) const
Returns the value of the property given by propertyId.
qreal doubleProperty(int propertyId) const
Returns the value of the property specified by propertyId.
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
qreal leftMargin() const
void setBorderBrush(const QBrush &brush)
void setBorderStyle(BorderStyle style)
void setBorder(qreal border)
Sets the width (in pixels) of the frame's border.
qreal bottomMargin() const
qreal rightMargin() const
qreal margin() const
Returns the width of the frame's external margin in pixels.
void setMargin(qreal margin)
Sets the frame's margin in pixels.
qreal topMargin() const
QTextFrameFormat()
Constructs a text frame format object with the default properties.
QTextImageFormat()
Creates a new image format object.
\reentrant
Definition qtextformat.h:45
Type
This enum describes the different types a length object can have.
Definition qtextformat.h:47
Type type() const
Returns the type of this length object.
Definition qtextformat.h:53
void setIndent(int indent)
Sets the list format's indentation.
void setStart(int indent)
QTextListFormat()
Constructs a new list format object.
void setBorderCollapse(bool borderCollapse)
QTextTableFormat()
Constructs a new table format object.
void setCellPadding(qreal padding)
Sets the cell padding for the table.
\inmodule QtCore
Definition qvariant.h:65
T value() const &
Definition qvariant.h:516
double toDouble(bool *ok=nullptr) const
Returns the variant as a double if the variant has userType() \l QMetaType::Double,...
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has userType() \l QMetaType::QVariantList.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
int userType() const
Definition qvariant.h:339
float toFloat(bool *ok=nullptr) const
Returns the variant as a float if the variant has userType() \l QMetaType::Double,...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
bool isNull() const
Returns true if this is a null variant, false otherwise.
const char * typeName() const
Returns the name of the type stored in the variant.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
QStringList toStringList() const
Returns the variant as a QStringList if the variant has userType() \l QMetaType::QStringList,...
QHash< int, QWidget * > hash
[35multi]
QMap< QString, QString > map
[6]
QSet< QString >::iterator it
EGLint EGLint * formats
Combined button and popup list for selecting options.
@ LayoutDirectionAuto
@ darkGray
Definition qnamespace.h:32
@ NoPen
@ NoBrush
Definition brush.cpp:5
QList< QString > QStringList
Constructs a string list that contains the given string, str.
static const QCssKnownValue properties[NumProperties - 1]
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QT_RETHROW
#define QT_CATCH(A)
#define QT_TRY
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLsizei const GLfloat * v
[13]
GLuint64 key
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat f
GLuint GLuint GLfloat weight
GLuint color
[2]
GLenum type
GLenum GLuint GLsizei const GLenum * props
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat p
[1]
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
QDataStream & operator>>(QDataStream &stream, QTextLength &length)
static size_t getHash(const QTextFormatPrivate *d, int format)
QDataStream & operator<<(QDataStream &stream, const QTextLength &length)
static size_t variantHash(const QVariant &variant)
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int quint32
Definition qtypes.h:50
int qint32
Definition qtypes.h:49
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
static int toInt(const QChar &qc, int R)
QVideoFrameFormat::PixelFormat fmt
const char property[13]
Definition qwizard.cpp:101
QList< int > list
[14]
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)