Warning, /plasma/qqc2-breeze-style/style/qtquickcontrols/ToolButton.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 import QtQuick
0005 import QtQuick.Templates as T
0006 import org.kde.kirigami as Kirigami
0007 import org.kde.breeze
0008 import org.kde.breeze.impl as Impl
0009 
0010 T.ToolButton {
0011     id: control
0012 
0013     // HACK: Compatibility with qqc2-desktop-style hack for showing arrows when buttons open menus
0014     // This one is at the level of `control` to make it more reliably accessible to the indicator.
0015     // Unlike qqc2-desktop-style, the arrow is in the indicator property instead of the background.
0016     property bool __showMenuArrow: false
0017 
0018     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0019                             implicitContentWidth + leftPadding + rightPadding,
0020                             implicitIndicatorWidth + leftPadding + rightPadding)
0021     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0022                              implicitContentHeight + topPadding + bottomPadding,
0023                              implicitIndicatorHeight + topPadding + bottomPadding)
0024 
0025     flat: true
0026 
0027     hoverEnabled: Qt.styleHints.useHoverEffects
0028 
0029     Kirigami.Theme.colorSet: /*control.highlighted ? Kirigami.Theme.Selection :*/ Kirigami.Theme.Button
0030     Kirigami.Theme.inherit: false//control.flat && !control.down && !control.checked
0031     // Absolutely terrible HACK:
0032     // For some reason, ActionToolBar overrides the colorSet and inherit attached properties
0033     Component.onCompleted: {
0034         //console.log("colorSet: " + Kirigami.Theme.colorSet)
0035         //console.log("inherit: " + Kirigami.Theme.inherit)
0036         Kirigami.Theme.colorSet = Kirigami.Theme.Button/*Qt.binding(() => control.highlighted ? Kirigami.Theme.Selection : Kirigami.Theme.Button)*/
0037         Kirigami.Theme.inherit = false//Qt.binding(() => control.flat && !(control.down || control.checked))
0038     }
0039 
0040     padding: Kirigami.Units.mediumSpacing
0041     leftPadding: {
0042         if ((!contentItem.hasIcon && contentItem.textBesideIcon) // False if contentItem has been replaced
0043             || display == T.AbstractButton.TextOnly
0044             || display == T.AbstractButton.TextUnderIcon) {
0045             return Impl.Units.largeHorizontalPadding
0046         } else {
0047             return control.horizontalPadding
0048         }
0049     }
0050     rightPadding: {
0051         if (contentItem.hasLabel && display != T.AbstractButton.IconOnly) { // False if contentItem has been replaced
0052             return Impl.Units.largeHorizontalPadding
0053         } else {
0054             return control.horizontalPadding
0055         }
0056     }
0057 
0058     spacing: Kirigami.Units.mediumSpacing
0059 
0060     icon.width: Kirigami.Units.iconSizes.sizeForLabels
0061     icon.height: Kirigami.Units.iconSizes.sizeForLabels
0062 
0063     Kirigami.MnemonicData.enabled: control.enabled && control.visible
0064     Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.ActionElement
0065     Kirigami.MnemonicData.label: control.display !== T.Button.IconOnly ? control.text : ""
0066     Shortcut {
0067         //in case of explicit & the button manages it by itself
0068         enabled: !(RegExp(/\&[^\&]/).test(control.text))
0069         sequence: control.Kirigami.MnemonicData.sequence
0070         onActivated: control.clicked()
0071     }
0072 
0073     contentItem:Impl.IconLabelContent {
0074         control: control
0075         text: control.Kirigami.MnemonicData.richTextLabel
0076     }
0077 
0078     // Using a Loader here reduces the RAM usage
0079     indicator: Loader {
0080         property alias iconHeight: control.icon.height
0081         property alias iconWidth: control.icon.width
0082         anchors {
0083             right: control.right
0084             rightMargin: control.rightPadding
0085             verticalCenter: control.verticalCenter
0086         }
0087         visible: control.__showMenuArrow
0088         active: visible
0089         sourceComponent: Component {
0090             Kirigami.Icon {
0091                 anchors.centerIn: parent
0092                 implicitHeight: iconHeight
0093                 implicitWidth: iconWidth
0094                 source: "arrow-down"
0095             }
0096         }
0097     }
0098 
0099     background: Impl.ButtonBackground {
0100         // HACK: Compatibility with qqc2-desktop-style hack for showing arrows when buttons open menus
0101         // This one is in the background because that's what Kirigami expects
0102         property alias showMenuArrow: control.__showMenuArrow
0103         control: control
0104     }
0105 }