Plasma-framework

ButtonContent.qml
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
8import QtQuick.Layouts
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11import org.kde.kirigami as Kirigami
12import "../" as PlasmaComponents
14RowLayout {
15 id: root
16
17 required property string labelText
18 required property T.Button button
19
20 readonly property bool usingFocusBackground: !button.flat && buttonSvg.hasElement("hint-focus-highlighted-background") && button.visualFocus && !(button.pressed || button.checked)
21 readonly property int defaultIconSize: button.flat ? Kirigami.Units.iconSizes.smallMedium : Kirigami.Units.iconSizes.small
22
23 spacing: button.spacing
25 GridLayout {
26 Layout.fillWidth: true
27 Layout.fillHeight: true
28 columns: root.button.display == T.Button.TextBesideIcon ? 2 : 1
29 rowSpacing: root.button.spacing
30 columnSpacing: rowSpacing
31
32 Kirigami.Icon {
33 id: icon
34
35 Layout.alignment: Qt.AlignCenter
36
37 Layout.fillWidth: root.button.display !== T.Button.TextBesideIcon || root.labelText.length === 0
38 Layout.fillHeight: true
39
40 Layout.minimumWidth: Math.min(root.width, root.height, implicitWidth)
41 Layout.minimumHeight: Math.min(root.width, root.height, implicitHeight)
42
43 Layout.maximumWidth: root.button.icon.width > 0 ? root.button.icon.width : Number.POSITIVE_INFINITY
44 Layout.maximumHeight: root.button.icon.height > 0 ? root.button.icon.height : Number.POSITIVE_INFINITY
45
46 implicitWidth: root.button.icon.width > 0 ? root.button.icon.width : root.defaultIconSize
47 implicitHeight: root.button.icon.height > 0 ? root.button.icon.height : root.defaultIconSize
48 visible: source.length > 0 && root.button.display !== T.Button.TextOnly
49 source: root.button.icon ? (root.button.icon.name || root.button.icon.source) : ""
50 selected: root.usingFocusBackground
51 }
52 PlasmaComponents.Label {
53 id: label
54 Layout.fillWidth: true
55 Layout.fillHeight: true
56 visible: text.length > 0 && root.button.display !== T.Button.IconOnly
57 text: root.labelText
58 font: root.button.font
59 color: root.usingFocusBackground ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
60 horizontalAlignment: root.button.display !== T.Button.TextUnderIcon && icon.visible ? Text.AlignLeft : Text.AlignHCenter
61 verticalAlignment: Text.AlignVCenter
62 elide: Text.ElideRight
63 }
64 }
65 KSvg.SvgItem {
66 visible: root.button.Accessible.role === Accessible.ButtonMenu && label.visible
67 Layout.preferredWidth: Kirigami.Units.iconSizes.small
68 Layout.preferredHeight: Layout.preferredWidth
69 Layout.alignment: Qt.AlignCenter
70 imagePath: "widgets/arrows"
71 elementId: "down-arrow"
72 }
73 KSvg.Svg {
74 id: buttonSvg
75 imagePath: "widgets/button"
76 }
77}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:54:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.