I have a div of fixed size and an Image
inside it. I create a Rectangle
over the Image
and I want to zoom into that Rectangle
.
In the following code:
highlightItem
is the Rectangle
inside the Image
and it contains x
, y
, width
and height
. output
is the Image
and it contains x
, y
, width
and height
.
What I tried to do is to "move" the Image
to the center of the Rectangle
and then scale the Image
.
var parentMiddleX = output.x + output.width/2;
var parentMiddleY = output.y + output.height/2;
var highlightMiddleX = highlightItem.x + highlightItem.width/2;
var highlightMiddleY = highlightItem.y + highlightItem.height/2;
output.x = (parentMiddleX - highlightMiddleX);
output.y = (parentMiddleY - highlightMiddleY);
output.scale = Math.sqrt((output.width*output.height)/(highlightItem.width*highlightItem.height));
Basically I want to do something similar to this, but in QML.