<commit_before>import QtQuick 2.0
import QtMultimedia 5.6
import com.vplay.qmltypes 1.0

Item {

    id: progress

    height: parent.height / 100
    width: parent.width

    property real position
    property real playedWidth
    property real unplayedWidth
    property real draggedPosition

    property real backgroundOpacity


    Timer {
        id: updateTimer
        interval: 500
        repeat: true
    }

    Component.onCompleted: {

        updateTimer.triggered.connect(calculatePosition)
        updateTimer.start()
    }

    function updateWidth() {

        calculatePosition()
    }

    function calculatePosition() {

        position = 100 - (((mainWindow.videoDuration - mainWindow.videoPosition)/mainWindow.videoDuration)*100)
        playedWidth = (position*parent.width)/100
        unplayedWidth = progress.width - played.width - indicator.width
        currentTimeObject.setMilliseconds(mainWindow.videoPosition, TimeDisplayType.CurrentTime)

    }

    function calculateDraggedPosition(xPos) {

        playedWidth = xPos
        unplayedWidth = progress.width - xPos - indicator.width
        video.seek((xPos/progress.width)*mainWindow.videoDuration)
    }

    Row
    {
        anchors.fill: parent

        Rectangle {
            id: played
            opacity: backgroundOpacity
            color: "red"
            height: progress.height
            width: playedWidth

            border.color: "black"
            border.width: 1

            MouseArea {
                id: rewindArea
                anchors.fill: parent
            }
        }
        Rectangle {
            id: indicator
            opacity: backgroundOpacity
            color: "white"
            width: height
            height: 4*progress.height
            radius: width/2
            y: -1.5*progress.height
            border.color: "black"
            border.width: 1

            onXChanged: {
                if (indicatorMouseArea.drag.active) {
                    calculateDraggedPosition(x)
                }
            }

            MouseArea {

                id: indicatorMouseArea
                anchors.fill: parent
                drag.target: indicator
                drag.axis: "XAxis"
                drag.minimumX: 0
                drag.maximumX: progress.width

                onPressed: {

                    if (video.playbackState === MediaPlayer.PlayingState) {
                        updateTimer.stop()
                        video.pause()
                        mainWindow.state = "seeking"
                    }
                }
                onReleased: {

                    if (video.playbackState === MediaPlayer.PausedState) {
                        video.pause()
                        updateTimer.start()
                        mainWindow.state = "playing_controls_shown"
                    }
                    else if (video.playbackState === MediaPlayer.PlayingState) {
                        updateTimer.start()
                        video.play()
                        mainWindow.state = "playing_controls_shown"
                    }
                }
            }
        }

        Rectangle {
            id: unplayed
            opacity: backgroundOpacity
            color: "#a8a8a9"
            height: progress.height
            width:unplayedWidth
            border.color: "black"
            border.width: 1
            MouseArea {
                id: fastForwardArea
                anchors.fill: parent
            }
        }
    }
}
<commit_msg>restore correct state after dragging progress indicator<commit_after>import QtQuick 2.0
import QtMultimedia 5.6
import com.vplay.qmltypes 1.0

Item {

    id: progress

    height: parent.height / 100
    width: parent.width

    property real position
    property real playedWidth
    property real unplayedWidth
    property real draggedPosition

    property real backgroundOpacity

    property int previousState

    Timer {
        id: updateTimer
        interval: 500
        repeat: true
    }

    Component.onCompleted: {

        updateTimer.triggered.connect(calculatePosition)
        updateTimer.start()
    }

    function updateWidth() {

        calculatePosition()
    }

    function calculatePosition() {

        position = 100 - (((mainWindow.videoDuration - mainWindow.videoPosition)/mainWindow.videoDuration)*100)
        playedWidth = (position*parent.width)/100
        unplayedWidth = progress.width - played.width - indicator.width
        currentTimeObject.setMilliseconds(mainWindow.videoPosition, TimeDisplayType.CurrentTime)

    }

    function calculateDraggedPosition(xPos) {

        playedWidth = xPos
        unplayedWidth = progress.width - xPos - indicator.width
        video.seek((xPos/progress.width)*mainWindow.videoDuration)
    }

    Row
    {
        anchors.fill: parent

        Rectangle {
            id: played
            opacity: backgroundOpacity
            color: "red"
            height: progress.height
            width: playedWidth

            border.color: "black"
            border.width: 1

            MouseArea {
                id: rewindArea
                anchors.fill: parent
            }
        }
        Rectangle {
            id: indicator
            opacity: backgroundOpacity
            color: "white"
            width: height
            height: 4*progress.height
            radius: width/2
            y: -1.5*progress.height
            border.color: "black"
            border.width: 1

            onXChanged: {
                if (indicatorMouseArea.drag.active) {
                    calculateDraggedPosition(x)
                }
            }

            MouseArea {

                id: indicatorMouseArea
                anchors.fill: parent
                drag.target: indicator
                drag.axis: "XAxis"
                drag.minimumX: 0
                drag.maximumX: progress.width

                onPressed: {

                    if (video.playbackState === MediaPlayer.PlayingState) {
                        previousState = MediaPlayer.PlayingState
                        updateTimer.stop()
                        video.pause()
                        mainWindow.state = "seeking"
                    }
                }
                onReleased: {

                    if (video.playbackState === MediaPlayer.PausedState) {

                        if (previousState === MediaPlayer.PlayingState) {

                            updateTimer.start()
                            video.play()
                            mainWindow.state = "playing_controls_shown"
                        }
                        else {

                            video.pause()
                            updateTimer.start()
                            mainWindow.state = "playing_controls_shown"
                        }
                    }

                }
            }
        }

        Rectangle {
            id: unplayed
            opacity: backgroundOpacity
            color: "#a8a8a9"
            height: progress.height
            width:unplayedWidth
            border.color: "black"
            border.width: 1
            MouseArea {
                id: fastForwardArea
                anchors.fill: parent
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.06984691088026244, 'fraction_numerical': 0.008747949699289229, 'mean_word_length': 1.2562442183163738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6293705', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1679, 'n_words': 351}