Advertisement
artemmarchenko

Untitled

Aug 7th, 2011
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 1.0
  2.  
  3. Item {
  4.     width: 600
  5.     height: 600
  6.     property int itemWidth: 50
  7.  
  8.  
  9.     ListView {
  10.         id: view
  11.         model: new Array(1,2,3,4,5,6,7,8)
  12.         delegate: item
  13.         anchors {
  14.             top: parent.top;
  15.             topMargin: 10;
  16.             horizontalCenter:
  17.             parent.horizontalCenter;
  18.             bottom:
  19.             parent.bottom;
  20.         }
  21.         width: model.length * itemWidth + (model.length - 1) * spacing
  22.         spacing: 2
  23.         orientation: Qt.Horizontal
  24.         snapMode: ListView.SnapOneItem
  25.         highlightRangeMode: ListView.ApplyRange
  26.         interactive: false
  27.         Component.onCompleted: currentIndex = -1;
  28.         onWidthChanged: {
  29.             console.log("view width changed to " + width)
  30.         }
  31.     }
  32.  
  33.  
  34.     Component {
  35.         id: item
  36.  
  37.         Rectangle {
  38.             width: itemWidth
  39.             height: 50
  40.             color: "red"
  41.             x: {
  42.                 if (ListView.isCurrentItem) {
  43.                     if (view.flickingHorizontally) {
  44.                         (view.width/2) - (width/2)
  45.                     } else {
  46.                         (view.width/2)-(width/2)
  47.                     }
  48.                 } else {
  49.                     if ( view.currentIndex==-1) {
  50.                         index * (width + view.spacing)
  51.                     } else {
  52.                         if ( index < view.currentIndex) {
  53.                             index * (width + view.spacing) + (width/2)
  54.                         } else {
  55.                             index * (width + view.spacing) - (width/2) - view.spacing
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.             y: ListView.isCurrentItem ? 200 : 0
  61.             Behavior on x { SpringAnimation { spring: 4; damping: 0.4 } }
  62.             Behavior on y { SpringAnimation { spring: 4; damping: 0.4 } }
  63.  
  64.             Text {
  65.                 id: t
  66.                 text: x
  67.             }
  68.             onXChanged: {
  69.                 t.text = x
  70.             }
  71.  
  72.             MouseArea {
  73.                 anchors.fill: parent
  74.                 onClicked: {
  75.                     if (!ListView.isCurrentItem)
  76.                         view.currentIndex = index;
  77.                     else
  78.                         view.currentIndex = -1;
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement