Warning, /plasma/qqc2-breeze-style/style/impl/IconLabelContent.qml is written in an unsupported language. File is not indexed.

0001 /* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0002  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003  */
0004 
0005 import QtQuick
0006 import QtQuick.Templates as T
0007 import org.kde.kirigami as Kirigami
0008 import org.kde.breeze
0009 
0010 import "." as Impl
0011 
0012 IconLabelLayout {
0013     id: root
0014     // NOTE: Remember to use root.mirrored, not control.mirrored in this file
0015     // Controls can change the mirrored property of this component and those
0016     // changes will be ignored if you use control.mirrored directly.
0017     property T.AbstractButton control: root.parent
0018     property bool reserveSpaceForIndicator: false
0019     property bool reserveSpaceForIcon: false
0020     property bool reserveSpaceForArrow: false
0021     property bool oppositeSideIndicator: {
0022         if (!control.indicator) { return false; }
0023         let indicatorCenter = control.indicator.x + control.indicator.width/2
0024         let controlCenter = control.width/2
0025         return root.mirrored ? indicatorCenter <= controlCenter : indicatorCenter > controlCenter
0026     }
0027 
0028     icon {
0029         name: control.icon.name
0030         source: control.icon.source
0031         width: control.icon.width
0032         height: control.icon.height
0033         color: control.icon.color
0034         cache: control.icon.cache
0035     }
0036     text: control.text
0037     font: control.font
0038     color: Kirigami.Theme.textColor
0039 
0040     property real padding: 0
0041     property real horizontalPadding: padding
0042     property real verticalPadding: padding
0043     leftPadding: {
0044         let lpad = horizontalPadding
0045         if (!oppositeSideIndicator) {
0046             if (control.indicator && control.indicator.visible && control.indicator.width > 0) {
0047                 lpad += control.indicator.width + root.spacing
0048             } else if (reserveSpaceForIndicator) {
0049                 lpad += Units.inlineControlHeight + root.spacing
0050             }
0051         }
0052         if (reserveSpaceForIcon && !hasIcon && control.icon.width > 0) {
0053             lpad += control.icon.width + root.spacing
0054         }
0055         return lpad
0056     }
0057     rightPadding: {
0058         let rpad = horizontalPadding
0059         if (oppositeSideIndicator) {
0060             if (control.indicator && control.indicator.visible && control.indicator.width > 0) {
0061                 rpad += control.indicator.width + root.spacing
0062             } else if (reserveSpaceForIndicator) {
0063                 rpad += Units.inlineControlHeight + root.spacing
0064             }
0065         }
0066         if (control.arrow && (control.arrow.visible || reserveSpaceForArrow) && control.arrow.width > 0) {
0067             rpad += control.arrow.width + root.spacing
0068         }
0069         return rpad
0070     }
0071     topPadding: verticalPadding
0072     bottomPadding: verticalPadding
0073     spacing: control.spacing
0074 
0075     mirrored: control.mirrored
0076     alignment: Qt.AlignCenter
0077     display: control.display
0078 
0079     iconComponent: Component {
0080         Kirigami.Icon {
0081             // This is set in IconLabelLayout
0082             property bool firstLayoutCompleted: false
0083             visible: valid
0084             Behavior on opacity {
0085                 enabled: firstLayoutCompleted
0086                 OpacityAnimator {
0087                     duration: Kirigami.Units.shortDuration
0088                 }
0089             }
0090         }
0091     }
0092 
0093     labelComponent: Component {
0094         Text {
0095             // This is set in IconLabelLayout
0096             property bool firstLayoutCompleted: false
0097             visible: text.length > 0
0098             linkColor: Kirigami.Theme.linkColor
0099             horizontalAlignment: Text.AlignHCenter
0100             verticalAlignment: Text.AlignVCenter
0101             elide: Text.ElideRight
0102             Behavior on x {
0103                 enabled: firstLayoutCompleted
0104                 XAnimator {
0105                     duration: Kirigami.Units.shortDuration
0106                 }
0107             }
0108             Behavior on y {
0109                 enabled: firstLayoutCompleted
0110                 YAnimator {
0111                     duration: Kirigami.Units.shortDuration
0112                 }
0113             }
0114             Behavior on opacity {
0115                 enabled: firstLayoutCompleted
0116                 OpacityAnimator {
0117                     duration: Kirigami.Units.shortDuration
0118                 }
0119             }
0120         }
0121     }
0122 }