Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Code highlighting in SlideViewer

m_webPage = new QWebPage(this);
const QString preHighlightHtml = QStringLiteral("<html>"
                        "<head>"
                        "<script src=\"qrc:///highlight/sh_main.js\"></script>"
                        "<script src=\"qrc:///highlight/sh_cpp.js\"></script>"
                        "</head>"
                        "<body onLoad=\"sh_highlightDocument();\">"
                        "<pre class=\"sh_cpp\">"
                        "%1" // code
                        "</pre></body></html>").arg(code.toHtmlEscaped());

m_webPage->currentFrame()->setHtml(preHighlightHtml);
m_webPage->currentFrame()->addToJavaScriptWindowObject("highlighter", this);
connect(m_webPage->currentFrame(),
        &QWebFrame::javaScriptWindowObjectCleared,
        this, &Highlighter::addJSCallback);
// Header file
Q_INVOKABLE void setHighlightCompleted(bool success);

// Source file
void Highlighter::setHighlightCompleted(bool success)
{
    emit highlightCompleted(success ? parseHighlightedHtml() : plainTextCode());
}
highlighter.setHighlightCompleted(true);

2 Comments

16 - Jul - 2014

Emmanuel

16 - Jul - 2014

Jesper K. Pedersen