Pinch Area with a VisualDataModel[SOLVED]



  • Hello everyone,

    I have a problem having a PinchArea within a visualDataModel. How can I manage to solve this problem please.

    here is the code :

    @
    // pinch.qml

    import QtQuick 1.1
    import "ImageLoader.js" as ImageLoader

    Rectangle
    {
    //width: view.width
    //height: view.height
    height: 720
    width: 1001
    color: "black"
    //color: pinchy.pinch.active ? "blue" : "gray"

    Component.onCompleted: ImageLoader.createImages()
    
    VisualDataModel
    {
        id: dataModel
        model: ListModel
        {
            id:innerModel
        }
    
        delegate: Image
        {
            width: view.width;
            height: view.height;
            source: url
            fillMode: Image.PreserveAspectFit
        }
    }
    
    // Where can I put this code to zoom the image?
    PinchArea
    {
        property int xpoint
        property int ypoint
        property int pinchscale
        property int pinchrotation
    
        id: pinchy
        enabled: false
        pinch.target: logo
        anchors.fill: parent
        pinch.dragAxis: Pinch.XandYAxis
        pinch.minimumScale: 0.5
        pinch.maximumScale: 2
        pinch.minimumX: 50
        pinch.maximumX: 300
        pinch.minimumY: 50
        pinch.maximumY: 300
        pinch.minimumRotation: -150
        pinch.maximumRotation: 150
    
        onPinchUpdated:
        {
            xpoint = pinch.center.x;
            ypoint = pinch.center.y;
            pinchrotation = pinch.rotation;
            pinchscale = pinch.scale
        }
    }
    
    ListView
    {
        id: view
        anchors.fill: parent;
        model: dataModel
        orientation: ListView.Horizontal
        snapMode: ListView.SnapOneItem;
        flickDeceleration: 0
        highlightFollowsCurrentItem: true
        highlightRangeMode: ListView.StrictlyEnforceRange
        preferredHighlightBegin: 0
        preferredHighlightEnd: 0
        cacheBuffer: width;
        focus: true
        Keys.onLeftPressed:
        {
            if (currentIndex > 0 )
                currentIndex = currentIndex-1;
        }
        Keys.onRightPressed:
        {
            if (currentIndex < count)
                currentIndex = currentIndex+1;
        }
    }
    
    Rectangle
    {
        id: enabler;
        height: 40;
        width: 50;
        radius: 7
        anchors.right: parent.right;
        color: pinchy.enabled ? "green" : "gray"
        Text
        {
            anchors
            {
                left:parent.left
                leftMargin:10
                top: parent.top
                topMargin: 10
            }
            text: pinchy.enabled ? "Disable" : "Enable"
        }
        MouseArea
        {
            anchors.fill: parent;
            onClicked: pinchy.enabled = !pinchy.enabled
        }
    }
    

    }
    @

    @
    // ImageLoader.js
    // I will try to load it another way next time

    function createImages()
    {
    var files = ["image.png","image1.png"];
    var i = 0;
    for (i=0; i<files.length; i++)
    {
    createImage(files[i]);
    }
    }

    function createImage(name)
    {
    innerModel.append({"url": name});
    }
    @

    @
    // main.cpp

    #include <QApplication>
    #include <QtDeclarative>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);

    QDeclarativeView *view = new QDeclarativeView();
    view->setSource(QUrl::fromLocalFile&#40;"./pinch.qml"&#41;&#41;;
    view->show(&#41;;
    
    return app.exec(&#41;;
    

    }
    @



  • The problem was so obvious... Just replace : pinch.target: logo by the appropriate item


Log in to reply
 

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