Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML PhotoShop like Transform Control
Forum Updated to NodeBB v4.3 + New Features

QML PhotoShop like Transform Control

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deus_duke
    wrote on 22 Sept 2011, 03:48 last edited by
    #1

    !https://lh3.googleusercontent.com/-2gr-oT-7swQ/Tnqtv-06zpI/AAAAAAAAAGM/OjSExWkKFgs/s360/TransformControlEx.gif(TransfromControlEx)!

    I am trying to create a PhotoShop like transform control as a QML Component. I am doing this by creating a series of circles and line, and then parenting them to a draggable image. Moving the different circles around the the image scale and rotate the image just like in PS. The problem is that since the transform control is a child of the image, the circle are getting scaled also. How would I go about keep this from happening the child of a component from scaling with the parent?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deus_duke
      wrote on 22 Sept 2011, 03:49 last edited by
      #2

      Tranform Control
      @import QtQuick 1.0

      Rectangle {
      id: transControl
      width: parent.width
      height: parent.height
      color: "#00000000"
      anchors.fill: parent

      property int gripSize: 10
      property int gripZ: 25
      property double originalWidth: width
      
      Rectangle {
          id: border
          width: parent.width
          height: parent.height
          color: "#00000000"
          border.color: "#000000"
          z: 0
      
          ResizeGrip {
              id: topLeftGrip
              type: "topLeft"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 - parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: 0 - parent.height / 2
              z: gripZ
          }
      
          ResizeGrip {
              id: topMiddleGrip
              type: "topMiddle"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: 0 - parent.height / 2
              z: gripZ
          }
      
          ResizeGrip {
              id: topRightGrip
              type: "topRight"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 + parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: 0 - parent.height / 2
              z: gripZ
          }
      
          ResizeGrip {
              id: midLeftGrip
              type: "middleLeft"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 - parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              z: gripZ
          }
      
          ResizeGrip {
              id: midRightGrip
              type: "middleRight"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 + parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              z: gripZ
              Scale{
                  id: mrScale
                  origin.x: midLeftGrip.x
                  origin.y: midLeftGrip.y
                  xScale: .5
              }
              MouseArea{
                  id: ma
                  anchors.fill: parent
                  drag.axis: Drag.XAxis
                  drag.target: midRightGrip
                  onPressed: {
                      console.log(midRightGrip.type + " was pressed");
                      midRightGrip.anchors.horizontalCenter = undefined;
                  }
                  onReleased: {
                      console.log(midRightGrip.type + " was released");
                      midRightGrip.anchors.horizontalCenter = midRightGrip.parent.horizontalCenter;
                  }
              }
              onXChanged: {
                  var parent = transControl.parent
                  if (ma.drag.active){
                      var distance = Math.abs(midRightGrip.x - midLeftGrip.x)
                      mrScale.xScale = distance
                      mrScale.xScale = distance / transControl.originalWidth
                      parent.transform = mrScale
                      console.log(transControl.originalWidth)
                      console.log("Distance is " + distance)
                      console.log("Scale is " + mrScale.xScale)
                      console.log(midRightGrip.type + " moved to " + midRightGrip.x)
                  }
              }
          }
      
          ResizeGrip {
              id: rgtLeftGrip
              type: "rightLeft"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 - parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: parent.height / 2
              z: gripZ
          }
      
          ResizeGrip {
              id: rgtMiddleGrip
              type: "rightMiddle"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: parent.height / 2
              z: gripZ
          }
      
          ResizeGrip {
              id: rgtRightGrip
              type: "rightRight"
              width: transControl.gripSize
              height: transControl.gripSize
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.horizontalCenterOffset: 0 + parent.width / 2
              anchors.verticalCenter: parent.verticalCenter
              anchors.verticalCenterOffset: parent.height / 2
              z: gripZ
          }
      }
      

      }
      @

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deus_duke
        wrote on 22 Sept 2011, 03:50 last edited by
        #3

        Code that instantiates it onto the draggable image
        @ var component = Qt.createComponent("Transform.qml");
        console.log("creating transform control");
        if (component.status == Component.Ready){
        var transform = component.createObject(di);
        transform.x = di.x - transform.width / 2
        transform.y = di.y - transform.height / 2
        }@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on 22 Sept 2011, 23:13 last edited by
          #4

          Hi,

          Rather than making your control a child of the Image you want to manipulate, can you make it a sibling? You could e.g. add a target property to transControl:

          @property Item target@

          which would be used internally where transControl.parent is currently used. Externally, you would then assign the target wherever the control is used:

          @Rectangle {
          Image { id: myImage }
          TransformControl { target: myImage }
          }@

          Regards,
          Michael

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deus_duke
            wrote on 23 Sept 2011, 14:11 last edited by
            #5

            I have updated the transControl as you have said with
            @property Item target@

            Then, on the javascript side when I create the control with
            @var component = Qt.createComponent("Transform.qml");
            component.target = target;@

            I get this error:
            Error: Cannot assign to non-existent property "target"

            Do you know what I am doing wrong?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbrasser
              wrote on 26 Sept 2011, 01:57 last edited by
              #6

              Hi,

              The target property is defined for the instances of the component, rather than the component itself, so it needs to be set on the objects returned from createObject:

              @var obj = component.createObject(parent)
              obj.target = targetItem
              @

              If you are using QtQuick 1.1 you can also do something like the following (which is faster and should potentially generate fewer warnings):

              @var obj = component.createObject(parent, { target: targetItem })

              Regards,
              Michael

              1 Reply Last reply
              0

              1/6

              22 Sept 2011, 03:48

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved