Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/ToolButton.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2017 The Qt Company Ltd.
0004     SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0005 
0006     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0007 */
0008 
0009 
0010 import QtQuick 2.6
0011 import QtQuick.Templates 2.15 as T
0012 import org.kde.kirigami 2.4 as Kirigami
0013 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
0014 
0015 T.ToolButton {
0016     id: controlRoot
0017 
0018     palette: Kirigami.Theme.inherit ? Kirigami.Theme.palette : undefined
0019     Kirigami.Theme.colorSet: flat ? Kirigami.Theme.Window : Kirigami.Theme.Button
0020     Kirigami.Theme.inherit: flat
0021 
0022     implicitWidth: Math.max((text && display !== T.AbstractButton.IconOnly ?
0023         implicitBackgroundWidth : implicitHeight) + leftInset + rightInset,
0024         implicitContentWidth + leftPadding + rightPadding)
0025     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0026                              implicitContentHeight + topPadding + bottomPadding)
0027 
0028     hoverEnabled: Qt.styleHints.useHoverEffects
0029 
0030     flat: true
0031     Kirigami.MnemonicData.enabled: controlRoot.enabled && controlRoot.visible
0032     Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl
0033     Kirigami.MnemonicData.label: controlRoot.text
0034 
0035     // KF6 TODO: investigate setting this by default
0036     // focusPolicy: Qt.TabFocus
0037 
0038     Shortcut {
0039         //in case of explicit & the button manages it by itself
0040         enabled: !(RegExp(/\&[^\&]/).test(controlRoot.text))
0041         sequence: controlRoot.Kirigami.MnemonicData.sequence
0042         onActivated: controlRoot.clicked()
0043     }
0044     background: StylePrivate.StyleItem {
0045         id: styleitem
0046         control: controlRoot
0047         elementType: "toolbutton"
0048         sunken: controlRoot.down
0049         on: controlRoot.checkable && controlRoot.checked
0050         hover: controlRoot.hovered
0051         text: controlRoot.Kirigami.MnemonicData.mnemonicLabel
0052         hasFocus: controlRoot.visualFocus || (!controlRoot.flat && controlRoot.pressed) || controlRoot.highlighted
0053         flat: controlRoot.flat
0054 
0055         // Set this to true or set `Accessible.role: Accessible.ButtonMenu`
0056         // to have the style render a menu arrow for the ToolButton.
0057         // Note: If you use this directly, ensure you check whether your background item
0058         // has this property at all, otherwise things will break with different
0059         // QtQuick styles!
0060         // TODO KF6: remove
0061         property bool showMenuArrow: controlRoot.Accessible.role === Accessible.ButtonMenu
0062 
0063         // note: keep in sync with DelayButton
0064         readonly property int toolButtonStyle: {
0065             switch (controlRoot.display) {
0066             case T.AbstractButton.IconOnly: return Qt.ToolButtonIconOnly;
0067             case T.AbstractButton.TextOnly: return Qt.ToolButtonTextOnly;
0068             case T.AbstractButton.TextBesideIcon:
0069             case T.AbstractButton.TextUnderIcon:
0070                 // TODO KF6: check if this condition is still needed
0071                 if (controlRoot.icon.name !== "" || controlRoot.icon.source.toString() !== "") {
0072                     // has icon
0073                     switch (controlRoot.display) {
0074                         case T.AbstractButton.TextBesideIcon: return Qt.ToolButtonTextBesideIcon;
0075                         case T.AbstractButton.TextUnderIcon: return Qt.ToolButtonTextUnderIcon;
0076                     }
0077                 } else {
0078                     return Qt.ToolButtonTextOnly;
0079                 }
0080             default: return Qt.ToolButtonFollowStyle;
0081             }
0082         }
0083 
0084         properties: {
0085             "icon": controlRoot.icon.name !== "" ? controlRoot.icon.name : controlRoot.icon.source,
0086             "iconColor": Qt.colorEqual(controlRoot.icon.color, "transparent") ? Kirigami.Theme.textColor : controlRoot.icon.color,
0087             "iconWidth": controlRoot.icon.width,
0088             "iconHeight": controlRoot.icon.height,
0089 
0090             "menu": showMenuArrow,
0091             "toolButtonStyle": toolButtonStyle,
0092         }
0093     }
0094 }