Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 2.59 KB | None | 0 0
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.0
  3. MouseArea
  4. {
  5.     id: container
  6.     height: 400; width: 600
  7.     Rectangle { id: point; visible: false; width: 6; height: 6; radius: 3; color: "black" }
  8.     onPressed: { point.visible = true; point.x = mouse.x - 3; point.y = mouse.y - 3; }
  9.     ListModel {
  10.         id: listModel
  11.         ListElement { lorem: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Proin nibh augue, suscipit a, scelerisque sed, lacinia in, mi. Cras vel lorem." }
  12.         ListElement { lorem: "Etiam pellentesque aliquet tellus. Phasellus pharetra nulla ac diam." }
  13.         ListElement { lorem: "Quisque semper justo at risus. Donec venenatis, turpis vel hendrerit interdum, dui ligula ultricies purus, sed posuere libero dui id orci." }
  14.         ListElement { lorem: "Nam congue, pede vitae dapibus aliquet, elit magna vulputate arcu, vel tempus metus leo non est." }
  15.     }
  16.     ListView {
  17.         id: messageListView
  18.         model: listModel
  19.         anchors.top: container.top; anchors.left: container.left; anchors.right: container.right
  20.         height: childrenRect.height
  21.         onCountChanged: console.log("count: " + count)
  22.         onHeightChanged: console.log("height: " + height) // sometimes wrong
  23.         onContentHeightChanged: console.log("contentHeight: " + contentHeight) // rather ok
  24.         delegate: Item {
  25.             id: messageItem
  26.             anchors.left: parent.left; anchors.right: parent.right
  27.             height: Math.max(50, messageText.height + 12)
  28.             Rectangle { anchors.fill: parent; anchors.margins: 1; opacity: 0.75; color: "green"; radius: 5 }
  29.             Text {
  30.                 id: messageText
  31.                 anchors.verticalCenter: parent.verticalCenter; anchors.left: parent.left; anchors.right: removeButton.left; anchors.margins: 10
  32.                 text: lorem
  33.                 color: "white"; horizontalAlignment: Text.AlignHCenter; wrapMode: Text.WordWrap
  34.                 font.pixelSize: 16; font.weight: Font.Bold
  35.                 style: Text.Outline; styleColor: "black"
  36.                 maximumLineCount: 6; elide: Text.ElideRight
  37.             }
  38.             Button {
  39.                 id: removeButton
  40.                 enabled: (index !== -1) && (messageItem.opacity === 1.0)
  41.                 anchors.right: parent.right; anchors.margins: 5
  42.                 anchors.verticalCenter: parent.verticalCenter; implicitHeight: 40; implicitWidth: 40
  43.                 onClicked: {
  44.                     console.log("remove: " + index);
  45.                     listModel.remove(index);
  46.                 }
  47.             }
  48.             ListView.onRemove: SequentialAnimation {
  49.                 PropertyAction { target: messageItem; property: "ListView.delayRemove"; value: true }
  50.                 /// PROBLEM BEGIN
  51.                 NumberAnimation { target: messageItem; properties: "opacity"; from: 1.0; to: 0.0; duration: 500 }
  52.                 /// PROBLEM END
  53.                 PropertyAction { target: messageItem; property: "ListView.delayRemove"; value: false }
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement