MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / convertFromPlainText

Function convertFromPlainText

Engine/Utils.cpp:34–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32#include <QtCore/QDebug>
33
34NATRON_NAMESPACE_ENTER
35
36/*!
37 \fn QString NATRON_NAMESPACE::convertFromPlainText(const QString &plain, WhiteSpaceMode mode)
38
39 Converts the plain text string \a plain to an HTML-formatted
40 paragraph while preserving most of its look.
41
42 \a mode defines how whitespace is handled.
43
44 This function was adapted from Qt::convertFromPlainText()
45 (see src/gui/text/qtextdocument.cpp in the Qt sources)
46 The difference is that in NATRON_NAMESPACE::WhiteSpaceNormal mode, spaces are preserved at the beginning of the line.
47 */
48QString
49convertFromPlainText(const QString &plain,
50 NATRON_NAMESPACE::WhiteSpaceMode mode)
51{
52 int col = 0;
53 bool bol = true;
54 QString rich;
55
56 rich += QLatin1String("<p>");
57 for (int i = 0; i < plain.length(); ++i) {
58 if ( plain[i] == QLatin1Char('\n') ) {
59 int c = 1;
60 while ( i + 1 < plain.length() && plain[i + 1] == QLatin1Char('\n') ) {
61 i++;
62 c++;
63 }
64 if (c == 1) {
65 rich += QLatin1String("<br>\n");
66 } else {
67 rich += QLatin1String("</p>\n");
68 while (--c > 1) {
69 rich += QLatin1String("<br>\n");
70 }
71 rich += QLatin1String("<p>");
72 }
73 col = 0;
74 bol = true;
75 } else {
76 bool bolagain = false;
77 if ( (mode == NATRON_NAMESPACE::WhiteSpacePre) && ( plain[i] == QLatin1Char('\t') ) ) {
78 rich += QChar(0x00a0U);
79 ++col;
80 while (col % 8) {
81 rich += QChar(0x00a0U);
82 ++col;
83 }
84 bolagain = bol;
85 } else if ( ( bol || (mode == NATRON_NAMESPACE::WhiteSpacePre) ) && plain[i].isSpace() ) {
86 rich += QChar(0x00a0U);
87 bolagain = bol;
88 } else if ( plain[i] == QLatin1Char('<') ) {
89 rich += QLatin1String("&lt;");
90 } else if ( plain[i] == QLatin1Char('>') ) {
91 rich += QLatin1String("&gt;");

Callers 15

makeDocumentationMethod · 0.85
ViewerTabMethod · 0.85
ProgressPanelMethod · 0.85
TabWidgetMethod · 0.85
createMenuMethod · 0.85
setObjectName_mt_safeMethod · 0.85
RotoPanelMethod · 0.85
insertItemRecursivelyMethod · 0.85
SequenceFileDialogMethod · 0.85

Calls 2

QCharClass · 0.85
lengthMethod · 0.80

Tested by

no test coverage detected