<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 QtQuick.Dialogs 1.1
import QtQuick.Controls.Styles 1.1
import xpiks 1.0
import QtGraphicalEffects 1.0
import "../Constants"
import "../Common.js" as Common;
import "../Components"
import "../StyledControls"
import "../Constants/UIConfig.js" as UIConfig

Rectangle {
    id: artworkEditComponent
    anchors.fill: parent
    color: Colors.artworkImageBackground

    property variant componentParent
    property var autoCompleteBox

    property int artworkIndex: -1
    property var keywordsModel

    signal dialogDestruction();
    Component.onDestruction: dialogDestruction();

    function onAutoCompleteClose() {
        autoCompleteBox = undefined
    }

    function reloadItemEditing(itemIndex) {
        if (itemIndex === artworkIndex) { return }

        var originalIndex = filteredArtItemsModel.getOriginalIndex(itemIndex)
        var metadata = filteredArtItemsModel.getArtworkMetadata(itemIndex)
        var keywordsModel = filteredArtItemsModel.getBasicModel(itemIndex)

        artworkProxy.setSourceArtwork(metadata, originalIndex)

        artworkEditComponent.artworkIndex = itemIndex
        artworkEditComponent.keywordsModel = keywordsModel
        rosterListView.currentIndex = itemIndex
        rosterListView.positionViewAtIndex(itemIndex, ListView.Contain)

        titleTextInput.forceActiveFocus()
        titleTextInput.cursorPosition = titleTextInput.text.length
    }

    function closePopup() {
        mainStackView.pop()
        artworkProxy.resetModel()
        settingsModel.saveArtworkEditUISettings()
        expandLeftPane()
    }

    Component.onCompleted: {
        focus = true

        titleTextInput.forceActiveFocus()
        titleTextInput.cursorPosition = titleTextInput.text.length
    }

    Connections {
        target: helpersWrapper
        onGlobalBeforeDestruction: {
            console.debug("UI:EditArtworkHorizontalDialog # globalBeforeDestruction")
            //closePopup()
        }
    }

    Connections {
        target: artItemsModel
        onFileWithIndexUnavailable: {
            if (artworkIndex == index) {
                console.debug("Artwork unavailable")
                closePopup()
            }
        }
    }

    MessageDialog {
        id: clearKeywordsDialog

        title: i18.n + qsTr("Confirmation")
        text: i18.n + qsTr("Clear all keywords?")
        standardButtons: StandardButton.Yes | StandardButton.No
        onYes: filteredArtItemsModel.clearKeywords(artworkEditComponent.artworkIndex)
    }

    Keys.onEscapePressed: closePopup()

    Connections {
        target: artworkProxy

        onCompletionsAvailable: {
            if (typeof artworkEditComponent.autoCompleteBox !== "undefined") {
                // update completion
                return
            }

            var directParent = artworkEditComponent;
            var currWordStartRect = flv.editControl.getCurrentWordStartRect()

            var tmp = flv.editControl.mapToItem(directParent,
                                                currWordStartRect.x - 17,
                                                flv.editControl.height + 1)

            var visibleItemsCount = Math.min(acSource.getCount(), 5);
            var popupHeight = visibleItemsCount * (25 + 1) + 10

            var isBelow = (tmp.y + popupHeight) < directParent.height;

            var options = {
                model: acSource,
                editableTags: flv,
                isBelowEdit: isBelow,
                "anchors.left": directParent.left,
                "anchors.leftMargin": Math.min(tmp.x, directParent.width - 200)
            }

            if (isBelow) {<commit_msg>Autocomplete tuning<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 QtQuick.Dialogs 1.1
import QtQuick.Controls.Styles 1.1
import xpiks 1.0
import QtGraphicalEffects 1.0
import "../Constants"
import "../Common.js" as Common;
import "../Components"
import "../StyledControls"
import "../Constants/UIConfig.js" as UIConfig

Rectangle {
    id: artworkEditComponent
    anchors.fill: parent
    color: Colors.artworkImageBackground

    property variant componentParent
    property var autoCompleteBox

    property int artworkIndex: -1
    property var keywordsModel

    signal dialogDestruction();
    Component.onDestruction: dialogDestruction();

    function onAutoCompleteClose() {
        autoCompleteBox = undefined
    }

    function reloadItemEditing(itemIndex) {
        if (itemIndex === artworkIndex) { return }

        closeAutoComplete()

        var originalIndex = filteredArtItemsModel.getOriginalIndex(itemIndex)
        var metadata = filteredArtItemsModel.getArtworkMetadata(itemIndex)
        var keywordsModel = filteredArtItemsModel.getBasicModel(itemIndex)

        artworkProxy.setSourceArtwork(metadata, originalIndex)

        artworkEditComponent.artworkIndex = itemIndex
        artworkEditComponent.keywordsModel = keywordsModel
        rosterListView.currentIndex = itemIndex
        rosterListView.positionViewAtIndex(itemIndex, ListView.Contain)

        titleTextInput.forceActiveFocus()
        titleTextInput.cursorPosition = titleTextInput.text.length
    }

    function closePopup() {
        mainStackView.pop()
        artworkProxy.resetModel()
        settingsModel.saveArtworkEditUISettings()
        expandLeftPane()
    }

    function closeAutoComplete() {
        if (typeof artworkEditComponent.autoCompleteBox !== "undefined") {
            artworkEditComponent.autoCompleteBox.closePopup()
        }
    }

    Component.onCompleted: {
        focus = true

        titleTextInput.forceActiveFocus()
        titleTextInput.cursorPosition = titleTextInput.text.length
    }

    Connections {
        target: helpersWrapper
        onGlobalBeforeDestruction: {
            console.debug("UI:EditArtworkHorizontalDialog # globalBeforeDestruction")
            //closePopup()
        }
    }

    Connections {
        target: artItemsModel
        onFileWithIndexUnavailable: {
            if (artworkIndex == index) {
                console.debug("Artwork unavailable")
                closePopup()
            }
        }
    }

    MessageDialog {
        id: clearKeywordsDialog

        title: i18.n + qsTr("Confirmation")
        text: i18.n + qsTr("Clear all keywords?")
        standardButtons: StandardButton.Yes | StandardButton.No
        onYes: filteredArtItemsModel.clearKeywords(artworkEditComponent.artworkIndex)
    }

    // Keys.onEscapePressed: closePopup()

    Connections {
        target: artworkProxy

        onCompletionsAvailable: {
            if (typeof artworkEditComponent.autoCompleteBox !== "undefined") {
                // update completion
                return
            }

            var directParent = artworkEditComponent;
            var currWordStartRect = flv.editControl.getCurrentWordStartRect()

            var tmp = flv.editControl.mapToItem(directParent,
                                                currWordStartRect.x - 17,
                                                flv.editControl.height + 1)

            var visibleItemsCount = Math.min(acSource.getCount(), 5);
            var popupHeight = visibleItemsCount * (25 + 1) + 10

            var isBelow = (tmp.y + popupHeight) < directParent.height;

            var options = {
                model: acSource,
                editableTags: flv,
                isBelowEdit: isBelow,
                "anchors.left": directParent.left,
                "anchors.leftMargin": Math.min(tmp.x, directParent.width - 200)
            }

            if (isBelow) {
{'fraction_non_alphanumeric': 0.07558690388461943, 'fraction_numerical': 0.008843036109064112, 'mean_word_length': 2.465888361911711, 'pattern_counts': {'":': 4, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2548139', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2385, 'n_words': 661}