DialogFiles.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import QtQuick 1.1
  2. import Qt.labs.folderlistmodel 1.0
  3. DialogLiquid {
  4. id: dlgFiles
  5. signal fileSelected( string file )
  6. signal fileCanceled()
  7. property string selectedFile: ""
  8. property string presetPath: ""
  9. Rectangle {
  10. id: background
  11. anchors.fill: parent
  12. color: "white"
  13. }
  14. height: 0.7*parent.height
  15. function stripFilePrefix(path) {
  16. var filePath = path.toString();
  17. return filePath.replace("file://", "")
  18. }
  19. function stripSuffix(path) {
  20. var filePath = path.toString()
  21. return filePath.substring(0, filePath.lastIndexOf("/"))
  22. }
  23. function setCurrentFolder(folder) {
  24. folderModel.folder = folder
  25. }
  26. Component.onCompleted: {
  27. if( presetPath != "" ) {
  28. setCurrentFolder( "file://" + presetPath )
  29. }
  30. }
  31. Component {
  32. id: delegateFolder
  33. Rectangle {
  34. id:wrapper
  35. height: 70
  36. width: list.width
  37. color: "transparent"
  38. radius: 10
  39. ListView.onAdd: SequentialAnimation {
  40. PauseAnimation { duration: 1+index>0 ? 40*index : 0 }
  41. NumberAnimation {
  42. target: wrapper
  43. property: "height"
  44. from: 0; to: 70
  45. duration: 250
  46. easing.type: Easing.InOutQuad
  47. }
  48. }
  49. Behavior on opacity { NumberAnimation{ duration: 300 } }
  50. Image {
  51. id: imgFolder
  52. anchors.verticalCenter: parent.verticalCenter
  53. anchors.left: parent.left
  54. anchors.leftMargin: 20
  55. source: folderModel.isFolder(index) ? "qrc:/qml/images/mime_folder.png" : "qrc:/qml/images/mime_wav.png"
  56. }
  57. Text {
  58. text: decodeURI(fileName)
  59. anchors.verticalCenter: parent.verticalCenter
  60. anchors.left: imgFolder.right
  61. anchors.leftMargin: 20
  62. font.pixelSize: 28
  63. color: folderModel.isFolder(index) ? "black" : "blue"
  64. }
  65. MouseArea {
  66. id: maFolder
  67. anchors.fill: parent
  68. onClicked: {
  69. if (folderModel.isFolder(index))
  70. {
  71. setCurrentFolder(filePath)
  72. }
  73. else
  74. {
  75. setCurrentFolder(folderModel.folder)
  76. var file = stripFilePrefix(decodeURI(filePath))
  77. console.log("Selected file: "+ file )
  78. selectedFile = file
  79. fileSelected( file )
  80. dlgShowHide()
  81. //pageImportWords.xmlfile = stripFilePrefix(decodeURI(filePath))
  82. }
  83. }
  84. onExited: {
  85. wrapper.color = "transparent"
  86. wrapper.opacity = 1
  87. }
  88. onPressedChanged: {
  89. if( pressed ) {
  90. wrapper.color = "black"
  91. wrapper.opacity = 0.5
  92. } else {
  93. wrapper.color = "transparent"
  94. wrapper.opacity = 1
  95. }
  96. }
  97. } //MouseArea
  98. }
  99. }
  100. Rectangle {
  101. id: header
  102. height: 30
  103. width: parent.width
  104. anchors.left: parent.left
  105. anchors.top: parent.top
  106. clip: true
  107. gradient: Gradient {
  108. GradientStop{ color: "lightgray"; position: 0 }
  109. GradientStop{ color: "gray"; position: 1 }
  110. }
  111. Image {
  112. id: imdFolder
  113. height: 26; width: height
  114. smooth: true
  115. source: "qrc:/qml/images/mime_folder.png"
  116. anchors.verticalCenter: parent.verticalCenter
  117. anchors.left: parent.left
  118. anchors.leftMargin: 10
  119. }
  120. Text {
  121. anchors.verticalCenter: parent.verticalCenter
  122. text: stripFilePrefix(folderModel.folder)
  123. font.pixelSize: 14
  124. anchors.left: imdFolder.right
  125. anchors.leftMargin: 10
  126. }
  127. }
  128. ListView {
  129. id: list
  130. clip: true
  131. anchors.top: header.bottom
  132. anchors.bottom: bottomPanel.top
  133. anchors.left: parent.left
  134. anchors.leftMargin: 5
  135. anchors.right: parent.right
  136. anchors.rightMargin: 5
  137. model: folderModel
  138. spacing: 2
  139. section.property: "path"
  140. delegate: delegateFolder
  141. }
  142. FolderListModel {
  143. id: folderModel
  144. nameFilters: [ "*.wav", "*.WAV"/*, "*.ogg", "*OGG"*/ ]
  145. sortField: "Type"
  146. }
  147. ToolBar {
  148. id: bottomPanel
  149. ToolButton {
  150. id: backFolder
  151. anchors.left: parent.left
  152. anchors.leftMargin: 10
  153. icon: "qrc:/qml/images/bar_back.png"
  154. onClicked: {
  155. //console.log( "***|"+stripFilePrefix(folderModel.folder) )
  156. if (stripFilePrefix(folderModel.folder) !== "/") {
  157. //setCurrentFolder(stripFilePrefix(stripSuffix(folderModel.folder)))
  158. setCurrentFolder( stripSuffix(folderModel.folder) )
  159. }
  160. }
  161. }
  162. ToolButton {
  163. id: cancelDialog
  164. anchors.right: parent.right
  165. anchors.rightMargin : 10
  166. icon: "qrc:/qml/images/bar_close.png"
  167. onClicked: {
  168. fileCanceled()
  169. dlgShowHide()
  170. }
  171. }
  172. }
  173. }