NumberPad.qml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import QtQuick 1.0
  5. View {
  6. id: numberPad
  7. property int selectedNumber: choises.currentIndex+1
  8. animSpeed: 200
  9. viewWidth: choises.width*1.2
  10. viewHeight: (choises.height+choises.cellHeight)*1.2
  11. color: "black"
  12. GridView {
  13. id: choises
  14. anchors.horizontalCenter: parent.horizontalCenter
  15. y: parent.height/2 - (height+cellHeight)/2
  16. currentIndex: 4
  17. width: 3*cellWidth
  18. height: width
  19. cellWidth: 60
  20. cellHeight: cellWidth
  21. model: 9
  22. boundsBehavior: Flickable.StopAtBounds
  23. focus: true
  24. z: -1
  25. delegate: Rectangle {
  26. color: index == choises.currentIndex ? "gray" : "black"
  27. radius: 5
  28. width: choises.cellWidth
  29. height: width
  30. border {
  31. color: "white"
  32. width: 1
  33. }
  34. Text {
  35. anchors.centerIn: parent
  36. font {
  37. pixelSize: 40
  38. family: "series 60 zdigi"
  39. }
  40. text: index+1
  41. color: "white"
  42. }
  43. }
  44. Keys.onPressed: {
  45. if (event.key == Qt.Key_Select || event.key == Qt.Key_Return ||
  46. event.key == Qt.Key_Enter) {
  47. parent.clicked(0);
  48. event.accepted = true;
  49. }
  50. }
  51. }
  52. Rectangle {
  53. color: choises.currentIndex == -1 ? "gray" : "black"
  54. radius: 5
  55. width: choises.cellWidth
  56. height: width
  57. anchors {
  58. top: choises.bottom
  59. horizontalCenter: parent.horizontalCenter
  60. }
  61. border {
  62. color: "white"
  63. width: 1
  64. }
  65. Text {
  66. anchors.centerIn: parent
  67. font {
  68. pixelSize: 40
  69. family: "series 60 zdigi"
  70. }
  71. text: "C"
  72. color: "white"
  73. }
  74. }
  75. onPressed: positionChanged(mouse);
  76. onPositionChanged: {
  77. if (choises.x < mouseX && choises.y < mouseY && mouseX < choises.x+choises.width && mouseY < choises.y+choises.height)
  78. choises.currentIndex = choises.indexAt(mouseX-choises.x, mouseY-choises.y);
  79. else if(choises.y+choises.height < mouseY && mouseY < choises.y+choises.height+choises.cellHeight &&
  80. choises.x+choises.cellWidth < mouseX && mouseX < choises.x+choises.cellWidth*2)
  81. choises.currentIndex = -1;
  82. else
  83. choises.currentIndex = -2;
  84. }
  85. onClicked: {
  86. if (choises.currentIndex == -2)
  87. viewLoader.close();
  88. else {
  89. mainBoard.focus = true;
  90. viewLoader.close();
  91. setSelectedNumber();
  92. }
  93. }
  94. Keys.onPressed: {
  95. if (event.key == Qt.Key_Down) {
  96. choises.currentIndex = -1;
  97. event.accepted = true;
  98. }
  99. if (event.key == Qt.Key_Up && choises.currentIndex == -1) {
  100. choises.currentIndex = 7;
  101. event.accepted = true;
  102. }
  103. if (choises.currentIndex == -1 &&(event.key == Qt.Key_Select ||
  104. event.key == Qt.Key_Return ||
  105. event.key == Qt.Key_Enter)) {
  106. clicked(0);
  107. event.accepted = true;
  108. }
  109. if (Qt.Key_0 <= event.key && event.key <= Qt.Key_9) {
  110. choises.currentIndex = event.key - Qt.Key_0 - 1;
  111. clicked(0);
  112. event.accepted = true;
  113. }
  114. }
  115. }