Kirigami2

BannerImage.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.6
8 import QtQuick.Layouts 1.2
9 import QtGraphicalEffects 1.0
10 import org.kde.kirigami 2.12 as Kirigami
11 
17 Kirigami.ShadowedImage {
18  id: root
19 
20  /*
21  * FIXME: compatibility
22  */
23  property alias imageSource: root.source
24  property alias iconSource: root.titleIcon
25 
30  property alias title: heading.text
31 
37  property alias titleIcon: headingIcon.source
38 
42  property int titleAlignment: Qt.AlignTop | Qt.AlignLeft
43 
47  property alias titleLevel: heading.level
48 
52  property alias titleWrapMode: heading.wrapMode
53 
54  property int leftPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
55  property int topPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
56  property int rightPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
57  property int bottomPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
58 
59  Layout.fillWidth: true
60 
61  Layout.preferredWidth: titleLayout.implicitWidth || sourceSize.width
62  Layout.preferredHeight: titleLayout.completed && source != "" ? width/(sourceSize.width / sourceSize.height) : Layout.minimumHeight
63  Layout.minimumHeight: titleLayout.implicitHeight > 0 ? titleLayout.implicitHeight + Kirigami.Units.smallSpacing * 2 : 0
64  property int implicitWidth: Layout.preferredWidth
65 
66  readonly property bool empty: bannerImage.title !== undefined && bannerImage.title.length === 0 &&
67  bannerImage.source !== undefined && bannerImage.source.length === 0 &&
68  bannerImage.titleIcon !== undefined &&bannerImage.titleIcon.length === 0
69 
70  fillMode: Image.PreserveAspectCrop
71  asynchronous: true
72 
73  color: "transparent"
74 
75  Component.onCompleted: {
76  titleLayout.completed = true;
77  }
78 
79  Kirigami.ShadowedRectangle {
80  anchors {
81  left: parent.left
82  right: parent.right
83  top: (root.titleAlignment & Qt.AlignTop) ? parent.top : undefined
84  bottom: (root.titleAlignment & Qt.AlignBottom) ? parent.bottom : undefined
85  }
86  height: Math.min(parent.height, titleLayout.height * 1.5)
87 
88  opacity: 0.5
89  color: "black"
90 
91  visible: root.source != "" && root.title != "" && ((root.titleAlignment & Qt.AlignTop) || (root.titleAlignment & Qt.AlignBottom))
92 
93  corners.topLeftRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topLeftRadius : 0
94  corners.topRightRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topRightRadius : 0
95  corners.bottomLeftRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomLeftRadius : 0
96  corners.bottomRightRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomRightRadius : 0
97  }
98 
99  RowLayout {
100  id: titleLayout
101  property bool completed: false
102  anchors {
103  left: root.titleAlignment & Qt.AlignLeft ? parent.left : undefined
104  top: root.titleAlignment & Qt.AlignTop ? parent.top : undefined
105  right: root.titleAlignment & Qt.AlignRight ? parent.right : undefined
106  bottom: root.titleAlignment & Qt.AlignBottom ? parent.bottom : undefined
107  horizontalCenter: root.titleAlignment & Qt.AlignHCenter ? parent.horizontalCenter : undefined
108  verticalCenter: root.titleAlignment & Qt.AlignVCenter ? parent.verticalCenter : undefined
109 
110  leftMargin: root.leftPadding
111  topMargin: root.topPadding
112  rightMargin: root.rightPadding
113  bottomMargin: root.bottomPadding
114  }
115  width: Math.min(implicitWidth, parent.width -root.leftPadding - root.rightPadding)
116  height: Math.min(implicitHeight, parent.height - root.topPadding - root.bottomPadding)
117  Kirigami.Icon {
118  id: headingIcon
119  Layout.minimumWidth: Kirigami.Units.iconSizes.large
120  Layout.minimumHeight: width
121  visible: valid
122  isMask: false
123  }
124  Kirigami.Heading {
125  id: heading
126  Layout.fillWidth: true
127  Layout.fillHeight: true
128  visible: text.length > 0
129  level: 1
130  color: source != "" ? "white" : Kirigami.Theme.textColor
131  wrapMode: Text.NoWrap
132  elide: Text.ElideRight
133  }
134  }
135 }
Definition: icon.h:19
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:36:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.