diff --git a/src/controls/AbstractItemViewHeader.qml b/src/controls/AbstractItemViewHeader.qml index c0d69c75..a3ce201f 100644 --- a/src/controls/AbstractItemViewHeader.qml +++ b/src/controls/AbstractItemViewHeader.qml @@ -1,45 +1,47 @@ /* * Copyright 2017 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.5 import QtQuick.Templates 2.0 as T2 import org.kde.kirigami 2.0 as Kirigami /** * An item that can be used as an header for a ListView. * It will play nice with the margin policies of ScrollablePage and can * automatically shrink when the list is scrolled, like the behavior * of list headers in many mobile applications. * @since 2.1 */ T2.Control { property int minimumHeight: Kirigami.Units.gridUnit * 2 + Kirigami.Units.smallSpacing * 2 property int maximumHeight: Kirigami.Units.gridUnit * 6 - property Flickable view: ListView.view + property ListView view: ListView.view - width: page.width + width: view.width - implicitHeight: Math.min(maximumHeight, Math.max(minimumHeight, -page.flickable.contentY - (view.headerPositioning == ListView.InlineHeader ? minimumHeight : 0) + minimumHeight)) + topPadding + bottomPadding + implicitHeight: topPadding + bottomPadding + (view.headerPositioning == ListView.InlineHeader + ? maximumHeight + : Math.min(maximumHeight, Math.max(minimumHeight, maximumHeight - Math.max(0, view.contentY)))) z: 9 topPadding: applicationWindow() && !applicationWindow().wideScreen && applicationWindow().header ? applicationWindow().header.paintedHeight : 0 rightPadding: Kirigami.Units.gridUnit } diff --git a/src/controls/ItemViewHeader.qml b/src/controls/ItemViewHeader.qml index c5739070..a3a525ec 100644 --- a/src/controls/ItemViewHeader.qml +++ b/src/controls/ItemViewHeader.qml @@ -1,113 +1,114 @@ /* * Copyright 2017 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.5 import QtQuick.Templates 2.0 as T2 import QtGraphicalEffects 1.0 import org.kde.kirigami 2.1 as Kirigami import "private" /** * An item that can be used as an header for a ListView. * It will play nice with the margin policies of ScrollablePage and can * automatically shrink when the list is scrolled, like the behavior * of list headers in many mobile applications. * It provides some default content: a title and an optional background image * @since 2.1 */ Kirigami.AbstractItemViewHeader { id: root property alias title: heading.text property alias color: heading.color property alias backgroundImage: image - maximumHeight: (backgroundImage.status == Image.Ready ? 10 : 6) * Kirigami.Units.gridUnit + maximumHeight: (backgroundImage.status == Image.Ready || backgroundImage.status == Image.Loading ? 10 : 6) * Kirigami.Units.gridUnit background: Rectangle { + id: backgroundItem color: Kirigami.Theme.backgroundColor Image { id: image anchors { fill: parent bottomMargin: rect.height } fillMode: Image.PreserveAspectCrop asynchronous: true } EdgeShadow { edge: root.view.headerPositioning == ListView.InlineHeader ? Qt.BottomEdge : Qt.TopEdge anchors { right: parent.right left: parent.left top: root.view.headerPositioning == ListView.InlineHeader ? undefined : parent.bottom bottom: root.view.headerPositioning == ListView.InlineHeader ? parent.top : undefined } } - property Page page: { + readonly property Page page: { var obj = root.view; while(obj && !obj.hasOwnProperty("title") && !obj.hasOwnProperty("isCurrentPage")) { obj = obj.parent } return obj; } Rectangle { id: rect - color: page.isCurrentPage ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor + color: backgroundItem.page.isCurrentPage ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor height: Kirigami.Units.smallSpacing anchors { left: parent.left right: parent.right bottom: parent.bottom } } } contentItem: Item { Kirigami.Heading { id: heading anchors { fill: parent margins: Kirigami.Units.smallSpacing } height: undefined text: page.title fontSizeMode: Text.Fit minimumPointSize: 10 font.pointSize: 30 horizontalAlignment: Text.AlignRight verticalAlignment: Text.AlignBottom color: root.backgroundImage.status === Image.Ready ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.highlightColor opacity: 1 elide: Text.ElideRight layer.enabled: root.backgroundImage.status === Image.Ready layer.effect: DropShadow { horizontalOffset: 0 verticalOffset: 2 radius: Kirigami.Units.smallSpacing*2 samples: 32 color: Qt.rgba(0, 0, 0, 0.7) } } } }