diff --git a/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml b/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml index 75797fc9a..0b352310c 100644 --- a/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml +++ b/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml @@ -9,6 +9,7 @@ import QtQuick.Layouts 1.12 import org.kde.plasma.core 2.0 as PlasmaCore import QtQuick.Templates 2.12 as T +import "private" as Private /** * Item to be used as a header or footer in plasmoids @@ -39,25 +40,24 @@ import QtQuick.Templates 2.12 as T property int location: PlasmoidHeading.Location.Header Layout.fillWidth: true - bottomPadding: !headingSvg.applicationFormFactor && location == PlasmoidHeading.Location.Footer ? 0 : headingSvg.fixedMargins.bottom - topPadding: headingSvg.applicationFormFactor || location == PlasmoidHeading.Location.Footer ? headingSvg.fixedMargins.bottom : 0 - leftPadding: headingSvg.applicationFormFactor ? headingSvg.fixedMargins.left : 0 - rightPadding: headingSvg.applicationFormFactor ? headingSvg.fixedMargins.right : 0 + bottomPadding: location == PlasmoidHeading.Location.Footer ? 0 : -backgroundMetrics.getMargin("bottom") + topPadding: location == PlasmoidHeading.Location.Footer ? -backgroundMetrics.getMargin("top") : 0 + leftPadding: -backgroundMetrics.getMargin("left") + rightPadding: -backgroundMetrics.getMargin("right") implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding) implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding) - leftInset: headingSvg.applicationFormFactor ? 0 : -headingSvg.fixedMargins.left - rightInset: headingSvg.applicationFormFactor ? 0 : -headingSvg.fixedMargins.right - topInset: headingSvg.applicationFormFactor || location == PlasmoidHeading.Location.Footer ? 0 : -headingSvg.fixedMargins.top - bottomInset: !headingSvg.applicationFormFactor && location == PlasmoidHeading.Location.Footer ? -headingSvg.fixedMargins.bottom : 0 + leftInset: backgroundMetrics.getMargin("left") + rightInset: backgroundMetrics.getMargin("right") + topInset: location == PlasmoidHeading.Location.Footer ? 0 : backgroundMetrics.getMargin("top") + bottomInset: location == PlasmoidHeading.Location.Footer ? backgroundMetrics.getMargin("bottom") : 0 PlasmaCore.ColorScope.colorGroup: location == PlasmoidHeading.Location.Header ? PlasmaCore.Theme.HeaderColorGroup : PlasmaCore.Theme.WindowColorGroup PlasmaCore.ColorScope.inherit: false background: PlasmaCore.FrameSvgItem { id: headingSvg - readonly property bool applicationFormFactor: typeof plasmoid !== "undefined" && plasmoid.formFactor === PlasmaCore.Types.Application visible: fromCurrentTheme imagePath: "widgets/plasmoidheading" prefix: location == PlasmoidHeading.Location.Header? 'header' : 'footer' @@ -77,5 +77,15 @@ import QtQuick.Templates 2.12 as T } return borders } + Private.BackgroundMetrics { + id: backgroundMetrics + function getMargin(margin) { + if (!hasInset) { + return -headingSvg.fixedMargins[margin]; + } else { + return -backgroundMetrics.fixedMargins[margin] + backgroundMetrics.inset[margin] + } + } + } } } diff --git a/src/declarativeimports/plasmaextracomponents/qml/Representation.qml b/src/declarativeimports/plasmaextracomponents/qml/Representation.qml index a78645f73..8ebffc9d1 100644 --- a/src/declarativeimports/plasmaextracomponents/qml/Representation.qml +++ b/src/declarativeimports/plasmaextracomponents/qml/Representation.qml @@ -6,11 +6,11 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 -import QtQuick.Window 2.2 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaExtras +import "private" as Private /** * Item to be used as root item for representations (full and compact) of plasmoids. @@ -50,20 +50,8 @@ import org.kde.plasma.components 2.0 as PlasmaExtras topPadding: header ? 0 : backgroundMetrics.getMargin("top") bottomPadding: footer ? 0 : backgroundMetrics.getMargin("bottom") - PlasmaCore.FrameSvgItem { + Private.BackgroundMetrics { id: backgroundMetrics - visible: false - imagePath: { - if (control.Window.window && (control.Window.window instanceof PlasmaCore.Dialog)) { - return "dialogs/background"; - } else if (plasmoid.formFactor == PlasmaCore.Types.Planar) { - return "widgets/background"; - // panels and other formfactors are explicitly not supported - } else { - return ""; - } - } - readonly property bool hasInset: backgroundMetrics.inset.left >= 0 && backgroundMetrics.inset.right >= 0 && backgroundMetrics.inset.top >= 0 && backgroundMetrics.inset.bottom >= 0 function getMargin(margin) { if (!hasInset) { return 0; diff --git a/src/declarativeimports/plasmaextracomponents/qml/private/BackgroundMetrics.qml b/src/declarativeimports/plasmaextracomponents/qml/private/BackgroundMetrics.qml new file mode 100644 index 000000000..dc1931b6f --- /dev/null +++ b/src/declarativeimports/plasmaextracomponents/qml/private/BackgroundMetrics.qml @@ -0,0 +1,25 @@ +/* + SPDX-FileCopyrightText: 2020 Marco Martin + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ +import QtQuick 2.12 +import QtQuick.Window 2.2 + +import org.kde.plasma.core 2.0 as PlasmaCore + +PlasmaCore.FrameSvgItem { + id: backgroundMetrics + visible: false + imagePath: { + if (Window.window && (Window.window instanceof PlasmaCore.Dialog)) { + return "dialogs/background"; + } else if (plasmoid.formFactor == PlasmaCore.Types.Planar) { + return "widgets/background"; + // panels and other formfactors are explicitly not supported + } else { + return ""; + } + } + readonly property bool hasInset: backgroundMetrics.inset.left >= 0 && backgroundMetrics.inset.right >= 0 && backgroundMetrics.inset.top >= 0 && backgroundMetrics.inset.bottom >= 0 +} diff --git a/src/declarativeimports/plasmaextracomponents/qml/private/qmldir b/src/declarativeimports/plasmaextracomponents/qml/private/qmldir new file mode 100644 index 000000000..a2922a055 --- /dev/null +++ b/src/declarativeimports/plasmaextracomponents/qml/private/qmldir @@ -0,0 +1 @@ +BackgroundMetrics 2.0 BackgroundMetrics.qml