PCL
pcl::WebView Class Reference

Client-side interface to a PixInsight WebView control. More...

#include <WebView.h>

+ Inheritance diagram for pcl::WebView:

Public Types

using content_event_handler = void(Control::*)(WebView &sender, const String &content)
 
using progress_event_handler = void(Control::*)(WebView &sender, int loadPercent)
 
using result_event_handler = void(Control::*)(WebView &sender, const Variant &result)
 
using state_event_handler = void(Control::*)(WebView &sender, bool state)
 
using view_event_handler = void(Control::*)(WebView &sender)
 
- Public Types inherited from pcl::Control
using child_event_handler = void(Control::*)(Control &sender, Control &child)
 
using close_event_handler = void(Control::*)(Control &sender, bool &allowClose)
 
using event_handler = void(Control::*)(Control &sender)
 
using file_drag_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, const StringList &files, unsigned modifiers, bool &wantsFiles)
 
using file_drop_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, const StringList &files, unsigned modifiers)
 
using keyboard_event_handler = void(Control::*)(Control &sender, int key, unsigned modifiers, bool &wantsKey)
 
using mouse_button_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, int button, unsigned buttons, unsigned modifiers)
 
using mouse_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, unsigned buttons, unsigned modifiers)
 
using mouse_wheel_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, int delta, unsigned buttons, unsigned modifiers)
 
using move_event_handler = void(Control::*)(Control &sender, const pcl::Point &newPos, const pcl::Point &oldPos)
 
using paint_event_handler = void(Control::*)(Control &sender, const pcl::Rect &updateRect)
 
using resize_event_handler = void(Control::*)(Control &sender, int newWidth, int newHeight, int oldWidth, int oldHeight)
 
using view_drag_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, const View &view, unsigned modifiers, bool &wantsView)
 
using view_drop_event_handler = void(Control::*)(Control &sender, const pcl::Point &pos, const View &view, unsigned modifiers)
 

Public Member Functions

 WebView (Control &parent=Control::Null())
 
 ~WebView () override
 
RGBA BackgroundColor () const
 
void EvaluateScript (const String &sourceCode, const IsoString &language=IsoString())
 
bool HasSelection () const
 
void LoadContent (const String &uri)
 
void OnHTMLAvailable (content_event_handler handler, Control &receiver)
 
void OnLoadFinished (state_event_handler handler, Control &receiver)
 
void OnLoadProgress (progress_event_handler handler, Control &receiver)
 
void OnLoadStarted (view_event_handler handler, Control &receiver)
 
void OnPlainTextAvailable (content_event_handler handler, Control &receiver)
 
void OnScriptResultAvailable (result_event_handler handler, Control &receiver)
 
void OnSelectionUpdated (view_event_handler handler, Control &receiver)
 
void Reload ()
 
void RequestHTML () const
 
void RequestPlainText () const
 
void SaveAsPDF (const String &filePath, double pageWidth=210, double pageHeight=297, double marginLeft=10, double marginTop=10, double marginRight=10, double marginBottom=10, bool landscape=false)
 
String SelectedText () const
 
void SetBackgroundColor (RGBA color)
 
void SetContent (const ByteArray &data, const IsoString &mimeType=IsoString())
 
void SetHTML (const IsoString &html)
 
void SetHTML (const String &html)
 
void SetPlainText (const IsoString &text)
 
void SetPlainText (const String &text)
 
void SetZoomFactor (double zoom)
 
void Stop ()
 
double ZoomFactor () const
 
- Public Member Functions inherited from pcl::Control
 Control (const Control &)=delete
 
 Control (Control &&)=delete
 
 Control (Control &parent=Null(), uint32=0)
 
 ~Control () override
 
void ActivateRealTimePreview ()
 
void ActivateTrackView ()
 
void ActivateWindow ()
 
void AdjustToContents ()
 
RGBA AlternateCanvasColor () const
 
RGBA BackgroundColor () const
 
pcl::Rect BoundsRect () const
 
void BringToFront ()
 
RGBA ButtonColor () const
 
RGBA ButtonTextColor () const
 
bool CanUpdate () const
 
RGBA CanvasColor ()
 
ControlChildByPos (const pcl::Point &p) const
 
ControlChildByPos (int x, int y) const
 
pcl::Rect ChildrenRect () const
 
ControlChildToFocus () const
 
void ClearInfoText ()
 
int ClientHeight () const
 
pcl::Rect ClientRect () const
 
int ClientWidth () const
 
void ControlToLocal (const Control &, int &x, int &y) const
 
pcl::Point ControlToLocal (const Control &w, const pcl::Point &p) const
 
pcl::Cursor Cursor () const
 
void DeactivateRealTimePreview ()
 
void DeactivateTrackView ()
 
void Disable (bool disabled=true)
 
void DisableExpansion (bool horzDisable=true, bool vertDisable=true)
 
void DisableMouseTracking (bool disable=true)
 
void DisableUpdates (bool disable=true)
 
double DisplayPixelRatio () const
 
virtual void Enable (bool enabled=true)
 
void EnableExpansion (bool horzEnable=true, bool vertEnable=true)
 
void EnableMouseTracking (bool=true)
 
void EnableUpdates (bool enable=true)
 
void EnsureLayoutUpdated ()
 
void EnsureUnique () override
 
void Focus (bool focus=true)
 
ControlFocusedChild () const
 
FocusStyles FocusStyle () const
 
pcl::Font Font () const
 
RGBA ForegroundColor () const
 
int FrameHeight () const
 
pcl::Rect FrameRect () const
 
int FrameWidth () const
 
pcl::Cursor GetCursor () const
 
pcl::Font GetFont () const
 
void GetMaxSize (int &w, int &h) const
 
void GetMinSize (int &w, int &h) const
 
void GetScaledMaxSize (int &w, int &h) const
 
void GetScaledMinSize (int &w, int &h) const
 
pcl::Sizer GetSizer () const
 
pcl::Point GlobalToLocal (const pcl::Point &p) const
 
void GlobalToLocal (int &x, int &y) const
 
int Height () const
 
void Hide ()
 
RGBA HighlightColor () const
 
RGBA HighlightedTextColor () const
 
String InfoText () const
 
bool IsActiveWindow () const
 
bool IsAncestorOf (const Control &) const
 
virtual bool IsEnabled () const
 
bool IsFixedHeight () const
 
bool IsFixedWidth () const
 
bool IsFocused () const
 
bool IsHidden () const
 
bool IsHorizontalExpansionEnabled () const
 
bool IsMaximized () const
 
bool IsMinimized () const
 
bool IsModal () const
 
bool IsMouseTrackingEnabled () const
 
bool IsRealTimePreviewActive () const
 
bool IsTrackViewActive () const
 
bool IsUnderMouse () const
 
bool IsVerticalExpansionEnabled () const
 
bool IsVisible () const
 
bool IsWindow () const
 
void LocalToControl (const Control &, int &x, int &y) const
 
pcl::Point LocalToControl (const Control &w, const pcl::Point &p) const
 
pcl::Point LocalToGlobal (const pcl::Point &p) const
 
void LocalToGlobal (int &x, int &y) const
 
pcl::Point LocalToParent (const pcl::Point &p) const
 
void LocalToParent (int &x, int &y) const
 
int LogicalPixelsToPhysical (int size) const
 
int LogicalPixelsToResource (int size) const
 
int MaxHeight () const
 
int MaxWidth () const
 
int MinHeight () const
 
int MinWidth () const
 
void Move (const pcl::Point &p)
 
void Move (int x, int y)
 
ControlNextSiblingToFocus () const
 
void OnChildCreate (child_event_handler, Control &)
 
void OnChildDestroy (child_event_handler, Control &)
 
void OnClose (close_event_handler, Control &)
 
void OnDestroy (event_handler, Control &)
 
void OnEnter (event_handler, Control &)
 
void OnFileDrag (file_drag_event_handler, Control &)
 
void OnFileDrop (file_drop_event_handler, Control &)
 
void OnGetFocus (event_handler, Control &)
 
void OnHide (event_handler, Control &)
 
void OnKeyPress (keyboard_event_handler, Control &)
 
void OnKeyRelease (keyboard_event_handler, Control &)
 
void OnLeave (event_handler, Control &)
 
void OnLoseFocus (event_handler, Control &)
 
void OnMouseDoubleClick (mouse_event_handler, Control &)
 
void OnMouseMove (mouse_event_handler, Control &)
 
void OnMousePress (mouse_button_event_handler, Control &)
 
void OnMouseRelease (mouse_button_event_handler, Control &)
 
void OnMouseWheel (mouse_wheel_event_handler, Control &)
 
void OnMove (move_event_handler, Control &)
 
void OnPaint (paint_event_handler, Control &)
 
void OnResize (resize_event_handler, Control &)
 
void OnShow (event_handler, Control &)
 
void OnViewDrag (view_drag_event_handler, Control &)
 
void OnViewDrop (view_drop_event_handler, Control &)
 
Controloperator= (const Control &)=delete
 
Controloperator= (Control &&)=delete
 
ControlParent () const
 
pcl::Point ParentToLocal (const pcl::Point &p) const
 
void ParentToLocal (int &x, int &y) const
 
int PhysicalPixelsToLogical (int size) const
 
pcl::Point Position () const
 
void Repaint ()
 
void Repaint (const pcl::Rect &r)
 
void Repaint (int x0, int y0, int x1, int y1)
 
void Resize (int w, int h)
 
double ResourcePixelRatio () const
 
int ResourcePixelsToLogical (int size) const
 
void Restyle ()
 
Point ScaledCursorHotSpot (const Point &hotSpot) const
 
Point ScaledCursorHotSpot (int xHot, int yHot) const
 
int ScaledMaxHeight () const
 
int ScaledMaxWidth () const
 
int ScaledMinHeight () const
 
int ScaledMinWidth () const
 
template<class R >
String ScaledResource (R resource) const
 
template<class S >
String ScaledStyleSheet (S cssCode, int fontDPI=0) const
 
void Scroll (const pcl::Point &d)
 
void Scroll (const pcl::Point &d, const pcl::Rect &r)
 
void Scroll (int dx, int dy)
 
void Scroll (int dx, int dy, int x0, int y0, int x1, int y1)
 
void SendToBack ()
 
void SetAlternateCanvasColor (RGBA)
 
void SetBackgroundColor (RGBA)
 
void SetButtonColor (RGBA)
 
void SetButtonTextColor (RGBA)
 
void SetCanvasColor (RGBA)
 
void SetChildToFocus (Control &)
 
void SetClientRect (const pcl::Rect &r)
 
void SetClientRect (int x0, int y0, int x1, int y1)
 
void SetCursor (const pcl::Cursor &)
 
void SetCursorToParent ()
 
void SetFixedHeight ()
 
void SetFixedHeight (int h)
 
void SetFixedSize ()
 
void SetFixedSize (int w, int h)
 
void SetFixedWidth ()
 
void SetFixedWidth (int w)
 
void SetFocusStyle (FocusStyles)
 
void SetFont (const pcl::Font &)
 
void SetForegroundColor (RGBA)
 
void SetHighlightColor (RGBA)
 
void SetHighlightedTextColor (RGBA)
 
void SetInfoText (const String &)
 
void SetMaxHeight ()
 
void SetMaxHeight (int h)
 
void SetMaxSize ()
 
void SetMaxSize (int w, int h)
 
void SetMaxWidth ()
 
void SetMaxWidth (int w)
 
void SetMinHeight ()
 
void SetMinHeight (int h)
 
void SetMinSize ()
 
void SetMinSize (int w, int h)
 
void SetMinWidth ()
 
void SetMinWidth (int w)
 
void SetNextSiblingToFocus (Control &)
 
void SetParent (Control &)
 
void SetRealTimePreviewActive (bool=true)
 
void SetScaledFixedHeight (int h)
 
void SetScaledFixedSize (int w, int h)
 
void SetScaledFixedWidth (int w)
 
void SetScaledMaxHeight (int h)
 
void SetScaledMaxSize (int w, int h)
 
void SetScaledMaxWidth (int w)
 
void SetScaledMinHeight (int h)
 
void SetScaledMinSize (int w, int h)
 
void SetScaledMinWidth (int w)
 
void SetSizer (pcl::Sizer &)
 
void SetStyleSheet (const String &css)
 
void SetTextColor (RGBA)
 
void SetToolTip (const String &)
 
void SetTrackViewActive (bool=true)
 
void SetVariableHeight ()
 
void SetVariableSize ()
 
void SetVariableWidth ()
 
void SetVisible (bool visible)
 
void SetWindowOpacity (double)
 
void SetWindowTitle (const String &)
 
void Show ()
 
pcl::Sizer Sizer () const
 
void StackUnder (Control &)
 
String StyleSheet () const
 
RGBA TextColor () const
 
String ToolTip () const
 
void Unfocus ()
 
void Update ()
 
void Update (const pcl::Rect &r)
 
void Update (int x0, int y0, int x1, int y1)
 
pcl::Rect VisibleRect () const
 
int Width () const
 
ControlWindow () const
 
double WindowOpacity () const
 
String WindowTitle () const
 
int X () const
 
int Y () const
 
- Public Member Functions inherited from pcl::UIObject
virtual ~UIObject () noexcept(false)
 
bool IsAlias () const
 
bool IsGarbage () const
 
