13#include <QApplication>
14#include <QWebEngineView>
15#include <qtwebenginecoreglobal.h>
16#include <QWebEngineDownloadRequest>
20#include <QWebEngineSettings>
21#include <QWebEngineProfile>
24#include <QWebEngineUrlScheme>
34#include "../qt5webdisplay/rootwebview.h"
35#include "../qt5webdisplay/rootwebpage.h"
36#include "../qt5webdisplay/rooturlschemehandler.h"
55 QApplication::sendPostedEvents();
56 QApplication::processEvents();
61namespace Experimental {
74 QApplication *
qapp{
nullptr};
78 std::unique_ptr<RootUrlSchemeHandler>
fHandler;
95 if (!
qapp && !QApplication::instance()) {
105 QWebEngineUrlScheme scheme(
"rootscheme");
106 scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
107 scheme.setDefaultPort(2345);
108 scheme.setFlags(QWebEngineUrlScheme::SecureScheme);
109 QWebEngineUrlScheme::registerScheme(scheme);
122 fTimer = std::make_unique<TQt6Timer>(interval,
kTRUE);
127 QString fullurl = QString(args.
GetFullUrl().c_str());
132 fHandler = std::make_unique<RootUrlSchemeHandler>();
133 QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(
"rootscheme",
fHandler.get());
134 QWebEngineProfile::defaultProfile()->connect(QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
135 [](QWebEngineDownloadRequest *request) { request->accept(); });
143 auto handle = std::make_unique<RQt6WebDisplayHandle>(fullurl.toLatin1().constData());
148 if (!qparent) handle->fView = view;
149 view->load(QUrl(fullurl));
153 int tmout_sec = 30, expired = tmout_sec * 100;
154 bool load_finished =
false, did_try =
false, get_content =
false, is_error =
false;
155 std::string content, pdffile;
160 QObject::connect(view, &RootWebView::loadFinished, [&load_finished, &is_error](
bool is_ok) {
161 load_finished =
true; is_error = !is_ok;
164 if (!pdffile.empty())
165 QObject::connect(view->page(), &RootWebPage::pdfPrintingFinished, [&expired, &is_error](
const QString &,
bool is_ok) {
166 expired = 0; is_error = !is_ok;
170 if (page_content.empty())
171 view->load(QUrl(fullurl));
173 view->setHtml(QString::fromUtf8(page_content.data(), page_content.size()), QUrl(
"file:///batch_page.html"));
176 while ((--expired > 0) && !get_content && !is_error) {
180 QApplication::sendPostedEvents();
181 QApplication::processEvents();
183 if (load_finished && !did_try) {
186 if (pdffile.empty()) {
187 view->page()->toHtml([&get_content, &content](
const QString& res) {
189 content = res.toLatin1().constData();
192 view->page()->printToPdf(QString::fromUtf8(pdffile.data(), pdffile.size()));
193 #if QT_VERSION < 0x050900
203 handle->SetContent(content);
208 for (expired=0;expired<100;++expired) {
209 QApplication::sendPostedEvents();
210 QApplication::processEvents();
236 GetMap().emplace(
"qt6", std::make_unique<Qt6Creator>());
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
R__EXTERN TApplication * gApplication
R__EXTERN TSystem * gSystem
QApplication * qapp
created QApplication
std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args) override
int fCounter
counter used to number handlers
char * qargv[2]
arg values
std::unique_ptr< RootUrlSchemeHandler > fHandler
specialized handler
std::unique_ptr< TQt6Timer > fTimer
timer to process ROOT events
RQt6WebDisplayHandle(const std::string &url)
RootWebView * fView
pointer on widget, need to release when handle is destroyed
virtual ~RQt6WebDisplayHandle()
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
bool IsHeadless() const
returns headless mode
int GetHeight() const
returns preferable web window height
const std::string & GetExtraArgs() const
get extra command line arguments for starting web browser command
std::string GetFullUrl() const
returns window url with append options
THttpServer * GetHttpServer() const
returns http server instance, used for window display
const std::string & GetPageContent() const
returns window url
void * GetDriverData() const
[internal] returns web-driver data, used to start window
int GetY() const
set preferable web window y position
int GetX() const
set preferable web window x position
int GetWidth() const
returns preferable web window width
Handle of created web-based display Depending from type of web display, holds handle of started brows...
static std::map< std::string, std::unique_ptr< Creator > > & GetMap()
Static holder of registered creators of web displays.
static std::unique_ptr< Creator > & FindCreator(const std::string &name, const std::string &libname="")
Search for specific browser creator If not found, try to add one.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
TQt6Timer(Long_t milliSec, Bool_t mode)
void Timeout() override
timeout handler used to process all qt6 events in main ROOT thread
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Handles synchronous and a-synchronous timer events.
struct ROOT::Experimental::RQt6CreatorReg newRQt6CreatorReg
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
ROOT::Experimental::RLogChannel & QtWebDisplayLog()