From 33882e4886b26b7cadbb28c56055e6ac128d6479 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 26 Aug 2021 17:04:22 +0200 Subject: [PATCH 1/2] Avoid creating then immediately discarding a page's ActionButton instance During page creation, the globalToolBarStyle property may not yet be properly initialised, which means we load and create ActionButton, then almost immediately afterwards discard it again once we know for sure we're using the ToolBar style. This also unfolds the binding for "actionButtons.active" since it was really hard to follow. --- src/controls/Page.qml | 45 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/controls/Page.qml b/src/controls/Page.qml index 7dd90177b..105b5d828 100644 --- a/src/controls/Page.qml +++ b/src/controls/Page.qml @@ -330,6 +330,7 @@ QQC2.Page { headerChanged(); parentChanged(root.parent); globalToolBar.syncSource(); + actionButtons.pageComplete = true } onParentChanged: { @@ -427,12 +428,44 @@ QQC2.Page { //It should be T2.Page, Qt 5.7 doesn't like it property Item page: root height: item ? item.implicitHeight : 0 - active: typeof applicationWindow !== "undefined" && (!globalToolBar.row || root.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.ToolBar) && - root.actions && (root.actions.main || root.actions.left || root.actions.right || root.actions.contextualActions.length) && - //Legacy - (typeof applicationWindow === "undefined" || - (!applicationWindow().header || applicationWindow().header.toString().indexOf("ToolBarApplicationHeader") === -1) && - (!applicationWindow().footer || applicationWindow().footer.toString().indexOf("ToolBarApplicationHeader") === -1)) + + property bool pageComplete: false + + active: { + // Important! Do not do anything until the page has been + // completed, so we are sure what the globalToolBarStyle is, + // otherwise we risk creating the content and then discarding it. + if (!pageComplete) { + return false; + } + + // Note: Do not use root.globalToolBarStyle here as it is + // evaluated too late and will cause active to be true for a + // brief period, triggering the loading process. + if (globalToolBar.row.globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.ToolBar) { + return false; + } + + if (!root.actions.main && !root.actions.left && !root.actions.right && root.actions.contextualActions.length == 0) { + return false; + } + + // Legacy + if (typeof applicationWindow === "undefined") { + return true; + } + + if (applicationWindow().header && applicationWindow().header.toString().indexOf("ToolBarApplicationHeader") !== -1) { + return false; + } + + if (applicationWindow().footer && applicationWindow().footer.toString().indexOf("ToolBarApplicationHeader") !== -1) { + return false; + } + + return true; + } + source: Qt.resolvedUrl("./private/ActionButton.qml") } ] -- GitLab From 0cddf386d6a9334d1e70f0f7dfff99d9ac9bbdb2 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 26 Aug 2021 17:19:53 +0200 Subject: [PATCH 2/2] Don't use DropShadow for overlay drawer handles There's no need for DropShadow here, we can replace the background rectangle with ShadowedRectangle and get shadows for "free". --- src/controls/OverlayDrawer.qml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/controls/OverlayDrawer.qml b/src/controls/OverlayDrawer.qml index b6f5cf9d7..df04e3816 100644 --- a/src/controls/OverlayDrawer.qml +++ b/src/controls/OverlayDrawer.qml @@ -7,7 +7,7 @@ import QtQuick 2.1 import QtGraphicalEffects 1.0 import QtQuick.Templates 2.0 as T2 -import org.kde.kirigami 2.5 +import org.kde.kirigami 2.15 import "private" import "templates" as T @@ -43,17 +43,7 @@ T.OverlayDrawer { parent: root.handle anchors.fill: parent - DropShadow { - anchors.fill: handleGraphics - visible: !parent.parent.handleAnchor || !parent.parent.handleAnchor.visible || root.handle.pressed || (root.modal && root.position > 0) - horizontalOffset: 0 - verticalOffset: Units.devicePixelRatio - radius: Units.gridUnit /2 - samples: 16 - color: Qt.rgba(0, 0, 0, root.handle.pressed ? 0.6 : 0.4) - source: handleGraphics - } - Rectangle { + ShadowedRectangle { id: handleGraphics anchors.centerIn: parent @@ -66,7 +56,11 @@ T.OverlayDrawer { Theme.inherit: false color: root.handle.pressed ? Theme.highlightColor : Theme.backgroundColor - visible: !parent.parent.handleAnchor || !parent.parent.handleAnchor.visible + visible: !parent.parent.handleAnchor || !parent.parent.handleAnchor.visible || root.handle.pressed || (root.modal && root.position > 0) + + shadow.color: Qt.rgba(0, 0, 0, root.handle.pressed ? 0.6 : 0.4) + shadow.yOffset: 1 + shadow.size: Units.gridUnit / 2 width: Units.iconSizes.smallMedium + Units.smallSpacing * 2 height: width -- GitLab