ContextMenuHandler

Since: BlackBerry 10.0.0

#include <bb/cascades/ContextMenuHandler>

A handler for communicating with the Context menu.

Example of how to connect a context menu handler to a visual node:

ImageView* myControl = ImageView::create();

ContextMenuHandler *contextMenuHandler = ContextMenuHandler::create()
    .onPopulating(myControl, 
        SLOT(myPopulating(bb::cascades::ContextMenuShowingEvent*)))
    .onVisualStateChanged(myControl, 
        SLOT(myVisualStateChanged(bb::cascades::ContextMenuVisualState::Type)));

myControl->setContextMenuHandler(contextMenuHandler);

An example in QML:

ImageView {
    contextMenuHandler: ContextMenuHandler {
        id: myHandler
        onPopulating: {
            // Abort the showing of the context menu if the user long-pressed
            // in the top left corner
            if (event.touchX < 100 && event.touchY < 100) {
                event.abort();
            }
        }
        onVisualStateChanged: {
            if (ContextMenuVisualState.VisibleCompact == myHandler.visualState) {
                hideSomethingInMyUi();
            }
            else if (ContextMenuVisualState.Hidden == myHandler.visualState) {
                showSomethingInMyUi();
            }
        }
    }
}


Overview

Inheritance

bb::cascades::BaseObject
bb::cascades::UIObject
bb::cascades::ContextMenuHandler

QML properties

visualState: bb::cascades::ContextMenuVisualState::Type [read-only]
attachedObjects: QDeclarativeListProperty< QObject > [read-only]Inherited
objectName: QStringInherited
parent: QObject [read-only]Inherited

QML signals

Properties Index

bb::cascades::ContextMenuVisualState::TypevisualState [read-only]
QDeclarativeListProperty< QObject >attachedObjects [read-only]Inherited
QStringobjectNameInherited
QObjectparent [read-only]Inherited

Public Functions Index

ContextMenuHandler (UIObject *parent=0)
virtual ~ContextMenuHandler ()
Q_SLOT voidcloseMenu ()
bb::cascades::ContextMenuVisualState::TypevisualState () const
virtual boolevent (QEvent *event)Inherited
voidsetObjectName (const QString &name)Inherited
virtual Q_INVOKABLE QStringtoDebugString () const Inherited

Static Public Functions Index

Buildercreate ()

Protected Functions Index

Only has inherited protected functions

BaseObject (QObject *parent=0)Inherited
virtual voidconnectNotify (const char *signal)Inherited
virtual voiddisconnectNotify (const char *signal)Inherited

Signals Index

voidhiding ()
voidpopulating (bb::cascades::ContextMenuShowingEvent *event)
voidshowing (bb::cascades::ContextMenuShowingEvent *event)
voidvisualStateChanged (bb::cascades::ContextMenuVisualState::Type newVisualState)
voidcreationCompleted ()Inherited
voidobjectNameChanged (const QString &objectName)Inherited

Properties

bb::cascades::ContextMenuVisualState::Type visualState[read-only]

The current visual state of the context menu.

Since:

BlackBerry 10.0.0

QDeclarativeListProperty< QObject > attachedObjectsInherited[read-only]

A hierarchical list of the UIObject's attached objects.

This QDeclarativeListProperty can contain any QObject. When a QObject is added to property, the UIObject takes ownership of the attached object.

This feature is typically used from QML to specify business logic object or any other shared objects for the subnodes of this UIObject. In C++ the same functionality can be achived by setting a parent of a QObject to be attached to the QObject which is going to own it.

QML usage example (MyObject is a custom class registered for QML using the qmlRegisterType() function):

Container {
    Label { text: "Title: " + myObject.title } 
    Label { text: "Subject: " + myObject.subject }
    attachedObjects: [
        MyObject { id: myObject
            title: "Hello World"
            subject: "Nice Day"
        }
    ]
}

Since:

BlackBerry 10.0.0

