From 7d80f01c31626979d78d35f084b5c3ab036289a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Venerandi?= Date: Thu, 27 Feb 2020 11:31:45 +0100 Subject: [PATCH] WIP: Create a new TopArea element using widgets/toparea svg Summary: This creates a new component that uses the widgets/toparea svg. First time I try to add something to PlasmaComponents, so I probably got stuff wrong and I probably have to still do thing like adding documentation. I'm creating the diff to get feedback on how to move forward with this. Depends on D27444 Reviewers: mart, ngraham Reviewed By: mart, ngraham Subscribers: ngraham, davidedmundson, ahiemstra, kde-frameworks-devel Tags: #frameworks Maniphest Tasks: T10470 Differential Revision: https://phabricator.kde.org/D27695 --- .../qml/PlasmoidHeading.qml | 83 +++++++++++++++++++ .../plasmaextracomponents/qml/qmldir | 1 + 2 files changed, 84 insertions(+) create mode 100644 src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml diff --git a/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml b/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml new file mode 100644 index 000000000..9d59dcca8 --- /dev/null +++ b/src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml @@ -0,0 +1,83 @@ +/* + * Copyright 2020 Niccolò Venerandi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.12 +import QtQuick.Layouts 1.12 + +import org.kde.plasma.core 2.0 as PlasmaCore +import QtQuick.Templates 2.12 as T + + /** + * Item to be used as a header or footer in plasmoids + * + * @inherit QtQuick.Templates.Frame + */ + T.Frame { + + /** + * Possible positions of the heading element + */ + enum Location { + /** + * Indicates that it's used as a header of the plasmoid, touching the top border + */ + Header, + /** + * Indicates that it's used as a footer of the plasmoid, touching the bottom border + */ + Footer + } + + /** + * location: int + * + * Indicates the position of the heading. The default is PlasmoidHeading.Location.Header. + */ + property int location: PlasmoidHeading.Location.Header + + Layout.fillWidth: true + bottomPadding: location == PlasmoidHeading.Location.Footer ? 0 : headingSvg.margins.top + topPadding: location == PlasmoidHeading.Location.Footer ? headingSvg.margins.bottom : 0 + + implicitHeight: contentHeight + topPadding + bottomPadding + contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) + + leftInset: -headingSvg.fixedMargins.left + rightInset: -headingSvg.fixedMargins.right + topInset: location == PlasmoidHeading.Location.Footer ? 0 : -headingSvg.margins.top + bottomInset: location == PlasmoidHeading.Location.Footer ? -headingSvg.fixedMargins.bottom : 0 + + background: PlasmaCore.FrameSvgItem { + id: headingSvg + imagePath: "widgets/plasmoidheading" + prefix: location == PlasmoidHeading.Location.Header? 'header' : 'footer' + enabledBorders: { + var borders = new Array() + borders |= PlasmaCore.FrameSvg.LeftBorder + borders |= PlasmaCore.FrameSvg.RightBorder + if (plasmoid.location !== PlasmaCore.Types.TopEdge || location != PlasmoidHeading.Location.Header) { + borders |= PlasmaCore.FrameSvg.TopBorder + } + if (plasmoid.location !== PlasmaCore.Types.BottomEdge || location != PlasmoidHeading.Location.Footer) { + borders |= PlasmaCore.FrameSvg.BottomBorder + } + return borders + } + } + } diff --git a/src/declarativeimports/plasmaextracomponents/qml/qmldir b/src/declarativeimports/plasmaextracomponents/qml/qmldir index 61cf7c672..0ee22d6dc 100644 --- a/src/declarativeimports/plasmaextracomponents/qml/qmldir +++ b/src/declarativeimports/plasmaextracomponents/qml/qmldir @@ -9,6 +9,7 @@ PageRow 2.0 PageRow.qml ScrollArea 2.0 ScrollArea.qml Title 2.0 Title.qml DescriptiveLabel 2.0 DescriptiveLabel.qml +PlasmoidHeading 2.0 PlasmoidHeading.qml ActivateAnimation 2.0 animations/ActivateAnimation.qml AppearAnimation 2.0 animations/AppearAnimation.qml