|
|
@ -19,13 +19,15 @@ |
|
|
|
* @date 2014 |
|
|
|
*/ |
|
|
|
|
|
|
|
#define QWEBENGINEINSPECTOR 1 |
|
|
|
#include <fstream> |
|
|
|
#include <QtNetwork/QNetworkReply> |
|
|
|
#include <QtWidgets/QFileDialog> |
|
|
|
#include <QtWidgets/QMessageBox> |
|
|
|
#include <QtWidgets/QInputDialog> |
|
|
|
#include <QtWebKitWidgets/QWebFrame> |
|
|
|
#include <QtWebKit/QWebSettings> |
|
|
|
#include <QtWebEngine/QtWebEngine> |
|
|
|
#include <QtWebEngineWidgets/QWebEngineView> |
|
|
|
#include <QtWebEngineWidgets/QWebEngineCallback> |
|
|
|
#include <QtGui/QClipboard> |
|
|
|
#include <QtCore/QtCore> |
|
|
|
#include <boost/algorithm/string.hpp> |
|
|
@ -154,31 +156,24 @@ Main::Main(QWidget *parent) : |
|
|
|
m_server->setIdentities(keysAsVector(owned())); |
|
|
|
m_server->StartListening(); |
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::loadStarted, [this]() |
|
|
|
{ |
|
|
|
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); |
|
|
|
QWebFrame* f = ui->webView->page()->mainFrame(); |
|
|
|
f->disconnect(SIGNAL(javaScriptWindowObjectCleared())); |
|
|
|
|
|
|
|
connect(f, &QWebFrame::javaScriptWindowObjectCleared, [f, this]() |
|
|
|
{ |
|
|
|
f->disconnect(); |
|
|
|
f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership); |
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/bignumber.min.js")); |
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/webthree.js")); |
|
|
|
f->evaluateJavaScript(contentsOfQResource(":/js/setup.js")); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::loadFinished, [=]() |
|
|
|
connect(ui->webView, &QWebEngineView::loadFinished, [this]() |
|
|
|
{ |
|
|
|
// f->disconnect();
|
|
|
|
// f->addToJavaScriptWindowObject("env", this, QWebFrame::QtOwnership);
|
|
|
|
auto f = ui->webView->page(); |
|
|
|
f->runJavaScript(contentsOfQResource(":/js/bignumber.min.js")); |
|
|
|
f->runJavaScript(contentsOfQResource(":/js/webthree.js")); |
|
|
|
f->runJavaScript(contentsOfQResource(":/js/setup.js")); |
|
|
|
}); |
|
|
|
|
|
|
|
connect(ui->webView, &QWebView::titleChanged, [=]() |
|
|
|
connect(ui->webView, &QWebEngineView::titleChanged, [=]() |
|
|
|
{ |
|
|
|
ui->tabWidget->setTabText(0, ui->webView->title()); |
|
|
|
}); |
|
|
|
|
|
|
|
ui->webView->page()->settings()->setAttribute(QWebEngineSettings::DeveloperExtrasEnabled, true); |
|
|
|
// QWebEngineInspector* inspector = new QWebEngineInspector();
|
|
|
|
// inspector->setPage(page);
|
|
|
|
readSettings(); |
|
|
|
installWatches(); |
|
|
|
startTimer(100); |
|
|
@ -361,7 +356,7 @@ QString Main::contents(QString _s) |
|
|
|
void Main::load(QString _s) |
|
|
|
{ |
|
|
|
QString contents = QString::fromStdString(dev::asString(dev::contents(_s.toStdString()))); |
|
|
|
ui->webView->page()->currentFrame()->evaluateJavaScript(contents); |
|
|
|
ui->webView->page()->runJavaScript(contents); |
|
|
|
/*
|
|
|
|
QFile fin(_s); |
|
|
|
if (!fin.open(QFile::ReadOnly)) |
|
|
@ -420,35 +415,35 @@ void Main::on_jsInput_returnPressed() |
|
|
|
ui->jsInput->setText(""); |
|
|
|
} |
|
|
|
|
|
|
|
QVariant Main::evalRaw(QString const& _js) |
|
|
|
{ |
|
|
|
return ui->webView->page()->currentFrame()->evaluateJavaScript(_js); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::eval(QString const& _js) |
|
|
|
{ |
|
|
|
if (_js.trimmed().isEmpty()) |
|
|
|
return; |
|
|
|
QVariant ev = ui->webView->page()->currentFrame()->evaluateJavaScript((_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")")); |
|
|
|
QVariant jsonEv = ui->webView->page()->currentFrame()->evaluateJavaScript("JSON.stringify(___RET)"); |
|
|
|
QString s; |
|
|
|
if (ev.isNull()) |
|
|
|
s = "<span style=\"color: #888\">null</span>"; |
|
|
|
else if (ev.type() == QVariant::String) |
|
|
|
s = "<span style=\"color: #444\">\"</span><span style=\"color: #c00\">" + ev.toString().toHtmlEscaped() + "</span><span style=\"color: #444\">\"</span>"; |
|
|
|
else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) |
|
|
|
s = "<span style=\"color: #00c\">" + ev.toString().toHtmlEscaped() + "</span>"; |
|
|
|
else if (jsonEv.type() == QVariant::String) |
|
|
|
s = "<span style=\"color: #840\">" + jsonEv.toString().toHtmlEscaped() + "</span>"; |
|
|
|
else |
|
|
|
s = "<span style=\"color: #888\">unknown type</span>"; |
|
|
|
m_consoleHistory.push_back(qMakePair(_js, s)); |
|
|
|
s = "<html><body style=\"margin: 0;\">" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); |
|
|
|
for (auto const& i: m_consoleHistory) |
|
|
|
s += "<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em; color: #888; font-weight: bold\">></span><span style=\"color: #35d\">" + i.first.toHtmlEscaped() + "</span></div>" |
|
|
|
"<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em\"> </span><span>" + i.second + "</span></div>"; |
|
|
|
s += "</div></body></html>"; |
|
|
|
ui->jsConsole->setHtml(s); |
|
|
|
auto f = [=](QVariant ev) { |
|
|
|
auto f2 = [=](QVariant jsonEv) { |
|
|
|
QString s; |
|
|
|
if (ev.isNull()) |
|
|
|
s = "<span style=\"color: #888\">null</span>"; |
|
|
|
else if (ev.type() == QVariant::String) |
|
|
|
s = "<span style=\"color: #444\">\"</span><span style=\"color: #c00\">" + ev.toString().toHtmlEscaped() + "</span><span style=\"color: #444\">\"</span>"; |
|
|
|
else if (ev.type() == QVariant::Int || ev.type() == QVariant::Double) |
|
|
|
s = "<span style=\"color: #00c\">" + ev.toString().toHtmlEscaped() + "</span>"; |
|
|
|
else if (jsonEv.type() == QVariant::String) |
|
|
|
s = "<span style=\"color: #840\">" + jsonEv.toString().toHtmlEscaped() + "</span>"; |
|
|
|
else |
|
|
|
s = "<span style=\"color: #888\">unknown type</span>"; |
|
|
|
m_consoleHistory.push_back(qMakePair(_js, s)); |
|
|
|
s = "<html><body style=\"margin: 0;\">" Div(Mono "position: absolute; bottom: 0; border: 0px; margin: 0px; width: 100%"); |
|
|
|
for (auto const& i: m_consoleHistory) |
|
|
|
s += "<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em; color: #888; font-weight: bold\">></span><span style=\"color: #35d\">" + i.first.toHtmlEscaped() + "</span></div>" |
|
|
|
"<div style=\"border-bottom: 1 solid #eee; width: 100%\"><span style=\"float: left; width: 1em\"> </span><span>" + i.second + "</span></div>"; |
|
|
|
s += "</div></body></html>"; |
|
|
|
ui->jsConsole->setHtml(s); |
|
|
|
}; |
|
|
|
ui->webView->page()->runJavaScript("JSON.stringify(___RET)", f2); |
|
|
|
}; |
|
|
|
auto c = (_js.startsWith("{") || _js.startsWith("if ") || _js.startsWith("if(")) ? _js : ("___RET=(" + _js + ")"); |
|
|
|
ui->webView->page()->runJavaScript(c, f); |
|
|
|
} |
|
|
|
|
|
|
|
static Public stringToPublic(QString const& _a) |
|
|
|