QString objectNameInherited

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.

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

ContextMenuHandler (

Creates a ContextMenuHandler.

Parameters
parent

The object that will own the created handler. This parameter is optional.

Since:

BlackBerry 10.0.0

virtual~ContextMenuHandler ()

Destructor.

Since:

BlackBerry 10.0.0

Q_SLOT void closeMenu ()

Closes the context menu.

Forcibly closes the context menu in the current context menu scope. Dialog and Sheet have their own context menu scope. This function will close the menu regardless of what state it is in. Even if it is in MultiSelect mode.

Normally, the user should be the one deciding when to close the menu. Only in cases where the user can't make that decision should this function be used.

Since:

BlackBerry 10.2.0

bb::cascades::ContextMenuVisualState::Type visualState ()

Returns the current visual state of the context menu.

Return:

The current visual state of the context menu.

Since:

BlackBerry 10.0.0

virtual bool event (Inherited

Overloaded to implement the event mechanism in Cascades.

Warning!

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
event

The received event.

Return:

True if the received event was recognized and processed, false otherwise.

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

Creates and returns a builder for constructing a ContextMenuHandler.

Example of how to use the builder to create a ContextMenuHandler:
ContextMenuHandler *pContextMenuHandler = ContextMenuHandler::create();
Return:

A Builder used to construct a ContextMenuHandler.

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

virtual void connectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The connected signal.

Since:

BlackBerry 10.0.0

virtual void disconnectNotify (
  • const char *signal)
Inherited

Overloaded to implement the event mechanism in Cascades.

If this function is overridden, it must be called by the derived class for events to work properly in Cascades.

Parameters
signal

The disconnected signal.

Since:

BlackBerry 10.0.0

Signals

void hiding ()

Emitted when the Context menu is about to be hidden for the target control.

This signal will be emitted when the Context menu starts to hide.

This signal will not be emitted if ContextMenuShowingEvent::abort() was called to abort showing the Context menu.

Since:

BlackBerry 10.0.0

void populating (

Emitted when the ContextMenu is ready to start populating for the target control.

This signal is emitted synchronously. During the signal call, the application has a chance to update the ActionSet of the target control before the menu is shown. The target control is typically the control for which this ContextMenuHandler is set as the Control::contextMenuHandler property.

No context actions are shown in the Context Menu until this call returns. However, if this call takes too long to return, the Context Menu will appear without any items, indicating that the items are being loaded. Action items from Control::contextActions will be added to the menu as soon as this call returns.

Calling ContextMenuShowingEvent::abort() will abort the showing of the Context Menu.

Parameters
event

The showing event.

Since:

BlackBerry 10.0.0

void showing (

Emitted when the ContextMenu is about to be shown for the target control.

This signal is emitted synchronously. During the signal call, the application has a chance to update the ActionSet of the target control before the menu is shown. The target control is typically the control for which this ContextMenuHandler is set as the Control::contextMenuHandler property.

No context actions are shown in the Context Menu until this call returns. However, if this call takes too long to return the Context Menu will appear without any items, indicating that the items are being loaded. Action items from Control::contextActions will be added the menu as soon as this call returns.

Calling ContextMenuShowingEvent::abort() will abort the showing of the Context Menu.

Parameters
event

The showing event.

Deprecated

Use ContextMenuHandler.populating or contextMenuHandler.visualState instead.

Since:

BlackBerry 10.0.0

void visualStateChanged (

Emitted when the visualState property changed.

Note:

Due to a work around for a Qt Core issue with accessing enums from QML, the argument of this signal doesn't follow naming convention for signals in which the signal arguments are typically named to match the associated property's name. Use the object's visualState property to access the current property value instead of the signal argument to avoid runtime errors.

For example, use visualState instead of newVisualState.
Parameters
newVisualState

The new value of the visualState property.

Since:

BlackBerry 10.0.0

void creationCompleted ()Inherited

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.

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-03-13

comments powered by Disqus