Warning, /pim/mimetreeparser/src/quick/qml/private/Banner.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 import QtQuick 2.15 0005 import QtQuick.Controls 2.15 as QQC2 0006 import QtQuick.Templates 2.15 as T 0007 import QtQuick.Layouts 1.15 0008 import org.kde.kirigami 2.20 as Kirigami 0009 0010 /** 0011 * @brief An banner Item with support for informational, positive, 0012 * warning and error types, and with support for associated actions. 0013 * 0014 * Banner can be used to inform or interact with the user 0015 * without requiring the use of a dialog and are positionned in the footer 0016 * or header of a page. For inline content, see org::kde::kirigami::InlineMessage. 0017 * 0018 * The Banner is hidden by default. 0019 * 0020 * Optionally, actions can be added which are shown alongside an 0021 * optional close button on the right side of the Item. If more 0022 * actions are set than can fit, an overflow menu is provided. 0023 * 0024 * Example usage: 0025 * @code{.qml} 0026 * Banner { 0027 * type: Kirigami.MessageType.Error 0028 * 0029 * text: "My error message" 0030 * 0031 * actions: [ 0032 * Kirigami.Action { 0033 * icon.name: "edit" 0034 * text: "Action text" 0035 * onTriggered: { 0036 * // do stuff 0037 * } 0038 * }, 0039 * Kirigami.Action { 0040 * icon.name: "edit" 0041 * text: "Action text" 0042 * onTriggered: { 0043 * // do stuff 0044 * } 0045 * } 0046 * ] 0047 * } 0048 * @endcode 0049 */ 0050 T.ToolBar { 0051 id: root 0052 0053 /** 0054 * @brief This signal is emitted when a link is hovered in the message text. 0055 * @param The hovered link. 0056 */ 0057 signal linkHovered(string link) 0058 0059 /** 0060 * @brief This signal is emitted when a link is clicked or tapped in the message text. 0061 * @param The clicked or tapped link. 0062 */ 0063 signal linkActivated(string link) 0064 0065 /** 0066 * @brief This property holds the link embedded in the message text that the user is hovering over. 0067 */ 0068 readonly property alias hoveredLink: label.hoveredLink 0069 0070 /** 0071 * @brief This property holds the message type. 0072 * 0073 * The following values are allowed: 0074 * * ``Kirigami.MessageType.Information`` 0075 * * ``Kirigami.MessageType.Positive`` 0076 * * ``Kirigami.MessageType.Warning`` 0077 * * ``Kirigami.MessageType.Error`` 0078 * 0079 * default: ``Kirigami.MessageType.Information`` 0080 * 0081 * @property Kirigami.MessageType type 0082 */ 0083 property int type: Kirigami.MessageType.Information 0084 0085 /** 0086 * @brief This property holds the message title. 0087 */ 0088 property string title 0089 0090 /** 0091 * @brief This property holds the message text. 0092 */ 0093 property string text 0094 0095 /** 0096 * @brief This property holds the icon name (default to predefined icons 0097 * depending on the title if not set). 0098 */ 0099 property string iconName 0100 0101 /** 0102 * @brief This property holds whether the close button is displayed. 0103 * 0104 * default: ``false`` 0105 */ 0106 property bool showCloseButton: false 0107 0108 /** 0109 * This property holds the list of Kirigami Actions to show in the banner's 0110 * internal kirigami::ActionToolBar. 0111 * 0112 * Actions are added from left to right. If more actions 0113 * are set than can fit, an overflow menu is provided. 0114 */ 0115 property list<Kirigami.Action> actions 0116 0117 padding: Kirigami.Units.smallSpacing 0118 0119 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, contentWidth + leftPadding + rightPadding) 0120 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, contentHeight + topPadding + bottomPadding) 0121 0122 visible: false 0123 0124 contentItem: GridLayout { 0125 columns: 3 0126 columnSpacing: Kirigami.Units.mediumSpacing 0127 0128 Item { 0129 Layout.preferredWidth: closeButton.visible ? closeButton.implicitWidth : Kirigami.Units.iconSizes.medium 0130 Layout.preferredHeight: closeButton.visible ? closeButton.implicitWidth : Kirigami.Units.iconSizes.medium 0131 Layout.alignment: Qt.AlignTop 0132 Layout.rowSpan: 2 0133 0134 Kirigami.Icon { 0135 source: { 0136 if (root.iconName.length > 0) { 0137 return root.iconName 0138 } 0139 switch (root.type) { 0140 case Kirigami.MessageType.Positive: 0141 return "emblem-positive"; 0142 case Kirigami.MessageType.Warning: 0143 return "data-warning"; 0144 case Kirigami.MessageType.Error: 0145 return "data-error"; 0146 default: 0147 return "data-information"; 0148 } 0149 } 0150 0151 anchors.centerIn: parent 0152 } 0153 } 0154 0155 Kirigami.Heading { 0156 id: heading 0157 0158 level: 2 0159 text: root.title 0160 visible: text.length > 0 0161 0162 Layout.row: visible ? 0 : 1 0163 Layout.column: 1 0164 } 0165 0166 Kirigami.SelectableLabel { 0167 id: label 0168 0169 color: Kirigami.Theme.textColor 0170 wrapMode: Text.WordWrap 0171 0172 text: root.text 0173 0174 onLinkHovered: link => root.linkHovered(link) 0175 onLinkActivated: link => root.linkActivated(link) 0176 0177 Layout.fillWidth: true 0178 Layout.alignment: Qt.AlignTop 0179 0180 Layout.row: heading.visible ? 1 : 0 0181 Layout.column: 1 0182 } 0183 0184 QQC2.ToolButton { 0185 id: closeButton 0186 0187 visible: root.showCloseButton 0188 text: i18ndc("mimetreeparser", "@action:button", "Close") 0189 0190 icon.name: "dialog-close" 0191 display: QQC2.ToolButton.IconOnly 0192 0193 onClicked: root.visible = false 0194 0195 Layout.alignment: Qt.AlignTop 0196 0197 QQC2.ToolTip.visible: Kirigami.Settings.tabletMode ? closeButton.pressed : closeButton.hovered 0198 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0199 QQC2.ToolTip.text: text 0200 0201 Layout.rowSpan: 2 0202 Layout.column: 2 0203 } 0204 0205 Kirigami.ActionToolBar { 0206 id: actionsLayout 0207 0208 flat: false 0209 actions: root.actions 0210 visible: root.actions.length > 0 0211 alignment: Qt.AlignRight 0212 0213 Layout.column: 0 0214 Layout.columnSpan: 3 0215 Layout.row: 2 0216 } 0217 } 0218 0219 background: Item { 0220 id: backgroundItem 0221 0222 readonly property color color: switch (root.type) { 0223 case Kirigami.MessageType.Positive: 0224 return Kirigami.Theme.positiveTextColor; 0225 case Kirigami.MessageType.Warning: 0226 return Kirigami.Theme.neutralTextColor; 0227 case Kirigami.MessageType.Error: 0228 return Kirigami.Theme.negativeTextColor; 0229 default: 0230 return Kirigami.Theme.activeTextColor; 0231 } 0232 0233 Rectangle { 0234 opacity: 0.2 0235 color: backgroundItem.color 0236 radius: Kirigami.Units.smallSpacing 0237 anchors.fill: parent 0238 } 0239 } 0240 }