Marker.qml 1.67 KB
Newer Older
luyikei's avatar
luyikei committed
1 2 3 4 5 6 7 8
import QtQuick 2.0

Rectangle {
    id: marker

    width: 1
    height: page.height
    color: "#3F6644"
9 10
    x: ftop( position )
    visible: x < sView.flickableItem.contentX ? false : true
luyikei's avatar
luyikei committed
11 12

    property int position: 0
13
    property int lastPosition: 0
luyikei's avatar
luyikei committed
14 15 16 17 18 19 20 21
    property var markerModel

    onPositionChanged: {
        length = Math.max( length, position + 100 );
    }

    onMarkerModelChanged: {
        position = markerModel["position"];
22
        lastPosition = markerModel["position"];
luyikei's avatar
luyikei committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    }

    Drag.keys: ["Marker"]
    Drag.active: markerMouseArea.drag.active
    Rectangle {
        x: - ( width - 1 ) / 2
        width: 5
        height: 9
        color: "#63ff44"

        MouseArea {
            id: markerMouseArea
            anchors.fill: parent
            drag.target: marker
            drag.axis: Drag.XAxis
            drag.minimumX: 0
luyikei's avatar
luyikei committed
39 40
            acceptedButtons: Qt.LeftButton | Qt.RightButton

41 42 43 44 45 46 47 48 49 50 51
            onPressed: {
                lastPosition = position;
            }

            onReleased: {
                if ( lastPosition === position )
                    return;
                timeline.moveMarker( lastPosition, position );
                lastPosition = position;
            }

luyikei's avatar
luyikei committed
52 53 54 55 56 57 58 59 60 61
            onClicked: {
                if ( mouse.button & Qt.RightButton ) {
                    markerContextMenu.popup();
                }
            }
        }

        MarkerContextMenu {
            id: markerContextMenu
            marker: marker
luyikei's avatar
luyikei committed
62 63
        }
    }
64 65 66 67 68 69 70 71 72 73

    Connections {
        target: timeline
        onMarkerMoved: {
            if ( position === from ) {
                markerModel["position"] = to;
                position = to;
            }
        }
    }
luyikei's avatar
luyikei committed
74 75
}