![]() |
ImFusion SDK 4.3
|
#include <ImFusion/GUI/DisplayWidget.h>
Render surface that hosts InteractiveViews and will call their render method on repaints. More...
Render surface that hosts InteractiveViews and will call their render method on repaints.
Additionally it distributes user events to the affected views. Until the release event, mouse move events are always sent to the view that received the press event, even if the mouse moves out of the view. The view layout has to be set manually every time a new view is added or the view won't be visible. The DisplayWidget has no dependency on the actual implementation of the InteractiveView and treats all views the same.
Public Slots | |
void | setRecording (bool enable, bool reset=true, bool continuous=false) |
If enabled and the recording path is not empty, all paintEvent results will be written to disk. | |
void | setRecordingOutputDir (const QString &path) |
Sets the path to the output file used in the recording. | |
bool | saveScreenshot (const QString &path) |
Saves the current screen content under the given path. | |
void | layoutViews (bool noAnimation=false) |
Layout the views. | |
void | resetLayout () |
void | fatalError (QString errorMessage) |
void | update () |
void | setFpsLimit (int fps) |
Limits the maximum frequency of display updates. | |
void | removeFpsLimit () |
Remove the limit on the frequency of display updates. | |
double | currentFps () |
Returns the current frame rate (independent of any FPS limit) | |
void | setContainerWidget (QWidget *widget) |
Sets the widget this QWindow is wrapped in (if any). | |
QWidget * | containerWidget () const |
bool | event (QEvent *event) override |
Handles any display event and hands it to corresponding views. | |
void | resizeEvent (QResizeEvent *event) override |
QPoint | mapFromOpenGL (const QPoint &point) const |
Converts the point from top-left to bottom-left coordinates. | |
QPointF | mapFromOpenGL (const QPointF &point) const |
QPoint | mapToOpenGL (const QPoint &point) const |
Converts the point from bottom-left to top-left coordinates. | |
QPointF | mapToOpenGL (const QPointF &point) const |
Signals | |
void | viewAdded (InteractiveView *v) |
Emitted after a view has been added. | |
void | viewRemoved (InteractiveView *v) |
Emitted after a view has been removed. This signal is not emitted when the DisplayLayout gets deleted and deletes all remaining views. | |
void | viewDeleted (InteractiveView *v) |
Emitted after a view has been deleted without being removed. | |
void | viewLayoutChanged () |
Emitted when the layout of the views has changed. | |
Public Member Functions | |
DisplayWidget (bool initialize=true, QWindow *parent=nullptr) | |
Creates a new empty DisplayWidget. | |
~DisplayWidget () override | |
Deletes all views. | |
void | init () |
Initialize the OpenGL context of this DisplayWidget. | |
void | deinit () |
Mark the display as deinitialized so that it will no longer perform any rendering. | |
void | setBackgroundColor (const QColor &color) |
QColor | backgroundColor () const |
virtual bool | addView (InteractiveView *view) |
Add view and pass ownership. If the view is not removed before this object is deleted it will be deleted too. | |
virtual bool | removeView (InteractiveView *view) |
Remove view. The user is responsible for deleting the view. | |
int | numViews () const |
Returns the number of views. | |
int | numVisibleViews () const |
Returns the number of visible views if no view is on fullscreen. | |
InteractiveView * | viewAt (int i) |
Returns the view with the index i or NULL if the view doesn't exist. | |
const InteractiveView * | viewAt (int i) const |
std::vector< InteractiveView * > | views () const |
InteractiveView * | view (int which=0) |
Access an interactive view, returns nullptr if which is out of bounds. | |
void | configure (const Properties *p) override |
Set one or multiple properties. | |
void | configuration (Properties *p) const override |
Retrieve the properties of this object. | |
bool | makeCurrent () |
Makes the underlying OpenGL context current against the QSurface of the display in the current thread. | |
void | doneCurrent () |
Deactivates any current OpenGL context in the current thread. | |
GUI::DisplayLayout * | layout () |
virtual void | render (bool swapBuffers=true) |
Clears the display and renders all views using the current OpenGL context. | |
QRect | viewport () const |
Returns the rendering viewport. | |
void | setCustomViewport (QRect viewport) |
Sets a custom rendering viewport. | |
std::unique_ptr< TypedImage< unsigned char > > | captureScreenshot (int width=0, int height=0, bool withAlpha=true) |
Capture the current content of the display into an image. | |
GUI::DisplayBase & | displayBaseAdapter () |
Return a helper struct implementing the GUI::DisplayBase interface for this DisplayWidget instance. | |
![]() | |
virtual void | configureDefaults () |
Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
void | registerParameter (ParameterBase *param) |
Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
void | unregisterParameter (const ParameterBase *param) |
Remove the given Parameter or SubProperty from the list of registered parameters. | |
Configurable (const Configurable &rhs) | |
Configurable (Configurable &&rhs) noexcept | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
Protected Slots | |
virtual void | animationFinished () |
virtual void | recordFrame () |
virtual void | onViewVisiblityChanged () |
virtual void | onViewVisiblityChangeRequested (bool visible) |
Protected Attributes | |
std::vector< InteractiveView * > | m_views |
std::shared_ptr< DataDisplayDispatcher > | m_dataDisplayDispatcher |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
Additional Inherited Members | |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
|
explicit |
Creates a new empty DisplayWidget.
initialize | Flag whether to fully initialize the DisplayWidget on construction. If you are embedding the DisplayWidget in a Qt window container, you need to postpone initialization to after calling QWidget::createWindowContainer. In this case, set it to false and call DisplayWidget::init() manually. |
parent | Parent Qt window. |
std::runtime_error | if the GL::ContextManager main context is not a GlContextQt (see class description). |
void deinit | ( | ) |
Mark the display as deinitialized so that it will no longer perform any rendering.
Can be used if the underlying OpenGL context has been destroyed already und there are still pending updates in the event queue.
|
virtual |
Add view and pass ownership. If the view is not removed before this object is deleted it will be deleted too.
Reimplemented in DisplayWidgetMulti.
|
virtual |
Remove view. The user is responsible for deleting the view.
Reimplemented in DisplayWidgetMulti.
int numVisibleViews | ( | ) | const |
Returns the number of visible views if no view is on fullscreen.
If fullscreen is enabled, this returns the number of views as if fullscreen would be disabled.
|
overridevirtual |
Set one or multiple properties.
Reimplemented from Configurable.
Reimplemented in DisplayWidgetMulti.
|
overridevirtual |
Retrieve the properties of this object.
Reimplemented from Configurable.
Reimplemented in DisplayWidgetMulti.
|
virtual |
Clears the display and renders all views using the current OpenGL context.
The related OpenGL context must be current before calling this method. Calls QOpenGLContext::swapBuffers if swapBuffers is set. If the context is shared it can also be current on another surface. For example to render the display into another QWindow (assuming it has a shared OpenGL backend):
Reimplemented in DisplayWidgetMulti.
QRect viewport | ( | ) | const |
Returns the rendering viewport.
The viewport is relative to the window, e.g. (0, 0) is the upper left corner of the window.
void setCustomViewport | ( | QRect | viewport | ) |
Sets a custom rendering viewport.
By default the DisplayWidget uses its complete geometry as viewport which is automatically resized with the window. If a non-empty custom viewport is set, this viewport is used instead and will NOT be changed on resize events. Passing an empty QRect restores the default behavior.
std::unique_ptr< TypedImage< unsigned char > > captureScreenshot | ( | int | width = 0, |
int | height = 0, | ||
bool | withAlpha = true ) |
Capture the current content of the display into an image.
width | Target width of the screenshot, will use the size of the DisplayWidget if set to 0 |
height | Target height of the screenshot, will use the size of the DisplayWidget if set to 0 |
withAlpha | Flag whether to capture the alpha channel as well. |
|
signal |
Emitted after a view has been deleted without being removed.
Do not connect to this signal if you don't know what you are doing! You have been warned...
|
slot |
If enabled and the recording path is not empty, all paintEvent results will be written to disk.
reset | resets the internal counter to 0 |
continuous | record a frame every 20ms versus on every OpenGL paint |
|
slot |
Sets the path to the output file used in the recording.
Can contain a QString placeholder (e.g. "test%1") that will be replaced successive number. If no placeholder is given each recording will override the last one. Contains "img_%1.png" by default.
|
slot |
Layout the views.
This function has to be called whenever a change in the position and/or size of the views was made or when the stretch factors were changed.
|
slot |
Sets the widget this QWindow is wrapped in (if any).
If this DisplayWidget is wrapped in a QWidget with QWidget::createWindowContainer, the resulting QWidget can be stored here for convenience. Since the geometry of the QWindow cannot be changed when inside a QWidget, this property is useful to change the geometry through the QWidget (e.g. resize or setGeometry). If you don't use QWidget::createWindowContainer, you can savely ignore this method.
|
overrideslot |
Handles any display event and hands it to corresponding views.
QMouseEvents, QWheelEvents and QTouchEvents are only passed to the view that contains the event position (in the case of QTouchEvent, all positions). If a view accepted a MouseButtonPress or TouchBegin, it will receive all following events independent of the position until a corresponding MouseButtonRelease or TouchEnd/TouchCancel event (i.e. the view gets an lock on all events). This ensures that dragging events are only handled by one view and don't change target when leaving a view. Views also receive Enter and Leave events when the mouse enters and leaves the view area (but only if no view has the afore mentioned event lock). QMouseEvents and QWheelEvent position are automatically converted from Qt window coordinates (top-left origin) to OpenGL coordinates (bottom-left origin). Because of limitations in Qt, this is not the case for QTouchEvents, which will always be in Qt window coordinates and must be converted when used (see mapToOpenGL).