[PlasmoidHeading] Use technique from Representation for inset/margins

This commit is contained in:
Mikel Johnson 2020-12-03 14:59:49 +00:00
parent da6b8c10c1
commit 479c90137f
4 changed files with 47 additions and 23 deletions

View File

@ -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]
}
}
}
}
}

View File

@ -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;

View File

@ -0,0 +1,25 @@
/*
SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
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
}

View File

@ -0,0 +1 @@
BackgroundMetrics 2.0 BackgroundMetrics.qml