Libplasma

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 // Can't rely on the transient Item::visible property
24 readonly property bool iconVisible: icon.source.toString() !== "" && button.display !== T.Button.TextOnly
25 readonly property bool labelVisible: labelText !== "" && root.button.display !== T.Button.IconOnly
26
27 spacing: button.spacing
28
29 GridLayout {
30 Layout.fillWidth: true
31 Layout.fillHeight: true
32 Layout.alignment: Qt.AlignCenter
33 columns: root.button.display == T.Button.TextBesideIcon ? 2 : 1
34 rowSpacing: root.button.spacing
35 columnSpacing: rowSpacing
36
38 id: icon
39
40 Layout.alignment: Qt.AlignCenter
41
42 Layout.fillWidth: root.button.display !== T.Button.TextBesideIcon || root.labelText === ""
43 Layout.fillHeight: true
44
45 Layout.minimumWidth: Math.min(root.width, root.height, implicitWidth)
46 Layout.minimumHeight: Math.min(root.width, root.height, implicitHeight)
47
48 Layout.maximumWidth: root.button.icon.width > 0 ? root.button.icon.width : Number.POSITIVE_INFINITY
49 Layout.maximumHeight: root.button.icon.height > 0 ? root.button.icon.height : Number.POSITIVE_INFINITY
50
51 implicitWidth: root.button.icon.width > 0 ? root.button.icon.width : root.defaultIconSize
52 implicitHeight: root.button.icon.height > 0 ? root.button.icon.height : root.defaultIconSize
53 visible: root.iconVisible
54 source: root.button.icon.name !== "" ? root.button.icon.name : root.button.icon.source
55 color: root.button.icon.color
56 selected: root.usingFocusBackground
57 }
58 PlasmaComponents.Label {
59 id: label
60 Layout.fillWidth: true
61 Layout.fillHeight: true
62 visible: root.labelVisible
63 text: root.labelText
64 font: root.button.font
65 color: root.usingFocusBackground ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
66 horizontalAlignment: root.button.display !== T.Button.TextUnderIcon && root.iconVisible ? Text.AlignLeft : Text.AlignHCenter
67 verticalAlignment: Text.AlignVCenter
68 elide: Text.ElideRight
69 }
70 }
71 KSvg.SvgItem {
72 visible: root.button.Accessible.role === Accessible.ButtonMenu && root.labelVisible
73 Layout.preferredWidth: Kirigami.Units.iconSizes.small
74 Layout.preferredHeight: Layout.preferredWidth
75 Layout.alignment: Qt.AlignCenter
76 imagePath: "widgets/arrows"
77 elementId: "down-arrow"
78 }
79 KSvg.Svg {
80 id: buttonSvg
81 imagePath: "widgets/button"
82 }
83}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:48:23 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.