<commit_before>
import QtQuick 2.0
import QtQuick.Controls 1.1

import QmlToolbox.Base 1.0


/**
*  ScrollBar
*
*  Horizontal or vertical scroll bar
*/
Item
{
    id: item

    signal scrolled(real value)

    readonly property bool hovered: mouseArea.containsMouse
    readonly property bool pressed: typeof(mouseArea.containsPress) != 'undefined' ? mouseArea.containsPress : false

    property real position: 0 ///< Current position
    property real size:     0 ///< Current size
    property real maxValue: 0 ///< Maximum size

    property bool vertical: true

    visible: item.maxValue > item.size

    property real fullSize: vertical ? height : width

    Rectangle
    {
        id: handle

        property real size: Math.max(30, Math.min(item.size / item.maxValue, 1.0) * item.fullSize)
        property real handlePos: mouseArea.drag.active ? 0 : (item.position / (item.maxValue - item.size)) * (item.fullSize - handle.size)

        x:      item.vertical ? Ui.style.paddingTiny                    : handlePos
        y:      item.vertical ? handlePos                               : Ui.style.paddingTiny
        width:  item.vertical ? parent.width - 2 * Ui.style.paddingTiny : size
        height: item.vertical ? size                                    : parent.height - 2 * Ui.style.paddingTiny

        color:  item.hovered ? Ui.style.controlColorHovered : Ui.style.controlColor
        radius: Ui.style.scrollBarRadius

        MouseArea
        {
            id: mouseArea

            anchors.fill: parent

            drag.target:   handle
            drag.minimumX: item.vertical ? Ui.style.paddingTiny        : 0
            drag.maximumX: item.vertical ? Ui.style.paddingTiny        : item.width - handle.width
            drag.minimumY: item.vertical ? 0                           : Ui.style.paddingTiny
            drag.maximumY: item.vertical ? item.height - handle.height : Ui.style.paddingTiny

            hoverEnabled: true
        }

        onXChanged:
        {
            if (mouseArea.drag.active && !vertical)
            {
                item.scrolled( Math.max(0, (x / (item.width - handle.width)) * (item.maxValue - item.size)) );
            }
        }

        onYChanged:
        {
            if (mouseArea.drag.active && vertical)
            {
                item.scrolled( Math.max(0, (y / (item.height - handle.height)) * (item.maxValue - item.size)) );
            }
        }
    }

    MouseArea
    {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.top:    parent.top
        anchors.bottom: handle.top

        onClicked:
        {
            item.scrolled( Math.max(0, item.position - item.size) );
        }
    }

    MouseArea
    {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.top:    handle.bottom
        anchors.bottom: parent.bottom

        onClicked:
        {
            item.scrolled( Math.min(item.maxValue - item.size, item.position + item.size) );
        }
    }
}<commit_msg>Fix horizontal scrollbar (clicking on white space to jump)<commit_after>
import QtQuick 2.0
import QtQuick.Controls 1.1

import QmlToolbox.Base 1.0


/**
*  ScrollBar
*
*  Horizontal or vertical scroll bar
*/
Item
{
    id: item

    signal scrolled(real value)

    readonly property bool hovered: mouseArea.containsMouse
    readonly property bool pressed: typeof(mouseArea.containsPress) != 'undefined' ? mouseArea.containsPress : false

    property real position: 0 ///< Current position
    property real size:     0 ///< Current size
    property real maxValue: 0 ///< Maximum size

    property bool vertical: true

    visible: item.maxValue > item.size

    property real fullSize: vertical ? height : width

    Rectangle
    {
        id: handle

        property real size: Math.max(30, Math.min(item.size / item.maxValue, 1.0) * item.fullSize)
        property real handlePos: mouseArea.drag.active ? 0 : (item.position / (item.maxValue - item.size)) * (item.fullSize - handle.size)

        x:      item.vertical ? Ui.style.paddingTiny                    : handlePos
        y:      item.vertical ? handlePos                               : Ui.style.paddingTiny
        width:  item.vertical ? parent.width - 2 * Ui.style.paddingTiny : size
        height: item.vertical ? size                                    : parent.height - 2 * Ui.style.paddingTiny

        color:  item.hovered ? Ui.style.controlColorHovered : Ui.style.controlColor
        radius: Ui.style.scrollBarRadius

        MouseArea
        {
            id: mouseArea

            anchors.fill: parent

            drag.target:   handle
            drag.minimumX: item.vertical ? Ui.style.paddingTiny        : 0
            drag.maximumX: item.vertical ? Ui.style.paddingTiny        : item.width - handle.width
            drag.minimumY: item.vertical ? 0                           : Ui.style.paddingTiny
            drag.maximumY: item.vertical ? item.height - handle.height : Ui.style.paddingTiny

            hoverEnabled: true
        }

        onXChanged:
        {
            if (mouseArea.drag.active && !vertical)
            {
                item.scrolled( Math.max(0, (x / (item.width - handle.width)) * (item.maxValue - item.size)) );
            }
        }

        onYChanged:
        {
            if (mouseArea.drag.active && vertical)
            {
                item.scrolled( Math.max(0, (y / (item.height - handle.height)) * (item.maxValue - item.size)) );
            }
        }
    }

    MouseArea
    {
        anchors.left:   item.vertical ? parent.left  : parent.left
        anchors.right:  item.vertical ? parent.right : handle.left
        anchors.top:    item.vertical ? parent.top   : parent.top
        anchors.bottom: item.vertical ? handle.top   : parent.bottom

        onClicked:
        {
            item.scrolled( Math.max(0, item.position - item.size) );
        }
    }

    MouseArea
    {
        anchors.left:   item.vertical ? parent.left   : handle.right
        anchors.right:  item.vertical ? parent.right  : parent.right
        anchors.top:    item.vertical ? handle.bottom : parent.top
        anchors.bottom: item.vertical ? parent.bottom : parent.bottom

        onClicked:
        {
            item.scrolled( Math.min(item.maxValue - item.size, item.position + item.size) );
        }
    }
}
{'fraction_non_alphanumeric': 0.1006742982593696, 'fraction_numerical': 0.006586169045005488, 'mean_word_length': 1.7082802547770701, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4041744', 'n_tokens_mistral': 1894, 'n_tokens_neox': 1799, 'n_words': 406}