FlickableViews.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import QtQuick 1.0
  2. SongItem {
  3. id: mainRect
  4. width: mainWindow.qmlWidth
  5. height: mainWindow.qmlHeight
  6. /* I'm not sure if this FocusScope below is helping. I wanted to make it so
  7. either the Combobox or the FlickableView had focus, and
  8. when the comboBox loses focus, flickableView returns focus to the
  9. thing that had it before.
  10. */
  11. FocusScope {
  12. id: mainScope
  13. width: parent.width; height: parent.height
  14. focus: true
  15. /* FocusScope {
  16. id: menuScope
  17. width: parent.width; height: parent.height */
  18. // Drop-down combobobox-style menu
  19. Rectangle {
  20. color: "transparent"
  21. id: comboBox
  22. objectName: "comboBox"
  23. width: parent.width;
  24. height: toolBar.height + dropDown.height
  25. // Toolbar:
  26. SongItem {
  27. id: toolBar
  28. x:2; y:2; width: parent.width - 4;
  29. radius: 5
  30. border.color: "grey"
  31. // Drop-down menu button:
  32. height: 42
  33. Row {
  34. spacing: 30
  35. Image {
  36. id: menuButton
  37. source: "qrc:/icons/bottom.png"
  38. height: 40
  39. width: 40
  40. }
  41. StyledText {
  42. font.pointSize: 12
  43. id: topText
  44. text: mainWindow.m3uTitle
  45. }
  46. }
  47. MouseArea {
  48. anchors.fill: parent
  49. onClicked: {
  50. comboBox.state = comboBox.state == '' ? "Menu" : '';
  51. }
  52. }
  53. }
  54. // Other buttons
  55. Row {
  56. spacing: 15
  57. height: toolBar.height
  58. anchors.right: parent.right
  59. Image {
  60. id: toggleQueueButton
  61. height: 40
  62. width: 40
  63. source: "qrc:/icons/playlist.png"
  64. MouseArea {
  65. anchors.fill: parent
  66. onClicked: mainWindow.toggleQueue();
  67. }
  68. }
  69. Image {
  70. id: shuffleButton
  71. height: 40
  72. width: 40
  73. source: "qrc:/icons/shuffle.png"
  74. visible: false
  75. MouseArea {
  76. anchors.fill: parent
  77. onClicked: playListModel.shuffle();
  78. }
  79. }
  80. Image {
  81. id: sortButton
  82. y: 1
  83. height: 40
  84. width: 40
  85. source: "qrc:/icons/sort.png"
  86. visible: false
  87. MouseArea {
  88. anchors.fill: parent
  89. onClicked: mainWindow.on_actionSort_Playlist_triggered();
  90. }
  91. }
  92. Image {
  93. y: 1
  94. id: reloadButton
  95. height: 40
  96. width: 40
  97. source: "qrc:/icons/reload.png"
  98. MouseArea {
  99. anchors.fill: parent
  100. onClicked: mainWindow.on_reloadButton_clicked();
  101. }
  102. }
  103. Image {
  104. y: 1
  105. id: addFeedButton
  106. height: 40
  107. width: 40
  108. source: "qrc:/icons/rss.png"
  109. MouseArea {
  110. anchors.fill: parent
  111. onClicked: mainWindow.on_actionAddFeed_triggered();
  112. }
  113. }
  114. }
  115. // The actual drop-down menu contents:
  116. MainMenu {
  117. id: dropDown
  118. y: 5
  119. anchors.top: toolBar.bottom
  120. z: 1
  121. width: parent.width
  122. }
  123. // states for showing and hiding the main menu.
  124. states: [
  125. State {
  126. name: ''
  127. PropertyChanges { target: dropDown; height: 0}
  128. PropertyChanges { target: menuButton; source: "qrc:/icons/bottom.png" }
  129. PropertyChanges { target: dropDown; focus: false}
  130. // PropertyChanges { target: mainScope; focus: true }
  131. PropertyChanges { target: flickableView; focus: true }
  132. },
  133. State {
  134. name: 'Menu'
  135. // when: !mainScope.activeFocus
  136. PropertyChanges { target: dropDown; height: 150 }
  137. PropertyChanges { target: dropDown; focus: true; }
  138. PropertyChanges { target: menuButton; source: "qrc:/icons/top.png" }
  139. // PropertyChanges { target: mainMenu; focus: true}
  140. }
  141. ]
  142. transitions: [
  143. Transition {
  144. NumberAnimation {
  145. target: dropDown;
  146. property: "height";
  147. duration: 600
  148. easing.type: Easing.OutQuint
  149. }
  150. }
  151. ]
  152. }
  153. // }
  154. // 3 ListViews in a Flickable area
  155. Flickable {
  156. id: flickableView
  157. objectName : "flickableView";
  158. anchors.top: comboBox.bottom;
  159. width: parent.width;
  160. contentWidth: parent.width * 3;
  161. anchors.bottom: parent.bottom;
  162. interactive: true
  163. maximumFlickVelocity: 300
  164. function snapToGrid(r) {
  165. flickableView.state = ''
  166. // console.log("snaptogrid r: " + r);
  167. if (r < 0.18) {
  168. if (playListModel.rowCount() == 0) {
  169. if (!mainWindow.isQueueEmpty) {
  170. mainWindow.toggleQueue();
  171. }
  172. else flickableView.state = 'Parentlist';
  173. }
  174. else {
  175. flickableView.state = 'Playlist';
  176. }
  177. }
  178. else if (r > 0.5) {
  179. if (itemsListModel.rowCount() == 0) {
  180. flickableView.state = 'Parentlist';
  181. }
  182. else {
  183. flickableView.state = 'Episodes';
  184. }
  185. }
  186. else {flickableView.state = 'Parentlist'; }
  187. // console.log (" state: " + flickableView.state);
  188. }
  189. onMovementEnded: {
  190. snapToGrid(visibleArea.xPosition);
  191. }
  192. Row {
  193. height: mainRect.height - comboBox.height
  194. /* FocusScope {
  195. id: viewScope
  196. width: parent.width;
  197. height: parent.height;
  198. focus: true */
  199. PlayListView {
  200. id: qmlListView
  201. width: mainRect.width
  202. }
  203. ParentListView {
  204. id: parentList
  205. width: mainRect.width
  206. }
  207. SubscriptionView {
  208. id: subscriptionView
  209. width: mainRect.width
  210. }
  211. // }
  212. }
  213. state: 'Parentlist'
  214. states: [
  215. State {
  216. name: 'Playlist'
  217. PropertyChanges { target: flickableView; contentX: qmlListView.x }
  218. PropertyChanges { target: qmlListView; focus: true }
  219. PropertyChanges { target: reloadButton; visible: true }
  220. PropertyChanges { target: shuffleButton; visible: true }
  221. PropertyChanges { target: toggleQueueButton; visible: mainWindow.isQueueEmpty || mainWindow.isPlayListEmpty ? false : true }
  222. PropertyChanges { target: sortButton; visible: true }
  223. PropertyChanges { target: addFeedButton; visible: false}
  224. },
  225. State {
  226. name: 'Parentlist'
  227. PropertyChanges { target: toggleQueueButton; visible: false }
  228. PropertyChanges { target: flickableView; contentX: parentList.x }
  229. PropertyChanges { target: parentList; focus: true }
  230. PropertyChanges { target: reloadButton;
  231. visible: mainWindow.showOption == "Subscriptions" ? true:false }
  232. PropertyChanges { target: addFeedButton;
  233. visible: mainWindow.showOption == "Subscriptions" ? true:false }
  234. PropertyChanges { target: sortButton; visible: false}
  235. },
  236. State {
  237. name: 'Episodes'
  238. PropertyChanges { target: toggleQueueButton; visible: false }
  239. PropertyChanges { target: flickableView; contentX: subscriptionView.x }
  240. PropertyChanges { target: subscriptionView; focus: true }
  241. PropertyChanges { target: reloadButton; visible: true }
  242. PropertyChanges { target: sortButton; visible: false }
  243. }
  244. ]
  245. transitions: [
  246. Transition {
  247. NumberAnimation {
  248. target: flickableView;
  249. property: "contentX";
  250. duration: 400
  251. easing.type: Easing.OutQuint
  252. }
  253. }
  254. ]
  255. }
  256. }
  257. }