FileListView.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import QtQuick 1.1
  2. //import QtMobility.gallery 1.1
  3. import com.nokia.meego 1.0
  4. import Qt.labs.folderlistmodel 1.0
  5. /* idea from ereader. */
  6. Page {
  7. id: pageFileListView
  8. tools: ToolBarLayout {
  9. opacity: userTheme.opacityToolbar
  10. ToolIcon {
  11. //iconId: "toolbar-back"
  12. iconSource: "images/toolbar/back.png"
  13. onClicked: {
  14. pageStack.pop()
  15. }
  16. }
  17. ToolIcon {
  18. //iconId: "toolbar-up"
  19. iconSource: "images/toolbar/folder_back.png"
  20. onClicked: {
  21. if (stripFilePrefix(folderModel.folder) !== "/") {
  22. setCurrentFolder(stripFilePrefix(stripSuffix(folderModel.folder)))
  23. }
  24. }
  25. }
  26. }
  27. BackgroundPage { }
  28. function stripFilePrefix(path) {
  29. var filePath = new String(path)
  30. return filePath.replace("file://", "")
  31. }
  32. function stripSuffix(path) {
  33. var filePath = new String(path)
  34. return filePath.substring(0, filePath.lastIndexOf("/"))
  35. }
  36. function setCurrentFolder(folder) {
  37. folderModel.folder = folder
  38. }
  39. QNMTitle {
  40. id: titlePage
  41. text: stripFilePrefix(folderModel.folder)
  42. image: "images/folder_docs.png"
  43. sizFont: 22
  44. busy: false
  45. }
  46. Component {
  47. id: delegateFolder
  48. Rectangle {
  49. id:wrapper
  50. height: 70
  51. width: list.width
  52. color: "transparent"
  53. radius: 10
  54. Behavior on opacity { NumberAnimation{ duration: 400 } }
  55. Image {
  56. id: imgFolder
  57. anchors.verticalCenter: parent.verticalCenter
  58. anchors.left: parent.left
  59. anchors.leftMargin: 20
  60. source: folderModel.isFolder(index) ? "images/folder.png" : "images/doc.png"
  61. }
  62. Text {
  63. text: decodeURI(fileName)
  64. anchors.verticalCenter: parent.verticalCenter
  65. anchors.left: imgFolder.right
  66. anchors.leftMargin: 20
  67. font.pixelSize: 30
  68. color: folderModel.isFolder(index) ? "black" : "blue"
  69. }
  70. MouseArea {
  71. id: maFolder
  72. anchors.fill: parent
  73. onClicked: {
  74. if (folderModel.isFolder(index)) {
  75. setCurrentFolder(filePath)
  76. }
  77. else {
  78. setCurrentFolder(folderModel.folder)
  79. //console.log("Selected file: "+stripFilePrefix(decodeURI(filePath)) )
  80. pageImportWords.xmlfile = stripFilePrefix(decodeURI(filePath))
  81. //pageImportWords._txtTF.text = stripFilePrefix(decodeURI(filePath))
  82. pageStack.pop()
  83. }
  84. }
  85. onExited: {
  86. wrapper.color = "transparent"
  87. wrapper.opacity = 1
  88. }
  89. onPressedChanged: {
  90. if( pressed ) {
  91. wrapper.color = "black"
  92. wrapper.opacity = 0.5
  93. } else {
  94. wrapper.color = "transparent"
  95. wrapper.opacity = 1
  96. }
  97. }
  98. } //MouseArea
  99. }
  100. }
  101. ListView {
  102. id: list
  103. clip: true
  104. anchors.top: titlePage.bottom
  105. anchors.bottom: parent.bottom
  106. width: parent.width
  107. model: folderModel
  108. spacing: 2
  109. section.property: "path"
  110. delegate: delegateFolder
  111. }
  112. SectionScroller {
  113. listView: list
  114. }
  115. ScrollDecorator { flickableItem: list }
  116. FolderListModel {
  117. id: folderModel
  118. nameFilters: [ "*.xml", "*.XML" ]
  119. sortField: "Type"
  120. }
  121. onStatusChanged: {
  122. if (status == PageStatus.Active) {
  123. /*
  124. if (engine.pathExist(lastPath)) {
  125. setCurrentFolder(lastPath)
  126. }
  127. else {
  128. setCurrentFolder("/home/user/MyDocs")
  129. }*/
  130. }/* else if (status == PageStatus.Activating) {
  131. }*/
  132. }
  133. }