Commit 2d0ca74d authored by Niccolò Venerandi's avatar Niccolò Venerandi
Browse files

Make panel containment apply margin instead of panel view based on applet preference.

parent 16b5f74d
......@@ -50,6 +50,13 @@ DragDrop.DropArea {
property int fixedWidth: 0
property int fixedHeight: 0
// This is invisible and only used to read panel margins
PlasmaCore.FrameSvgItem {
id: panelSvg
visible: false
imagePath: "widgets/panel-background"
}
//END properties
//BEGIN functions
......@@ -272,14 +279,26 @@ function checkLastSpacer() {
}
}
Layout.minimumWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.minimumWidth > 0 ? applet.Layout.minimumWidth : root.height) : root.width)
Layout.minimumHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.minimumHeight > 0 ? applet.Layout.minimumHeight : root.width) : root.height)
//Margins are either the size of the margins in the SVG, unless that prevents the panel from being at least half a smallMedium icon + smallSpace) tall at which point we set the margin to whatever allows it to be that...or if it still won't fit, 1.
//the size a margin should be to force a panel to be the required size above
readonly property real spacingAtMinSize: Math.max(1, (currentLayout.isLayoutHorizontal ? root.height+panelSvg.fixedMargins.top*2 : root.width+panelSvg.fixedMargins.left*2) - units.iconSizes.smallMedium - units.smallSpacing*2)/2
readonly property bool fillArea: applet && (applet.constraintHints & PlasmaCore.Types.CanFillArea)
Layout.topMargin: (currentLayout.isLayoutHorizontal && !fillArea) ?Math.round(Math.min(spacingAtMinSize, panelSvg.fixedMargins.top)) : 0
Layout.bottomMargin: (currentLayout.isLayoutHorizontal && !fillArea) ? Math.round(Math.min(spacingAtMinSize, panelSvg.fixedMargins.bottom)) : 0
Layout.leftMargin: (!currentLayout.isLayoutHorizontal && !fillArea) ? Math.round(Math.min(spacingAtMinSize, panelSvg.fixedMargins.left)) : 0
Layout.rightMargin: (!currentLayout.isLayoutHorizontal && !fillArea) ? Math.round(Math.min(spacingAtMinSize, panelSvg.fixedMargins.right)) : 0
Layout.minimumWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.minimumWidth > 0 ? applet.Layout.minimumWidth : root.height) : root.width) - Layout.leftMargin - Layout.rightMargin
Layout.minimumHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.minimumHeight > 0 ? applet.Layout.minimumHeight : root.width) : root.height) - Layout.bottomMargin - Layout.topMargin
Layout.preferredWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.preferredWidth > 0 ? applet.Layout.preferredWidth : root.height) : root.width)
Layout.preferredHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.preferredHeight > 0 ? applet.Layout.preferredHeight : root.width) : root.height)
Layout.preferredWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.preferredWidth > 0 ? applet.Layout.preferredWidth : root.height) : root.width) - Layout.leftMargin - Layout.rightMargin
Layout.preferredHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.preferredHeight > 0 ? applet.Layout.preferredHeight : root.width) : root.height) - Layout.bottomMargin - Layout.topMargin
Layout.maximumWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.maximumWidth > 0 ? applet.Layout.maximumWidth : (Layout.fillWidth ? root.width : root.height)) : root.height) - Layout.leftMargin - Layout.rightMargin
Layout.maximumHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.maximumHeight > 0 ? applet.Layout.maximumHeight : (Layout.fillHeight ? root.height : root.width)) : root.width) - Layout.bottomMargin - Layout.topMargin
Layout.maximumWidth: (currentLayout.isLayoutHorizontal ? (applet && applet.Layout.maximumWidth > 0 ? applet.Layout.maximumWidth : (Layout.fillWidth ? root.width : root.height)) : root.height)
Layout.maximumHeight: (!currentLayout.isLayoutHorizontal ? (applet && applet.Layout.maximumHeight > 0 ? applet.Layout.maximumHeight : (Layout.fillHeight ? root.height : root.width)) : root.width)
property int oldX: x
property int oldY: y
......@@ -346,6 +365,14 @@ function checkLastSpacer() {
//END components
//BEGIN UI elements
anchors {
leftMargin: currentLayout.isLayoutHorizontal ? panelSvg.fixedMargins.left : 0
rightMargin: currentLayout.isLayoutHorizontal ? panelSvg.fixedMargins.right : 0
topMargin: currentLayout.isLayoutHorizontal ? 0 : panelSvg.fixedMargins.top
bottomMargin: currentLayout.isLayoutHorizontal ? 0 : panelSvg.fixedMargins.bottom
}
Item {
id: lastSpacer
parent: currentLayout
......
......@@ -34,6 +34,12 @@ PlasmaCore.FrameSvgItem {
readonly property bool verticalPanel: containment && containment.formFactor === PlasmaCore.Types.Vertical
readonly property real spacingAtMinSize: Math.max(1, (verticalPanel ? root.width : root.height) - PlasmaCore.Units.iconSizes.smallMedium - PlasmaCore.Units.smallSpacing*2)/2
readonly property int topPadding: Math.round(Math.min(root.fixedMargins.top, spacingAtMinSize));
readonly property int bottomPadding: Math.round(Math.min(root.fixedMargins.bottom, spacingAtMinSize));
readonly property int leftPadding: Math.round(Math.min(root.fixedMargins.left, spacingAtMinSize));
readonly property int rightPadding: Math.round(Math.min(root.fixedMargins.right, spacingAtMinSize));
function adjustPrefix() {
if (!containment) {
return "";
......@@ -97,24 +103,10 @@ PlasmaCore.FrameSvgItem {
return containment.backgroundHints;
}
}
}
Item {
id: containmentParent
anchors {
fill: parent
//Margins are either the size of the margins in the SVG, unless that prevents the panel from being at least half a smallMedium icon + smallSpace) tall at which point we set the margin to whatever allows it to be that...or if it still won't fit, 1.
//the size a margin should be to force a panel to be the required size above
readonly property real spacingAtMinSize: Math.max(1, (verticalPanel ? root.width : root.height) - PlasmaCore.Units.iconSizes.smallMedium - PlasmaCore.Units.smallSpacing*2)/2
topMargin: Math.round(Math.min(root.fixedMargins.top, spacingAtMinSize));
bottomMargin: Math.round(Math.min(root.fixedMargins.bottom, spacingAtMinSize));
//Base the left/right fixedMargins on height as well, to have a good radial symmetry
leftMargin: Math.round(Math.min(root.fixedMargins.left, spacingAtMinSize));
rightMargin: Math.round(Math.min(root.fixedMargins.right, spacingAtMinSize));
}
anchors.fill: parent
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment