SelectorSubViewPage.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import Qt.labs.components 1.1
  7. Page {
  8. id: mainPage
  9. property bool checkableMode: false
  10. property string selectedValue
  11. property string initialValue
  12. tools: checkableMode ? checkableModeToolBar : selectableModeToolBar
  13. state: "NORMAL"
  14. function getItemValue(index) {
  15. return model.get(index);
  16. }
  17. ToolBarLayout {
  18. id: checkableModeToolBar
  19. ToolButton {
  20. platformInverted: window.platformInverted
  21. text: "Done"
  22. onClicked: {
  23. selectionItem.subTitle = selectedValue;
  24. pageStack.pop();
  25. }
  26. }
  27. ToolButton {
  28. platformInverted: window.platformInverted
  29. text: "Cancel"
  30. onClicked: {
  31. pageStack.pop();
  32. listModel.setCheckedExclusively(initialValue);
  33. selectedValue = initialValue;
  34. }
  35. }
  36. }
  37. ToolBarLayout {
  38. id: selectableModeToolBar
  39. ToolButton {
  40. platformInverted: window.platformInverted
  41. text: "Cancel"
  42. onClicked: pageStack.pop();
  43. }
  44. }
  45. ListModel {
  46. id: listModel
  47. function setCheckedExclusively(value) {
  48. for (var i = 0; i< count ;i++) {
  49. if (get(i).value == value)
  50. setProperty(i, "itemChecked", true);
  51. else
  52. setProperty(i, "itemChecked", false);
  53. }
  54. }
  55. ListElement { value: "Value is one"; itemChecked: true}
  56. ListElement { value: "Value is two"; itemChecked: false}
  57. ListElement { value: "Value is three"; itemChecked: false}
  58. ListElement { value: "Value is four"; itemChecked: false}
  59. ListElement { value: "Value is five"; itemChecked: false}
  60. ListElement { value: "Value is six"; itemChecked: false}
  61. ListElement { value: "Value is seven"; itemChecked: false}
  62. ListElement { value: "Value is eight"; itemChecked: false}
  63. ListElement { value: "Value is nine"; itemChecked: false}
  64. ListElement { value: "Value is ten"; itemChecked: false}
  65. }
  66. CheckableGroup{
  67. id: checkableGroup
  68. }
  69. Component {
  70. id: delegate
  71. ListItem {
  72. id: listItem
  73. platformInverted: window.platformInverted
  74. ListItemText {
  75. id: itemText
  76. anchors.verticalCenter: parent.verticalCenter
  77. anchors.left: parent.left
  78. anchors.leftMargin: platformStyle.paddingLarge
  79. platformInverted: window.platformInverted
  80. role: "Title"
  81. text: value
  82. }
  83. RadioButton{
  84. anchors.verticalCenter: parent.verticalCenter
  85. anchors.right: parent.right
  86. anchors.rightMargin: platformStyle.paddingLarge
  87. checked: itemChecked
  88. platformExclusiveGroup: checkableGroup
  89. visible: checkableMode
  90. onCheckedChanged: {
  91. listModel.setProperty(index, "itemChecked", checked);
  92. if (checked)
  93. selectedValue = value;
  94. }
  95. onVisibleChanged: {
  96. checked = itemChecked;
  97. }
  98. }
  99. onClicked: {
  100. if (!checkableMode) {
  101. selectionItem.subTitle = value;
  102. pageStack.pop();
  103. }
  104. }
  105. }
  106. }
  107. ListView {
  108. id: listView
  109. anchors.fill: parent
  110. model: listModel
  111. delegate: delegate
  112. }
  113. onStatusChanged: {
  114. if (status === PageStatus.Activating) {
  115. initialValue = selectedValue;
  116. }
  117. }
  118. }