LayoutUpdateHandler

Since: BlackBerry 10.0.0

#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 + "]");
                }
            }
        ]
    }
}


Overview

Inheritance

bb::cascades::BaseObject
bb::cascades::LayoutUpdateHandler

QML properties

layoutFrame: QRectF [read-only]
objectName: QStringInherited
parent: QObject [read-only]Inherited

QML signals

Properties Index

QRectFlayoutFrame [read-only]
QStringobjectNameInherited
QObjectparent [read-only]Inherited

Public Functions Index

LayoutUpdateHandler ()
LayoutUpdateHandler (Control *target)
virtual ~LayoutUpdateHandler ()
QRectFlayoutFrame () const
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited

Static Public Functions Index

Buildercreate (Control *target)

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited

Signals Index

voidlayoutFrameChanged (const QRectF &layoutFrame)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

QRectF layoutFrame[read-only]

A read only property representing the layout frame of the target control.

Since:

BlackBerry 10.0.0

QString objectNameInherited

This property is overridden from QObject.

See also:

QObject::objectName().

Since:

BlackBerry 10.0.0

QObject parentInherited[read-only]

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.

Since:

BlackBerry 10.0.0

Public Functions

LayoutUpdateHandler ()

Constructs a LayoutUpdateHandler without a specified target control.

Note:

There is no way to specify the target control for a handler constructed with this constructor.

Since:

BlackBerry 10.0.0

LayoutUpdateHandler (

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.

Since:

BlackBerry 10.0.0

virtual~LayoutUpdateHandler ()

Destructor.

Since:

BlackBerry 10.0.0

QRectF layoutFrame ()

Returns the current layout frame (position and dimensions) of the target control.

Return:

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.

Since:

BlackBerry 10.0.0

void setObjectName (Inherited

Sets the objectName property.

Parameters
name

The new name for the object.

Since:

BlackBerry 10.0.0

virtual Q_INVOKABLE QString toDebugString ()Inherited

Returns a debug string representing this object.

Return:

A debug string for the object.

Since:

BlackBerry 10.0.0

Static Public Functions

Builder create (

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.

Since:

BlackBerry 10.0.0

Protected Functions

(Only has inherited protected functions)

BaseObject (Inherited

Constructs an instance of BaseObject's subclass.

Parameters
parent

An optional parent, defaults to 0.

Since:

BlackBerry 10.0.0

Signals

void layoutFrameChanged (

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).

Since:

BlackBerry 10.0.0

void creationCompleted ()Inherited

Emitted 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 indicates 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.

See also:

QmlDocument

Since:

BlackBerry 10.0.0

void objectNameChanged (Inherited

This signal is emitted when the objectName property is changed.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-29



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus