Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/plasmaextracomponents/qml/PlasmoidHeading.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2020 Niccolò Venerandi <niccolo@venerandi.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.12 | ||||
21 | import QtQuick.Layouts 1.12 | ||||
22 | | ||||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
24 | import QtQuick.Templates 2.12 as T | ||||
25 | | ||||
26 | /** | ||||
27 | * Item to be used as a header or footer in plasmoids | ||||
28 | * | ||||
29 | * @inherit QtQuick.Templates.Frame | ||||
30 | */ | ||||
31 | T.Frame { | ||||
32 | | ||||
33 | /** | ||||
34 | * Possible positions of the heading element | ||||
35 | */ | ||||
36 | enum Location { | ||||
37 | /** | ||||
38 | * Indicates that it's used as a header of the plasmoid, touching the top border | ||||
39 | */ | ||||
40 | Header, | ||||
41 | /** | ||||
42 | * Indicates that it's used as a footer of the plasmoid, touching the bottom border | ||||
43 | */ | ||||
44 | Footer | ||||
45 | } | ||||
46 | | ||||
47 | /** | ||||
48 | * location: int | ||||
49 | * | ||||
50 | * Indicates the position of the heading. The default is PlasmoidHeading.Location.Header. | ||||
51 | */ | ||||
52 | property int location: PlasmoidHeading.Location.Header | ||||
53 | | ||||
54 | Layout.fillWidth: true | ||||
55 | bottomPadding: location == PlasmoidHeading.Location.Footer ? 0 : headingSvg.margins.top | ||||
56 | topPadding: location == PlasmoidHeading.Location.Footer ? headingSvg.margins.bottom : 0 | ||||
57 | | ||||
58 | implicitHeight: contentHeight + topPadding + bottomPadding | ||||
59 | contentHeight: contentItem.implicitHeight || (contentChildren.length === 1 ? contentChildren[0].implicitHeight : 0) | ||||
60 | | ||||
61 | leftInset: -headingSvg.fixedMargins.left | ||||
62 | rightInset: -headingSvg.fixedMargins.right | ||||
63 | topInset: location == PlasmoidHeading.Location.Footer ? 0 : -headingSvg.margins.top | ||||
64 | bottomInset: location == PlasmoidHeading.Location.Footer ? -headingSvg.fixedMargins.bottom : 0 | ||||
65 | | ||||
66 | background: PlasmaCore.FrameSvgItem { | ||||
67 | id: headingSvg | ||||
68 | imagePath: "widgets/plasmoidheading" | ||||
69 | prefix: location == PlasmoidHeading.Location.Header? 'header' : 'footer' | ||||
70 | enabledBorders: { | ||||
71 | var borders = new Array() | ||||
72 | borders |= PlasmaCore.FrameSvg.LeftBorder | ||||
73 | borders |= PlasmaCore.FrameSvg.RightBorder | ||||
74 | if (plasmoid.location !== PlasmaCore.Types.TopEdge || location != PlasmoidHeading.Location.Header) { | ||||
75 | borders |= PlasmaCore.FrameSvg.TopBorder | ||||
76 | } | ||||
77 | if (plasmoid.location !== PlasmaCore.Types.BottomEdge || location != PlasmoidHeading.Location.Footer) { | ||||
78 | borders |= PlasmaCore.FrameSvg.BottomBorder | ||||
79 | } | ||||
80 | return borders | ||||
81 | } | ||||
82 | } | ||||
83 | } |