import QtQuick 2.0

Rectangle {
    id: rec

    property var img_src_on
    property var img_src_off

    //自定义点击信号
    signal clickedLeft()
    signal clickedRight()

    Image {
        id: icon
        width: parent.width
        height: parent.height
        source: img_src_off
        fillMode: Image.PreserveAspectFit
        clip: true
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        hoverEnabled: true

        //接受左键和右键输入
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked: function(mouse){
            //左键点击
            if (mouse.button === Qt.LeftButton)
            {
                parent.clickedLeft()
            }
            else if(mouse.button === Qt.RightButton)
            {
                parent.clickedRight()
            }
        }

        //指针进入
        onEntered: {
            icon.source = img_src_on
        }

        //指针退出
        onExited: {
            icon.source = img_src_off
        }
    }
}

