<commit_before>import Qt 4.7
import "./styles/default" as DefaultStyles

Item {
    id: toggleSwitch    // "switch" is a reserved word

    property int minimumWidth: defaultStyle.minimumWidth
    property int minimumHeight: defaultStyle.minimumHeight
    width: Math.max(minimumWidth, grooveLoader.item.width)
    height: Math.max(minimumHeight, grooveLoader.item.height)

    signal clicked
    property bool pressed: mousearea.pressed
    property alias containsMouse: mousearea.containsMouse
    property bool checked: false

    property Component groove: defaultStyle.groove
    property Component handle: defaultStyle.handle

    property color backgroundColor: checked ? "#cef" : "#fff"
    property color textColor: "#333"

    Loader {
        id: grooveLoader;
        sourceComponent: groove
        anchors.fill:parent
        property real grooveLength: item.width
    }

    Loader {
        id: handleLoader
        sourceComponent: handle
        anchors.verticalCenter:parent.verticalCenter
    }

    MouseArea {
        id: mousearea
        enabled: toggleSwitch.enabled
        hoverEnabled: true
        anchors.fill: parent

        drag.axis: Drag.XAxis
        drag.minimumX:0
        drag.maximumX:toggleSwitch.width - handleLoader.item.width
        drag.target:handleLoader.item

        onPressed: toggleSwitch.pressed = true  // needed when hover is enabled
        onEntered: if (toggleSwitch.pressed && enabled) toggleSwitch.pressed = true
        onExited: toggleSwitch.pressed = false
        onReleased: {
            if(toggleSwitch.pressed && enabled) { // No click if release outside area
                toggleSwitch.pressed = false
                checked = !checked;
            }
            if (drag.active) {
                if (handleLoader.item.x > (drag.maximumValueX - drag.minimumValueX)/2)
                    checked = true
                else
                    checked = false
            } else if (toggleSwitch.pressed && enabled) { // No click if release outside area
                toggleSwitch.pressed  = false
                checked = !checked;
                toggleSwitch.clicked()
            }
            handleLoader.item.x = checked ? drag.maximumValueX : drag.minimumValueX
            toggleSwitch.clicked()
        }
    }

    DefaultStyles.SwitchStyle { id: defaultStyle }
}<commit_msg>Fixed a regression in Switch<commit_after>import Qt 4.7
import "./styles/default" as DefaultStyles

Item {
    id: toggleSwitch    // "switch" is a reserved word

    property int minimumWidth: defaultStyle.minimumWidth
    property int minimumHeight: defaultStyle.minimumHeight
    width: Math.max(minimumWidth, grooveLoader.item.width)
    height: Math.max(minimumHeight, grooveLoader.item.height)

    signal clicked
    property bool pressed: mousearea.pressed
    property alias containsMouse: mousearea.containsMouse
    property bool checked: false

    property Component groove: defaultStyle.groove
    property Component handle: defaultStyle.handle

    property color backgroundColor: checked ? "#cef" : "#fff"
    property color textColor: "#333"

    Loader {
        id: grooveLoader;
        sourceComponent: groove
        anchors.fill:parent
        property real grooveLength: item.width
    }

    Loader {
        id: handleLoader
        sourceComponent: handle
        anchors.verticalCenter:parent.verticalCenter
    }

    MouseArea {
        id: mousearea
        enabled: toggleSwitch.enabled
        hoverEnabled: true
        anchors.fill: parent

        drag.axis: Drag.XAxis
        drag.minimumX:0
        drag.maximumX:toggleSwitch.width - handleLoader.item.width
        drag.target:handleLoader.item

        onPressed: toggleSwitch.pressed = true  // needed when hover is enabled
        onEntered: if (toggleSwitch.pressed && enabled) toggleSwitch.pressed = true
        onExited: toggleSwitch.pressed = false
        onReleased: {
            if(toggleSwitch.pressed && enabled) { // No click if release outside area
                toggleSwitch.pressed = false
                checked = !checked;
            }
            if (drag.active) {
                if (handleLoader.item.x > (drag.maximumX - drag.minimumX)/2)
                    checked = true
                else
                    checked = false
            } else if (toggleSwitch.pressed && enabled) { // No click if release outside area
                toggleSwitch.pressed  = false
                checked = !checked;
                toggleSwitch.clicked()
            }
            handleLoader.item.x = checked ? drag.maximumX : drag.minimumX
            toggleSwitch.clicked()
        }
    }

    DefaultStyles.SwitchStyle { id: defaultStyle }
}
{'fraction_non_alphanumeric': 0.07459207459207459, 'fraction_numerical': 0.0029667302394575123, 'mean_word_length': 2.132050431320504, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '281134', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1151, 'n_words': 316}