From 28c8a186171a44e783855c9e2282fdfdf39ec13a Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 20 May 2021 12:42:54 +0100 Subject: [PATCH] Allow rich text to contain and embed html tags --- qrenderdoc/Code/QRDUtils.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 0d8fd0676..decddd753 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -207,6 +207,8 @@ struct RichResourceText int idealWidth = 0; int numLines = 1; + bool forcehtml = false; + // cache the context once we've obtained it. ICaptureContext *ctxptr = NULL; @@ -325,9 +327,15 @@ struct RichResourceText } else { - QString htmlfrag = v.toString().toHtmlEscaped(); + QString htmlfrag = v.toString(); + + if(!forcehtml) + { + htmlfrag = htmlfrag.toHtmlEscaped(); + htmlfrag.replace(lit(" "), lit(" ")); + } + int newlines = htmlfrag.count(QLatin1Char('\n')); - htmlfrag.replace(lit(" "), lit(" ")); htmlfrag.replace( lit("\n"), lit("
")); @@ -507,7 +515,8 @@ void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseU // do a simple string search first before using regular expressions if(!text.contains(lit("ResourceId::")) && !text.contains(lit("GPUAddress::")) && - !text.contains(lit("__rd_msgs::")) && !text.contains(QLatin1Char('@')) && !parseURLs) + !text.contains(lit("__rd_msgs::")) && !text.contains(QLatin1Char('@')) && !parseURLs && + !(text.startsWith(lit("")) && text.endsWith(lit("")))) return; // two forms: GPUAddress::012345 - typeless @@ -536,6 +545,12 @@ void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseU return; } + const bool forcehtml = text.startsWith(lit("")) && text.endsWith(lit("")); + if(forcehtml) + { + text = text.mid(8, text.length() - 17); + } + // use regexp to split up into fragments of text and resourceid. The resourceid is then // formatted on the fly in RichResourceText::cacheDocument static QRegularExpression resRE( @@ -546,6 +561,7 @@ void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseU RichResourceTextPtr linkedText(new RichResourceText); linkedText->ctxptr = ctx; + linkedText->forcehtml = forcehtml; if(match.hasMatch()) { @@ -629,14 +645,18 @@ void RichResourceTextInitialise(QVariant &var, ICaptureContext *ctx, bool parseU if(!text.isEmpty()) { // if we didn't get any fragments that means we only encountered false positive matches e.g. - // @2x. Return the normal text as non-richresourcetext - if(linkedText->fragments.empty()) + // @2x. Return the normal text as non-richresourcetext unless we're forcing it + if(linkedText->fragments.empty() && !forcehtml) return; HandleURLFragment(linkedText, text, parseURLs); } - linkedText->doc.setHtml(text); + var = QVariant::fromValue(linkedText); + } + else if(forcehtml) + { + linkedText->fragments.push_back(text); var = QVariant::fromValue(linkedText); return;