05-30-2012
12:37 PM
- last edited on
05-31-2012
11:03 AM
by
mgoulet
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?
Solved! Go to Solution.
06-01-2012 10:39 AM - edited 06-01-2012 10:39 AM
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
06-04-2012 03:22 PM
Hi there,
Have you made any progress on this front since Friday?
Martin
06-04-2012 03:47 PM
06-05-2012 11:50 AM
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;
}
}
06-05-2012 01:07 PM
Excellent!
Thank you for sharing your solution;
Regards,
Martin