PDA

View Full Version : Higlighting wrong item



Kapil
21st April 2006, 09:41
Hi...

I am facing a problem while highlighting the Q3Canvas items...
I have drawn few CanvasLines which criss cross each other...
now i have activated the Mouse events on it.. when clicked on the any item it returns me the point...
with the point using the collisions function of Canvas am able to extract all the items... but when i compare it with my list of Canvas Line, it returns me the first line drawn always no matter which one i click...

Note: When i removed the criss-crossing of them and each set of lines were independent and not overlapping, i was returned the exact item on which i had clicked... The problem comes when the lines cut eachother i.e. there is atleast one intersection point between them..

what can be the solution to this problem....
i am finding it hard to come up with a solution...

Thank you.

with regards,
Kapil

jacek
21st April 2006, 10:15
Did you actually care to read the docs?

Q3CanvasItemList Q3Canvas::collisions ( const QPoint & p ) const
Returns a list of canvas items that collide with the point p. The list is ordered by z coordinates, from highest z coordinate (front-most item) to lowest z coordinate (rear-most item).

Kapil
21st April 2006, 10:30
hi..

yaa i had read it and used it with the same concept but the problem was there... i would show u those few lines where i had done so...


Q3CanvasItemList l = m_pCanvas->collisions(item);
selCanItem = l;
for (Q3CanvasItemList::Iterator it= selCanItem.begin(); it!= selCanItem.end(); ++it)
{
if ( (*it)->rtti() == 7 )
{
for(i=0;i<42;i++)
{
if((i<GlobalOutYLineList.size()) && ((*it)->collidesWith(GlobalOutYLineList.at(i))))
{
QMessageBox::information(this, tr("CGUITileType"),tr("GlobalOutYLineList Line %1 Mouse Event Handled ").arg(i));
m_pCLineGlobalOutY[i]->setPen(QPen(Qt::red));
startPoint = m_pCLineGlobalOutY[i]->startPoint();
endPoint = m_pCLineGlobalOutY[i]->endPoint();
m_pCLineGlobalOutY[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x (),endPoint.y());
m_pCLineGlobalOutY[i]->show();
break;
}
else if((i<V1_DirectInputLineList.size())&& ((*it)->collidesWith(V1_DirectInputLineList.at(i))))
{
QMessageBox::information(this, tr("CGUITileType"),tr("V1_DirectInputLineList Line %1 Mouse Event Handled ").arg(i));
m_pV1_CLineDirectInput[i]->setPen(QPen(Qt::red));
startPoint = m_pV1_CLineDirectInput[i]->startPoint();
endPoint = m_pV1_CLineDirectInput[i]->endPoint();
m_pV1_CLineDirectInput[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x (),endPoint.y());
m_pV1_CLineDirectInput[i]->show();
break;
}


Now the problem is no matter which canvas item i click, it enters the first 'if' and highlights the 0th item...

Kapil

jacek
21st April 2006, 11:08
What are the bounding boxes for these two lines?

Kapil
21st April 2006, 11:19
hi...

i have not used boundingRect() function for the lines anywhere to find the bounding boxes..
i have created QList and stored the line items in it and then compared it with the Q3CanvasItemList with the collideswith(0 function...

How can knowing the bounding box help ???
I would also try it out .....

Kapil

jacek
21st April 2006, 15:08
i have not used boundingRect() function for the lines anywhere to find the bounding boxes..
Nevermind, Q3CanvasLines::areaPoints() will be used to detect collision for lines.


Now the problem is no matter which canvas item i click, it enters the first 'if' and highlights the 0th item...
And what item it should highlight? Maybe you should skip the "else" keyword?

I don't see much sense in this part:

startPoint = m_pCLineGlobalOutY[i]->startPoint();
endPoint = m_pCLineGlobalOutY[i]->endPoint();
m_pCLineGlobalOutY[i]->setPoints(startPoint.x(),startPoint.y(),endPoint.x (),endPoint.y());Haven't you messed the variable names somewhere?