1/* 2 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org> 3 * SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com> 4 * SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7import QtQuick 2.12 8import QtQuick.Layouts 1.12 9import QtQuick.Templates @QQC2_VERSION@ as T 10import org.kde.plasma.core 2.0 as PlasmaCore 11import "../" as PlasmaComponents 12 13GridLayout { 14 id: root 15 16 property string labelText: "" 17 18 readonly property bool usingFocusBackground: !parent.flat && buttonSvg.hasElement("hint-focus-highlighted-background") && parent.visualFocus && !(parent.pressed || parent.checked) 19 20 PlasmaCore.ColorScope.inherit: true 21 22 columns: parent.display == T.Button.TextBesideIcon ? 2 : 1 23 24 rowSpacing: parent.spacing 25 columnSpacing: rowSpacing 26 27 PlasmaCore.IconItem { 28 id: icon 29 30 readonly property int defaultIconSize: root.parent.flat ? PlasmaCore.Units.iconSizes.smallMedium : PlasmaCore.Units.iconSizes.small 31 32 Layout.alignment: Qt.AlignCenter 33 34 Layout.fillWidth: root.parent.display !== T.Button.TextBesideIcon || label.text.length == 0 35 Layout.fillHeight: true 36 37 Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth) 38 Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight) 39 40 Layout.maximumWidth: root.parent.icon.width > 0 ? root.parent.icon.width : Number.POSITIVE_INFINITY 41 Layout.maximumHeight: root.parent.icon.height > 0 ? root.parent.icon.height : Number.POSITIVE_INFINITY 42 43 implicitWidth: root.parent.icon.width > 0 ? root.parent.icon.width : defaultIconSize 44 implicitHeight: root.parent.icon.height > 0 ? root.parent.icon.height : defaultIconSize 45 colorGroup: parent.PlasmaCore.ColorScope.colorGroup 46 visible: source.length > 0 && root.parent.display !== T.Button.TextOnly 47 source: root.parent.icon ? (root.parent.icon.name || root.parent.icon.source) : "" 48 status: usingFocusBackground ? PlasmaCore.Svg.Selected : PlasmaCore.Svg.Normal 49 } 50 PlasmaComponents.Label { 51 id: label 52 Layout.fillWidth: true 53 Layout.fillHeight: true 54 visible: text.length > 0 && root.parent.display !== T.Button.IconOnly 55 text: labelText 56 font: root.parent.font 57 color: usingFocusBackground ? PlasmaCore.ColorScope.highlightedTextColor : PlasmaCore.ColorScope.textColor 58 horizontalAlignment: root.parent.display !== T.Button.TextUnderIcon && icon.visible ? Text.AlignLeft : Text.AlignHCenter 59 verticalAlignment: Text.AlignVCenter 60 elide: Text.ElideRight 61 } 62 PlasmaCore.Svg { 63 id: buttonSvg 64 imagePath: "widgets/button" 65 } 66} 67