<commit_before>/*
 *   Copyright 2015 <NAME> <<EMAIL>>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.1
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.0
import "private"

/**
 * ScrollablePage is a container for all the app pages: everything pushed to the
 * ApplicationWindow stackView should be a Page or ScrollablePage instabnce.
 * This Page subclass is for content that has to be scrolled around, such as
 * bigger content than the screen that would normally go in a Flickable
 * or a ListView.
 * Scrolling and scrolling indicators will be automatically managed
 *
 *
 * @code
 * ScrollablePage {
 *     id: root
 *     //The rectangle will automatically bescrollable
 *     Rectangle {
 *         width: root.width
 *         height: 99999
 *     }
 * }
 * @endcode
 *
 * @code
 * ScrollablePage {
 *     id: root
 *
 *     //support for the popular "pull down to refresh" behavior in mobile apps
 *     supportsRefreshing: true
 *
 *     //The ListView will automatically receive proper scroll indicators
 *     ListView {
 *         model: myModel
 *         delegate: BasicListItem { ... }
 *     }
 * }
 * @endcode
 *
 * @inherit Page
 */
Page {
    id: root

    /**
     * refreshing: bool
     * If true the list is asking for refresh and will show a loading spinner.
     * it will automatically be set to true when the user pulls down enough the list.
     * This signals the application logic to start its refresh procedure.
     * The application itself will have to set back this property to false when done.
     */
    property alias refreshing: scrollView.refreshing

    /**
     * supportsRefreshing: bool
     * If true the list supports the "pull down to refresh" behavior.
     * default is false.
     */
    property alias supportsRefreshing: scrollView.supportsRefreshing

    /**
     * flickable: Flickable
     * The main Flickable item of this page
     */
    property alias flickable: scrollView.flickableItem

    /**
     * The main content Item of this page.
     * In the case of a ListView or GridView, both contentItem and flickable
     * will be a pointer to the ListView (or GridView)
     * NOTE: can't be contentItem as Page's contentItem is final
     */
    default property QtObject mainItem

    /**
     * keyboardNavigationEnabled: bool
     * If true, and if flickable is an item view, like a ListView or
     * a GridView, it will be possible to navigate the list current item
     * to next and previous items with keyboard up/down arrow buttons.
     * Also, any key event will be forwarded to the current list item.
     * default is true.
     */
    property bool keyboardNavigationEnabled: true

    RefreshableScrollView {
        id: scrollView
        z: 0
        //child of root as it shouldn't have margins
        parent: root
        topPadding: (applicationWindow() && applicationWindow().header ? applicationWindow().header.preferredHeight : 0) + (contentItem == flickable ? 0 : root.topPadding)
        leftPadding: contentItem == flickable ? 0 : root.leftPadding
        rightPadding: contentItem == flickable ? 0 : root.rightPadding
        bottomPadding: contentItem == flickable ? 0 : root.bottomPadding
        anchors {
            fill: parent
            topMargin: root.header ? root.header.height : 0
        }
    }

    anchors.topMargin: 0

    Keys.onUpPressed: {
        if (root.keyboardNavigationEnabled && root.flickable.decrementCurrentIndex) {
            root.flickable.decrementCurrentIndex()
        }
    }
    Keys.onDownPressed: {
        if (root.keyboardNavigationEnabled && root.flickable.incrementCurrentIndex) {
            root.flickable.incrementCurrentIndex()
        }
    }
    Keys.forwardTo: root.keyboardNavigationEnabled && ("currentItem" in root.flickable) ? [ root.flickable.currentItem ] : []
    Item {
        id: overlay
        parent: root
        z: 9998
        anchors.fill: parent
        property QtObject oldMainItem
    }

    //HACK to get the mainItem as the last one, all the other eventual items as an overlay
    //no idea if is the way the user expects
    onMainItemChanged: {
         if (mainItem.hasOwnProperty("anchors")) {
             scrollView.contentItem = mainItem
         //don't try to reparent drawers
         } else if (mainItem.hasOwnProperty("dragMargin")) {
             return;
         }
         if (overlay.oldMainItem && overlay.oldMainItem.parent != applicationWindow().overlay) {
             overlay.oldMainItem.parent = overlay
         }
         overlay.oldMainItem = mainItem
    }
}<commit_msg>don't try to reparent if parent prop doesn't exists<commit_after>/*
 *   Copyright 2015 <NAME> <<EMAIL>>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.1
import QtQuick.Layouts 1.2
import org.kde.kirigami 2.0
import "private"

/**
 * ScrollablePage is a container for all the app pages: everything pushed to the
 * ApplicationWindow stackView should be a Page or ScrollablePage instabnce.
 * This Page subclass is for content that has to be scrolled around, such as
 * bigger content than the screen that would normally go in a Flickable
 * or a ListView.
 * Scrolling and scrolling indicators will be automatically managed
 *
 *
 * @code
 * ScrollablePage {
 *     id: root
 *     //The rectangle will automatically bescrollable
 *     Rectangle {
 *         width: root.width
 *         height: 99999
 *     }
 * }
 * @endcode
 *
 * @code
 * ScrollablePage {
 *     id: root
 *
 *     //support for the popular "pull down to refresh" behavior in mobile apps
 *     supportsRefreshing: true
 *
 *     //The ListView will automatically receive proper scroll indicators
 *     ListView {
 *         model: myModel
 *         delegate: BasicListItem { ... }
 *     }
 * }
 * @endcode
 *
 * @inherit Page
 */
