KarmaListPage.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
  2. import QtQuick 1.1
  3. import "../js/core.js" as Core
  4. import "../delegates"
  5. import "../parts"
  6. KPage {
  7. property int karmaId
  8. property string personName
  9. property string currentTitle
  10. property string currentPoints
  11. property int filter: 0
  12. id: listpanel
  13. ListModel {
  14. id: itemModel
  15. }
  16. KButton{
  17. id: filterSelector
  18. anchors.top:titlebar.bottom
  19. width: parent.width
  20. text: selectionDialog.model.get(filter).modelData
  21. onClicked: {
  22. selectionDialog.visible=true
  23. }
  24. }
  25. Flickable{
  26. id: flicklist
  27. width: parent.width; height: parent.height-titlebar.height - filterSelector.height
  28. contentWidth: parent.width;
  29. //contentHeight: height+100
  30. anchors.top: filterSelector.bottom
  31. anchors.right: parent.right
  32. ListView {
  33. id: view
  34. model: itemModel
  35. anchors.fill: parent
  36. clip:true
  37. delegate: KarmaItemDelegate {
  38. title: model.title
  39. points: model.points
  40. onPressAndHold: {
  41. karmaId=model.id
  42. currentTitle=model.title
  43. currentPoints=model.points
  44. contexMenu.open();
  45. }
  46. onClicked:pageStack.push(Qt.resolvedUrl("KarmaFact.qml"), {karmaId: model.id, karmaName: personName, karmaTitle: model.title, karmaPoints: model.points, karmaDescription: model.description})
  47. }
  48. }
  49. }
  50. //Page layout is divided in 3
  51. TitleBar{
  52. id:titlebar
  53. KButton{
  54. id:titleButton
  55. text:"+"
  56. anchors.right:parent.right
  57. anchors.top:parent.top
  58. anchors.rightMargin: 10
  59. anchors.topMargin: 5
  60. onClicked: pageStack.push(Qt.resolvedUrl("AddKarmaForm.qml"))
  61. }
  62. }
  63. KToolBar {
  64. id: listTools
  65. KButton{
  66. text:qsTr("Back")
  67. onClicked: pageStack.pop()
  68. }
  69. }
  70. KContextMenu {
  71. id: contexMenu
  72. KMenuItem {
  73. text: "Delete item"
  74. onClicked:{ deleteItem(karmaId)}
  75. }
  76. KMenuItem {
  77. text: "Edit item"
  78. onClicked:{karmaCreateDialog.open() }
  79. }
  80. }
  81. KarmaFactFilterDialog{
  82. id: selectionDialog
  83. onAccepted: filter=selectionDialog.currentValue
  84. }
  85. onVisibleChanged: {
  86. if(visible == true) {
  87. updateUi();
  88. }
  89. }
  90. function updateUi() {
  91. view.model = 0;
  92. Core.readKarmaList(itemModel);
  93. view.model = itemModel;
  94. }
  95. function deleteItem(id){
  96. Core.deleteKarma(id);
  97. updateUi();
  98. }
  99. function update()
  100. {
  101. // read the TodoItem with the provided karmaId
  102. var item = Core.readKarmaItem(karmaId);
  103. // get values from UI fields
  104. item.title = karmaCreateDialog.title;
  105. item.points = karmaCreateDialog.points;
  106. item.description = karmaCreateDialog.description;
  107. // new Data() will return the current date
  108. item.modified = new Date();
  109. // update the todoItem in Database
  110. Core.updateKarma(item);
  111. }
  112. }