Libplasma

PlasmoidHeading.qml
1/*
2 SPDX-FileCopyrightText: 2020 Niccolò Venerandi <niccolo@venerandi.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9import QtQuick.Templates as T
10
11import org.kde.plasma.core as PlasmaCore
12import org.kde.ksvg as KSvg
13import org.kde.plasma.plasmoid
14import org.kde.kirigami as Kirigami
15
16/**
17 * Item to be used as a header or footer in plasmoids
18 *
19 * @inherit QtQuick.Templates.ToolBar
20 */
21T.ToolBar {
22 id: control
23
24 Layout.fillWidth: true
25 bottomPadding: position === T.ToolBar.Footer ? 0 : -backgroundMetrics.getMargin("bottom")
26 topPadding: position === T.ToolBar.Footer ? -backgroundMetrics.getMargin("top") : 0
27
28 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
29 contentWidth + leftPadding + rightPadding)
30 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
31 contentHeight + topPadding + bottomPadding)
32
33 leftInset: backgroundMetrics.getMargin("left")
34 rightInset: backgroundMetrics.getMargin("right")
35 topInset: position === T.ToolBar.Footer ? 0 : backgroundMetrics.getMargin("top")
36 bottomInset: position === T.ToolBar.Footer ? backgroundMetrics.getMargin("bottom") : 0
37
38 Kirigami.Theme.colorSet: position === T.ToolBar.Header ? Kirigami.Theme.Header : Kirigami.Theme.Window
39 Kirigami.Theme.inherit: false
40
41 property /*Qt.Edges*/ int enabledBorders: {
42 const w = Window.window;
43 const popup = w as PlasmaCore.PopupPlasmaWindow;
44 if (!popup) {
45 return Qt.LeftEdge | Qt.TopEdge | Qt.RightEdge | Qt.BottomEdge;
46 }
47
48 const windowBorders = popup.borders;
49 let borders = Qt.TopEdge | Qt.BottomEdge;
50
51 if (windowBorders & Qt.LeftEdge && Math.floor(background.Kirigami.ScenePosition.x) <= 0) {
52 borders |= Qt.LeftEdge;
53 }
54 if (windowBorders & Qt.RightEdge && Math.ceil(background.Kirigami.ScenePosition.x + background.width) >= w.width) {
55 borders |= Qt.RightEdge;
56 }
57
58 return borders;
59 }
60 background: KSvg.FrameSvgItem {
61 id: headingSvg
62 // This graphics has to back with the dialog background, so it can be used if:
63 // * both this and the dialog background are from the current theme
64 // * both this and the dialog background are from fallback
65 visible: fromCurrentImageSet === backgroundSvg.fromCurrentImageSet
66 imagePath: "widgets/plasmoidheading"
67 prefix: control.position === T.ToolBar.Header ? "header" : "footer"
68 KSvg.Svg {
69 id: backgroundSvg
70 imagePath: "dialogs/background"
71 }
72
73 enabledBorders: {
74 let borders = KSvg.FrameSvg.NoBorder;
75 if (control.enabledBorders & Qt.LeftEdge) {
76 borders |= KSvg.FrameSvg.LeftBorder;
77 }
78 if (control.enabledBorders & Qt.RightEdge) {
79 borders |= KSvg.FrameSvg.RightBorder;
80 }
81 if (control.enabledBorders & Qt.TopEdge) {
82 borders |= KSvg.FrameSvg.TopBorder;
83 }
84 if (control.enabledBorders & Qt.BottomEdge) {
85 borders |= KSvg.FrameSvg.BottomBorder;
86 }
87 return borders;
88 }
89
90 BackgroundMetrics {
91 id: backgroundMetrics
92
93 function getMargin(margin: string): real {
94 const w = Window.window;
95
96 // TODO: This shouldn't be duck-typed
97 if (w && w.hasOwnProperty("leftPadding")
98 && w.hasOwnProperty("topPadding")
99 && w.hasOwnProperty("rightPadding")
100 && w.hasOwnProperty("bottomPadding")) {
101 switch (margin) {
102 case "left":
103 return -w.leftPadding;
104 case "top":
105 return -w.topPadding;
106 case "right":
107 return -w.rightPadding;
108 case "bottom":
109 default:
110 return -w.bottomPadding;
111 }
112 } else if (!hasInset) {
113 return -headingSvg.fixedMargins[margin];
114 } else {
115 return -fixedMargins[margin] + inset[margin];
116 }
117 }
118 }
119 }
120}
KGUIADDONS_EXPORT QWindow * window(QObject *job)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:54:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.