Qml scaling problem



  • Hello friends,

    I have a grid where I place elements from a panel. I have zoom option implemented with item scale property. The problem is when I applied zoom scale -/+ 0.1 and I want to put an element from the panel on the grid, it's not placed where I point with the mouse. I'm blocked...

    Friends, does anyone have any idea how I coulf fix it?

    Thanks in advance,
    Karen



  • Hi,

    could you post some slice of your code?



  • Hi mcosta, here is a javascript file with the logic:

    @var itemComponent = null;
    var draggedItem = null;
    var startingMouse;
    var posnInWindow;
    var posnObject;

    function startDrag(mouse)
    {
    posnInWindow = hallItem.mapToItem(hallEditor, 0, 0);

    startingMouse = { x: mouse.x, y: mouse.y }
    
    loadComponent();
    

    }

    function addTable(object) {
    hallEditor.addTable(object)
    }

    function loadComponent() {
    if (itemComponent != null) {
    createItem();
    return;
    }

    itemComponent = Qt.createComponent(hallItem.componentFile);
    
    if (itemComponent.status === Component.Loading)
        component.statusChanged.connect(createItem);
    else
        createItem();
    

    }

    function createItem() {
    if (itemComponent.status === Component.Ready && draggedItem == null) {
    draggedItem = itemComponent.createObject(hallEditor, {"image": hallItem.image, "x": posnInWindow.x, "y": posnInWindow.y, "z": 1, "scale": hallscene.scale});
    } else if (itemComponent.status === Component.Error) {
    draggedItem = null;
    console.log("error creating component");
    console.log(itemComponent.errorString());
    }
    }

    function continueDrag(mouse)
    {
    if (draggedItem == null)
    return;

    draggedItem.x = mouse.x + posnInWindow.x - startingMouse.x;
    draggedItem.y = mouse.y + posnInWindow.y - startingMouse.y;
    
    var itemPosY = window.doubleToInt((draggedItem.y - hallscene.y) / 20);
    var itemPosX = window.doubleToInt((draggedItem.x - hallscene.x) / 20);
    
    var Object = { x: itemPosX * 20, y: itemPosY * 20, width: draggedItem.width, height: draggedItem.height, numId: draggedItem.numId, rotation: draggedItem.rotation}
    
    hallEditor.isCollisionTest(draggedItem, Object)
    

    }

    function endDrag(mouse)
    {
    if (draggedItem == null)
    return;

    if (draggedItem.x < hallEditorFon.x || draggedItem.y < hallEditorFon.y || draggedItem.x + draggedItem.width > hallEditorFon.width || draggedItem.y + draggedItem.height > hallEditorFon.height || draggedItem.collision) {
        draggedItem.destroy();
        draggedItem = null;
    } else {
        draggedItem.parent = hallscene
        draggedItem.scale = 1;
        draggedItem.numId = hallscene.numTable;
        hallscene.numTable++;
    
        var itemPosY = window.doubleToInt((draggedItem.y + -hallscene.y) / 20);
        var itemPosX = window.doubleToInt((draggedItem.x + -hallscene.x) / 20);
    
        draggedItem.y = itemPosY * 20;
        draggedItem.x = itemPosX * 20;
        draggedItem.created = true;
    

    // console.log("x", draggedItem.x, "y", draggedItem.y);

        hallEditor.push_back(draggedItem)
    
        draggedItem = null;
    }
    

    }
    @

    I used these qml properties:
    @ scale: 1;
    transformOrigin: Item.TopLeft@

    thanks in advance,
    Karen


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.