Logo ROOT  
Reference Guide
rootwebview.cpp
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2017-06-29
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#include "rootwebview.h"
14#include "rootwebpage.h"
15
16#include <QMimeData>
17#include <QDragEnterEvent>
18#include <QDropEvent>
19
20/** \class RootWebView
21\ingroup qt5webdisplay
22*/
23
24RootWebView::RootWebView(QWidget *parent, unsigned width, unsigned height, int x, int y) :
25 QWebEngineView(parent),
26 fWidth(width),
27 fHeight(height),
28 fX(x),
29 fY(y)
30{
31 setObjectName("RootWebView");
32
33 setPage(new RootWebPage(this));
34
35 connect(page(), &QWebEnginePage::windowCloseRequested, this, &RootWebView::onWindowCloseRequested);
36
37 connect(page(), &QWebEnginePage::loadFinished /* loadStarted */, this, &RootWebView::onLoadStarted);
38
39 setAcceptDrops(true);
40
41 if ((fX >= 0) || (fY >= 0)) move(fX > 0 ? fX : 0, fY > 0 ? fY : 0);
42
43 // do not destroy view on close, one require some time to handle close events
44 setAttribute( Qt::WA_DeleteOnClose, false );
45}
46
48{
49 if (fWidth && fHeight)
50 return QSize(fWidth, fHeight);
51 return QWebEngineView::sizeHint();
52}
53
54void RootWebView::dragEnterEvent( QDragEnterEvent *e )
55{
56 if (e->mimeData()->hasText())
57 e->acceptProposedAction();
58}
59
60
62{
63 emit drop(event);
64}
65
66void RootWebView::closeEvent(QCloseEvent *)
67{
68 page()->runJavaScript("if (window && window.onqt5unload) window.onqt5unload();");
69}
70
72{
73 // page()->runJavaScript("var jsroot_qt5_identifier = true;");
74 // page()->runJavaScript("window.jsroot_qt5_identifier = true;");
75 // page()->runJavaScript("console.log('window type = ' + typeof window + ' 1: ' + typeof jsroot_qt5_identifier + ' 2: ' + typeof window.jsroot_qt5_identifier);");
76}
77
79{
80 close();
81}
#define e(i)
Definition: RSha256.hxx:103
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
virtual QSize sizeHint() const
Definition: rootwebview.cpp:47
virtual void dropEvent(QDropEvent *event)
Definition: rootwebview.cpp:61
unsigned fWidth
Definition: rootwebview.h:21
void onLoadStarted()
Definition: rootwebview.cpp:71
void onWindowCloseRequested()
Definition: rootwebview.cpp:78
void drop(QDropEvent *event)
virtual void dragEnterEvent(QDragEnterEvent *e)
Definition: rootwebview.cpp:54
unsigned fHeight
Definition: rootwebview.h:21
virtual void closeEvent(QCloseEvent *)
Definition: rootwebview.cpp:66
RootWebView(QWidget *parent=nullptr, unsigned width=0, unsigned height=0, int x=-1, int y=-1)
Definition: rootwebview.cpp:24
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17