IntSelector.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Qt 4.7
  2. Item {
  3. property int value
  4. property int min: 0
  5. property int max: 999
  6. property int selected: 0
  7. property int itemWidth: intSelector.width
  8. property int itemHeight: intSelector.height
  9. id: intSelector
  10. clip: true
  11. function populate() {
  12. // populate previous days
  13. for (var i = min; i <= max; i++) {
  14. intModel.append({
  15. "value": i
  16. });
  17. }
  18. value = i;
  19. }
  20. Component {
  21. id: intSelectorComponent
  22. Item {
  23. height: itemHeight
  24. width: itemWidth
  25. MouseArea {
  26. anchors.fill: parent
  27. onClicked: intListView.currentIndex = index
  28. }
  29. Text {
  30. id: textItem
  31. font.pixelSize: applicationFontSize - 4
  32. text: model.value
  33. color: heiaLightGrey
  34. anchors.horizontalCenter: parent.horizontalCenter
  35. }
  36. Rectangle {
  37. anchors.bottom: parent.bottom
  38. anchors.horizontalCenter: parent.horizontalCenter
  39. height: 32
  40. width: 32
  41. radius: 16
  42. smooth: true
  43. color: current ? heiaFocusColorOuter : heiaLightGrey
  44. Rectangle {
  45. anchors.horizontalCenter: parent.horizontalCenter
  46. anchors.verticalCenter: parent.verticalCenter
  47. height: parent.height - heiaBorderWidth
  48. width: parent.width - heiaBorderWidth
  49. radius: 16
  50. smooth: true
  51. color: current ? heiaFocusColorInner : heiaDarkGrey
  52. }
  53. }
  54. }
  55. }
  56. ListModel {
  57. id: intModel
  58. }
  59. ListView {
  60. width: itemWidth
  61. height: itemHeight
  62. id: intListView
  63. model: dateModel
  64. delegate: intSelectorComponent
  65. onCurrentIndexChanged: value = currentIndex
  66. Component.onCompleted: {
  67. populate()
  68. intListView.currentIndex = selected - min
  69. positionViewAtIndex(intListView.currentIndex, ListView.Center);
  70. }
  71. onFocusChanged: intSelector.clip = intSelector.activeFocus
  72. }
  73. }