diff --git a/src/controls/ScrollablePage.qml b/src/controls/ScrollablePage.qml index 1fdc72ea..9e8b4d12 100644 --- a/src/controls/ScrollablePage.qml +++ b/src/controls/ScrollablePage.qml @@ -1,185 +1,185 @@ /* * Copyright 2015 Marco Martin * * 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.4 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 * * Another behavior added by this class is a "scroll down to refresh" behavior * It also can give the contents of the flickable to have more top margins in order * to make possible to scroll down the list to reach it with the thumb while using the * phone with a single hand. * * Implementations should handle the refresh themselves as follows * * @code * Kirigami.ScrollablePage { * id: view * supportsRefreshing: true * onRefreshingChanged: { * if (refreshing) { * myModel.refresh(); * } * } * ListView { * //NOTE: MyModel doesn't come from the components, * //it's purely an example on how it can be used together * //some application logic that can update the list model * //and signals when it's done. * model: MyModel { * onRefreshDone: view.refreshing = false; * } * delegate: BasicListItem {} * } * } * [...] * @endcode * */ 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 /** * verticalScrollBarPolicy: Qt.ScrollBarPolicy * The vertical scrollbar policy */ property alias verticalScrollBarPolicy: scrollView.verticalScrollBarPolicy /** * horizontalScrollBarPolicy: Qt.ScrollBarPolicy * The horizontal scrollbar policy */ property alias horizontalScrollBarPolicy: scrollView.horizontalScrollBarPolicy /** * 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 Theme.colorSet: flickable && flickable.hasOwnProperty("model") ? Theme.View : Theme.Window clip: true contentItem: RefreshableScrollView { id: scrollView //NOTE: here to not expose it to public api property QtObject oldMainItem page: root clip: false topPadding: contentItem == flickableItem ? 0 : root.topPadding leftPadding: root.leftPadding rightPadding: root.rightPadding bottomPadding: contentItem == flickableItem ? 0 : root.bottomPadding anchors { top: root.header ? root.header.bottom //FIXME: for nowassuming globalToolBarItem is in a Loader, which needs to be got rid of - : (root.globalToolBarItem && globalToolBarItem.visible ? + : (globalToolBarItem && globalToolBarItem.parent && globalToolBarItem.visible ? globalToolBarItem.parent.bottom : parent.top) bottom: root.footer ? root.footer.top : parent.bottom left: parent.left right: parent.right } } anchors.topMargin: 0 Keys.forwardTo: root.keyboardNavigationEnabled && root.flickable ? (("currentItem" in root.flickable) && root.flickable.currentItem ? [ root.flickable.currentItem, root.flickable ] : [ root.flickable ]) : [] //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; //reparent sheets } else if (mainItem.hasOwnProperty("sheetOpen")) { if (mainItem.parent == root || mainItem.parent == null) { mainItem.parent = root; } root.data.push(mainItem); return; } if (scrollView.oldMainItem && scrollView.oldMainItem.hasOwnProperty("parent") && scrollView.oldMainItem.parent != applicationWindow().overlay) { scrollView.oldMainItem.parent = overlay } scrollView.oldMainItem = mainItem } } diff --git a/src/controls/private/PrivateActionToolButton.qml b/src/controls/private/PrivateActionToolButton.qml index 3d7f6169..d9851176 100644 --- a/src/controls/private/PrivateActionToolButton.qml +++ b/src/controls/private/PrivateActionToolButton.qml @@ -1,117 +1,117 @@ /* * Copyright 2016 Marco Martin * * 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.6 import QtQuick.Layouts 1.2 import QtQuick.Controls 2.0 as Controls import org.kde.kirigami 2.4 Controls.ToolButton { id: control implicitWidth: menuArrow.visible || (showText && ( kirigamiAction ? kirigamiAction.text.length > 0 : text.length > 0)) ? Math.max(layout.implicitWidth + Units.largeSpacing*2, background.implicitWidth) : implicitHeight implicitHeight: background.implicitHeight Theme.colorSet: Theme.Button Theme.inherit: kirigamiAction && kirigamiAction.icon.color.a === 0 Theme.backgroundColor: kirigamiAction && kirigamiAction.icon.color.a ? kirigamiAction.icon.color : undefined Theme.textColor: kirigamiAction && !flat && kirigamiAction.icon.color.a ? Theme.highlightedTextColor : undefined hoverEnabled: true flat: true //TODO: replace with upstream action when we depend on Qt 5.10 property Action kirigamiAction property bool showText: true property bool showMenuArrow: true //we need our own text delegate text: "" checkable: kirigamiAction && kirigamiAction.checkable checked: (kirigamiAction && kirigamiAction.checked) || menu.visible enabled: kirigamiAction && kirigamiAction.enabled opacity: enabled ? 1 : 0.4 visible: kirigamiAction && kirigamiAction.visible onClicked: { if (kirigamiAction) { kirigamiAction.trigger(); } //fallbacks needed for Qt 5.9 if (kirigamiAction.children.length > 0 && !menu.visible) { if (menu.hasOwnProperty("popup")) { menu.popup(control, 0, control.height) } else { menu.visible = true; } } } ActionsMenu { id: menu y: control.height - actions: control.kirigamiAction ? control.kirigamiAction.children : "" + actions: control.kirigamiAction ? control.kirigamiAction.children : null submenuComponent: Component { ActionsMenu {} } } contentItem: MouseArea { hoverEnabled: true onPressed: mouse.accepted = false Theme.colorSet: checked && (!control.flat && control.kirigamiAction && control.kirigamiAction.icon.color.a) ? Theme.Selection : control.Theme.colorSet Theme.inherit: control.kirigamiAction && Theme.colorSet != Theme.Selection && control.kirigamiAction.icon.color.a == 0 RowLayout { id: layout anchors.centerIn: parent Icon { id: mainIcon Layout.minimumWidth: Units.iconSizes.smallMedium Layout.minimumHeight: Units.iconSizes.smallMedium source: control.kirigamiAction ? (control.kirigamiAction.icon ? control.kirigamiAction.icon.name : control.kirigamiAction.iconName) : "" visible: control.kirigamiAction && control.kirigamiAction.iconName != "" color: control.flat && control.kirigamiAction && control.kirigamiAction.icon && control.kirigamiAction.icon.color.a > 0 ? control.kirigamiAction.icon.color : label.color } Controls.Label { id: label MnemonicData.enabled: control.enabled MnemonicData.controlType: MnemonicData.ActionElement MnemonicData.label: control.kirigamiAction ? control.kirigamiAction.text : "" text: MnemonicData.richTextLabel visible: control.showText && text.length > 0 } Icon { id: menuArrow Layout.minimumWidth: Units.iconSizes.small Layout.minimumHeight: Units.iconSizes.small source: "arrow-down" visible: showMenuArrow && menu.actions && menu.actions.length > 0 } } } Controls.ToolTip { visible: control.hovered && text.length > 0 text: kirigamiAction ? (kirigamiAction.tooltip.length ? kirigamiAction.tooltip : kirigamiAction.text) : "" delay: 1000 timeout: 5000 y: control.height } }