qlayer

0th

Percentile

Create a layer

This function constructs a Layer, an item in the canvas that may paint part of the plot and/or respond to user input. The behavior of the layer is implemented using R functions, which are passed to the constructor. Other arguments determine the scaling and positioning of the layer, and whether the drawing of the layer is cached and/or clipped.

Usage
qlayer(parent, paintFun, keyPressFun, keyReleaseFun, mouseDoubleClickFun,
    mouseMoveFun, mousePressFun, mouseReleaseFun, wheelFun,
    hoverMoveFun, hoverEnterFun, hoverLeaveFun, contextMenuFun,
    dragEnterFun, dragLeaveFun, dragMoveFun, dropFun, focusInFun,
    focusOutFun, sizeHintFun, limits=qrect(), row=0, col=0, rowSpan=1,
    colSpan=1, geometry=qrect(0, 0, 600, 400), clip=cache, cache=FALSE)
Arguments
parent
The scene, for a top-level layer, or the parent layer that contains the new layer in a grid layout
paintFun
The function that implements painting, called whenever the layer needs to be repainted. All drawing occurs in data/layer coordinates.
keyPressFun
The function called when a key is pressed
keyReleaseFun
The function called when a key is released
mouseDoubleClickFun
The function called when a mouse button is double-clicked
mouseMoveFun
The function called when the mouse is moved while holding down a button
mousePressFun
The function called when a mouse button is pressed
mouseReleaseFun
The function called when a mouse button is released
wheelFun
The function called when the mouse wheel is turned
hoverMoveFun
The function called when the mouse moves without any buttons pressed
hoverEnterFun
The function called when the mouse pointer enters the layer
hoverLeaveFun
The function called when the mouse pointer leaves the layer
contextMenuFun
The function called when a context menu is requested, such as through a right mouse button click
dragEnterFun
The function called when the pointer enters the layer while dragging something
dragLeaveFun
The function called when the pointer leaves the layer while dragging something
dragMoveFun
The function called when the pointer moves within the layer while dragging something
dropFun
The function called when something is dropped on the layer
focusInFun
The function called when the layer gains the keyboard focus
focusOutFun
The function called when the layer loses the keyboard focus
sizeHintFun
The function called to determine the size constraints of the layer. Not currently documented.
limits
A QRectF, possibly created by qrect, indicating the X and Y scales of the layer in data/layer coordinates
row
The 0-based row index of the layer in the parent grid layout
col
The 0-based column index of the layer in the parent grid layout
rowSpan
The 0-based number of rows spanned by the layer in the layout
colSpan
The 0-based number of cols spanned by the layer in the layout
geometry
A QRectF, possibly created by qrect, indicating the position and size of the layer in figure/scene coordinates. This is overridden by the parent grid layout, so is really only useful for a top-level layer.
clip
Logical indicating whether to clip drawing to within the layer
cache
Logical indicating whether to cache drawing, which helps performance for relatively static layers sitting under more dynamic ones
Details

All drawing and user input handling is performed by R callbacks, which must accept a specific set of arguments. The paint callback, passed as paintFun, must take at least two arguments, conventionally named layer and painter. The layer argument is a C++ RLayer object, the same instance that was created by calling the constructor. All painting is performed through the painter argument, which is a C++ Painter object. See the paint functions for more details. The paintFun may take one additional, optional argument, conventionally named exposed, which is the rectangle, in layer coordinates, that needs to be drawn.

All of the other callbacks, except for sizeHintFun, are event handlers. Two arguments are passed, conventionally named layer and event. The former is the layer constructed in the call to qlayer, and the latter describes the event as an instance of C++ QGraphicsSceneEvent. The exact subclass depends on the event. Manipulating an event currently requires low-level calls through the qtbase package. See its documentation.

Value

  • The layer, a C++ instance of RLayer

Aliases
  • qlayer
Examples
scene <- qscene()
layer <- qlayer(scene, function(layer, painter) {
qdrawCircle(1:10, 1:10)
}, limits = qtbase::qrect(0, 0, 11, 11))
qplotView(scene)
Documentation reproduced from package qtpaint, version 1.1.0, License: GPL version 2 or later

Community examples

Looks like there are no examples yet.