12#include <QtGui/private/qtexthtmlparser_p.h>
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;
142 bool *fontSizeModified)
147QQuickStyledText::~QQuickStyledText()
157 bool *fontSizeModified)
159 if (
string.isEmpty())
162 styledText.d->
parse();
178 bool formatChanged =
false;
181 while (!
ch->isNull()) {
191 if (rangeStart !=
drawText.size() && formatStack.
size()) {
195 formatRange.
start = rangeStart;
197 ranges.
append(formatRange);
198 formatChanged =
false;
199 }
else if (ranges.
size()) {
208 if (formatStack.
size()) {
209 formatChanged =
true;
215 if (formatStack.
size())
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()) {
259 formatRange.
start = rangeStart;
261 ranges.
append(formatRange);
262 }
else if (ranges.
size()) {
287 static const qreal scaling[] = { 0.7, 0.8, 1.0, 1.2, 1.5, 2.0, 2.4 };
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')) {
318 if (tagLength == 1) {
319 format.setFontItalic(
true);
323 if (tagLength == 1) {
333 format.setFontFixedPitch(
true);
337 if (tagLength == 1) {
338 format.setFontUnderline(
true);
347 }
else if (char0 ==
QLatin1Char(
'h') && tagLength == 2) {
359 if (tagLength == 1) {
360 format.setFontStrikeOut(
true);
367 format.setFontStrikeOut(
true);
412 }
else if (
ch->isSpace()) {
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) {
491 }
else if (char0 ==
QLatin1Char(
'h') && tagLength == 2) {
499 if (tagLength == 1) {
517 }
else if (!
ch->isSpace()){
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;
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());
585 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"type"))) {
596 }
while (!
ch->isNull() && !attr.first.isEmpty());
614 if (is_equal_ignoring_case(attr.first,
QLatin1String(
"type"))) {
616 if (is_equal_ignoring_case(attr.second,
QLatin1String(
"disc")))
618 else if (is_equal_ignoring_case(attr.second,
QLatin1String(
"square")))
621 }
while (!
ch->isNull() && !attr.first.isEmpty());
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;
654 image->position = textOut.
size() + (trailingSpace ? 0 : 1);
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());
685 image->pix =
nullptr;
690 imgWidth =
image->size.width();
691 image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
698 image->position = textOut.
size() + (trailingSpace ? 0 : 1);
699 imgWidth =
image->size.width();
700 image->offset = -std::fmod(imgWidth, spaceWidth) / 2.0;
704 }
while (!
ch->isNull() && !attr.first.isEmpty());
720 while (!
ch->isNull()) {
764 const char baseChar = upper ?
'A' :
'a';
783 static const char romanSymbolsLower[] =
"iiivixxxlxcccdcmmmm";
784 static const char romanSymbolsUpper[] =
"IIIVIXXXLXCCCDCMMMM";
791 int c[] = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
793 for (
int i = 12;
i >= 0;
n %=
c[
i],
i--) {
796 int startDigit =
i + (
i + 3) / 4;
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
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
qreal horizontalAdvance(const QString &string, int length=-1) const
Returns the horizontal advance in pixels of the first length characters of text.
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.
qsizetype size() const noexcept
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
T & top()
Returns a reference to the stack's top item.
T pop()
Removes the top item from the stack and returns it.
void push(const T &t)
Adds element t to the top of the stack.
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
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.
bool isNull() const
Returns true if this string is null; otherwise returns false.
qsizetype size() const
Returns the number of characters in this string.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & append(QChar c)
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.
std::pair< T1, T2 > QPair
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