Page {
    id: root

    /**
     * refreshing: bool
     * If true the list is asking for refresh and will show a loading spinner.
     * it will automatically be set to true when the user pulls down enough the list.
     * This signals the application logic to start its refresh procedure.
     * The application itself will have to set back this property to false when done.
     */
    property alias refreshing: scrollView.refreshing

    /**
     * supportsRefreshing: bool
     * If true the list supports the "pull down to refresh" behavior.
     * default is false.
     */
    property alias supportsRefreshing: scrollView.supportsRefreshing

    /**
     * flickable: Flickable
     * The main Flickable item of this page
     */
    property alias flickable: scrollView.flickableItem

    /**
     * The main content Item of this page.
     * In the case of a ListView or GridView, both contentItem and flickable
     * will be a pointer to the ListView (or GridView)
     * NOTE: can't be contentItem as Page's contentItem is final
     */
    default property QtObject mainItem

    /**
     * keyboardNavigationEnabled: bool
     * If true, and if flickable is an item view, like a ListView or
     * a GridView, it will be possible to navigate the list current item
     * to next and previous items with keyboard up/down arrow buttons.
     * Also, any key event will be forwarded to the current list item.
     * default is true.
     */
    property bool keyboardNavigationEnabled: true

    RefreshableScrollView {
        id: scrollView
        z: 0
        //child of root as it shouldn't have margins
        parent: root
        topPadding: (applicationWindow() && applicationWindow().header ? applicationWindow().header.preferredHeight : 0) + (contentItem == flickable ? 0 : root.topPadding)
        leftPadding: contentItem == flickable ? 0 : root.leftPadding
        rightPadding: contentItem == flickable ? 0 : root.rightPadding
        bottomPadding: contentItem == flickable ? 0 : root.bottomPadding
        anchors {
            fill: parent
            topMargin: root.header ? root.header.height : 0
        }
    }

    anchors.topMargin: 0

    Keys.onUpPressed: {
        if (root.keyboardNavigationEnabled && root.flickable.decrementCurrentIndex) {
            root.flickable.decrementCurrentIndex()
        }
    }
    Keys.onDownPressed: {
        if (root.keyboardNavigationEnabled && root.flickable.incrementCurrentIndex) {
            root.flickable.incrementCurrentIndex()
        }
    }
    Keys.forwardTo: root.keyboardNavigationEnabled && ("currentItem" in root.flickable) ? [ root.flickable.currentItem ] : []
    Item {
        id: overlay
        parent: root
        z: 9998
        anchors.fill: parent
        property QtObject oldMainItem
    }

    //HACK to get the mainItem as the last one, all the other eventual items as an overlay
    //no idea if is the way the user expects
    onMainItemChanged: {
         if (mainItem.hasOwnProperty("anchors")) {
             scrollView.contentItem = mainItem
         //don't try to reparent drawers
         } else if (mainItem.hasOwnProperty("dragMargin")) {
             return;
         }
         if (overlay.oldMainItem && overlay.oldMainItem.hasOwnProperty("parent") && overlay.oldMainItem.parent != applicationWindow().overlay) {
             overlay.oldMainItem.parent = overlay
         }
         overlay.oldMainItem = mainItem
    }
}
{'fraction_non_alphanumeric': 0.07376895712413406, 'fraction_numerical': 0.007302003370155402, 'mean_word_length': 2.5645645645645647, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3287420', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2801, 'n_words': 1115}