Ruler.qml 4.35 KB
Newer Older
luyikei's avatar
luyikei committed
1 2 3 4
import QtQuick 2.0

Rectangle {
    id: ruler
5
    height: parent.height
luyikei's avatar
luyikei committed
6 7 8 9
    width: parent.width - initPosOfCursor
    color: "#333333"

    Column {
10
        Rectangle {
luyikei's avatar
luyikei committed
11
            id: markersArea
12 13 14 15 16
            height: 9
            width: ruler.width
            color: "#666666"
        }

luyikei's avatar
luyikei committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        Rectangle {
            id: curveBorder
            height: 7
            width: parent.width
            gradient: Gradient {
                GradientStop {
                    position: 0.00;
                    color: "#000000";
                }
                GradientStop {
                    position: 0.20;
                    color: "#999999";
                }
                GradientStop {
                    position: 1.00;
                    color: "#222222";
                }
            }
        }

37 38
        ListView {
            model: ruler.width / ppu // pixels per minimum unit
luyikei's avatar
luyikei committed
39
            height: 35
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
            width: parent.width
            orientation: Qt.Horizontal
            layoutDirection: Qt.LeftToRight
            delegate: Item {
                width: ppu
                height: 35
                Rectangle {
                    id: scale
                    width: 1
                    height: ruler.height / 2
                    anchors.bottom: parent.bottom
                    gradient: Gradient {
                        GradientStop {
                            position: 0.00;
                            color: "#00000088";
                        }
                        GradientStop {
                            position: 1.00;
                            color: "#c2c2c2";
luyikei's avatar
luyikei committed
59 60
                        }
                    }
61
                }
luyikei's avatar
luyikei committed
62

63
                Component.onCompleted: {
64
                    if ( index % 15 == 0 ) {
65 66 67 68 69 70 71 72 73
                        // Text
                        var obj = Qt.createQmlObject('import QtQuick 2.0; Text {'+
                                               'color: "white";' +
                                               'font.pointSize: ruler.height / 6' +
                                               '}',
                                               this
                                               );
                        obj.text = Qt.binding( function()
                        {
74
                            return timecodeFromFrames( ptof( x ) );
75 76 77 78
                        } );
                        scale.color = "#AA7777";
                        scale.width = 2;
                        scale.gradient = undefined;
luyikei's avatar
luyikei committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                    }
                }
            }
        }

        Rectangle {
            height: 1
            width: ruler.width
            color: "#000000"
            gradient: Gradient {
                GradientStop {
                    position: 0.00;
                    color: "#ff6e00";
                }
                GradientStop {
                    position: 1.00;
                    color: "#7a0000";
                }
            }
        }
    }

101 102 103 104
    MouseArea {
        anchors.fill: parent

        onPressed: {
105
            cursorPosition = ptof( mouseX );
106 107 108
        }

        onReleased: {
109
            workflow.setPosition( cursorPosition );
110 111 112
        }

        onClicked: {
113 114
            cursorPosition = ptof( mouseX );
            workflow.setPosition( cursorPosition );
115 116 117
        }

        onPositionChanged: {
118 119
            cursorPosition = ptof( mouseX );
            workflow.setPosition( cursorPosition );
120 121 122
        }
    }

luyikei's avatar
luyikei committed
123 124 125 126 127 128 129
    DropArea {
        id: markersDropArea
        width: parent.width
        height: markersArea.height
        keys: ["Marker"]

        onPositionChanged: {
130 131 132 133 134 135 136 137 138 139 140 141 142
            var newPosition = ptof( drag.x );

            var samePosMarkersCount = 0;
            for ( var i = 0; i < markers.count; ++i ) {
                if ( markers.get( i )["position"] === newPosition )
                    samePosMarkersCount++;
            }

            // Move the marker to the right a bit
            if ( samePosMarkersCount >= 2 )
                newPosition += Math.max( ptof( 1 ), 1 );

            drag.source.position = newPosition;
luyikei's avatar
luyikei committed
143 144 145 146 147 148 149 150 151
        }
    }

    MouseArea {
        id: markersMouseArea
        width: parent.width
        height: markersArea.height

        onClicked: {
152
            timeline.addMarker( ptof( mouseX ) );
luyikei's avatar
luyikei committed
153 154 155
        }
    }

luyikei's avatar
luyikei committed
156 157 158
    Connections {
        target: workflow
        onFrameChanged: {
159
            cursorPosition = newFrame;
luyikei's avatar
luyikei committed
160 161 162 163
        }
    }
}