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. [SOLVED] Limit dragging range
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Limit dragging range

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 268 Views
  • 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.
  • MarkkyboyM Offline
    MarkkyboyM Offline
    Markkyboy
    wrote on last edited by Markkyboy
    #1

    I've created a rotary style volume control. I can animate the movement from 0 to 10 and back, but I'd like to control it by touch.

    I have tried to use mapToRange() as shown to me before here on the forum, but I've no idea how to use it with the mouse.

    Here's what I have so far, using ArunPK's "CircularSlider.qml";

        CircularSlider {
            id: volume
            width: 800
            height: width
            minValue: 0
            maxValue: 100
            startAngle: -135
            endAngle: 135
            interactive: true
            // red dot
            handleWidth: 30
            handleRadius: handleWidth/2
            handleHeight: handleWidth
            handleVerticalOffset: 50
            handleColor: "red"
    
            value: progress.angle
            anchors.centerIn: parent
    
            CircularProgress {
                id: progress
                size: 950
                lineWidth: 320
                primaryColor: "#191919"
                anchors.centerIn: parent
                rotation: volume.startAngle
                property real angle: mapToRange(value, 10, 0, 10, 0)
    
                function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew) { return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew }
    
                Rectangle {
                    width: 800
                    height: width
                    radius: width/2
                    color: progress.primaryColor
                    anchors.centerIn: parent
                }
    
                MouseArea {
                    id: mouse
                    anchors.fill: parent
                    property real truex: mouseX - volume.width/2
                    property real truey: volume.height / 2-mouseY
                    property real angle: Math.atan2(truex, truey)
                    property real exactangle: parseInt(angle * 180 / Math.PI)
                    property real modulo: exactangle
                    onPositionChanged: {
                        if  (mouse.angle < 0)
                             progress.angle = exactangle
                        else progress.angle = exactangle
                    }
                }
            }
            Repeater {
                model: 11
                Label {
                    id: digits
                    text: index
                    color: Theme.primaryColor
                    font.pixelSize: 60
                    property real angle: index * 27
                    rotation: -digits.angle + volume.endAngle
                    transform: [ Translate { x: volume.width / 2 - width / 2; y: -110 },
                        Rotation { origin.x: volume.width / 2; origin.y: volume.height / 2; angle: digits.angle + volume.startAngle }
                    ]
                }
            }
        }
    

    Screenshot_20240419_001.png

    Don't just sit there standing around, pick up a shovel and sweep up!

    I live by the sea, not in it.

    MarkkyboyM 1 Reply Last reply
    0
    • MarkkyboyM Markkyboy

      I've created a rotary style volume control. I can animate the movement from 0 to 10 and back, but I'd like to control it by touch.

      I have tried to use mapToRange() as shown to me before here on the forum, but I've no idea how to use it with the mouse.

      Here's what I have so far, using ArunPK's "CircularSlider.qml";

          CircularSlider {
              id: volume
              width: 800
              height: width
              minValue: 0
              maxValue: 100
              startAngle: -135
              endAngle: 135
              interactive: true
              // red dot
              handleWidth: 30
              handleRadius: handleWidth/2
              handleHeight: handleWidth
              handleVerticalOffset: 50
              handleColor: "red"
      
              value: progress.angle
              anchors.centerIn: parent
      
              CircularProgress {
                  id: progress
                  size: 950
                  lineWidth: 320
                  primaryColor: "#191919"
                  anchors.centerIn: parent
                  rotation: volume.startAngle
                  property real angle: mapToRange(value, 10, 0, 10, 0)
      
                  function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew) { return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew }
      
                  Rectangle {
                      width: 800
                      height: width
                      radius: width/2
                      color: progress.primaryColor
                      anchors.centerIn: parent
                  }
      
                  MouseArea {
                      id: mouse
                      anchors.fill: parent
                      property real truex: mouseX - volume.width/2
                      property real truey: volume.height / 2-mouseY
                      property real angle: Math.atan2(truex, truey)
                      property real exactangle: parseInt(angle * 180 / Math.PI)
                      property real modulo: exactangle
                      onPositionChanged: {
                          if  (mouse.angle < 0)
                               progress.angle = exactangle
                          else progress.angle = exactangle
                      }
                  }
              }
              Repeater {
                  model: 11
                  Label {
                      id: digits
                      text: index
                      color: Theme.primaryColor
                      font.pixelSize: 60
                      property real angle: index * 27
                      rotation: -digits.angle + volume.endAngle
                      transform: [ Translate { x: volume.width / 2 - width / 2; y: -110 },
                          Rotation { origin.x: volume.width / 2; origin.y: volume.height / 2; angle: digits.angle + volume.startAngle }
                      ]
                  }
              }
          }
      

      Screenshot_20240419_001.png

      MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by
      #2

      @Markkyboy - solved it, answer staring me in the face. Have been using CircularSlider all wrong!, doh!

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      0

      • Login

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