#if defined(QCS_QTHTML)
#include "basedocument.h"
#include "documentpage.h"
#include "csoundhtmlview.h"
#include "ui_html5guidisplay.h"
#include
#include
#include
#include
#include
CsoundHtmlView::CsoundHtmlView(QWidget *parent) :
QDockWidget(parent),
webView(nullptr),
ui(new Ui::Html5GuiDisplay),
documentPage(0),
m_csoundEngine(nullptr),
m_options(nullptr)
{
ui->setupUi(this);
#ifdef USE_WEBKIT
webView = new QWebView(this);
ui->inspectRow->hide(); // inspector included in QtWebKit, no need for that
#else
webView = new QWebEngineView(this);
//webView->page()->profile()->clearHttpCache();
QObject::connect(webView, &QWebEngineView::loadFinished, this, &CsoundHtmlView::removeTemporaryHtmlFile );
#endif
csoundHtmlWrapper.setCsoundHtmlView(this);
csoundHtmlOnlyWrapper.setCsoundHtmlView(this);
ui->mainLayout->addWidget(webView); // mainLayout is vertical layout box
webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
#ifdef USE_WEBKIT
QObject::connect(webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(addJSObject())); // to enable adding the object after reload
// add javascript inspector - open with right click on htmlview
webView->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
QWebInspector inspector;
inspector.setPage(webView->page());
inspector.setVisible(true);
#else
// Enable dev tools by default for the test browser
connect(ui->inspectButton, SIGNAL(clicked()),this, SLOT(showDebugWindow()));
webView->page()->setWebChannel(&channel);
//qDebug() << "Setting JavaScript object on init.";
channel.registerObject("csound", &csoundHtmlWrapper);
#endif
}
CsoundHtmlView::~CsoundHtmlView()
{
delete ui;
}
QString getElement(const QString &text, const QString &tag)
{
QString::SectionFlags sectionflags = QString::SectionIncludeLeadingSep | QString::SectionIncludeTrailingSep | QString::SectionCaseInsensitiveSeps;
QString element = text.section("<" + tag, 1, 1, sectionflags);
element = element.section("" + tag + ">", 0, 0, sectionflags);
return element;
}
void CsoundHtmlView::load(DocumentPage *documentPage_)
{
qDebug();
documentPage = documentPage_;
auto text = documentPage.load()->getFullText();
auto filename = documentPage.load()->getFileName();
QFile csdfile(filename);
csdfile.open(QIODevice::WriteOnly);
QTextStream out(&csdfile);
out << text;
csdfile.close();
auto html = getElement(text, "html");
if (html.size() > 0) {
#ifdef USE_WEBENGINE
// Inject necessary code to load qtwebchannel/qwebchannel.js.
QString injection = R"(
)";
// Tricky because now HTML doesn't have to have a element,
// and both and can have attributes. So we need to find an
// injection point that is the very first place allowed to put a