Libplasma

Representation.qml
1/*
2 SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9
10import org.kde.plasma.components as PlasmaComponents
11
12/**
13 * Item to be used as root item for representations (full and compact) of plasmoids.
14 * It's a QtQuickControls2 Page, and like that one, has an header, a contentItem and a Footer
15 * It may go over the plasmoid edges (both on desktop and popups) with the properties applyHorizontalPadding and applyVerticalPadding.
16 * When the contentItem is a ScrollView or a Scrollarea, the plasmoid margins will be automatically removed.
17 *
18 * This code will create a full representation with a listview that will automatically
19 * fill the whole area without margins from the plasmoid popup borders
20 * @code{.qml}
21 * Plasmoid.Representation: PlasmaExtras.Representation {
22 * header: PlasmaExtras.BasicPlasmoidHeading {}
23 * contentItem: PlasmaComponent.ScrollView {
24 * ListView {
25 * // ...
26 * }
27 * }
28 * }
29 * @endcode
30 *
31 * @since 5.77
32 * @inherit QtQuick.Templates.Page
33 */
34PlasmaComponents.Page {
35 id: control
36
37 // TODO KF6: should become possible to set the paddings directly (which won't be negative anymore)
38 /**
39 * collapseMarginsHint: bool
40 * if true, the representation will remove any borders its container may have put and will be collapsed above its borders
41 */
42 property bool collapseMarginsHint: contentItem instanceof PlasmaComponents.ScrollView
43
44 leftPadding: backgroundMetrics.getMargin("left")
45 rightPadding: backgroundMetrics.getMargin("right")
46 topPadding: header?.visible ? 0 : backgroundMetrics.getMargin("top")
47 bottomPadding: footer?.visible ? 0 : backgroundMetrics.getMargin("bottom")
48
49 BackgroundMetrics {
50 id: backgroundMetrics
51
52 function getMargin(margin: string): real {
53 if (hasInset && control.collapseMarginsHint) {
54 return -fixedMargins[margin] + inset[margin];
55 } else {
56 return 0;
57 }
58 }
59 }
60}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:06:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.