qlands
8th June 2010, 15:08
Hi,
I am writing a graphical application that require scale of graphic items. In the application the user drags and drops polygon from a toolbar (like Dia does). When the polygon lands into the scene it has an standard size. I need to implement the scale of the items. I'm using the setScale function. The problem that I have happens when the user want to scale an already scaled item. For example if I scale an item to 2.0 the result is a item twice its original size, if I do 2.0 again the function uses the original polygon and not the scaled one resulting in the same size.
I tried to work around the problem with the following code:
//Scaled polygon
QPolygonF spoly;
//One polygon in the scene
tnkPolygonSymbol *item;
//Gets one polygon from the scene
item = qgraphicsitem_cast<tnkPolygonSymbol *>(scenes[currentPage]->items()[0]);
//Scale the item to double
item->setScale(2.0);
//Gets the scaled polygon from the scene
spoly = item->mapToScene(item->polygon());
//Restores the polygon to the original size
item->setScale(1.0);
//Replaces the current polygon with the scaled polygon
item->setPolygon(spoly);
However this does not work. The result of the process is shown in this image:
http://www.qlands.com/other_files/scene02.jpg
After the process, the bounding rectangle is double its original size but the resized polygon is away from its bounding rectangle. This may happen because the coordinate values of the spoly are not the same as the item in the scene. I tried to set the coordinates of spoly with moveTo, CeterOn, etc and nothing seems to work.
Any ideas will be appreciated.
Thanks,
Carlos.
I am writing a graphical application that require scale of graphic items. In the application the user drags and drops polygon from a toolbar (like Dia does). When the polygon lands into the scene it has an standard size. I need to implement the scale of the items. I'm using the setScale function. The problem that I have happens when the user want to scale an already scaled item. For example if I scale an item to 2.0 the result is a item twice its original size, if I do 2.0 again the function uses the original polygon and not the scaled one resulting in the same size.
I tried to work around the problem with the following code:
//Scaled polygon
QPolygonF spoly;
//One polygon in the scene
tnkPolygonSymbol *item;
//Gets one polygon from the scene
item = qgraphicsitem_cast<tnkPolygonSymbol *>(scenes[currentPage]->items()[0]);
//Scale the item to double
item->setScale(2.0);
//Gets the scaled polygon from the scene
spoly = item->mapToScene(item->polygon());
//Restores the polygon to the original size
item->setScale(1.0);
//Replaces the current polygon with the scaled polygon
item->setPolygon(spoly);
However this does not work. The result of the process is shown in this image:
http://www.qlands.com/other_files/scene02.jpg
After the process, the bounding rectangle is double its original size but the resized polygon is away from its bounding rectangle. This may happen because the coordinate values of the spoly are not the same as the item in the scene. I tried to set the coordinates of spoly with moveTo, CeterOn, etc and nothing seems to work.
Any ideas will be appreciated.
Thanks,
Carlos.