<commit_before>/*
Copyright (c) 2013 <NAME> <<EMAIL>>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0

Item {
    anchors.fill: parent
    property var settingsUrl: timeController.resultUrl
    property var settingsZoomLimit: timeController.zoomLimit
    property bool initialLoad: true
    Component.onCompleted: {
        settingsUrl = timeController.resultUrl
        settingsZoomLimit = timeController.zoomLimit
    }
    Item {
        id: resultSelector
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 10
        height: 50

        CheckBox {
            anchors.top: parent.top
            id: showResults
            checked: timeController.showResults
            //: The label text for checkbox that selects if results are shown under the clock
            text: qsTr("Show results") + lang.lang
        }

        Text {
            anchors.top: showResults.bottom
            anchors.left: parent.left
            opacity: showResults.checked ? 1 : 0.5
            id: head
            //: The label text above url text input for result file
            text: qsTr("Result address: ") + lang.lang
            font.pixelSize: 16
        }
        Button {
            id: resultButton
            //: Button to open file browser to find the results to be shown
            text: qsTr("Browse files") + lang.lang
            anchors.top: showResults.bottom
            anchors.left: head.right
            onClicked: loadResults.open()
        }

        TextField {
            id: resultFile
            anchors.right: parent.right
            anchors.top: resultButton.bottom
            anchors.left: parent.left
            font.pixelSize: 16
            text: timeController.resultUrl

            onTextChanged: {
                if (settingsUrl !== undefined && text != settingsUrl) {
                    initialLoad = false;
                }
                if (text != view.url) {
                    if (view.url == "") {
                        view.url = text
                    } else {
                        loadurltimer.restart()
                    }
                }
            }

            Component.onCompleted: {text = timeController.resultUrl}
        }
        Timer {
            id: loadurltimer
            running: false
            repeat: false
            interval: 1000
            onTriggered: {
                if (resultFile.text != view.url)
                    view.url = resultFile.text
            }
        }
        WebView {
            anchors.fill: resultLimiter
            id: view
            clip: true
            pixelAligned: false
            interactive: false
            opacity: showResults.checked ? 1 : 0.7
            visible: true
            z: -1
            function setSize() {
                var scale = view.experimental.test.contentsScale;
                if (initialLoad
                        && settingsZoomLimit.x > -1
                        && settingsZoomLimit.y > -1
                        && settingsZoomLimit.width > -1
                        && settingsZoomLimit.height > -1) {
                    resultLimiterBorder.x = settingsZoomLimit.x * scale
                    resultLimiterBorder.y = settingsZoomLimit.y * scale
                    resultLimiterBorder.width = settingsZoomLimit.width * scale
                    resultLimiterBorder.height = settingsZoomLimit.height * scale
                    return;
                }
                resultLimiterBorder.x = 0
                resultLimiterBorder.y = 0
                resultLimiterBorder.height = view.contentHeight
                resultLimiterBorder.width = view.contentWidth
                timeController.zoomLimit = Qt.rect(
                    (resultLimiterBorder.x + view.contentX)/scale,
                    (resultLimiterBorder.y + view.contentY)/scale,
                    resultLimiterBorder.width/scale,
                    resultLimiterBorder.height/scale);
            }
            onContentHeightChanged: setSize()
            onContentWidthChanged: setSize()
            onLoadingChanged: {
                if (loadRequest.status == WebView.LoadSucceededStatus &&
                        resultFile.text != loadRequest.url) {
                    resultFile.text = loadRequest.url
                    loadurltimer.stop();
                }
            }
            Component.onCompleted: {
                view.experimental.preferences.javascriptEnabled = false;
            }
        }
        MouseArea {
            anchors.top: resultFile.bottom
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            id: resultLimiter
            hoverEnabled: true
            property string direction: ""
            property variant panstart: Qt.point(0, 0)
            property variant pressloc: Qt.point(0, 0)
            property bool directionLock: false

            Rectangle {
                id: resultLimiterBorder
                x: timeController.zoomLimit.x
                y: timeController.zoomLimit.y
                width: timeController.zoomLimit.width
                height: timeController.zoomLimit.height
                opacity: showResults.checked ? 1 : 0.7
                border.width: 2
                border.color: "black"
                color: "transparent"

                Component.onCompleted: {
                    x = timeController.zoomLimit.x
                    y = timeController.zoomLimit.y
                    width = timeController.zoomLimit.width
                    height = timeController.zoomLimit.height
                }
            }

            onPressed: {
                if (mouse.buttons == Qt.LeftButton) {
                    directionLock = true;
                    panstart = Qt.point(mouse.x, mouse.y);
                    pressloc = Qt.point(mouse.x, mouse.y);
                }
            }

            onReleased: {
                if (mouse.buttons != Qt.LeftButton) {
                    directionLock = false;
                    if (direction != "") {
                        var scale = view.experimental.test.contentsScale;
                        timeController.zoomLimit = Qt.rect(
                            (resultLimiterBorder.x + view.contentX)/scale,
                            (resultLimiterBorder.y + view.contentY)/scale,
                            resultLimiterBorder.width/scale,
                            resultLimiterBorder.height/scale);
                    }
                }
            }

            onWheel: {
                /* TODO: Use pixelDelta if available */
                pan(wheel.angleDelta.x, wheel.angleDelta.y);
            }

            function pan(dx, dy) {
                if (view.contentY + dy < 0) {
                    dy = -view.contentY
                } else if (view.contentHeight - view.contentY - dy < view.height)  {
                    dy = Math.floor(view.contentHeight - view.contentY - view.height);
                }
<commit_msg>Pass simulated click events to web page allowing navigation<commit_after>/*
Copyright (c) 2013 <NAME> <<EMAIL>>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.0
import QtWebKit 3.0
import QtWebKit.experimental 1.0

Item {
    anchors.fill: parent
    property var settingsUrl: timeController.resultUrl
    property var settingsZoomLimit: timeController.zoomLimit
    property bool initialLoad: true
    Component.onCompleted: {
        settingsUrl = timeController.resultUrl
        settingsZoomLimit = timeController.zoomLimit
    }
    Item {
        id: resultSelector
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        anchors.margins: 10
        height: 50

        CheckBox {
            anchors.top: parent.top
            id: showResults
            checked: timeController.showResults
            //: The label text for checkbox that selects if results are shown under the clock
            text: qsTr("Show results") + lang.lang
        }

        Text {
            anchors.top: showResults.bottom
            anchors.left: parent.left
            opacity: showResults.checked ? 1 : 0.5
            id: head
            //: The label text above url text input for result file
            text: qsTr("Result address: ") + lang.lang
            font.pixelSize: 16
        }
        Button {
            id: resultButton
            //: Button to open file browser to find the results to be shown
            text: qsTr("Browse files") + lang.lang
            anchors.top: showResults.bottom
            anchors.left: head.right
            onClicked: loadResults.open()
        }

        TextField {
            id: resultFile
            anchors.right: parent.right
            anchors.top: resultButton.bottom
            anchors.left: parent.left
            font.pixelSize: 16
            text: timeController.resultUrl

            onTextChanged: {
                if (settingsUrl !== undefined && text != settingsUrl) {
                    initialLoad = false;
                }
                if (text != view.url) {
                    if (view.url == "") {
                        view.url = text
                    } else {
                        loadurltimer.restart()
                    }
                }
            }

            Component.onCompleted: {text = timeController.resultUrl}
        }
        Timer {
            id: loadurltimer
            running: false
            repeat: false
            interval: 1000
            onTriggered: {
                if (resultFile.text != view.url)
                    view.url = resultFile.text
            }
        }
        WebView {
            anchors.fill: resultLimiter
            id: view
            clip: true
            pixelAligned: false
            interactive: true
            opacity: showResults.checked ? 1 : 0.7
            visible: true
            z: -1
            function setSize() {
                var scale = view.experimental.test.contentsScale;
                if (initialLoad
                        && settingsZoomLimit.x > -1
                        && settingsZoomLimit.y > -1
                        && settingsZoomLimit.width > -1
                        && settingsZoomLimit.height > -1) {
                    resultLimiterBorder.x = settingsZoomLimit.x * scale
                    resultLimiterBorder.y = settingsZoomLimit.y * scale
                    resultLimiterBorder.width = settingsZoomLimit.width * scale
                    resultLimiterBorder.height = settingsZoomLimit.height * scale
                    return;
                }
                resultLimiterBorder.x = 0
                resultLimiterBorder.y = 0
                resultLimiterBorder.height = view.contentHeight
                resultLimiterBorder.width = view.contentWidth
                timeController.zoomLimit = Qt.rect(
                    (resultLimiterBorder.x + view.contentX)/scale,
                    (resultLimiterBorder.y + view.contentY)/scale,
                    resultLimiterBorder.width/scale,
                    resultLimiterBorder.height/scale);
            }
            onContentHeightChanged: setSize()
            onContentWidthChanged: setSize()
            onLoadingChanged: {
                if (loadRequest.status == WebView.LoadSucceededStatus &&
                        resultFile.text != loadRequest.url) {
                    resultFile.text = loadRequest.url
                    loadurltimer.stop();
                }
            }
            Component.onCompleted: {
                view.experimental.preferences.javascriptEnabled = false;
            }
        }
        MouseArea {
            id: resultLimiter
            anchors.top: resultFile.bottom
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.margins: 5

            clip: true
            hoverEnabled: true
            property string direction: ""
            property variant panstart: Qt.point(0, 0)
            property variant pressloc: Qt.point(0, 0)
            property bool directionLock: false

            Rectangle {
                id: resultLimiterBorder
                x: timeController.zoomLimit.x
                y: timeController.zoomLimit.y
                width: timeController.zoomLimit.width
                height: timeController.zoomLimit.height
                opacity: showResults.checked ? 1 : 0.7
                border.width: 2
                border.color: "black"
                color: "transparent"

                Component.onCompleted: {
                    x = timeController.zoomLimit.x
                    y = timeController.zoomLimit.y
                    width = timeController.zoomLimit.width
                    height = timeController.zoomLimit.height
                }
            }

            onPressed: {
                if (mouse.buttons == Qt.LeftButton) {
                    directionLock = true;
                    panstart = Qt.point(mouse.x, mouse.y);
                    pressloc = Qt.point(mouse.x, mouse.y);
                }
            }

            onReleased: {
                if (mouse.buttons != Qt.LeftButton) {
                    directionLock = false;
                    if (direction != "") {
                        var scale = view.experimental.test.contentsScale;
                        timeController.zoomLimit = Qt.rect(
                            (resultLimiterBorder.x + view.contentX)/scale,
                            (resultLimiterBorder.y + view.contentY)/scale,
                            resultLimiterBorder.width/scale,
                            resultLimiterBorder.height/scale);
                    } else {
                        var dx = pressloc.x - mouse.x;
                        var dy = pressloc.y - mouse.y;
                        dx = dx*dx;
                        dy = dy*dy;
                        /* Check if movement is less than 5 pixels */
                        if (dx+dy < 25) {
                            /* Simulate the click */
                            timeController.click(view, Qt.point(mouse.x, mouse.y));
                        }
                    }
                }
            }

            onWheel: {
                /* TODO: Use pixelDelta if available */
                pan(wheel.angleDelta.x, wheel.angleDelta.y);
            }

            function pan(dx, dy) {
                if (view.contentY + dy < 0) {
                    dy = -view.contentY
                } else if (view.contentHeight - view.contentY - dy < view.height)  {
                    dy = Math.floor(view.contentHeight - view.contentY - view.height);
                }

{'fraction_non_alphanumeric': 0.07069167643610785, 'fraction_numerical': 0.005861664712778429, 'mean_word_length': 1.39957805907173, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, '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': '2217215', 'n_tokens_mistral': 4222, 'n_tokens_neox': 3939, 'n_words': 1122}