Advertisement
Guest User

Untitled

a guest
Oct 18th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. import QtQuick 2.0
  2. import QtQuick.Controls 2.15
  3. import QtGraphicalEffects 1.0
  4.  
  5. Item {
  6. property int listHeight: 300
  7. property color comboBgColor: "#FFFFFF"
  8. property color itemBgColor: "#cccccc"
  9. property color itemTextColor: "#000000"
  10. property color downArrowColor: "#FF0000"
  11. property var model: ListModel {}
  12. property int count: model.rowCount()
  13. property int currentIndex: phoneList.currentIndex
  14. property string currentText: phoneSelector.model.get(currentIndex).name
  15. property bool opened: false
  16.  
  17. id: phoneSelector
  18.  
  19. Rectangle {
  20. id: phoneSelectorBG
  21. anchors.fill: parent
  22. radius: height / 2
  23. color: comboBgColor
  24. }
  25.  
  26. MouseArea {
  27. id: mouseArea
  28. hoverEnabled: true
  29. anchors.fill: phoneSelectorBG
  30. z: 1
  31.  
  32. onContainsMouseChanged: {
  33. if (containsMouse) {
  34. cursorShape = Qt.PointingHandCursor
  35. } else {
  36. cursorShape = Qt.ArrowCursor
  37. }
  38. }
  39.  
  40. onFocusChanged: {
  41. if (!focus) {
  42. opened = false
  43. }
  44. }
  45.  
  46. onClicked: {
  47. if (opened) {
  48. opened = false
  49. } else {
  50. opened = true
  51. forceActiveFocus()
  52. }
  53. }
  54.  
  55. enabled: phoneSelector.count > 0
  56. }
  57.  
  58. Label {
  59. id: currentItemText
  60. anchors.verticalCenter: parent.verticalCenter
  61. anchors.left: parent.left
  62. anchors.right: downArrow.left
  63. anchors.rightMargin: 15
  64. anchors.leftMargin: 15
  65. color: "black"
  66. text: count > 0 ? phoneSelector.currentText : "No Phones Connected..."
  67. elide: Text.ElideRight
  68. }
  69.  
  70. Image {
  71. id: downArrow
  72. height: 15
  73. width: height
  74. sourceSize: height
  75. anchors.verticalCenter: parent.verticalCenter
  76. anchors.right: parent.right
  77. anchors.rightMargin: 10
  78. source: "../Images/icons/down_arrow.svg"
  79. visible: false
  80. }
  81.  
  82. ColorOverlay {
  83. z: 1
  84. anchors.fill: downArrow
  85. source: downArrow
  86. color: downArrowColor
  87. antialiasing: true
  88. smooth: true
  89. rotation: opened ? -180 : 0
  90.  
  91. Behavior on rotation {
  92. PropertyAnimation {
  93. duration: 100
  94. easing {type: Easing.InExpo}
  95. }
  96. }
  97. }
  98.  
  99. ListView {
  100. id: phoneList
  101. width: parent.width
  102. anchors.top: parent.bottom
  103. anchors.topMargin: 15
  104. anchors.bottomMargin: 15
  105. anchors.horizontalCenter: parent.horizontalCenter
  106. height: listHeight
  107. spacing: 10
  108. visible: phoneSelector.opened
  109. clip: true
  110. currentIndex: 0
  111.  
  112. model: parent.model
  113.  
  114. delegate: ItemDelegate {
  115. id: phoneItemDelegate
  116. width: parent.width
  117.  
  118. background: Rectangle {
  119. color: "transparent"
  120. }
  121.  
  122. MouseArea {
  123. id: delegateMouseArea
  124. hoverEnabled: true
  125. anchors.fill: itemBG
  126.  
  127. onContainsMouseChanged: {
  128. if (containsMouse) {
  129. cursorShape = Qt.PointingHandCursor
  130. } else {
  131. cursorShape = Qt.ArrowCursor
  132. }
  133. }
  134.  
  135. onPressedChanged: {
  136. if (pressed) {
  137. highlight.visible = true
  138. highlight.width = itemBG.width
  139. } else {
  140. highlight.visible = false
  141. highlight.width = itemBG.width * .75
  142. phoneList.currentIndex = index
  143. phoneSelector.opened = false
  144. }
  145. }
  146. }
  147.  
  148. Text {
  149. id: itemText
  150. text: name
  151. anchors.left: parent.left
  152. anchors.leftMargin: 15
  153. anchors.verticalCenter: itemBG.verticalCenter
  154. anchors.right: parent.right
  155. anchors.rightMargin: 15
  156. z: 1
  157. color: itemTextColor
  158. }
  159.  
  160. Rectangle {
  161. id: itemBG
  162. width: phoneSelector.width
  163. height: itemText.height * 1.5
  164. radius: height / 2
  165. color: itemBgColor
  166. z: 0
  167. }
  168.  
  169. Rectangle {
  170. id: highlight
  171. radius: 360
  172. anchors.verticalCenter: itemBG.verticalCenter
  173. anchors.horizontalCenter: itemBG.horizontalCenter
  174. opacity: .5
  175. color: "white"
  176. visible: false
  177. height: itemBG.height
  178. width: itemBG.width * .75
  179. antialiasing: true
  180. z: 2
  181.  
  182. Behavior on width {
  183. PropertyAnimation {
  184. duration: animationDuration
  185. easing {
  186. type: Easing.OutExpo
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193.  
  194. QtObject {
  195. id: listModelHandler
  196.  
  197. function getItemName(index) {
  198. return phoneSelector.model.get(index).name
  199. }
  200. }
  201.  
  202.  
  203. }
  204.  
  205. /*##^##
  206. Designer {
  207. D{i:0;autoSize:true;height:480;width:640}
  208. }
  209. ##^##*/
  210.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement