Dial.qml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2017 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
  3. // Qt-Security score:significant reason:default
  4. import QtQuick
  5. import QtQuick.Templates as T
  6. import QtQuick.Controls.Imagine
  7. import QtQuick.Controls.Imagine.impl
  8. T.Dial {
  9. id: control
  10. implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
  11. (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding)
  12. implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
  13. (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding)
  14. topPadding: background ? background.topPadding : 0
  15. leftPadding: background ? background.leftPadding : 0
  16. rightPadding: background ? background.rightPadding : 0
  17. bottomPadding: background ? background.bottomPadding : 0
  18. topInset: background ? -background.topInset || 0 : 0
  19. leftInset: background ? -background.leftInset || 0 : 0
  20. rightInset: background ? -background.rightInset || 0 : 0
  21. bottomInset: background ? -background.bottomInset || 0 : 0
  22. handle: Image {
  23. x: control.background.x + control.background.width / 2 - width / 2
  24. y: control.background.y + control.background.height / 2 - height / 2
  25. source: Imagine.url + "dial-handle"
  26. ImageSelector on source {
  27. states: [
  28. {"disabled": !control.enabled},
  29. {"pressed": control.pressed},
  30. {"focused": control.visualFocus},
  31. {"mirrored": control.mirrored},
  32. {"hovered": control.enabled && control.hovered}
  33. ]
  34. }
  35. transform: [
  36. Translate {
  37. y: -Math.min(control.background.width, control.background.height) * 0.4
  38. + (control.handle ? control.handle.height / 2 : 0)
  39. },
  40. Rotation {
  41. angle: control.angle
  42. origin.x: control.handle ? control.handle.width / 2 : 0
  43. origin.y: control.handle ? control.handle.height / 2 : 0
  44. }
  45. ]
  46. }
  47. background: NinePatchImage {
  48. fillMode: Image.PreserveAspectFit
  49. source: Imagine.url + "dial-background"
  50. NinePatchImageSelector on source {
  51. states: [
  52. {"disabled": !control.enabled},
  53. {"pressed": control.pressed},
  54. {"focused": control.visualFocus},
  55. {"mirrored": control.mirrored},
  56. {"hovered": control.enabled && control.hovered}
  57. ]
  58. }
  59. }
  60. }