VideoPlayerControls.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.meego 1.0
  6. import "util.js" as Util
  7. Item {
  8. id: videoPlayerControls
  9. property bool isPlaying: true
  10. property int timePlayed: 0
  11. property int timeDuration: 0
  12. property bool showBackground: true
  13. property bool showBackButton: true
  14. // Property used to indicate scrubbed position. Calculated directly to
  15. // milliseconds (from the given timeDuration property).
  16. property int playbackPosition: 0
  17. property bool enableScrubbing: false
  18. signal backButtonPressed
  19. signal playPressed
  20. signal pausePressed
  21. Item {
  22. anchors.fill: parent
  23. // Use the same background image as the ToolBar.
  24. BorderImage {
  25. // Styling for the ToolBar
  26. property Style tbStyle: ToolBarStyle {}
  27. id: background
  28. anchors.fill: parent
  29. opacity: visual.controlOpacity
  30. source: videoPlayerControls.showBackground
  31. ? tbStyle.background
  32. : ""
  33. border { left: 10; top: 10; right: 10; bottom: 10 }
  34. }
  35. Loader {
  36. id: backButtonLoader
  37. width: childrenRect.width
  38. anchors {
  39. verticalCenter: parent.verticalCenter
  40. left: parent.left
  41. leftMargin: videoPlayerControls.showBackButton
  42. ? visual.controlMargins / 2 : 0
  43. }
  44. sourceComponent: videoPlayerControls.showBackButton
  45. ? backButtonComponent
  46. : undefined
  47. }
  48. Component {
  49. id: backButtonComponent
  50. Item {
  51. width: backButton.width + separatorLine.width
  52. height: videoPlayerControls.height
  53. ToolIcon {
  54. id: backButton
  55. platformIconId: "toolbar-back"
  56. width: visual.controlWidth
  57. height: visual.controlHeight
  58. anchors.verticalCenter: parent.verticalCenter
  59. onClicked: videoPlayerControls.backButtonPressed()
  60. }
  61. Rectangle {
  62. id: separatorLine
  63. y: 1
  64. width: visual.separatorWidth
  65. height: videoPlayerControls.height
  66. color: visual.separatorColor
  67. anchors {
  68. left: backButton.right
  69. leftMargin: visual.controlMargins / 2
  70. }
  71. }
  72. }
  73. }
  74. Button {
  75. id: playButton
  76. iconSource: videoPlayerControls.isPlaying
  77. ? "image://theme/icon-m-toolbar-mediacontrol-pause-white"
  78. : "image://theme/icon-m-toolbar-mediacontrol-play-white"
  79. opacity: visual.controlOpacity
  80. width: visual.controlWidth
  81. height: visual.controlHeight
  82. anchors {
  83. verticalCenter: backButtonLoader.verticalCenter
  84. left: backButtonLoader.right
  85. leftMargin: visual.controlMargins * 2
  86. }
  87. onClicked: {
  88. if (videoPlayerControls.isPlaying) {
  89. videoPlayerControls.pausePressed()
  90. } else {
  91. videoPlayerControls.playPressed()
  92. }
  93. }
  94. }
  95. VideoInfoTextLabel {
  96. id: timeElapsedLabel
  97. text: Util.milliSecondsToString(timePlayed)
  98. anchors {
  99. bottom: playButton.verticalCenter
  100. left: playButton.right
  101. right: parent.right
  102. leftMargin: visual.controlMargins
  103. rightMargin: visual.controlMargins
  104. }
  105. }
  106. VideoInfoTextLabel {
  107. id: timeDurationLabel
  108. text: Util.milliSecondsToString(timeDuration)
  109. anchors {
  110. bottom: playButton.verticalCenter
  111. right: parent.right
  112. rightMargin: visual.controlMargins
  113. }
  114. }
  115. ProgressBar {
  116. id: progressBar
  117. anchors {
  118. top: playButton.verticalCenter
  119. left: playButton.right
  120. right: timeDurationLabel.right
  121. leftMargin: visual.controlMargins
  122. }
  123. value: videoPlayerControls.timePlayed /
  124. videoPlayerControls.timeDuration
  125. }
  126. MouseArea {
  127. id: progressMA
  128. enabled: videoPlayerControls.enableScrubbing
  129. width: progressBar.width
  130. height: parent.height
  131. anchors.bottom: parent.bottom
  132. anchors.left: progressBar.left
  133. onPositionChanged: {
  134. var selectedPosition = mouseX < 0 ?
  135. 0 : mouseX/progressMA.width * videoPlayerControls.timeDuration;
  136. videoPlayerControls.playbackPosition = selectedPosition;
  137. }
  138. onPressed: {
  139. videoPlayerControls.playbackPosition =
  140. mouseX/progressMA.width * videoPlayerControls.timeDuration;
  141. }
  142. }
  143. }
  144. }