Warning, /frameworks/kirigami/src/controls/private/BannerImage.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import QtQuick.Controls as QQC2 0010 import org.kde.kirigami as Kirigami 0011 0012 /** 0013 * This Component is used as the header of GlobalDrawer and as the header 0014 * of Card, It can be accessed there as a grouped property but can never 0015 * be instantiated directly. 0016 * \private 0017 */ 0018 Kirigami.ShadowedImage { 0019 id: root 0020 0021 //BEGIN properties 0022 /** 0023 * @brief This property holds an icon to be displayed alongside the title. 0024 * 0025 * It can be a QIcon, a FreeDesktop-compatible icon name, or any URL understood by QtQuick.Image. 0026 * 0027 * @property var titleIcon 0028 */ 0029 property alias titleIcon: headingIcon.source 0030 0031 /** 0032 * @brief This property holds the title's text which is to be displayed on top. 0033 * of the image. 0034 * @see QtQuick.Text::text 0035 * @property string title 0036 */ 0037 property alias title: heading.text 0038 0039 /** 0040 * @brief This property holds the title's position. 0041 * 0042 * default: ``Qt.AlignTop | Qt.AlignLeft`` 0043 * 0044 * @property Qt::Alignment titleAlignment 0045 */ 0046 property int titleAlignment: Qt.AlignTop | Qt.AlignLeft 0047 0048 /** 0049 * @brief This property holds the title's level. 0050 * 0051 * Available text size values range from 1 (largest) to 5 (smallest). 0052 * 0053 * default: ``1`` 0054 * 0055 * @see org::kde::kirigami::Heading::level 0056 * @property int titleLevel 0057 */ 0058 property alias titleLevel: heading.level 0059 0060 /** 0061 * @brief This property holds the title's wrap mode. 0062 * 0063 * default: ``Text.NoWrap`` 0064 * 0065 * @see QtQuick.Text::wrapMode 0066 * @property int titleWrapMode 0067 */ 0068 property alias titleWrapMode: heading.wrapMode 0069 0070 /** 0071 * @brief This property holds whether the title is part of an item considered 0072 * checkable. 0073 * 0074 * If true, a checkbox will appear in the top-right corner of the title area. 0075 * 0076 * default: false 0077 * 0078 * @property bool checkable 0079 */ 0080 property bool checkable: false 0081 0082 /** 0083 * @brief This property holds whether the title's checkbox is currently checked. 0084 * 0085 * If using this outside of a GlobalDrawer or a Card, you must manually bind 0086 * this to the checked condition of the parent item, or whatever else in your 0087 * UI signals checkability. You must also handle the `toggled` signal when 0088 * the user manually clicks the checkbox. 0089 * 0090 * default: false 0091 * 0092 * @property bool checked 0093 */ 0094 property bool checked: false 0095 0096 property int leftPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing 0097 property int topPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing 0098 property int rightPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing 0099 property int bottomPadding: headingIcon.valid ? Kirigami.Units.smallSpacing * 2 : Kirigami.Units.largeSpacing 0100 0101 property int implicitWidth: Layout.preferredWidth 0102 0103 readonly property bool empty: title.length === 0 && // string 0104 source.toString().length === 0 && // QUrl 0105 !titleIcon // QVariant hanled by Kirigami.Icon 0106 //END properties 0107 0108 signal toggled(bool checked) 0109 0110 Layout.fillWidth: true 0111 0112 Layout.preferredWidth: titleLayout.implicitWidth || sourceSize.width 0113 Layout.preferredHeight: titleLayout.completed && source.toString().length > 0 ? width/(sourceSize.width / sourceSize.height) : Layout.minimumHeight 0114 Layout.minimumHeight: titleLayout.implicitHeight > 0 ? titleLayout.implicitHeight + Kirigami.Units.smallSpacing * 2 : 0 0115 0116 onTitleAlignmentChanged: { 0117 // VERTICAL ALIGNMENT 0118 titleLayout.anchors.top = undefined 0119 titleLayout.anchors.verticalCenter = undefined 0120 titleLayout.anchors.bottom = undefined 0121 shadowedRectangle.anchors.top = undefined 0122 shadowedRectangle.anchors.verticalCenter = undefined 0123 shadowedRectangle.anchors.bottom = undefined 0124 0125 if (root.titleAlignment & Qt.AlignTop) { 0126 titleLayout.anchors.top = root.top 0127 shadowedRectangle.anchors.top = root.top 0128 } 0129 else if (root.titleAlignment & Qt.AlignVCenter) { 0130 titleLayout.anchors.verticalCenter = root.verticalCenter 0131 shadowedRectangle.anchors.verticalCenter = root.verticalCenter 0132 } 0133 else if (root.titleAlignment & Qt.AlignBottom) { 0134 titleLayout.anchors.bottom = root.bottom 0135 shadowedRectangle.anchors.bottom = root.bottom 0136 } 0137 0138 // HORIZONTAL ALIGNMENT 0139 titleLayout.anchors.left = undefined 0140 titleLayout.anchors.horizontalCenter = undefined 0141 titleLayout.anchors.right = undefined 0142 if (root.titleAlignment & Qt.AlignRight) { 0143 titleLayout.anchors.right = root.right 0144 } 0145 else if (root.titleAlignment & Qt.AlignHCenter) { 0146 titleLayout.anchors.horizontalCenter = root.horizontalCenter 0147 } 0148 else if (root.titleAlignment & Qt.AlignLeft) { 0149 titleLayout.anchors.left = root.left 0150 } 0151 } 0152 fillMode: Image.PreserveAspectCrop 0153 asynchronous: true 0154 0155 color: "transparent" 0156 0157 Component.onCompleted: { 0158 titleLayout.completed = true; 0159 } 0160 0161 Kirigami.ShadowedRectangle { 0162 id: shadowedRectangle 0163 anchors { 0164 left: parent.left 0165 right: parent.right 0166 } 0167 height: Math.min(parent.height, titleLayout.height * 1.5) 0168 0169 opacity: 0.5 0170 color: "black" 0171 0172 corners.topLeftRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topLeftRadius : 0 0173 corners.topRightRadius: root.titleAlignment & Qt.AlignTop ? root.corners.topRightRadius : 0 0174 corners.bottomLeftRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomLeftRadius : 0 0175 corners.bottomRightRadius: root.titleAlignment & Qt.AlignBottom ? root.corners.bottomRightRadius : 0 0176 0177 visible: root.source.toString().length !== 0 && root.title.length !== 0 && ((root.titleAlignment & Qt.AlignTop) || (root.titleAlignment & Qt.AlignVCenter) || (root.titleAlignment & Qt.AlignBottom)) 0178 } 0179 0180 RowLayout { 0181 id: titleLayout 0182 property bool completed: false 0183 anchors { 0184 leftMargin: root.leftPadding 0185 topMargin: root.topPadding 0186 rightMargin: root.rightPadding 0187 bottomMargin: root.bottomPadding 0188 } 0189 width: Math.min(implicitWidth, parent.width -root.leftPadding -root.rightPadding - (checkboxLoader.active ? Kirigami.Units.largeSpacing : 0)) 0190 height: Math.min(implicitHeight, parent.height -root.topPadding -root.bottomPadding) 0191 Kirigami.Icon { 0192 id: headingIcon 0193 Layout.minimumWidth: Kirigami.Units.iconSizes.large 0194 Layout.minimumHeight: width 0195 visible: valid 0196 isMask: false 0197 } 0198 Kirigami.Heading { 0199 id: heading 0200 Layout.fillWidth: true 0201 Layout.fillHeight: true 0202 verticalAlignment: Text.AlignVCenter 0203 visible: text.length > 0 0204 level: 1 0205 color: root.source.toString().length > 0 ? "white" : Kirigami.Theme.textColor 0206 wrapMode: Text.NoWrap 0207 elide: Text.ElideRight 0208 } 0209 } 0210 0211 Loader { 0212 id: checkboxLoader 0213 anchors { 0214 top: parent.top 0215 right: parent.right 0216 topMargin: root.topPadding 0217 } 0218 active: root.checkable 0219 sourceComponent: QQC2.CheckBox { 0220 checked: root.checked 0221 onToggled: root.toggled(checked); 0222 } 0223 } 0224 }