bool IsNull () const
 
bool IsSameObject (const UIObject &o) const
 
bool IsUnique () const
 
String ObjectId () const
 
IsoString ObjectType () const
 
bool operator< (const UIObject &o) const
 
bool operator== (const UIObject &o) const
 
size_type RefCount () const
 
void SetObjectId (const String &id)
 

Additional Inherited Members

- Static Public Member Functions inherited from pcl::Control
static void HideToolTip ()
 
static ControlNull ()
 
static void ShowToolTip (const Point &pos, const String &text, const Control &control=Control::Null(), const Rect &rect=Rect(0))
 
static void ShowToolTip (int x, int y, const String &text, const Control &control=Control::Null(), const Rect &rect=Rect(0))
 
static String ToolTipText ()
 
- Static Public Member Functions inherited from pcl::UIObject
static UIObjectNull ()
 
- Protected Member Functions inherited from pcl::UIObject
 UIObject ()=default
 
 UIObject (const UIObject &x)
 
 UIObject (UIObject &&x)
 
UIObjectoperator= (const UIObject &x)
 
UIObjectoperator= (UIObject &&x)
 

Detailed Description

WebView is a specialized control for rendering text and HTML content on the PixInsight platform. The underlying implementation, which is based on Qt5's QWebEngineView class, has full HTML 5.1 support and an advandced, last-generation JavaScript engine.

It is very important to point out that this class is not intended to implement a web browser, even one with barebones functionality. The purpose of WebView is to render high-quality, interactive contents such as tables, spreadsheets and graphics, where the contained data are dynamically generated as HTML and JavaScript code.

Definition at line 92 of file WebView.h.

Constructor & Destructor Documentation

◆ WebView()

pcl::WebView::WebView ( Control parent = Control::Null())

Constructs a WebView control.

Parameters
parentThe parent control of this object. The default value is a null control.

◆ ~WebView()

pcl::WebView::~WebView ( )
inlineoverride

Destroys a WebView control.

Definition at line 107 of file WebView.h.

Member Function Documentation

◆ BackgroundColor()

RGBA pcl::WebView::BackgroundColor ( ) const

Returns the background color of the WebView rendition encoded in 32-bit RGBA format.

◆ EvaluateScript()

void pcl::WebView::EvaluateScript ( const String sourceCode,
const IsoString language = IsoString() 
)

Executes a script in this WebView.

Parameters
sourceCodeA string containing valid source code in the specified language.
languageThe name of a supported scripting language. Currently only the JavaScript language is supported by this function. JavaScript is assumed if this string is either empty or equal to "JavaScript".

This function is asynchronous: It will return immediately without waiting for the script to complete execution. Once the script has finished, its result value will be sent to the OnScriptResultAvailable() event handler, if defined for this object. The result value is the value of the last executed expression statement in the script that is not in a function definition. Note that for scripts whose value is not required, the OnScriptResultAvailable event handler is not necessary.

The script will be executed by a web-oriented JavaScript engine with full support of the HTML 5.1 standard in current versions of PixInsight. Note that this engine is completely different from the core JavaScript Runtime (PJSR), so no PJSR resources are available. If you want to execute JavaScript code in PJSR, use MetaModule::EvaluateScript() instead of this member function.

This function has no way to know if script execution failed, for example as a result of syntax errors, invalid code, or exceptions thrown from JavaScript code. A Variant will always be generated to transport the result, but it may not transport a valid object (see Variant::IsValid()) if the script failed. How to diagnose script execution is completely up to the caller implementation.

Note
This function can only be called from the root thread, since the underlying JavaScript engine in not reentrant in current versions of PixInsight. Calling this function from a running thread will throw an Error exception.
Warning
You should make sure that your code has been well tested before calling this function. The core PixInsight application will wait until the script terminates execution. If your code enters an infinite loop, it may lead to a crash of the PixInsight platform. Also bear in mind that scripts are extremely powerful and potentially dangerous if you don't know well what you are doing. What happens during execution of your scripts is your entire responsibility.

◆ HasSelection()

bool pcl::WebView::HasSelection ( ) const

Returns true if there is a non-empty text selection in this WebView.

◆ LoadContent()

void pcl::WebView::LoadContent ( const String uri)

Loads the content of this WebView from a local or external resource.

Parameters
uriA valid Uniform Resource Identifier, as defined by RFC 3986 (Uniform Resource Identifier: Generic Syntax).

See SetContent() for important information on WebView's asynchronous content rendering, also applicable to this member function.

See also
SetContent()

