import QtQuick 2.9
Item
{
visible: true
width: 1620
height: 720
id:background
Image
{
source: "images/2560.png"
anchors.fill: parent
}
Flickable
{
id: flick
anchors.top: parent.top;
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 3
contentWidth: 0
contentHeight: 0
clip: true
Image
{
id: image
smooth: true
transformOrigin: Item.Center
source:"mark.png"
onStatusChanged:
{
if(status === Image.Ready)
{
image.width *= 0.5
image.height *= 0.5
image.x = background.width*0.5-0.5*image.width
image.y = background.height*0.5-0.5*image.height
/*mouseArea.drag.minimumX = 0
mouseArea.drag.maximumX = flick.width - image.width
mouseArea.drag.minimumY = 0
mouseArea.drag.maximumY = flick.height - image.height*/
}
}
}
}
function makeImageCenter(imageWidth,imageHeight)
{
var cx = image.x + 0.5*image.width
var cy = image.y + 0.5*image.height
image.width = imageWidth
image.height = imageHeight
image.x = cx - image.width*0.5
image.y = cy - image.height*0.5
}
MouseArea
{
id: mouseArea
anchors.fill: flick
drag.target: image
onWheel:
{
var diff_w = 0.0
var diff_h = 0.0
if(wheel.angleDelta.y > 0)
{
diff_w = image.width * 0.02
diff_h = image.height * 0.02
}
else if(wheel.angleDelta.y < 0)
{
diff_w = -image.width * 0.02
diff_h = -image.height * 0.02
}
else
{
image.width = width
image.height = height
}
if(wheel.angleDelta.y != 0)
background.makeImageCenter(image.width+diff_w,image.height+diff_h)
drag.minimumX = 0
drag.maximumX = flick.width - image.width
drag.minimumY = 0
drag.maximumY = flick.height - image.height
}
}
}