Add a Representation component
Add a Page-derived component intended as a root for full representations. It may go over the plasmoid edges (both on desktop and popups) with the properties applyHorizontalPadding and applyVerticalPadding. When the contentItem is a ScrollView or a Scrollarea, the plasmoid margins will be automatically removed.
This commit is contained in:
parent
f52823935c
commit
0e973e852f
@ -39,22 +39,25 @@ import QtQuick.Templates 2.12 as T
|
|||||||
property int location: PlasmoidHeading.Location.Header
|
property int location: PlasmoidHeading.Location.Header
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
bottomPadding: location == PlasmoidHeading.Location.Footer ? 0 : headingSvg.fixedMargins.top
|
bottomPadding: !headingSvg.applicationFormFactor && location == PlasmoidHeading.Location.Footer ? 0 : headingSvg.fixedMargins.bottom
|
||||||
topPadding: location == PlasmoidHeading.Location.Footer ? headingSvg.fixedMargins.bottom : 0
|
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
|
||||||
|
|
||||||
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding)
|
implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, implicitContentHeight + topPadding + bottomPadding)
|
||||||
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
|
implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
|
||||||
|
|
||||||
leftInset: -headingSvg.fixedMargins.left
|
leftInset: headingSvg.applicationFormFactor ? 0 : -headingSvg.fixedMargins.left
|
||||||
rightInset: -headingSvg.fixedMargins.right
|
rightInset: headingSvg.applicationFormFactor ? 0 : -headingSvg.fixedMargins.right
|
||||||
topInset: location == PlasmoidHeading.Location.Footer ? 0 : -headingSvg.fixedMargins.top
|
topInset: headingSvg.applicationFormFactor || location == PlasmoidHeading.Location.Footer ? 0 : -headingSvg.fixedMargins.top
|
||||||
bottomInset: location == PlasmoidHeading.Location.Footer ? -headingSvg.fixedMargins.bottom : 0
|
bottomInset: !headingSvg.applicationFormFactor && location == PlasmoidHeading.Location.Footer ? -headingSvg.fixedMargins.bottom : 0
|
||||||
|
|
||||||
PlasmaCore.ColorScope.colorGroup: location == PlasmoidHeading.Location.Header ? PlasmaCore.Theme.HeaderColorGroup : PlasmaCore.Theme.WindowColorGroup
|
PlasmaCore.ColorScope.colorGroup: location == PlasmoidHeading.Location.Header ? PlasmaCore.Theme.HeaderColorGroup : PlasmaCore.Theme.WindowColorGroup
|
||||||
PlasmaCore.ColorScope.inherit: false
|
PlasmaCore.ColorScope.inherit: false
|
||||||
|
|
||||||
background: PlasmaCore.FrameSvgItem {
|
background: PlasmaCore.FrameSvgItem {
|
||||||
id: headingSvg
|
id: headingSvg
|
||||||
|
readonly property bool applicationFormFactor: typeof plasmoid !== "undefined" && plasmoid.formFactor === PlasmaCore.Types.Application
|
||||||
visible: fromCurrentTheme
|
visible: fromCurrentTheme
|
||||||
imagePath: "widgets/plasmoidheading"
|
imagePath: "widgets/plasmoidheading"
|
||||||
prefix: location == PlasmoidHeading.Location.Header? 'header' : 'footer'
|
prefix: location == PlasmoidHeading.Location.Header? 'header' : 'footer'
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item to be used as root item for representations (full and compact) of plasmoids.
|
||||||
|
* It's a QtQuickControls2 Page, and like that one, has an header, a contentItem and a Footer
|
||||||
|
* It may go over the plasmoid edges (both on desktop and popups) with the properties applyHorizontalPadding and applyVerticalPadding.
|
||||||
|
* When the contentItem is a ScrollView or a Scrollarea, the plasmoid margins will be automatically removed.
|
||||||
|
*
|
||||||
|
* This code will create a full representation with a listview that will automatically
|
||||||
|
* full the whole area without margins from the plasmoid popup borders
|
||||||
|
* @code
|
||||||
|
* Plasmoid.Representation: PlasmaExtras.Representation {
|
||||||
|
* header: PlasmaExtras.BasicPlasmoidHeading{}
|
||||||
|
* contentItem: PlasmaComponent.ScrollView {
|
||||||
|
* ListView {
|
||||||
|
* ....
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @since 5.77
|
||||||
|
* @inherit QtQuick.Templates.Page
|
||||||
|
*/
|
||||||
|
|
||||||
|
PlasmaComponents.Page {
|
||||||
|
id: control
|
||||||
|
|
||||||
|
// TODO KF6: should become possible to set the paddings directly (which won't be negative anymore)
|
||||||
|
/**
|
||||||
|
* collapseMarginsHint: bool
|
||||||
|
* if true, the representation will remove any borders its container may have put and will be collapsed above its borders
|
||||||
|
*/
|
||||||
|
property bool collapseMarginsHint: (control.contentItem instanceof PlasmaComponents.ScrollView) || (control.contentItem instanceof ScrollArea)
|
||||||
|
|
||||||
|
leftPadding: backgroundMetrics.getMargin("left")
|
||||||
|
rightPadding: backgroundMetrics.getMargin("right")
|
||||||
|
topPadding: header ? 0 : backgroundMetrics.getMargin("top")
|
||||||
|
bottomPadding: footer ? 0 : backgroundMetrics.getMargin("bottom")
|
||||||
|
|
||||||
|
PlasmaCore.FrameSvgItem {
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
return control.collapseMarginsHint ? -backgroundMetrics.fixedMargins[margin] + backgroundMetrics.inset[margin] : 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ Title 2.0 Title.qml
|
|||||||
DescriptiveLabel 2.0 DescriptiveLabel.qml
|
DescriptiveLabel 2.0 DescriptiveLabel.qml
|
||||||
PlasmoidHeading 2.0 PlasmoidHeading.qml
|
PlasmoidHeading 2.0 PlasmoidHeading.qml
|
||||||
BasicPlasmoidHeading 2.0 BasicPlasmoidHeading.qml
|
BasicPlasmoidHeading 2.0 BasicPlasmoidHeading.qml
|
||||||
|
Representation 2.0 Representation.qml
|
||||||
|
|
||||||
ActivateAnimation 2.0 animations/ActivateAnimation.qml
|
ActivateAnimation 2.0 animations/ActivateAnimation.qml
|
||||||
AppearAnimation 2.0 animations/AppearAnimation.qml
|
AppearAnimation 2.0 animations/AppearAnimation.qml
|
||||||
|
@ -1079,6 +1079,11 @@ QObject *Dialog::margins() const
|
|||||||
return d->frameSvgItem->fixedMargins();
|
return d->frameSvgItem->fixedMargins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject *Dialog::inset() const
|
||||||
|
{
|
||||||
|
return d->frameSvgItem->inset();
|
||||||
|
}
|
||||||
|
|
||||||
void Dialog::setFramelessFlags(Qt::WindowFlags flags)
|
void Dialog::setFramelessFlags(Qt::WindowFlags flags)
|
||||||
{
|
{
|
||||||
if (d->type == Dialog::Normal)
|
if (d->type == Dialog::Normal)
|
||||||
|
@ -89,6 +89,13 @@ class PLASMAQUICK_EXPORT Dialog : public QQuickWindow, public QQmlParserStatus
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(QObject *margins READ margins CONSTANT)
|
Q_PROPERTY(QObject *margins READ margins CONSTANT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Margins where the dialog background actually starts, excluiding things like shadows or borders
|
||||||
|
* @see DialogMargins
|
||||||
|
* @since 5.77
|
||||||
|
*/
|
||||||
|
Q_PROPERTY(QObject *inset READ inset CONSTANT)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plasma Location of the dialog window. Useful if this dialog is a popup for a panel
|
* Plasma Location of the dialog window. Useful if this dialog is a popup for a panel
|
||||||
*/
|
*/
|
||||||
@ -170,6 +177,7 @@ public:
|
|||||||
void setLocation(Plasma::Types::Location location);
|
void setLocation(Plasma::Types::Location location);
|
||||||
|
|
||||||
QObject *margins() const;
|
QObject *margins() const;
|
||||||
|
QObject *inset() const;
|
||||||
|
|
||||||
void setFramelessFlags(Qt::WindowFlags flags);
|
void setFramelessFlags(Qt::WindowFlags flags);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user