<commit_before>/*
 * This file is a part of Xpiks - cross platform application for
 * keywording and uploading images for microstocks
 * Copyright (C) 2014-2016 <NAME> <<EMAIL>>
 *
 * Xpiks is distributed under the GNU General Public License, version 3.0
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import xpiks 1.0
import "../Constants"
import "../StyledControls"
import "../Constants/UIConfig.js" as UIConfig

Flickable {
    id: flowListView
    anchors.fill: parent
    anchors.leftMargin: 5
    anchors.topMargin: 5
    anchors.bottomMargin: 5
    contentWidth: parent.width
    contentHeight: flow.childrenRect.height
    boundsBehavior: Flickable.StopAtBounds
    flickableDirection: Flickable.VerticalFlick
    rightMargin: 10
    interactive: false
    clip: true

    property int scrollStep: 10
    property alias count: repeater.count
    property int currentIndex: -1
    property variant currentItem;
    property alias delegate: repeater.delegate
    property alias flow: flow.flow
    property alias model: repeater.model
    property alias isFocused: nextTagTextInput.activeFocus
    property alias editEnabled: editWrapper.enabled
    property int flowSpacing: 5
    property bool stealWheel: true
    property alias editControl: nextTagTextInput
    property bool autoCompleteActive: acSource.isActive

    signal tagAdded(string text)
    signal removeLast()
    signal tagsPasted(var tagsList)
    signal copyRequest();
    signal backTabPressed();
    signal tabPressed();
    signal editActivated();
    signal clickedInside();

    signal completionRequested(string prefix);

    function completionCancel() {
        acSource.cancelCompletion();
    }

    function moveSelectionUp() {
        acSource.moveSelectionUp();
    }

    function moveSelectionDown() {
        acSource.moveSelectionDown();
    }

    function acceptSelected() {
        acSource.acceptSelected()
    }

    function activateEdit() {
        if (editEnabled && !nextTagTextInput.activeFocus) {
            scrollToBottom()
            nextTagTextInput.forceActiveFocus()
            editActivated();
        }

        clickedInside()
    }

    function getEditedText() {
        var tagText = nextTagTextInput.text;
        return helpersWrapper.sanitizeKeyword(tagText);
    }

    function raiseAddTag(text) {
        var canBeAdded = helpersWrapper.isKeywordValid(text);
        if (canBeAdded) {
            tagAdded(text);
        }
        return canBeAdded;
    }

    function scrollDown () {
        var flickable = flowListView;
        if (flowListView.contentHeight >= flowListView.height) {
            flickable.contentY = Math.min (flickable.contentY + scrollStep + flowSpacing, flickable.contentHeight - flickable.height);

            var lines = Math.floor(flickable.contentY / (scrollStep + flowSpacing));
            flickable.contentY = lines*(scrollStep + flowSpacing)
        }
    }

    function scrollUp () {
        var flickable = flowListView;
        if (flowListView.contentHeight >= flowListView.height) {
            flickable.contentY = Math.max (flickable.contentY - scrollStep - flowSpacing, 0);

            var lines = Math.floor(flickable.contentY / (scrollStep + flowSpacing));
            flickable.contentY = lines*(scrollStep + flowSpacing)
        }
    }

    function scrollToBottom() {
        if (flowListView.contentHeight >= flowListView.height) {
            flowListView.contentY = flowListView.contentHeight - flowListView.height
        }
    }

    function adjustEdit() {
        if (Math.abs(editWrapper.y - flowListView.contentY) <= flowListView.height)  {
            flowListView.scrollToBottom()
        }
    }

    function forceRefreshRepeater() {
        repeater.update()
    }

    function removeFocus() {
        // bump
    }

    function onBeforeClose() {
        var tagText = getEditedText();
        if (raiseAddTag(tagText)) {
            nextTagTextInput.text = '';
        }
    }

    MouseArea {
        anchors.left: parent.left
        anchors.top: parent.top
        width: parent.width
        height: flowListView.contentHeight > flowListView.height ? flowListView.contentHeight : flowListView.height

        onClicked: {
            activateEdit()
            mouse.accepted = false
        }

        propagateComposedEvents: true
        preventStealing: true

        onWheel: {
            if (!stealWheel && !nextTagTextInput.activeFocus || flowListView.height >= flowListView.contentHeight) {
                wheel.accepted = false
                return
            }

            if (wheel.angleDelta.y < 0) {
                var maxScrollPos = flowListView.contentHeight - flowListView.height
                if (Math.abs(flowListView.contentY - maxScrollPos) > scrollStep) {
                    scrollDown()
                } else {
                    scrollToBottom()
                    wheel.accepted = false
                }
            } else {
                if (flowListView.contentY > scrollStep) {
                    scrollUp()
                } else {
                    flowListView.contentY = 0
                    wheel.accepted = false
                }
            }
        }
    }
<commit_msg>Fixed scroll jumping. closes #272<commit_after>/*
 * This file is a part of Xpiks - cross platform application for
 * keywording and uploading images for microstocks
 * Copyright (C) 2014-2016 <NAME> <<EMAIL>>
 *
 * Xpiks is distributed under the GNU General Public License, version 3.0
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import xpiks 1.0
import "../Constants"
import "../StyledControls"
import "../Constants/UIConfig.js" as UIConfig

Flickable {
    id: flowListView
    anchors.fill: parent
    anchors.leftMargin: 5
    anchors.topMargin: 5
    anchors.bottomMargin: 5
    contentWidth: parent.width
    contentHeight: flow.childrenRect.height
    boundsBehavior: Flickable.StopAtBounds
    flickableDirection: Flickable.VerticalFlick
    rightMargin: 10
    interactive: false
    clip: true

    property int scrollStep: 10
    property alias count: repeater.count
    property int currentIndex: -1
    property variant currentItem;
    property alias delegate: repeater.delegate
    property alias flow: flow.flow
    property alias model: repeater.model
    property alias isFocused: nextTagTextInput.activeFocus
    property alias editEnabled: editWrapper.enabled
    property int flowSpacing: 5
    property bool stealWheel: true
    property alias editControl: nextTagTextInput
    property bool autoCompleteActive: acSource.isActive

    signal tagAdded(string text)
    signal removeLast()
    signal tagsPasted(var tagsList)
    signal copyRequest();
    signal backTabPressed();
    signal tabPressed();
    signal editActivated();
    signal clickedInside();

    signal completionRequested(string prefix);

    function completionCancel() {
        acSource.cancelCompletion();
    }

    function moveSelectionUp() {
        acSource.moveSelectionUp();
    }

    function moveSelectionDown() {
        acSource.moveSelectionDown();
    }

    function acceptSelected() {
        acSource.acceptSelected()
    }

    function activateEdit() {
        if (editEnabled && !nextTagTextInput.activeFocus) {
            scrollToBottom()
            nextTagTextInput.forceActiveFocus()
            editActivated();
        }

        clickedInside()
    }

    function getEditedText() {
        var tagText = nextTagTextInput.text;
        return helpersWrapper.sanitizeKeyword(tagText);
    }

    function raiseAddTag(text) {
        var canBeAdded = helpersWrapper.isKeywordValid(text);
        if (canBeAdded) {
            tagAdded(text);
        }
        return canBeAdded;
    }

    function scrollDown () {
        var flickable = flowListView;
        if (flowListView.contentHeight >= flowListView.height) {
            flickable.contentY = Math.min (flickable.contentY + scrollStep + flowSpacing, flickable.contentHeight - flickable.height);

            var lines = Math.floor(flickable.contentY / (scrollStep + flowSpacing));
            flickable.contentY = lines*(scrollStep + flowSpacing)
        }
    }

    function scrollUp () {
        var flickable = flowListView;
        if (flowListView.contentHeight >= flowListView.height) {
            flickable.contentY = Math.max (flickable.contentY - scrollStep - flowSpacing, 0);

            var lines = Math.floor(flickable.contentY / (scrollStep + flowSpacing));
            flickable.contentY = lines*(scrollStep + flowSpacing)
        }
    }

    function scrollToBottom() {
        if (flowListView.contentHeight >= flowListView.height) {
            flowListView.contentY = flowListView.contentHeight - flowListView.height
        }
    }

    function adjustEdit() {
        if (Math.abs(editWrapper.y - flowListView.contentY) <= flowListView.height)  {
            flowListView.scrollToBottom()
        }
    }

    function forceRefreshRepeater() {
        repeater.update()
    }

    function removeFocus() {
        // bump
    }

    function onBeforeClose() {
        var tagText = getEditedText();
        if (raiseAddTag(tagText)) {
            nextTagTextInput.text = '';
        }
    }

    MouseArea {
        anchors.left: parent.left
        anchors.top: parent.top
        width: parent.width
        height: flowListView.contentHeight > flowListView.height ? flowListView.contentHeight : flowListView.height

        onClicked: {
            activateEdit()
            mouse.accepted = false
        }

        propagateComposedEvents: true
        preventStealing: true

        onWheel: {
            if (!stealWheel && !nextTagTextInput.activeFocus || flowListView.height >= flowListView.contentHeight) {
                wheel.accepted = false
                return
            }

            if (wheel.angleDelta.y < 0) {
                var maxScrollPos = flowListView.contentHeight - flowListView.height
                if (Math.abs(flowListView.contentY - maxScrollPos) > scrollStep) {
                    scrollDown()
                } else {
                    scrollToBottom()
                    wheel.accepted = false
                }
            } else if (wheel.angleDelta.y > 0) {
                if (flowListView.contentY > scrollStep) {
                    scrollUp()
                } else {
                    flowListView.contentY = 0
                    wheel.accepted = false
                }
            }
        }
    }

{'fraction_non_alphanumeric': 0.08075949367088607, 'fraction_numerical': 0.005569620253164557, 'mean_word_length': 2.2992761692650334, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1070697', 'n_tokens_mistral': 3236, 'n_tokens_neox': 3069, 'n_words': 841}