QWebEnginePage* QWebEngineView::page() const { Q_D(const QWebEngineView); if (!d->page) { QWebEngineView *that = const_cast<QWebEngineView*>(this); that->setPage(new QWebEnginePage(that)); } return d->page; }
QWebEngineView *VUtils::getWebEngineView(QWidget *p_parent) { QWebEngineView *viewer = new QWebEngineView(p_parent); VPreviewPage *page = new VPreviewPage(viewer); page->setBackgroundColor(Qt::transparent); viewer->setPage(page); viewer->setZoomFactor(g_config->getWebZoomFactor()); return viewer; }
int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setQuitOnLastWindowClosed(false); app.setApplicationName("electric-webview"); app.setApplicationVersion("1.0"); QCommandLineParser cmdParser; cmdParser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions); cmdParser.setApplicationDescription("Electric WebView is a scriptable WebView for developers."); cmdParser.addHelpOption(); cmdParser.addVersionOption(); cmdParser.addOption(QCommandLineOption(QStringList() << "t" << "transport", "Command Transport Layer to use.", "tcp|unixsocket|websocket")); cmdParser.addOption(QCommandLineOption(QStringList() << "r" << "reverse", "Enable reverse mode. The ID is used to identify your session in the server.", "ID")); cmdParser.addOption(QCommandLineOption(QStringList() << "s" << "script", "Script to run.", "path")); cmdParser.process(app); if (cmdParser.value("transport").isEmpty()) { qDebug().noquote() << "You must provide a command transport layer"; return -1; } CommandServer *commandServer = new CommandServer(); commandServer->setTransport(cmdParser.value("transport")); commandServer->setReverse(cmdParser.isSet("reverse")); commandServer->setReverseId(cmdParser.value("reverse")); commandServer->initialize(); QWebEngineView *webView = new QWebEngineView; webView->setPage(new WebPage); ElectricWebView::instance()->setWebView(webView); ElectricWebView::instance()->initialize(); QObject::connect(commandServer, &CommandServer::newCommand, ElectricWebView::instance()->commandHandler(), &CommandHandler::processCommand); if (cmdParser.isSet("script")) ElectricWebView::instance()->runScript(cmdParser.value("transport"), cmdParser.value("script")); return app.exec(); }