Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
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
        }
    }
}
posted on 2019-08-20 13:53 ccsdu2009 阅读(1460) 评论(0)  编辑 收藏 引用 所属分类: QT编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理