Browse Source

Move to Chromium.

cl-refactor
Gav Wood 10 years ago
parent
commit
a10292205e
  1. 5
      alethzero/CMakeLists.txt
  2. 15
      alethzero/Main.ui
  3. 87
      alethzero/MainWin.cpp
  4. 2
      alethzero/MainWin.h

5
alethzero/CMakeLists.txt

@ -14,6 +14,9 @@ include_directories(..)
include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS})
include_directories(${JSON_RPC_CPP_INCLUDE_DIRS})
find_package (Qt5WebEngine QUIET)
find_package (Qt5WebEngineWidgets QUIET)
qt5_wrap_ui(ui_Main.h Main.ui)
qt5_wrap_ui(ui_Debugger.h Debugger.ui)
qt5_wrap_ui(ui_Transact.h Transact.ui)
@ -39,6 +42,8 @@ target_link_libraries(${EXECUTABLE} Qt5::Core)
target_link_libraries(${EXECUTABLE} Qt5::Widgets)
target_link_libraries(${EXECUTABLE} Qt5::WebKit)
target_link_libraries(${EXECUTABLE} Qt5::WebKitWidgets)
target_link_libraries(${EXECUTABLE} Qt5::WebEngine)
target_link_libraries(${EXECUTABLE} Qt5::WebEngineWidgets)
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} evm)

15
alethzero/Main.ui

@ -95,13 +95,7 @@
<widget class="QLineEdit" name="urlEdit"/>
</item>
<item>
<widget class="QWebView" name="webView">
<property name="url">
<url>
<string>about:blank</string>
</url>
</property>
</widget>
<widget class="QWebEngineView" name="webView" native="true"/>
</item>
</layout>
</widget>
@ -1672,6 +1666,12 @@ font-size: 14pt</string>
<header>DownloadView.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QWebEngineView</class>
<extends>QWidget</extends>
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>shhTo</tabstop>
@ -1686,7 +1686,6 @@ font-size: 14pt</string>
<tabstop>jsConsole</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>urlEdit</tabstop>
<tabstop>webView</tabstop>
<tabstop>idealPeers</tabstop>
<tabstop>forceAddress</tabstop>
<tabstop>port</tabstop>

87
alethzero/MainWin.cpp

@ -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]()
connect(ui->webView, &QWebEngineView::loadFinished, [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"));
});
// 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::loadFinished, [=]()
{
});
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\">&gt;</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\">&nbsp;</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\">&gt;</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\">&nbsp;</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)

2
alethzero/MainWin.h

@ -74,8 +74,6 @@ public:
NatSpecFace* natSpec() { return &m_natSpecDB; }
QVariant evalRaw(QString const& _js);
QString pretty(dev::Address _a) const override;
QString prettyU256(dev::u256 _n) const override;
QString render(dev::Address _a) const override;

Loading…
Cancel
Save