Advertisement
artemmarchenko

Untitled

Aug 7th, 2011
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 1.0
  2.  
  3. Rectangle {
  4.     id: wholeScreen
  5.     width: 400
  6.     height: 300
  7. //    color: "lightyellow"
  8.     property bool elementIsDown: false
  9.  
  10.     ListModel {
  11.         id: someModel
  12.         ListElement { }
  13.         ListElement { }
  14.         ListElement { }
  15.         ListElement { }
  16.         ListElement { }
  17.     }
  18.  
  19.     function calcXFromIndex(index) {
  20.         var effectiveIndex = index
  21.         if ((index > 2) && elementIsDown) {
  22.             effectiveIndex -= 1
  23.         }
  24.  
  25.         return effectiveIndex * 60
  26.  
  27.     }
  28.  
  29.     Rectangle {
  30.         id: row
  31.         anchors.top: parent.top
  32.         anchors.left: parent.left
  33.         anchors.right: anchors.right
  34.         height: 100
  35.         color: "white"
  36.         Repeater {
  37.             id: rep
  38.             model:  someModel
  39.             Rectangle {
  40.                 width: 40
  41.                 height: 40
  42.                 x: calcXFromIndex(index)
  43.                 Text {
  44.                     id: t
  45.                     anchors.fill: parent
  46.                     text: x.toString()
  47.                 }
  48.                 onXChanged: {
  49.                     //                    if (index == 3) {
  50.                     console.log("x changed to " + x)
  51.                     t.text = index + ": " + x
  52.                     //                    }
  53.                 }
  54.  
  55.                 color: "red"
  56.                 Behavior on x { SpringAnimation { spring: 4; damping: 0.4 } }
  57.                 Behavior on y { SpringAnimation { spring: 4; damping: 0.4 } }
  58.             }
  59.         }
  60.     }
  61.  
  62.     Rectangle {
  63.         id: rectMove
  64.         anchors.top: row.bottom
  65.         anchors.bottom: parent.bottom
  66.         anchors.left: parent.left
  67.         anchors.right: parent.horizontalCenter
  68.         anchors.topMargin: 60
  69.         color: "blue"
  70.  
  71.         MouseArea {
  72.             anchors.fill: parent
  73.             onClicked: {
  74.                 var targetElement = row.children[2]
  75.                 if (!elementIsDown) {
  76.                     targetElement.y += 50
  77.                 } else {
  78.                     targetElement.y -= 50
  79.                 }
  80.  
  81.                 elementIsDown = !elementIsDown
  82.             }
  83.         }
  84.     }
  85.  
  86.     Rectangle {
  87.         anchors.top: rectMove.top
  88.         anchors.bottom: rectMove.bottom
  89.         anchors.left: rectMove.right
  90.         anchors.right: parent.right
  91.         color: "red"
  92.  
  93.         MouseArea {
  94.             anchors.fill: parent
  95.             onClicked: {
  96.                 someModel.insert (3, {})
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement