LayoutUpdateHandler
#include <bb/cascades/LayoutUpdateHandler>
Used for listening to layout and sizing changes on a control.
The layoutFrame property provides read only access to target control's layout frame. The layout frame is defined by a QRectF object that specifies a rectangle's X and Y coordinates and length and width.
The property is changed asynchronously when the layout system changes the target control's layout position and dimensions.
Updates are triggered only once a change in position or dimensions has been completed. Updates will not be made for any intermediate values while a control is being implicitly animated by the layout system.
The target control can only be specified during construction time using the constructor, builder, or as a parent component in QML. The update handler cannot be changed at run time.
Here's an example for how to track a container's layout position and size changes in C++.
Control *pButton = Button::create().text("Check out my layout!");
LayoutUpdateHandler::create(pButton)
.onLayoutFrameChanged(this, SLOT(handleLayoutFrameUpdated(QRectF)));
// pButton owns the created handler so there is no need to keep a reference to it,
// and it will be deleted when the button is deleted.
In QML, the handler must be attached to a Control derivative, otherwise the handler will have no effect. Here's an example of how the handler can be used in QML. The position and size of the blue container is bound to the layout position and size of the button.
Container {
layout: AbsoluteLayout {}
// The position and size of this container is bound to
// the position and size of the button.
Container {
preferredWidth: handler.layoutFrame.width + 20
preferredHeight: handler.layoutFrame.height + 20
layoutProperties: AbsoluteLayoutProperties {
positionX: handler.layoutFrame.x - 10
positionY: handler.layoutFrame.y - 10
}
background: Color.Blue
}
Button {
text: "I'm being followed!"
layoutProperties: AbsoluteLayoutProperties {
id: props
}
onClicked: {
props.positionX += 10;
props.positionY += 10;
}
attachedObjects: [
// This handler is tracking the layout frame of the button.
LayoutUpdateHandler {
id: handler
onLayoutFrameChanged: {
// Individual layout frame values can be
// retrieved from the signal parameter
console.log("Layout Frame: [" +
layoutFrame.x + ", " + layoutFrame.y +
layoutFrame.width + ", " +
layoutFrame.height + "]");
}
}
]
}
}
BlackBerry 10.0.0
Inheritance
| bb::cascades::BaseObject | ||
| bb::cascades::LayoutUpdateHandler | ||
QML properties
| layoutFrame | : QRectF [read-only] |
| objectName | : QString |
| parent | : QObject [read-only] |
QML signals
Properties Index
| QRectF | layoutFrame [read-only] |
| QString | objectName |
| QObject | parent [read-only] |
Public Functions Index
| LayoutUpdateHandler () | |
| LayoutUpdateHandler (Control *target) | |
| virtual | ~LayoutUpdateHandler () |
| QRectF | layoutFrame () const |
| void | setObjectName (const QString &name) |
| virtual Q_INVOKABLE QString | toDebugString () const |
Static Public Functions Index
| Builder | create (Control *target) |
Protected Functions Index
Only has inherited protected functions
| BaseObject (QObject *parent=0) |
Signals Index
| void | layoutFrameChanged (const QRectF &layoutFrame) |
| void | creationCompleted () |
| void | objectNameChanged (const QString &objectName) |
Properties
QRectF
A read only property representing the layout frame of the target control.
The property changes whenever the layout position and/or size of the target control is updated.
A layoutFrameChanged(const QRect&) signal is emitted whenever the property changes.
The default value of this property is a null (QRectF::isNull() returns true) rectangle positioned at 0,0 if the handler doesn't have a target or if the target hasn't been laid out yet.
BlackBerry 10.0.0
QString
This property is overridden from QObject.
As the objectName property is overridden from the QObject class, this signal will not be emitted if setObjectName() function is called directly on QObject.
The default value of this property is QString::null.
QObject::objectName().
BlackBerry 10.0.0
QObject
A read-only property that represents this object's parent.
The parent of an object is specified using QObject::setParent(QObject*). The purpose of the property is to expose the object's parent to QML.
This property is read-only to prevent modifications from QML, where typically the parent is declaratively set. In C++ code, the parent can be explicitly set using QObject::setParent(QObject*), or implicitly set by adding it to a visual container.
The default value of this property is 0.
BlackBerry 10.0.0
Public Functions
Constructs a LayoutUpdateHandler without a specified target control.
There is no way to specify the target control for a handler constructed with this constructor.
BlackBerry 10.0.0
Constructs a LayoutUpdateHandler with a specified control as the target node.
The constructed handler will receive layout frame updates from the control and emit the layoutFrameChanged() signal.
The passed control will assume ownership of this instance of LayoutUpdateHandler.
| Parameters | |
|---|---|
| target |
A control which will be used as a target for this handler. |
BlackBerry 10.0.0
virtual
Destructor.
BlackBerry 10.0.0
QRectF
Returns the current layout frame (position and dimensions) of the target control.
A rectangle representing the current layout frame, or a null rectangle (QRectF::isNull() returns true) positioned at 0,0 if the target control hasn't been laid out yet.
BlackBerry 10.0.0
void 
Sets the objectName property.
| Parameters | |
|---|---|
| name |
The new name for the object. |
BlackBerry 10.0.0
virtual Q_INVOKABLE QString 
Returns a debug string representing this object.
A debug string for the object.
BlackBerry 10.0.0
Static Public Functions
Builder
Constructs a Builder for a LayoutUpdateHandler with a specified control as the target node.
The constructed handler will receive layout frame updates from the control and emit the layoutFrameChanged() signal.
The passed control will assume ownership of this instance of LayoutUpdateHandler.
LayoutUpdateHandler::create(pControl)
.onLayoutFrameChanged(pMyObject, SLOT(onLayoutFrameChanged(QRectF)));
| Parameters | |
|---|---|
| target |
A non-null control that will be used as a target for this handler. |
BlackBerry 10.0.0
Protected Functions
(Only has inherited protected functions)
Constructs an instance of BaseObject's subclass.
| Parameters | |
|---|---|
| parent |
An optional parent, defaults to 0. |
BlackBerry 10.0.0
Signals
void
Emitted when target control's layout position and/or size changed.
This signal is emitted when the target control's layout is updated.
The parameter is a rectangle with x, y, width, and height values representing the layout position and dimensions of the target control.
The layout information that is sent refers to local coordinates, which means that it is relative to the parent's position and does not take transforms into consideration.
| Parameters | |
|---|---|
| layoutFrame |
A rectangle representing the size and position of the target control in local coordinates (meaning it is relative to control's parent). |
BlackBerry 10.0.0
void 
This signal is emitted only when this object is instantiated as a result of loading a QML document and creating the root node, or when an object is being constructed using its builder class.
This signal is emitted only when this object is instantiated as a result of loading a QML document and creating the root node (only after the root component that caused this instantiation has completed construction), or when the object is being constructed from its builder class. This signal is emitted to indicate that the construction and initialization of the object has been completed, the properties are initialized, and any QML binding values have been assigned to the object.
This signal is not emitted when the object is constructed from C++ using the constructor. If the object is constructed using its builder class, the signal is emitted when the the builder class returns the fully constructed object.
This signal can be used when there is an activity that needs to be performed, such as a property state integrity verification after the object is instantiated from a QML document or a builder, but before control is returned to the application.
BlackBerry 10.0.0
void 
This signal is emitted when the objectName property is changed.
BlackBerry 10.0.0