fancypicker.qml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. import Qt 4.7
  5. Rectangle {
  6. id: container
  7. function initialize() {}
  8. color: "black"
  9. anchors.fill: parent
  10. Flickable {
  11. id: flickable
  12. anchors.fill: parent
  13. clip: true
  14. contentWidth: imageContainer.width; contentHeight: imageContainer.height
  15. Item {
  16. id: imageContainer
  17. width: Math.max(bigImage.width * bigImage.scale, flickable.width)
  18. height: Math.max(bigImage.height * bigImage.scale, flickable.height)
  19. Image {
  20. id: bigImage;
  21. scale: slider.value
  22. anchors.centerIn: parent
  23. smooth: !flickable.moving
  24. asynchronous: true
  25. onStatusChanged: { slider.minimum = Math.min(flickable.width / width, flickable.height / height) }
  26. }
  27. }
  28. }
  29. Text {
  30. id: imageName
  31. anchors { bottomMargin: 10; bottom: picker.top; horizontalCenter: container.horizontalCenter }
  32. color: "black"
  33. opacity: 0.8
  34. text: bigImage.source
  35. font.bold: true
  36. style: Text.Outline; styleColor: "white"
  37. }
  38. Slider {
  39. id: slider
  40. anchors.right: parent.right; anchors.rightMargin: 18
  41. anchors.top: parent.top; anchors.topMargin: 20
  42. anchors.bottom: hider.top; anchors.bottomMargin: 40
  43. Behavior on opacity { NumberAnimation { } }
  44. opacity: 0.8
  45. value: 1.2 // zoom a little when FancyPicker is opened to better demonstrate flicking
  46. }
  47. Rectangle {
  48. id: picker
  49. width: container.width; height: 100
  50. anchors.bottom: container.bottom
  51. gradient: Gradient {
  52. GradientStop { position: 0.0; color: "#CC343434" }
  53. GradientStop { position: 1.0; color: "#66000000" }
  54. }
  55. ListModel {
  56. id: imageModel
  57. ListElement { name: "qtqp_back1.jpg" }
  58. ListElement { name: "qtqp_back2.jpg" }
  59. ListElement { name: "qtqp_back3.jpg" }
  60. }
  61. Component {
  62. id: imageDelegate
  63. Item {
  64. id: wrapper
  65. width: 80; height: 80
  66. Rectangle {
  67. id: pickerItem
  68. x: 10; y: 10
  69. width: 80; height: 80
  70. focus: true
  71. opacity: 0.5
  72. radius: 3
  73. border.width: 2; border.color: "#AA444444"
  74. color: "white"
  75. Image {
  76. id: image
  77. x: 1; y: 1
  78. width: pickerItem.width - 2; height: pickerItem.height - 2
  79. source: name
  80. asynchronous: true
  81. }
  82. MouseArea {
  83. anchors.fill: parent
  84. onClicked: { view.currentIndex = index }
  85. }
  86. states: [
  87. State {
  88. name: "selected"
  89. when: wrapper.ListView.isCurrentItem
  90. PropertyChanges { target: image; opacity: 1 }
  91. PropertyChanges { target: pickerItem; opacity: 1; border.color: "black" }
  92. StateChangeScript { script: bigImage.source = image.source }
  93. }
  94. ]
  95. transitions: Transition {
  96. from: "*"
  97. to: "selected"
  98. reversible: true
  99. NumberAnimation { duration: 500; easing.type: "OutCirc"; properties: "opacity,rotation" }
  100. }
  101. }
  102. }
  103. }
  104. ListView {
  105. id: view
  106. anchors.fill: parent; anchors.rightMargin: 200
  107. model: imageModel
  108. delegate: imageDelegate
  109. spacing: 10
  110. orientation: "Horizontal"
  111. }
  112. states: State {
  113. name: "hidden"
  114. when: hider.hidden
  115. PropertyChanges { target: picker; opacity: 0.1; height: 0 }
  116. PropertyChanges { target: imageName; opacity: 0 }
  117. }
  118. transitions: Transition {
  119. from: "*"; to: "hidden"; reversible: true
  120. NumberAnimation { easing.type: "InOutQuad"; properties: "opacity, height"; duration: 1000 }
  121. }
  122. }
  123. Rectangle {
  124. id: hider
  125. property bool hidden: false
  126. width: 60; height: 60
  127. anchors { right: parent.right; bottom: parent.bottom; rightMargin: 4; bottomMargin: 13 }
  128. radius: 5
  129. border.color: "#AA444444"; border.width: 1
  130. Behavior on opacity { NumberAnimation { } }
  131. gradient: Gradient {
  132. GradientStop { position: 0.0; color: "#AA999999" }
  133. GradientStop { position: 1.0; color: "#AA333333" }
  134. }
  135. Text {
  136. id: hiderText
  137. anchors.centerIn: parent
  138. text: "Hide"
  139. }
  140. MouseArea {
  141. anchors.fill: parent
  142. onClicked: { hider.hidden = !hider.hidden }
  143. }
  144. states: State {
  145. name: "hidden"
  146. when: hider.hidden
  147. PropertyChanges { target: hiderText; text: "Show" }
  148. PropertyChanges { target: hider; opacity: 0.4 }
  149. PropertyChanges { target: slider; opacity: 0.4 }
  150. }
  151. }
  152. }