Qt 6.x
The Qt SDK
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
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.end()) {
411 properties.erase(it);
412 }
413
415 if (it != properties.end()) {
417 properties.erase(it);
418 }
419
421 if (it != properties.end()) {
423 properties.erase(it);
424 }
425
427 if (it != properties.end()) {
428 properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().first());
429 properties.erase(it);
430 }
431 }
432
433 stream << fmt.format_type << properties;
434 return stream;
435}
436
438{
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
872 : format_type(InvalidFormat)
873{
874}
875
882 : format_type(type)
883{
884}
885
886
894 : d(rhs.d), format_type(rhs.format_type)
895{
896}
897
905{
906 d = rhs.d;
907 format_type = rhs.format_type;
908 return *this;
909}
910
923{
924}
925
926
930QTextFormat::operator QVariant() const
931{
932 return QVariant::fromValue(*this);
933}
934
940{
941 if (format_type != other.format_type)
942 return;
943
944 if (!d) {
945 d = other.d;
946 return;
947 }
948
949 if (!other.d)
950 return;
951
953
954 const QList<QT_PREPEND_NAMESPACE(Property)> &otherProps = other.d.constData()->props;
955 p->props.reserve(p->props.size() + otherProps.size());
956 for (int i = 0; i < otherProps.size(); ++i) {
957 const QT_PREPEND_NAMESPACE(Property) &prop = otherProps.at(i);
958 p->insertProperty(prop.key, prop.value);
959 }
960}
961
968{
969 return format_type;
970}
971
976{
977 return QTextBlockFormat(*this);
978}
979
984{
985 return QTextCharFormat(*this);
986}
987
992{
993 return QTextListFormat(*this);
994}
995
1000{
1001 return QTextTableFormat(*this);
1002}
1003
1008{
1009 return QTextFrameFormat(*this);
1010}
1011
1016{
1017 return QTextImageFormat(*this);
1018}
1019
1026{
1027 return QTextTableCellFormat(*this);
1028}
1029
1037bool QTextFormat::boolProperty(int propertyId) const
1038{
1039 if (!d)
1040 return false;
1041 const QVariant prop = d->property(propertyId);
1042 if (prop.userType() != QMetaType::Bool)
1043 return false;
1044 return prop.toBool();
1045}
1046
1054int QTextFormat::intProperty(int propertyId) const
1055{
1056 // required, since the default layout direction has to be LayoutDirectionAuto, which is not integer 0
1057 int def = (propertyId == QTextFormat::LayoutDirection) ? int(Qt::LayoutDirectionAuto) : 0;
1058
1059 if (!d)
1060 return def;
1061 const QVariant prop = d->property(propertyId);
1062 if (prop.userType() != QMetaType::Int)
1063 return def;
1064 return prop.toInt();
1065}
1066
1076{
1077 if (!d)
1078 return 0.;
1079 const QVariant prop = d->property(propertyId);
1080 if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float)
1081 return 0.;
1082 return qvariant_cast<qreal>(prop);
1083}
1084
1094{
1095 if (!d)
1096 return QString();
1097 const QVariant prop = d->property(propertyId);
1098 if (prop.userType() != QMetaType::QString)
1099 return QString();
1100 return prop.toString();
1101}
1102
1112{
1113 if (!d)
1114 return QColor();
1115 const QVariant prop = d->property(propertyId);
1116 if (prop.userType() != QMetaType::QColor)
1117 return QColor();
1118 return qvariant_cast<QColor>(prop);
1119}
1120
1129QPen QTextFormat::penProperty(int propertyId) const
1130{
1131 if (!d)
1132 return QPen(Qt::NoPen);
1133 const QVariant prop = d->property(propertyId);
1134 if (prop.userType() != QMetaType::QPen)
1135 return QPen(Qt::NoPen);
1136 return qvariant_cast<QPen>(prop);
1137}
1138
1148{
1149 if (!d)
1150 return QBrush(Qt::NoBrush);
1151 const QVariant prop = d->property(propertyId);
1152 if (prop.userType() != QMetaType::QBrush)
1153 return QBrush(Qt::NoBrush);
1154 return qvariant_cast<QBrush>(prop);
1155}
1156
1164{
1165 if (!d)
1166 return QTextLength();
1167 return qvariant_cast<QTextLength>(d->property(propertyId));
1168}
1169
1179{
1181 if (!d)
1182 return list;
1183 const QVariant prop = d->property(propertyId);
1184 if (prop.userType() != QMetaType::QVariantList)
1185 return list;
1186
1187 const QList<QVariant> propertyList = prop.toList();
1188 for (const auto &var : propertyList) {
1189 if (var.userType() == QMetaType::QTextLength)
1190 list.append(qvariant_cast<QTextLength>(var));
1191 }
1192
1193 return list;
1194}
1195
1201QVariant QTextFormat::property(int propertyId) const
1202{
1203 return d ? d->property(propertyId) : QVariant();
1204}
1205
1211void QTextFormat::setProperty(int propertyId, const QVariant &value)
1212{
1213 if (!d)
1214 d = new QTextFormatPrivate;
1215 if (!value.isValid())
1216 clearProperty(propertyId);
1217 else
1218 d->insertProperty(propertyId, value);
1219}
1220
1227{
1228 if (!d)
1229 d = new QTextFormatPrivate;
1231 const int numValues = value.size();
1232 list.reserve(numValues);
1233 for (int i = 0; i < numValues; ++i)
1234 list << value.at(i);
1235 d->insertProperty(propertyId, list);
1236}
1237
1243void QTextFormat::clearProperty(int propertyId)
1244{
1245 if (!d)
1246 return;
1247 d->clearProperty(propertyId);
1248}
1249
1250
1275{
1276 if (!d)
1277 return -1;
1278 const QVariant prop = d->property(ObjectIndex);
1279 if (prop.userType() != QMetaType::Int) // ####
1280 return -1;
1281 return prop.toInt();
1282}
1283
1292{
1293 if (o == -1) {
1294 if (d.constData())
1296 } else {
1297 if (!d.constData())
1298 d = new QTextFormatPrivate;
1299 // ### type
1301 }
1302}
1303
1310bool QTextFormat::hasProperty(int propertyId) const
1311{
1312 return d ? d->hasProperty(propertyId) : false;
1313}
1314
1315/*
1316 Returns the property type for the given \a propertyId.
1317
1318 \sa hasProperty(), allPropertyIds(), Property
1319*/
1320
1325{
1327 if (d) {
1328 for (int i = 0; i < d->props.size(); ++i)
1329 map.insert(d->props.at(i).key, d->props.at(i).value);
1330 }
1331 return map;
1332}
1333
1339{
1340 return d ? d->props.size() : 0;
1341}
1342
1358{
1359 if (format_type != rhs.format_type)
1360 return false;
1361
1362 if (d == rhs.d)
1363 return true;
1364
1365 if (d && d->props.isEmpty() && !rhs.d)
1366 return true;
1367
1368 if (!d && rhs.d && rhs.d->props.isEmpty())
1369 return true;
1370
1371 if (!d || !rhs.d)
1372 return false;
1373
1374 return *d == *rhs.d;
1375}
1376
1454
1463 : QTextFormat(fmt)
1464{
1465}
1466
1503#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1516#else
1517/* // Qt 7 documents this function
1518 \fn QStringList QTextCharFormat::fontFamilies() const
1519 \since 5.13
1520
1521 Returns the text format's font families.
1522
1523 \sa font()
1524*/
1525#endif
1526
1536#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
1549#else
1550/* // Qt 7 documents this function
1551 \fn QStringList QTextCharFormat::fontStyleName() const
1552 \since 5.13
1553
1554 Returns the text format's font style name.
1555
1556 \sa font(), QFont::styleName()
1557*/
1558#endif
1559
1635{
1637 return underlineStyle() == SingleUnderline;
1639}
1640
1655{
1657 // for compatibility
1659}
1660
1985{
1987 if (prop.userType() == QMetaType::QStringList)
1988 return prop.toStringList();
1989 else if (prop.userType() != QMetaType::QString)
1990 return QStringList();
1991 return QStringList(prop.toString());
1992}
1993
1994
2095{
2097 : font.resolveMask();
2098
2103
2104 if (mask & QFont::SizeResolved) {
2105 const qreal pointSize = font.pointSizeF();
2106 if (pointSize > 0) {
2107 setFontPointSize(pointSize);
2108 } else {
2109 const int pixelSize = font.pixelSize();
2110 if (pixelSize > 0)
2112 }
2113 }
2114
2134 }
2145}
2146
2151{
2152 return d ? d->font() : QFont();
2153}
2154
2219
2228 : QTextFormat(fmt)
2229{
2230}
2231
2240{
2242 list.reserve(tabs.size());
2244 while (iter != tabs.constEnd()) {
2245 QVariant v;
2246 v.setValue(*iter);
2247 list.append(v);
2248 ++iter;
2249 }
2251}
2252
2260{
2262 if (variant.isNull())
2263 return QList<QTextOption::Tab>();
2265 QList<QVariant> variantsList = qvariant_cast<QList<QVariant> >(variant);
2266 QList<QVariant>::Iterator iter = variantsList.begin();
2267 answer.reserve(variantsList.size());
2268 while(iter != variantsList.end()) {
2269 answer.append( qvariant_cast<QTextOption::Tab>(*iter));
2270 ++iter;
2271 }
2272 return answer;
2273}
2274
2650 : QTextFormat(ListFormat)
2651{
2652 setIndent(1);
2653 setStart(1);
2654}
2655
2664 : QTextFormat(fmt)
2665{
2666}
2667
2857{
2860}
2861
2870 : QTextFormat(fmt)
2871{
2872}
2873
2942{
2943 setProperty(FrameMargin, amargin);
2944 setProperty(FrameTopMargin, amargin);
2946 setProperty(FrameLeftMargin, amargin);
2947 setProperty(FrameRightMargin, amargin);
2948}
2949
2950
2971{
2973 return margin();
2975}
2976
2991{
2993 return margin();
2995}
2996
3011{
3013 return margin();
3015}
3016
3031{
3033 return margin();
3035}
3036
3163{
3165 setCellSpacing(2);
3166 setBorder(1);
3167}
3168
3178{
3179}
3180
3390
3400{
3401}
3402
3906 : QTextCharFormat()
3907{
3909}
3910
3920{
3921}
3922
3945// ------------------------------------------------------
3946
3948{
3949}
3950
3952{
3953 formats.clear();
3954 objFormats.clear();
3955 hashes.clear();
3956}
3957
3959{
3960 size_t hash = getHash(format.d, format.format_type);
3961 auto i = hashes.constFind(hash);
3962 while (i != hashes.constEnd() && i.key() == hash) {
3963 if (formats.value(i.value()) == format) {
3964 return i.value();
3965 }
3966 ++i;
3967 }
3968
3969 int idx = formats.size();
3970 formats.append(format);
3971
3972 QT_TRY{
3973 QTextFormat &f = formats.last();
3974 if (!f.d)
3975 f.d = new QTextFormatPrivate;
3976 f.d->resolveFont(defaultFnt);
3977
3978 hashes.insert(hash, idx);
3979
3980 } QT_CATCH(...) {
3981 formats.pop_back();
3982 QT_RETHROW;
3983 }
3984 return idx;
3985}
3986
3988{
3989 size_t hash = getHash(format.d, format.format_type);
3990 auto i = hashes.constFind(hash);
3991 while (i != hashes.constEnd() && i.key() == hash) {
3992 if (formats.value(i.value()) == format) {
3993 return true;
3994 }
3995 ++i;
3996 }
3997 return false;
3998}
3999
4001{
4002 if (objectIndex == -1)
4003 return -1;
4004 return objFormats.at(objectIndex);
4005}
4006
4007void QTextFormatCollection::setObjectFormatIndex(int objectIndex, int formatIndex)
4008{
4009 objFormats[objectIndex] = formatIndex;
4010}
4011
4013{
4014 const int objectIndex = objFormats.size();
4016 return objectIndex;
4017}
4018
4020{
4021 if (idx < 0 || idx >= formats.size())
4022 return QTextFormat();
4023
4024 return formats.at(idx);
4025}
4026
4028{
4029 defaultFnt = f;
4030 for (int i = 0; i < formats.size(); ++i)
4031 if (formats.at(i).d)
4032 formats[i].d->resolveFont(defaultFnt);
4033}
4034
4035#ifndef QT_NO_DEBUG_STREAM
4037{
4038 QDebugStateSaver saver(dbg);
4039 dbg.nospace() << "QTextLength(QTextLength::Type(" << l.type() << "))";
4040 return dbg;
4041}
4042
4044{
4045 QDebugStateSaver saver(dbg);
4046 dbg.nospace() << "QTextFormat(QTextFormat::FormatType(" << f.type() << "))";
4047 return dbg;
4048}
4049
4050#endif
4051
4053
4054#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:30
\inmodule QtCore
\inmodule QtCore
\reentrant
Definition qfont.h:20
StyleHint
Style hints are used by the \l{QFont}{font matching} algorithm to find an appropriate default family ...
Definition qfont.h:23
StyleStrategy styleStrategy() const
Returns the StyleStrategy.
Definition qfont.cpp:1379
QString styleName() const
Definition qfont.cpp:828
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
Definition qfont.cpp:1059
StyleHint styleHint() const
Returns the StyleHint.
Definition qfont.cpp:1392
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition qfont.cpp:1289
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition qfont.cpp:1236
Capitalization
Definition qfont.h:94
qreal letterSpacing() const
Definition qfont.cpp:1598
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:1854
HintingPreference hintingPreference() const
Definition qfont.cpp:959
SpacingType
Definition qfont.h:103
@ PercentageSpacing
Definition qfont.h:104
Capitalization capitalization() const
Definition qfont.cpp:1720
QStringList families() const
Definition qfont.cpp:2469
Weight weight() const
Returns the weight of the font, using the same scale as the \l{QFont::Weight} enumeration.
Definition qfont.cpp:1118
@ StretchResolved
Definition qfont.h:121
@ LetterSpacingResolved
Definition qfont.h:124
@ SizeResolved
Definition qfont.h:112
@ OverlineResolved
Definition qfont.h:118
@ UnderlineResolved
Definition qfont.h:117
@ StyleHintResolved
Definition qfont.h:113
@ StyleNameResolved
Definition qfont.h:127
@ AllPropertiesResolved
Definition qfont.h:130
@ StrikeOutResolved
Definition qfont.h:119
@ KerningResolved
Definition qfont.h:122
@ WeightResolved
Definition qfont.h:115
@ CapitalizationResolved
Definition qfont.h:123
@ HintingPreferenceResolved
Definition qfont.h:126
@ FixedPitchResolved
Definition qfont.h:120
@ WordSpacingResolved
Definition qfont.h:125
@ StyleStrategyResolved
Definition qfont.h:114
@ StyleResolved
Definition qfont.h:116
@ FamiliesResolved
Definition qfont.h:128
qreal wordSpacing() const
Definition qfont.cpp:1648
int pointSize() const
Returns the point size of the font.
Definition qfont.cpp:863
int stretch() const
Returns the stretch factor for the font.
Definition qfont.cpp:1541
bool kerning() const
Returns true if kerning should be used when drawing text with this font.
Definition qfont.cpp:1344
void setPixelSize(int)
Sets the font size to pixelSize pixels, with a maxiumum size of an unsigned 16-bit integer.
Definition qfont.cpp:1034
bool fixedPitch() const
Returns true if fixed pitch has been set; otherwise returns false.
Definition qfont.cpp:1316
HintingPreference
Definition qfont.h:52
void setResolveMask(uint mask)
Definition qfont.h:252
uint resolveMask() const
Definition qfont.h:251
qreal pointSizeF() const
Returns the point size of the font.
Definition qfont.cpp:1019
SpacingType letterSpacingType() const
Definition qfont.cpp:1637
Style style() const
Returns the style of the font.
Definition qfont.cpp:1090
StyleStrategy
The style strategy tells the \l{QFont}{font matching} algorithm what type of fonts should be used to ...
Definition qfont.h:36
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition qfont.cpp:995
Weight
Qt uses a weighting scale from 1 to 1000 compatible with OpenType.
Definition qfont.h:60
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition qfont.cpp:1263
@ StyleNormal
Definition qfont.h:74
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
bool isEmpty() const noexcept
Definition qlist.h:390
iterator end()
Definition qlist.h:609
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
const_iterator constBegin() const noexcept
Definition qlist.h:615
iterator begin()
Definition qlist.h:608
void reserve(qsizetype size)
Definition qlist.h:746
void append(parameter_type t)
Definition qlist.h:441
const_iterator constEnd() const noexcept
Definition qlist.h:616
void clear()
Definition qlist.h:417
Definition qmap.h:186
iterator insert(const Key &key, const T &value)
Definition qmap.h:687
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:1833
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1930
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Definition qhash.h:1511
const_iterator constFind(const Key &key) const noexcept
Definition qhash.h:1921
\inmodule QtGui
Definition qpen.h:25
qreal widthF() const
Returns the pen width with floating point precision.
Definition qpen.cpp:598
QColor color() const
Returns the color of this pen's brush.
Definition qpen.cpp:718
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:127
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.
Property
This enum describes the different properties a format can have.
@ 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.
QTextTableFormat()
Constructs a new table format object.
void setCellSpacing(qreal spacing)
Sets the cell spacing for the table.
\inmodule QtCore
Definition qvariant.h:64
T value() const &
Definition qvariant.h:511
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:707
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:336
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:531
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:31
@ NoPen
@ NoBrush
Definition brush.cpp:5
static const QCssKnownValue properties[NumProperties - 1]
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter * iter
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:281
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
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:1219
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:145
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:163
unsigned int quint32
Definition qtypes.h:45
int qint32
Definition qtypes.h:44
unsigned int uint
Definition qtypes.h:29
double qreal
Definition qtypes.h:92
static int toInt(const QChar &qc, int R)
QVideoFrameFormat::PixelFormat fmt
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId
const char property[13]
Definition qwizard.cpp:101
QList< int > list
[14]
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]