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

KDE's Doxygen guidelines are available online.