Warning, /maui/mauikit/src/controls.6/IconLabel.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * Copyright 2020 Camilo Higuita <milo.h@aol.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Library General Public License as 0006 * published by the Free Software Foundation; either version 2, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details 0013 * 0014 * You should have received a copy of the GNU Library General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 import QtQuick 0021 import QtQuick.Controls 0022 import QtQuick.Layouts 0023 0024 import org.mauikit.controls 1.3 as Maui 0025 0026 /** 0027 * @inherit QtQuick.Item 0028 * @brief A icon and a label put together in two possible positions, a horizontal or vertical layout. 0029 * 0030 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-item.html">This control inherits from QQC2 Item, to checkout its inherited properties refer to the Qt Docs.</a> 0031 * 0032 * This is a base template for other controls, such as for setting the contents of the ToolButton, Button, MenuItem, etc, in the style. 0033 * 0034 * @note This control is only a visual item, and does not handle any event or gets any focus. 0035 * 0036 * @image html Misc/iconlabel.png 0037 * 0038 * @code 0039 * ColumnLayout 0040 * { 0041 * anchors.centerIn: parent 0042 * spacing: Maui.Style.space.big 0043 * 0044 * Maui.IconLabel 0045 * { 0046 * icon: ({name: "folder", height: "22", width: "22", color: "yellow"}) 0047 * text: "Testing" 0048 * display: ToolButton.TextBesideIcon 0049 * alignment: Qt.AlignLeft 0050 * color: "yellow" 0051 * } 0052 * 0053 * Maui.IconLabel 0054 * { 0055 * icon: ({name: "vvave", height: "64", width: "64"}) 0056 * text: "Vvave" 0057 * display: ToolButton.TextUnderIcon 0058 * alignment: Qt.AlignHCenter 0059 * } 0060 * } 0061 * @endcode 0062 * 0063 * @warning To set the `icon` properties, you need to set it as a dictionary map. The supported key values are: 0064 * - name 0065 * - source 0066 * - color 0067 * - height 0068 * - width 0069 * - cache 0070 * @see icon 0071 * 0072 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/IconLabel.qml">You can find a more complete example at this link.</a> 0073 */ 0074 Item 0075 { 0076 id: control 0077 0078 focus: false 0079 0080 implicitWidth: _layoutButton.implicitWidth + leftPadding + rightPadding 0081 implicitHeight: _layoutButton.implicitHeight + topPadding + bottomPadding 0082 0083 /** 0084 * @brief The color for the text. 0085 * By default this is set to `Theme.textColor`. 0086 * @note to set the icon color, use the `icon.color` property. 0087 * @property color IconLabel::color 0088 */ 0089 property alias color : _label.color 0090 0091 /** 0092 * @brief The text to be used. 0093 * @property string IconLabel::text 0094 */ 0095 property alias text : _label.text 0096 0097 /** 0098 * @brief This is a dictionary, which represents the properties for the icon. 0099 * The supported key values are: 0100 * - name 0101 * - source 0102 * - color 0103 * - height 0104 * - width 0105 * - cache 0106 * 0107 * @code 0108 * Maui.IconLabel 0109 * { 0110 * icon: ({name: "folder", height: "22", width: "22", color: "yellow"}) 0111 * } 0112 * @endcode 0113 * 0114 */ 0115 property var icon 0116 0117 /** 0118 * @brief How to display the icon and the label. 0119 * The available options are: 0120 * - ToolButton.TextBesidesIcon 0121 * - ToolButton.TextUnderIcon 0122 * - ToolButton.TextOnly 0123 * - ToolButton.IconOnly 0124 * 0125 * By default this is set to `ToolButton.IconOnly` 0126 */ 0127 property int display : ToolButton.IconOnly 0128 0129 /** 0130 * @brief The preferred horizontal alignment of the text. 0131 * By default this is set to `Qt.AlignLeft`. 0132 * @note The alignment will depend on the width of the container. If there is a width bigger then the implicit width, then the alignment will be set as preferred. 0133 * @property enum IconLabel::alignment 0134 */ 0135 property alias alignment : _label.horizontalAlignment 0136 0137 // font.pointSize: control.display === ToolButton.TextUnderIcon ? Maui.Style.fontSizes.small : Maui.Style.fontSizes.medium 0138 0139 /** 0140 * @brief The total padding all around the element. 0141 * By default this is set to `0`. 0142 */ 0143 property int padding : 0 0144 0145 /** 0146 * @brief Left padding. 0147 * By default this is set to `padding` 0148 */ 0149 property int leftPadding: padding 0150 0151 /** 0152 * @brief Right padding. 0153 * By default this is set to `padding` 0154 */ 0155 property int rightPadding: padding 0156 0157 /** 0158 * @brief Bottom padding. 0159 * By default this is set to `padding` 0160 */ 0161 property int bottomPadding: padding 0162 0163 /** 0164 * @brief Top padding. 0165 * By default this is set to `padding` 0166 */ 0167 property int topPadding: padding 0168 0169 /** 0170 * @brief The spacing value between the icon element and the text label. 0171 * By default this is set to `Style.space.small`. 0172 * @see Style 0173 */ 0174 property int spacing: Maui.Style.space.small 0175 0176 /** 0177 * @brief The font properties of the text. 0178 * By default this is set to `Style.defaultFont`. 0179 * @property font IconLabel::font 0180 */ 0181 property alias font : _label.font 0182 0183 /** 0184 * @brief An alias tot he QQC2 Label handling the text. 0185 * Exposed for fine tuning the label properties. 0186 * @property Label IconLabel::label 0187 */ 0188 property alias label : _label 0189 0190 GridLayout 0191 { 0192 id: _layoutButton 0193 0194 anchors.fill: parent 0195 0196 anchors.leftMargin: control.leftPadding 0197 anchors.rightMargin: control.rightPadding 0198 anchors.bottomMargin: control.bottomPadding 0199 anchors.topMargin: control.topPadding 0200 0201 rowSpacing: control.spacing 0202 columnSpacing: control.spacing 0203 0204 columns: control.display === ToolButton.TextUnderIcon ? 1 : 2 0205 0206 Maui.Icon 0207 { 0208 id: _icon 0209 0210 implicitHeight: visible && control.icon ? control.icon.height : 0 0211 implicitWidth: visible && control.icon ? control.icon.width : 0 0212 0213 Layout.alignment: Qt.AlignCenter 0214 0215 visible: String(_icon.source).length > 0 && (control.display !== ToolButton.TextOnly) 0216 0217 color: control.icon ? control.icon.color : control.color 0218 source: control.icon ? control.icon.name || control.icon.source : "" 0219 } 0220 0221 Label 0222 { 0223 id: _label 0224 0225 visible: text.length && (control.display === ToolButton.TextOnly || control.display === ToolButton.TextBesideIcon || control.display === ToolButton.TextUnderIcon || !_icon.visible) 0226 0227 opacity: visible ? ( enabled ? 1 : 0.5) : 0 0228 0229 horizontalAlignment: Qt.AlignLeft 0230 verticalAlignment: Qt.AlignVCenter 0231 0232 Layout.fillWidth: true 0233 0234 color: Maui.Style.defaultFont 0235 font: Maui.Style.defaultFont 0236 0237 elide: Text.ElideRight 0238 wrapMode: Text.NoWrap 0239 0240 Behavior on opacity 0241 { 0242 NumberAnimation 0243 { 0244 duration: Maui.Style.units.shortDuration 0245 easing.type: Easing.InQuad 0246 } 0247 } 0248 } 0249 } 0250 }