12#include <QtGui/private/qtexthtmlparser_p.h>
54 QList<QQuickStyledTextImgTag*> &imgTags,
58 bool *fontSizeModified)
60 fontSizeModified(fontSizeModified),
context(
context), preloadImages(preloadImages)
70 bool parseOrderedListAttributes(
const QChar *&
ch,
const QString &textIn);
71 bool parseUnorderedListAttributes(
const QChar *&
ch,
const QString &textIn);
79 while (
ch->isSpace() && !
ch->isNull())
95 bool hasNewLine =
true;
96 bool updateImagePositions =
false;
97 bool preFormat =
false;
98 bool prependSpace =
false;
114 static const int tabsize = 6;
138 QList<QQuickStyledTextImgTag*> &imgTags,
142 bool *fontSizeModified)
147QQuickStyledText::~QQuickStyledText()
153 QList<QQuickStyledTextImgTag*> &imgTags,
157 bool *fontSizeModified)
159 if (
string.isEmpty())
162 styledText.d->
parse();
167 QVector<QTextLayout::FormatRange> ranges;
168 QStack<QTextCharFormat> formatStack;
178 bool formatChanged =
false;
181 while (!
ch->isNull()) {
191 if (rangeStart !=
drawText.size() && formatStack.size()) {
194 formatRange.
format = formatStack.top();
195 formatRange.start = rangeStart;
196 formatRange.length =
drawText.size() - rangeStart;
197 ranges.append(formatRange);
198 formatChanged =
false;
199 }
else if (ranges.size()) {
200 ranges.last().length +=
drawText.size() - rangeStart;
208 if (formatStack.size()) {
209 formatChanged =
true;
215 if (formatStack.size())
216 format = formatStack.top();
218 formatChanged =
true;
230 }
else if (
ch->isSpace()) {
235 for (
const QChar *
n =
ch + 1; !
n->isNull() &&
n->isSpace(); ++
n)
255 if (rangeStart !=
drawText.size() && formatStack.size()) {
258 formatRange.
format = formatStack.top();
259 formatRange.start = rangeStart;
260 formatRange.length =
drawText.size() - rangeStart;
261 ranges.append(formatRange);
262 }
else if (ranges.size()) {
263 ranges.last().length +=
drawText.size() - rangeStart;
274 textOut.append(
space);
287 static const qreal scaling[] = { 0.7, 0.8, 1.0, 1.2, 1.5, 2.0, 2.4 };
299 int tagStart =
ch - textIn.constData();
301 while (!
ch->isNull()) {
306 const QChar char0 =
tag.at(0).toLower();
308 if (tagLength == 1) {
311 }
else if (tagLength == 2 &&
tag.at(1).toLower() ==
QLatin1Char(
'r')) {
312 textOut.append(
QChar(QChar::LineSeparator));
318 if (tagLength == 1) {
319 format.setFontItalic(
true);
323 if (tagLength == 1) {
325 textOut.append(QChar::LineSeparator);
331 textOut.append(QChar::LineSeparator);
333 format.setFontFixedPitch(
true);
337 if (tagLength == 1) {
338 format.setFontUnderline(
true);
347 }
else if (char0 ==
QLatin1Char(
'h') && tagLength == 2) {
351 textOut.append(QChar::LineSeparator);
359 if (tagLength == 1) {
360 format.setFontStrikeOut(
true);
367 format.setFontStrikeOut(
true);
377 textOut.append(
QChar(QChar::LineSeparator));
408 textOut +=
QString(2, QChar::Nbsp);
412 }
else if (
ch->isSpace()) {
446 int tagStart =
ch - textIn.constData();
448 while (!
ch->isNull()) {
453 const QChar char0 =
tag.at(0).toLower();
458 else if (
tag.at(1).toLower() ==
QLatin1Char(
'r') && tagLength == 2)
467 if (tagLength == 1) {
468 textOut.append(QChar::LineSeparator);
475 textOut.append(QChar::LineSeparator);
487 textOut.append(QChar::LineSeparator);
491 }
else if (char0 ==
QLatin1Char(
'h') && tagLength == 2) {
492 textOut.append(QChar::LineSeparator);
499 if (tagLength == 1) {
510 textOut.append(QChar::LineSeparator);
517 }
else if (!
ch->isSpace()){
528 int entityStart =
ch - textIn.constData();
529 int entityLength = 0;
530 while (!
ch->isNull()) {
533#if QT_CONFIG(texthtmlparser)
535 if (!parsedEntity.isNull())
536 textOut += parsedEntity;
539 qCWarning(lcStyledText) <<
"StyledText doesn't support entity" << entity;
542 auto entity =
QStringView(textIn).
mid(entityStart - 1, entityLength + 1);
543 textOut += entity + *
ch;
554 QPair<QStringView,QStringView> attr;
557 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"color"))) {
560 }
else if (is_equal_ignoring_case(attr.first,
QLatin1String(
"size"))) {
562 int size = attr.second.toInt();
568 }
while (!
ch->isNull() && !attr.first.isEmpty());
582 QPair<QStringView,QStringView> attr;
585 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"type"))) {
596 }
while (!
ch->isNull() && !attr.first.isEmpty());
611 QPair<QStringView,QStringView> attr;
614 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"type"))) {
616 if (is_equal_ignoring_case(attr.second,
QLatin1String(
"disc")))
617 listItem.format =
Disc;
618 else if (is_equal_ignoring_case(attr.second,
QLatin1String(
"square")))
621 }
while (!
ch->isNull() && !attr.first.isEmpty());
631 QPair<QStringView,QStringView> attr;
634 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"href"))) {
635 format.setAnchorHref(attr.second.toString());
637 format.setFontUnderline(
true);
640 }
while (!
ch->isNull() && !attr.first.isEmpty());
647 qreal imgWidth = 0.0;
649 const qreal spaceWidth = fm.horizontalAdvance(QChar::Nbsp);
650 const bool trailingSpace = textOut.endsWith(
space);
654 image->position = textOut.size() + (trailingSpace ? 0 : 1);
656 QPair<QStringView,QStringView> attr;
659 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"src"))) {
660 image->url =
QUrl(attr.second.toString());
661 }
else if (is_equal_ignoring_case(attr.first,
QLatin1String(
"width"))) {
662 image->size.setWidth(attr.second.toString().toInt());
663 }
else if (is_equal_ignoring_case(attr.first,
QLatin1String(
"height"))) {
664 image->size.setHeight(attr.second.toString().toInt());
665 }
else if (is_equal_ignoring_case(attr.first,
QLatin1String(
"align"))) {
666 if (is_equal_ignoring_case(attr.second,
QLatin1String(
"top"))) {
668 }
else if (is_equal_ignoring_case(attr.second,
QLatin1String(
"middle"))) {
672 }
while (!
ch->isNull() && !attr.first.isEmpty());
690 if (!
image->url.isValid()) {
692 qCWarning(lcStyledText) <<
"StyledText - Invalid base url in img tag";
694 imgWidth =
image->size.width();
695 image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
702 image->position = textOut.size() + (trailingSpace ? 0 : 1);
703 imgWidth =
image->size.width();
704 image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
705 QPair<QStringView,QStringView> attr;
708 }
while (!
ch->isNull() && !attr.first.isEmpty());
722 int attrStart =
ch - textIn.constData();
724 while (!
ch->isNull()) {
740 return QPair<QStringView,QStringView>(attr,
val);
748 return QPair<QStringView,QStringView>();
753 int valStart =
ch - textIn.constData();
768 const char baseChar = upper ?
'A' :
'a';
787 static const char romanSymbolsLower[] =
"iiivixxxlxcccdcmmmm";
788 static const char romanSymbolsUpper[] =
"IIIVIXXXLXCCCDCMMMM";
795 int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
797 for (
int i = 12;
i >= 0;
n %=
c[
i],
i--) {
800 int startDigit =
i + (
i + 3) / 4;
810 romanNumeral.append(romanSymbols.mid(startDigit,
numDigits));
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
static QColor fromString(QAnyStringView name) noexcept
\reentrant \inmodule QtGui
int pixelSize() const
Returns the pixel size of the font if it was set with setPixelSize().
int pointSize() const
Returns the point size of the font.
qreal pointSizeF() const
Returns the point size of the font.
bool isEmpty() const noexcept
T value(qsizetype i) const
void append(parameter_type t)
The QQmlContext class defines a context within a QML engine.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
bool parseCloseTag(const QChar *&ch, const QString &textIn, QString &textOut)
static const QChar singleQuote
QPair< QStringView, QStringView > parseAttribute(const QChar *&ch, const QString &textIn)
void parseImageAttributes(const QChar *&ch, const QString &textIn, QString &textOut)
static const QChar lessThan
void setFontSize(int size, QTextCharFormat &format)
bool parseTag(const QChar *&ch, const QString &textIn, QString &textOut, QTextCharFormat &format)
bool parseAnchorAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format)
static const QChar ampersand
static const QChar greaterThan
static const QChar equals
static const QChar bullet
void parseEntity(const QChar *&ch, const QString &textIn, QString &textOut)
static const QChar doubleQuote
static const QChar lineFeed
QStringView parseValue(const QChar *&ch, const QString &textIn)
static QString toRoman(int value, bool upper)
bool updateImagePositions
bool parseFontAttributes(const QChar *&ch, const QString &textIn, QTextCharFormat &format)
bool parseOrderedListAttributes(const QChar *&ch, const QString &textIn)
static const QChar square
QList< QQuickStyledTextImgTag * > * imgTags
void appendText(const QString &textIn, int start, int length, QString &textOut)
void skipSpace(const QChar *&ch)
QQuickStyledTextPrivate(const QString &t, QTextLayout &l, QList< QQuickStyledTextImgTag * > &imgTags, const QUrl &baseUrl, QQmlContext *context, bool preloadImages, bool *fontSizeModified)
static QString toAlpha(int value, bool upper)
bool parseUnorderedListAttributes(const QChar *&ch, const QString &textIn)
static void parse(const QString &string, QTextLayout &layout, QList< QQuickStyledTextImgTag * > &imgTags, const QUrl &baseUrl, QQmlContext *context, bool preloadImages, bool *fontSizeModified)
\inmodule QtCore\reentrant
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const QChar * constData() const
Returns a pointer to the data stored in the QString.
qsizetype size() const noexcept
Returns the number of characters in this string.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setFormats(const QList< FormatRange > &overrides)
void setText(const QString &string)
Sets the layout's text to the given string.
QFont font() const
Returns the current font that is used for the layout, or a default font if none is set.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
paint drawText(0, 50, "Hi")
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
GLenum GLuint GLint level
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum format
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * string
[0]
QT_BEGIN_NAMESPACE Q_GUI_EXPORT int qt_defaultDpi()
QLatin1StringView QLatin1String
static void parseAttribute(void *value, void *extraData)
static int numDigits(qlonglong n)
QUrl url("example.com")
[constructor-url-reference]
\inmodule QtCore \reentrant