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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 3
Registered: ‎04-03-2013
My Device: BlackBerry 10 dev alpha B
My Carrier: none
Accepted Solution

How to get the coordinate of the screen when touched.

Hello everyone!

 

I'm a beginner at blackberry development, also a beginner at programming in general ^^

 

I've made a few app's using just QML, and take some C++ tutorials

 

I'm trying to get the coordinate of screen when the user touches it, as I wasn't able to do that using just QML, so I found the source TouchEvent and tried to make it work on C++, to get the windowX and windowY coordinates of the touch.

http://developer.blackberry.com/cascades/reference/bb__cascades__touchevent.html

 

I'm using the image on background to try getting the event touch.
So far, it's:

HPP:

class LostInSpace : public QObject
{
    Q_OBJECT
public:
    LostInSpace(bb::cascades::Application *app);
    virtual  ~LostInSpace() {}
public slots:
Q_INVOKABLE float screentouchY(bb::cascades::TouchEvent* event);
Q_INVOKABLE float screentouchX(bb::cascades::TouchEvent* event);


private:
QPointer<bb::cascades::ImageView> fundo;

};

 CPP:

LostInSpace::LostInSpace(bb::cascades::Application *app)

{
	
	QmlDocument *qml =
QmlDocument::create("asset:///main.qml").parent(this);
	qml->setContextProperty("app", this);
	AbstractPane *root = qml->createRootObject<AbstractPane>();

	app->setScene(root);

	fundo = root->findChild<ImageView*>("fundo");
	bool res = QObject::connect(fundo, SIGNAL(touch(bb::cascades::TouchEvent*)),this, SLOT(screentouchY(bb::cascades::TouchEvent*)));
	Q_ASSERT(res);
	res = QObject::connect(fundo, SIGNAL(touch(bb::cascades::TouchEvent*)),
this, SLOT(screentouchX(bb::cascades::TouchEvent*)));
	Q_ASSERT(res);

}

float LostInSpace::screentouchY(bb::cascades::TouchEvent* event) {
	return event->windowY();
}
float LostInSpace::screentouchX(bb::cascades::TouchEvent* event) {
	return event->windowX();
}

 QML:  (I'll do the animations later, this is just to see if it work. I'm getting a "unknown simbol app" at the onTouch, I tought I just had to put "qml->setContextProperty("app", this);"  at the constructor)

ImageView {
                objectName: "fundo"
                imageSource: "images/fundo1.png"
                touchPropagationMode: TouchPropagationMode.Full
                onTouch: {
                    tiro.translationX = app.screentouchX();
                    tiro.translationY = app.screentouchY();
                }
            }


Any help will be much appreciated! 

Thank you!

 

 

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to get the coordinate of the screen when touched.

Hey there,

 

You don't need to do that.. You can access the TouchEvent 'event' object within the onTouch: { } area of QML...

 

ImageView {
                objectName: "fundo"
                imageSource: "images/fundo1.png"
                touchPropagationMode: TouchPropagationMode.Full
                onTouch: {
                    tiro.translationX = event.windowX
                    tiro.translationY = event.windowY
                }
            }

 

New Developer
Posts: 3
Registered: ‎04-03-2013
My Device: BlackBerry 10 dev alpha B
My Carrier: none

Re: How to get the coordinate of the screen when touched.

Sorry, I marked as solution, but i'm still getting the error "Unknown symbol event"

Any idea?
Highlighted
Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: How to get the coordinate of the screen when touched.

You only have access to 'event' within the onTouch: { } area.. be sure you are using it there..