CLProgressBar.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Copyright © 2010 Digia Plc
  3. * Copyright © 2010 Nokia Corporation
  4. *
  5. * All rights reserved.
  6. *
  7. * Nokia and Nokia Connecting People are registered trademarks of
  8. * Nokia Corporation.
  9. * Java and all Java-based marks are trademarks or registered
  10. * trademarks of
  11. * Sun Microsystems, Inc. Other product and company names
  12. * mentioned herein may be
  13. * trademarks or trade names of their respective owners.
  14. *
  15. *
  16. * Subject to the conditions below, you may, without charge:
  17. *
  18. * · Use, copy, modify and/or merge copies of this software and
  19. * associated documentation files (the "Software")
  20. *
  21. * · Publish, distribute, sub-licence and/or sell new software
  22. * derived from or incorporating the Software.
  23. *
  24. *
  25. * This file, unmodified, shall be included with all copies or
  26. * substantial portions
  27. * of the Software that are distributed in source code form.
  28. *
  29. * The Software cannot constitute the primary value of any new
  30. * software derived
  31. * from or incorporating the Software.
  32. *
  33. * Any person dealing with the Software shall not misrepresent
  34. * the source of the Software.
  35. *
  36. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  37. * KIND, EXPRESS OR IMPLIED,
  38. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  39. * MERCHANTABILITY, FITNESS FOR A
  40. * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  41. * AUTHORS OR COPYRIGHT
  42. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  43. * WHETHER IN AN ACTION
  44. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  45. * CONNECTION WITH THE
  46. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  47. */
  48. import Qt 4.7
  49. import "../"
  50. Rectangle {
  51. id: structure
  52. // Operational properties
  53. property real minValue: 0
  54. property real maxValue: 100
  55. property real value: 60
  56. property int percentage: Math.round((value-minValue)/(maxValue-minValue) * 100) //read-only
  57. // CLStyle properties
  58. property CLStyle style: CLStyle {}
  59. property int spacing: 1
  60. property color bgColor: style.bgColor
  61. property color colorWhenDefault: style.colorWhenDefault
  62. property real roundness: style.roundness
  63. property int borderWidth: style.borderWidth
  64. property color borderColor: style.borderColor
  65. property Gradient gradientBg: style.gradientBg
  66. property Gradient gradientWhenDefault: style.gradientWhenDefault
  67. property bool gradientDefaultOn: style.gradientDefaultOn
  68. property bool gradientBgOn: style.gradientBgOn
  69. property Gradient nullGradient: Gradient{}
  70. onValueChanged: {
  71. if (value < minValue) value = minValue;
  72. if (value > maxValue) value = maxValue;
  73. }
  74. width: 300
  75. height: 20
  76. color: bgColor
  77. border.color: borderColor
  78. border.width: borderWidth
  79. smooth: true
  80. clip: true
  81. radius: (height/2) * roundness
  82. gradient: (gradientBgOn)?gradientBg:nullGradient
  83. Rectangle {
  84. id: bar
  85. width: Math.round( ((value-minValue)/(maxValue-minValue))*(structure.width - 2*spacing - 2*structure.borderWidth) )
  86. height: Math.round( structure.height - 2*spacing - 2*structure.borderWidth )
  87. x: spacing + structure.borderWidth
  88. y: spacing + structure.borderWidth
  89. smooth: true
  90. color: colorWhenDefault
  91. gradient: (gradientDefaultOn)?gradientWhenDefault:nullGradient
  92. radius: (height/2) * roundness
  93. Behavior on width { SmoothedAnimation { target: bar; property: "width"; velocity: 300; } }
  94. }
  95. }