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 org.kde.kirigami 2.12 as Kirigami
10 
11 /**
12  * This Component is used as the header of GlobalDrawer and as the header
13  * of Card, It can be accessed there as a grouped property but can never
14  * be instantiated directly.
15  * \private
16  */
17 Kirigami.ShadowedImage {
18  id: root
19 
20 //BEGIN properties
21  /*
22  * FIXME: compatibility
23  *
24  * @deprecated Please use `source` property instead!
25  */
26  property alias imageSource: root.source
27 
28  /*
29  * FIXME: compatibility
30  *
31  * @deprecated Please use `titleIcon` property instead!
32  */
33  property alias iconSource: root.titleIcon
34 
35  /**
36  * @brief This property holds an icon to be displayed alongside the title.
37  *
38  * It can be a QIcon, a FreeDesktop-compatible icon name, or any URL understood by QtQuick.Image.
39  *
40  * @property var titleIcon
41  */
42  property alias titleIcon: headingIcon.source
43 
44  /**
45  * @brief This property holds the title's text which is to be displayed on top.
46  * of the image.
47  * @see QtQuick.Text::text
48  * @property string title
49  */
50  property alias title: heading.text
51 
52  /**
53  * @brief This property holds the title's position.
54  *
55  * default: ``Qt.AlignTop | Qt.AlignLeft``
56  *
57  * @property Qt::Alignment titleAlignment
58  */
59  property int titleAlignment: Qt.AlignTop | Qt.AlignLeft
60 
61  /**
62  * @brief This property holds the title's level.
63  *
64  * Available text size values range from 1 (largest) to 5 (smallest).
65  *
66  * default: ``1``
67  *
68  * @see kirigami::Heading::level
69  * @property int titleLevel
70  */
71  property alias titleLevel: heading.level
72 
73  /**
74  * @brief This property holds the title's wrap mode.
75  *
76  * default: ``Text.NoWrap``
77  *
78  * @see QtQuick.Text.wrapMode
79  * @property int titleWrapMode
80  */
81  property alias titleWrapMode: heading.wrapMode
82 
83  property int leftPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
84  property int topPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
85  property int rightPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
86  property int bottomPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing
87 
88  property int implicitWidth: Layout.preferredWidth
89 
90  readonly property bool empty: title.length === 0 && // string
91  source.toString().length === 0 && // QUrl
92  !titleIcon // QVariant hanled by Kirigami.Icon
93 //END properties
94 
95  Layout.fillWidth: true
96 
97  Layout.preferredWidth: titleLayout.implicitWidth || sourceSize.width
98  Layout.preferredHeight: titleLayout.completed && source.toString() !== "" ? width/(sourceSize.width / sourceSize.height) : Layout.minimumHeight
99  Layout.minimumHeight: titleLayout.implicitHeight > 0 ? titleLayout.implicitHeight + Kirigami.Units.smallSpacing * 2 : 0
100 
101  onTitleAlignmentChanged: {
102  Qt.callLater(titleLayout.implicitWidthChanged)
103  Qt.callLater(titleLayout.implicitHeightChanged)
104  }
105  fillMode: Image.PreserveAspectCrop
106  asynchronous: true
107 
108  color: "transparent"
109 
110  Component.onCompleted: {
111  titleLayout.completed = true;
112  }
113 
114  Kirigami.ShadowedRectangle {
115  anchors {
116  left: parent.left
117  right: parent.right
118  top: (root.titleAlignment & Qt.AlignTop) ? parent.top : undefined
119  bottom: (root.titleAlignment & Qt.AlignBottom) ? parent.bottom : undefined
120  verticalCenter: (root.titleAlignment & Qt.AlignVCenter) ? parent.verticalCenter : undefined
121  }
122  height: Math.min(parent.height, titleLayout.height * 1.5)
123 
124  opacity: 0.5
125  color: "black"
126 
127  visible: root.source.toString().length !== 0 && root.title.length !== 0 && ((root.titleAlignment & Qt.AlignTop) || (root.titleAlignment & Qt.AlignVCenter) || (root.titleAlignment & Qt.AlignBottom))
128 
129  corners.topLeftRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topLeftRadius : 0
130  corners.topRightRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topRightRadius : 0
131  corners.bottomLeftRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomLeftRadius : 0
132  corners.bottomRightRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomRightRadius : 0
133  }
134 
135  RowLayout {
136  id: titleLayout
137  property bool completed: false
138  anchors {
139  left: root.titleAlignment & Qt.AlignLeft ? parent.left : undefined
140  top: root.titleAlignment & Qt.AlignTop ? parent.top : undefined
141  right: root.titleAlignment & Qt.AlignRight ? parent.right : undefined
142  bottom: root.titleAlignment & Qt.AlignBottom ? parent.bottom : undefined
143  horizontalCenter: root.titleAlignment & Qt.AlignHCenter ? parent.horizontalCenter : undefined
144  verticalCenter: root.titleAlignment & Qt.AlignVCenter ? parent.verticalCenter : undefined
145 
146  leftMargin: root.leftPadding
147  topMargin: root.topPadding
148  rightMargin: root.rightPadding
149  bottomMargin: root.bottomPadding
150  }
151  width: Math.min(implicitWidth, parent.width -root.leftPadding - root.rightPadding)
152  height: Math.min(implicitHeight, parent.height - root.topPadding - root.bottomPadding)
153  Kirigami.Icon {
154  id: headingIcon
155  Layout.minimumWidth: Kirigami.Units.iconSizes.large
156  Layout.minimumHeight: width
157  visible: valid
158  isMask: false
159  }
160  Kirigami.Heading {
161  id: heading
162  Layout.fillWidth: true
163  Layout.fillHeight: true
164  verticalAlignment: Text.AlignVCenter
165  visible: text.length > 0
166  level: 1
167  color: root.source.toString() !== "" ? "white" : Kirigami.Theme.textColor
168  wrapMode: Text.NoWrap
169  elide: Text.ElideRight
170  }
171  }
172 }
QTextStream & right(QTextStream &stream)
QTextStream & left(QTextStream &stream)
QStringView level(QStringView ifopt)
QString toString() const const
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Dec 6 2023 04:01:16 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.