◆ Reload()

void pcl::WebView::Reload ( )

Reloads the content of this WebView. If no content has previously been loaded, calling this function has no effect.

◆ RequestHTML()

void pcl::WebView::RequestHTML ( ) const

Requests retrieval of the current content of this WebView as HTML code encoded in UTF-16.

This function is asynchronous. Once the requested content is available, it will be sent to the OnHTMLAvailable() event handler, if defined for this object.

◆ RequestPlainText()

void pcl::WebView::RequestPlainText ( ) const

Requests retrieval of the current content of this WebView as plain Unicode text encoded in UTF-16, with all HTML markup removed.

This function is asynchronous. Once the requested content is available, it will be sent to the OnPlainTextAvailable() event handler, if defined for this object.

◆ SaveAsPDF()

void pcl::WebView::SaveAsPDF ( const String filePath,
double  pageWidth = 210,
double  pageHeight = 297,
double  marginLeft = 10,
double  marginTop = 10,
double  marginRight = 10,
double  marginBottom = 10,
bool  landscape = false 
)

Writes the current content of this WebView as a PDF document.

Parameters
filePathPath to the output file.
pageWidthPage width in millimeters. The default width is 210 mm, corresponding to the standard A4 size.
pageHeightPage height in millimeters. The default height is 297 mm, corresponding to the standard A4 size.
marginLeftLeft margin in millimeters. The default left margin is 10 mm.
marginTopTop margin in millimeters. The default top margin is 10 mm.
marginRightRight margin in millimeters. The default right margin is 10 mm.
marginBottomBottom margin in millimeters. The default bottom margin is 10 mm.
landscapeIf true, the document will be generated with landscape orientation. This means that the width and height dimensions will be reversed. If false, the normal portrait orientation will be applied. This parameter is false by default.

◆ SelectedText()

String pcl::WebView::SelectedText ( ) const

Returns the currently selected text as plain text. Returns an empty string if there is no text selection.

◆ SetBackgroundColor()

void pcl::WebView::SetBackgroundColor ( RGBA  color)

Sets the background color of the WebView rendition. The specified color must be encoded in 32-bit RGBA format.

◆ SetContent()

void pcl::WebView::SetContent ( const ByteArray data,
const IsoString mimeType = IsoString() 
)

Sets the content of this WebView.

Parameters
dataThe content as a sequence of bytes, stored as a dynamic array of unsigned 8-bit integers.
mimeTypeA MIME type describing the type of the data. By default, that is, if an empty string is specified, the type will be detected based on heuristics.

The content loading process is asynchronous. This member function will return immediately before the content has actually been loaded and rendered in this WebView. After calling this function, a sequence of events will be generated:

  • A load started event. Can be received by a handler set with OnLoadStarted().
  • A number of successive load progress events. Can be received by a handler set with OnLoadProgress().
  • A final load finished event. Can be received by a handler set with OnLoadFinished(). This event handler in particular is necessary if the caller depends on (or has to wait for) the content being rendered by this WebView.
See also
SetHTML(), SetPlainText(), LoadContent()

◆ SetHTML() [1/2]

void pcl::WebView::SetHTML ( const IsoString html)

Sets the content of this WebView in HTML format, encoded as UTF-8. See SetContent() for important information on WebView's asynchronous content rendering.

◆ SetHTML() [2/2]

void pcl::WebView::SetHTML ( const String html)

Sets the content of this WebView in HTML format, encoded as UTF-16. See SetContent() for important information on WebView's asynchronous content rendering.

◆ SetPlainText() [1/2]

void pcl::WebView::SetPlainText ( const IsoString text)

Sets the content of this WebView as plain Unicode text encoded as UTF-8. See SetContent() for important information on WebView's asynchronous content rendering.

◆ SetPlainText() [2/2]

void pcl::WebView::SetPlainText ( const String text)

Sets the content of this WebView as plain Unicode text encoded as UTF-16. See SetContent() for important information on WebView's asynchronous content rendering.

◆ SetZoomFactor()

void pcl::WebView::SetZoomFactor ( double  zoom)

Sets the zoom factor of this WebView rendition. The specified zoom factor must be in the range [0.25,5.0].

◆ Stop()

void pcl::WebView::Stop ( )

Stops loading the content of this WebView. If there is no ongoing content loading operation, calling this function has no effect.

◆ ZoomFactor()

double pcl::WebView::ZoomFactor ( ) const

Returns the zoom factor of this WebView rendition. The returned value is in the range [0.25,5.0].


The documentation for this class was generated from the following file: