MainPage.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.symbian 1.1
  6. import com.nokia.extras 1.1
  7. import "../Constants.js" as Constants
  8. Page {
  9. id: mainPage
  10. property int checkedItemsCount: 0
  11. tools: sharedToolBar
  12. state: "NORMAL"
  13. ToolBar {
  14. id: sharedToolBar
  15. tools: mainToolBarLayout
  16. platformInverted: window.platformInverted
  17. }
  18. ToolBarLayout {
  19. id: mainToolBarLayout
  20. ToolButton {
  21. flat: true
  22. iconSource: "toolbar-back"
  23. platformInverted: window.platformInverted
  24. onClicked: window.pageStack.depth <= 1 ? window.pageStack.pop() : window.pageStack.pop()
  25. }
  26. ToolButton {
  27. flat: true
  28. iconSource: "toolbar-delete"
  29. platformInverted: window.platformInverted
  30. onClicked: {
  31. mainPage.state = "DELETE";
  32. }
  33. }
  34. ToolButton {
  35. flat: true
  36. iconSource: platformInverted ? "../Images/Icons/information_userguide_w.svg" : "../Images/Icons/information_userguide.svg"
  37. platformInverted: window.platformInverted
  38. onClicked: window.pageStack.push(Qt.resolvedUrl("../InfoPage.qml"), {text: Constants.DELETEMULTIPLE_INFOTEXT});
  39. }
  40. }
  41. ToolBarLayout {
  42. id: deleteModeToolBarLayout
  43. ToolButton {
  44. id: deleteButton;
  45. platformInverted: window.platformInverted
  46. text: "Delete"
  47. enabled: checkedItemsCount > 0
  48. onClicked:{
  49. queryDialog.open();
  50. }
  51. }
  52. ToolButton {
  53. id: cancelButton;
  54. platformInverted: window.platformInverted
  55. text: "Cancel"
  56. onClicked: mainPage.state = "NORMAL";
  57. }
  58. }
  59. DataModel{
  60. id: listModel
  61. }
  62. DeleteQueryDialog{
  63. id: queryDialog
  64. }
  65. InfoBanner{
  66. id: banner
  67. platformInverted: window.platformInverted
  68. timeout: 5000
  69. }
  70. Component {
  71. id: delegate
  72. ListItem {
  73. id: listItem
  74. platformInverted: window.platformInverted
  75. Column{
  76. anchors.fill: parent.paddingItem
  77. ListItemText {
  78. role: "Title"
  79. platformInverted: window.platformInverted
  80. text: name
  81. width: parent.width
  82. }
  83. ListItemText {
  84. role: "SubTitle"
  85. platformInverted: window.platformInverted
  86. text: "2nd line"
  87. width: parent.width
  88. }
  89. }
  90. CheckBox {
  91. id: checkBox
  92. anchors.verticalCenter: parent.verticalCenter
  93. anchors.right: parent.paddingItem.right
  94. platformInverted: window.platformInverted
  95. checked: isChecked
  96. visible: mainPage.state == "DELETE"
  97. onCheckedChanged: {
  98. if (checked)
  99. checkedItemsCount++;
  100. else
  101. checkedItemsCount--;
  102. listModel.setProperty(index, "isChecked", checked);
  103. }
  104. onVisibleChanged: {
  105. checked = isChecked;
  106. }
  107. }
  108. onClicked: {
  109. if (mainPage.state == "DELETE")
  110. checkBox.checked = !checkBox.checked
  111. }
  112. }
  113. }
  114. ListView {
  115. id: listView
  116. anchors.fill: parent
  117. model: listModel
  118. delegate: delegate
  119. }
  120. states: [
  121. State {
  122. name: "NORMAL"
  123. },
  124. State {
  125. name: "DELETE"
  126. }
  127. ]
  128. onStateChanged: {
  129. console.log("State changed to: " + state);
  130. if (state == "NORMAL") {
  131. sharedToolBar.setTools(mainToolBarLayout);
  132. listModel.uncheckAllItems();
  133. }
  134. else
  135. sharedToolBar.setTools(deleteModeToolBarLayout);
  136. }
  137. }