Warning, /maui/mauikit/src/controls.6/Chip.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 0002 import QtQuick.Controls 0003 import QtQuick.Layouts 0004 0005 import org.mauikit.controls 1.3 as Maui 0006 0007 /** 0008 * @inherit QtQuick.Controls.ItemDelegate 0009 * @since org.mauikit.controls 1.0 0010 * 0011 * @brief This an information element, similar to a button, but more compact. 0012 * 0013 * Chips allow users to enter information, make selections, filter content, or trigger actions. While buttons are expected to appear consistently and with familiar calls to action, chips should appear dynamically as a group of multiple interactive elements. 0014 * 0015 * This component is similar to the MauiKit Badge control, but this one is interactive. 0016 * @see Badge 0017 * 0018 * @image html Chip/chips.png "Colorful chips" 0019 * 0020 * @code 0021 * Flow 0022 * { 0023 * width: 400 0024 * anchors.centerIn: parent 0025 * spacing: Maui.Style.space.big 0026 * 0027 * Maui.Chip 0028 * { 0029 * text: "Chip1" 0030 * color: "#757575" 0031 * } 0032 * 0033 * Maui.Chip 0034 * { 0035 * text: "Chip2" 0036 * icon.name: "actor" 0037 * color: "#03A9F4" 0038 * } 0039 * 0040 * Maui.Chip 0041 * { 0042 * text: "Chip3" 0043 * icon.name: "anchor" 0044 * color: "#4CAF50" 0045 * } 0046 * 0047 * Maui.Chip 0048 * { 0049 * text: "Chip4" 0050 * color: "#E1BEE7" 0051 * } 0052 * 0053 * Maui.Chip 0054 * { 0055 * text: "Chip5" 0056 * color: "#FFC107" 0057 * } 0058 * 0059 * Maui.Chip 0060 * { 0061 * text: "Chip6" 0062 * color: "#607D8B" 0063 * } 0064 * 0065 * Maui.Chip 0066 * { 0067 * text: "Chip7" 0068 * color: "#FF5722" 0069 * icon.source: "/home/camiloh/Downloads/5911329.jpeg" 0070 * } 0071 * } 0072 * @endcode 0073 * 0074 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/Chip.qml">You can find a more complete example at this link.</a> 0075 */ 0076 ItemDelegate 0077 { 0078 id: control 0079 0080 Maui.Theme.colorSet: Maui.Theme.Tooltip 0081 0082 hoverEnabled: !Maui.Handy.isMobile 0083 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding 0084 implicitWidth: _layout.implicitWidth + leftPadding + rightPadding 0085 0086 padding: Maui.Style.defaultPadding 0087 spacing: Maui.Style.space.small 0088 0089 icon.height: Maui.Style.iconSize 0090 icon.width: Maui.Style.iconSize 0091 0092 /** 0093 * @brief The Label element used for the title text. 0094 * This is exposed to tweak the text font properties. 0095 * @property Label Chip::label 0096 */ 0097 property alias label : _label1 0098 0099 /** 0100 * @brief The name of the icon to be used. 0101 * This is an alias to the `icon.name` group property. 0102 * @property string Chip::iconSource 0103 */ 0104 property alias iconSource : control.icon.name 0105 0106 /** 0107 * @brief The name of the image source to be used. 0108 * This is an alias to the `icon.source` group property. 0109 * @property url Chip::imageSource 0110 */ 0111 property alias imageSource : control.icon.source 0112 0113 /** 0114 * @brief Whether a close button should be displayed, to dismiss the chip. 0115 * By default it is set to `false`. 0116 */ 0117 property bool showCloseButton : false 0118 0119 /** 0120 * @brief The background color for the chip. The label text color will be adapted from this color considering the brightness, to use either a light or dark text color. 0121 */ 0122 property color color : Maui.Theme.backgroundColor 0123 0124 ToolTip.visible: hovered && ToolTip.text.length > 0 0125 0126 /** 0127 * @brief Emitted once the close button is clicked. To enable the close button see the `showCloseButton: true` property. 0128 * @see showCloseButton 0129 */ 0130 signal close() 0131 0132 background: Rectangle 0133 { 0134 id: _background 0135 0136 color: control.checked ? Maui.Theme.highlightColor : (control.pressed ? Qt.darker(control.color) : (control.hovered ? Qt.lighter(control.color): control.color)) 0137 radius: Maui.Style.radiusV 0138 } 0139 0140 contentItem: RowLayout 0141 { 0142 id: _layout 0143 spacing: control.spacing 0144 0145 Maui.IconItem 0146 { 0147 iconSizeHint: Math.max(control.icon.width, control.icon.height) 0148 imageSizeHint: Math.max(control.icon.width, control.icon.height) 0149 0150 fillMode: Image.PreserveAspectCrop 0151 0152 color: _label1.color 0153 iconSource: control.icon.name 0154 imageSource: control.icon.source 0155 0156 maskRadius: height 0157 } 0158 0159 Label 0160 { 0161 id: _label1 0162 text: control.text 0163 Layout.fillHeight: true 0164 Layout.fillWidth: true 0165 verticalAlignment: Qt.AlignVCenter 0166 color: Maui.ColorUtils.brightnessForColor(_background.color) === Maui.ColorUtils.Light ? "#333" :"#fafafa" 0167 wrapMode: Text.Wrap 0168 } 0169 0170 Loader 0171 { 0172 active: control.showCloseButton 0173 visible: active 0174 0175 asynchronous: true 0176 0177 Layout.alignment: Qt.AlignRight 0178 0179 sourceComponent: Maui.CloseButton 0180 { 0181 icon.width: 16 0182 icon.height: 16 0183 icon.color: hovered ? Maui.Theme.negativeTextColor : _label1.color 0184 0185 padding: 0 0186 onClicked: control.close() 0187 } 0188 } 0189 } 0190 }