import QtQuick

Item {
    id: root

    property var targetWindow: null
    property int handleSize: 7

    function beginResize(edges) {
        if (targetWindow && targetWindow.startSystemResize)
            targetWindow.startSystemResize(edges)
    }

    MouseArea {
        anchors.left: parent.left
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        width: root.handleSize
        cursorShape: Qt.SizeHorCursor
        onPressed: root.beginResize(Qt.LeftEdge)
    }

    MouseArea {
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        width: root.handleSize
        cursorShape: Qt.SizeHorCursor
        onPressed: root.beginResize(Qt.RightEdge)
    }

    MouseArea {
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        height: root.handleSize
        cursorShape: Qt.SizeVerCursor
        onPressed: root.beginResize(Qt.TopEdge)
    }

    MouseArea {
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        height: root.handleSize
        cursorShape: Qt.SizeVerCursor
        onPressed: root.beginResize(Qt.BottomEdge)
    }

    MouseArea {
        anchors.left: parent.left
        anchors.top: parent.top
        width: root.handleSize * 2
        height: root.handleSize * 2
        cursorShape: Qt.SizeFDiagCursor
        onPressed: root.beginResize(Qt.LeftEdge | Qt.TopEdge)
    }

    MouseArea {
        anchors.right: parent.right
        anchors.top: parent.top
        width: root.handleSize * 2
        height: root.handleSize * 2
        cursorShape: Qt.SizeBDiagCursor
        onPressed: root.beginResize(Qt.RightEdge | Qt.TopEdge)
    }

    MouseArea {
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        width: root.handleSize * 2
        height: root.handleSize * 2
        cursorShape: Qt.SizeBDiagCursor
        onPressed: root.beginResize(Qt.LeftEdge | Qt.BottomEdge)
    }

    MouseArea {
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        width: root.handleSize * 2
        height: root.handleSize * 2
        cursorShape: Qt.SizeFDiagCursor
        onPressed: root.beginResize(Qt.RightEdge | Qt.BottomEdge)
    }
}
