Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha
My Carrier: Telus
Accepted Solution

Managing Cascades events

[ Edited ]

How do we consume the up event if onTouchEnter was called? I have a few of these containers on screen. When I"m in the down state on one container and I move to another, I get the up event on the newly selected container. Is there something I can call in onTouchEnter to ignore the next up event?

Please use plain text.
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: Managing Cascades events

[ Edited ]

Hi,
One solution could be to save a reference to a VisualNode in your application. When you receive a "Down" event, you save the node reference internally. When the "Up" event is triggered, you can check the originating VisualNode against the saved value. This will give you flexibility within your application and specify more granularity setting up touch rules between specific VisualNodes.


For example:


//In header
private:
VisualNode* target;

public slots:
void onTouchSlot(bb::cascades::TouchEvent*);

//In CPP
VisualNode* container1 = m_Nav->findChild<VisualNode*>("container1");
            VisualNode* container2 = m_Nav->findChild<VisualNode*>("container2");

QObject::connect(container1, SIGNAL(touch(bb::cascades::TouchEvent*)), this, SLOT(onTouchSlot(bb::cascades::TouchEvent*)));

QObject::connect(container2, SIGNAL(touch(bb::cascades::TouchEvent*)), this, SLOT(onTouchSlot(bb::cascades::TouchEvent*)));


void App:: onTouchSlot(bb::cascades::TouchEvent* event)
{
    int touchType = event->touchType();

    if (touchType == TouchType:: Down)
    {
        target = event->target();
    }
    else if (touchType == TouchType::Up)
    {
        if (target == event->target())
        {
            qWarning() << "Same VisualNode";
        }
        else
        {
            qWarning() << "Different VisualNode";
        }
    }

}

Let me know if you make any progress!

 

Cheers,

 

Martin

Please use plain text.
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: Managing Cascades events

Hi there,

 

Have you made any progress on this front since Friday?

 

Martin

 

Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha
My Carrier: Telus

Re: Managing Cascades events

Seems to work. I was trying to solve this in QML only. Would there be a way to do this?
Please use plain text.
Developer
level32
Posts: 52
Registered: ‎03-29-2012
My Device: Playbook, Dev Alpha
My Carrier: Telus

Re: Managing Cascades events

I was able to get it to work in QML.

Here's the QML that is the base of all my custom buttons:

PanelButton.qml

import bb.cascades 1.0

Container {
    property variant pageToLoad: ""
  property variant state: TouchEvent.Up

  id: panelBtn layout: DockLayout { } //the background image is 9 sliced and expands to the size of the button ImageView { layoutProperties: DockLayoutProperties { horizontalAlignment: HorizontalAlignment.Fill verticalAlignment: VerticalAlignment.Fill } id: "btnBG" imageSource: "asset:///ui/panel_up" scalingMethod: ScalingMethod.Fill minWidth: 60 minHeight: 60 } // onTouch: { // if (event.isUp () && panelBtn.state == TouchType.Down) { panelBtn.state = TouchType.Up; btnBG.imageSource = "asset:///ui/panel_up"; root.navClick (pageToLoad); } // if (event.isDown ()) { btnBG.imageSource = "asset:///ui/panel_down"; panelBtn.state = TouchType.Down; } else if(event.isCancel ()) { btnBG.imageSource = "asset:///ui/panel_up"; panelBtn.state = TouchType.Up; } } // onTouchExit: { btnBG.imageSource = "asset:///ui/panel_up"; panelBtn.state = TouchType.Up; } // onTouchEnter: { btnBG.imageSource = "asset:///ui/panel_up"; panelBtn.state = TouchType.Up; } }

 

Please use plain text.
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Device: BB Alpha
My Carrier: N/A

Re: Managing Cascades events

Excellent!

 

Thank you for sharing your solution;

 

Regards,

 

Martin

Please use plain text.