Advertisement
Bartel

CustomQQuickDial.qml

Mar 22nd, 2019
2,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 3.24 KB | None | 0 0
  1. in main.cpp:
  2.  
  3. include "customqquickdial.h"
  4.  
  5.     qmlRegisterType<CustomQQuickDial>("CustomQQuickDial", 1, 0, "CustomQQuickDial" );
  6.  
  7.  
  8. in CustomQQuickDial.qml:
  9.  
  10. import CustomQQuickDial 1.0
  11.  
  12. CustomQQuickDial {
  13.             id: dial
  14.             implicitWidth: 100
  15.             implicitHeight: 100
  16.             stepSize: 1/21
  17.             snapMode: Dial.SnapAlways
  18.             wheelEnabled: true
  19.             wrap: true
  20.             background: Rectangle {
  21.                 id: backG
  22.                 x: dial.width / 2 - width / 2
  23.                 y: dial.height / 2 - height / 2
  24.                 width: dial.width
  25.                 height: width
  26.                 color: "transparent"
  27.                 radius: width / 2
  28.                 border.color: Qt.lighter("#333333")
  29.                 border.width: 15
  30.                 opacity: dial.enabled ? 1 : 0.3
  31.                
  32.                 Rectangle {
  33.                     id: circle
  34.                     anchors.horizontalCenter: parent.horizontalCenter
  35.                     anchors.verticalCenter: parent.verticalCenter
  36.                     height: parent.height/2
  37.                     width: parent.width/2
  38.                     radius: height/2
  39.                 }
  40.                 MouseArea {
  41.                     anchors.fill: parent
  42.                     propagateComposedEvents: true
  43.                     onWheel: {
  44.                         if(wheel.angleDelta.y === 120)
  45.                         {
  46.                             if(dial.value < (1.0-dial.stepSize))
  47.                                 dial.increase()
  48.                             else
  49.                                 dial.value = 0;
  50.                         }
  51.                         else if(wheel.angleDelta.y === -120)
  52.                         {
  53.                             if(dial.value > 0)
  54.                                 dial.decrease()
  55.                             else
  56.                                 dial.value = 1-dial.stepSize;
  57.                         }
  58.                     }
  59.                     onClicked: mouse.accepted = false;
  60.                     onPressed: mouse.accepted = false;
  61.                     onReleased: mouse.accepted = false;
  62.                     onDoubleClicked: mouse.accepted = false;
  63.                     onPositionChanged: mouse.accepted = false;
  64.                     onPressAndHold: mouse.accepted = false;
  65.                 }
  66.             }
  67.             handle: Rectangle {
  68.                 id: handleItem
  69.                 x: dial.background.x + dial.background.width / 2 - width / 2
  70.                 y: dial.background.y + dial.background.height / 2 - height / 2
  71.                 width: backG.border.width
  72.                 height: backG.border.width
  73.                 radius: backG.border.width / 2
  74.                 antialiasing: true
  75.                 opacity: dial.enabled ? 1 : 0.3
  76.                 transform: [
  77.                     Translate {
  78.                         y: -Math.min(dial.background.width+25, dial.background.height+25) * 0.4 + handleItem.height / 2
  79.                     },
  80.                     Rotation {
  81.                         angle: dial.angle
  82.                         origin.x: handleItem.width / 2
  83.                         origin.y: handleItem.height / 2
  84.                     }
  85.                 ]
  86.             }
  87.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement