Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-17829

PinchArea and Flickable don't work well enough together

    XMLWordPrintable

Details

    • ea304fb207b681ee084c4ce9bc61d1dd847bd7b0

    Description

      Run the code below. Place a finger on the screen and drag the content of the screen. Then without letting go, place another finger on the screen and try to pinch. This won't work, which is a serious issue of poor usability.

      Similarly, starting with a pinch to zoom out, then letting go with one finger ends the pinch making the image slide back to the corner, when it should stay where it is until the user release both fingers. Dragging it while one finger remains on the screen doesn't work either.

      import QtQuick 1.1
      Rectangle {
          width: 640
          height: 854
      
          color: "gray"
          Flickable {
              id: flick
              anchors.fill: parent
              contentWidth: 850
              contentHeight: 500
      
              PinchArea {
                  width: Math.max(flick.contentWidth, flick.width)
                  height: Math.max(flick.contentHeight, flick.height)
      
                  function distance(p1, p2) {
                      var dx = p2.x-p1.x;
                      var dy = p2.y-p1.y;
                      return Math.sqrt(dx*dx + dy*dy);
                  }
      
                  property real initialDistance
                  property real initialContentWidth
                  property real initialContentHight
      
                  onPinchStarted: {
                      initialDistance = distance(pinch.point1, pinch.point2);
                      initialContentWidth = flick.contentWidth;
                      initialContentHight = flick.contentHeight;
                  }
      
                  onPinchUpdated: {
                      // adjust content pos due to drag
                      flick.contentX += pinch.previousCenter.x - pinch.center.x
                      flick.contentY += pinch.previousCenter.y - pinch.center.y
      
                      // resize content
                      var currentDistance = distance(pinch.point1, pinch.point2);
                      var scale = currentDistance/initialDistance;
                      flick.resizeContent(initialContentWidth*scale, initialContentHight*scale, pinch.center)
                  }
      
                  onPinchFinished: flick.returnToBounds() // Move its content within bounds.
      
                  Rectangle {
                      width: flick.contentWidth
                      height: flick.contentHeight
                      color: "white"
                      Image {
                          anchors.fill: parent
                          source: "qt-logo.jpg"
                          MouseArea {
                              anchors.fill: parent
                              onDoubleClicked: {
                                  flick.contentWidth = 850
                                  flick.contentHeight = 500
                              }
                          }
                      }
                  }
              }
          }
      
          Text {
              id: scaleText
              anchors.centerIn: parent
              font.pixelSize: 30
              text: flick.contentHeight/500;
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes