Kirigami2

LinkButton.qml
1/*
2 * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import QtQuick.Controls as QQC2
9import QtQuick.Templates as T
10import org.kde.kirigami as Kirigami
11
12/**
13 * @brief A button that looks like a link.
14 *
15 * It uses the link color settings and triggers an action when clicked.
16 *
17 * Maps to the Command Link in the HIG:
18 * https://develop.kde.org/hig/components/navigation/commandlink/
19 *
20 * @since 5.52
21 * @since org.kde.kirigami 2.6
22 * @inherit QtQuick.Controls.Label
23 */
24QQC2.Label {
25 id: control
26
27 property T.Action action
28
29 /**
30 * @brief This property holds the mouse buttons that the mouse area reacts to.
31 * @see QtQuick.MouseArea::acceptedButtons
32 * @property Qt::MouseButtons acceptedButtons
33 */
34 property alias acceptedButtons: area.acceptedButtons
35
36 /**
37 * @brief This property holds the mouse area element covering the button.
38 * @property MouseArea area
39 */
40 property alias mouseArea: area
41
42 activeFocusOnTab: true
43 Accessible.role: Accessible.Button
44 Accessible.name: text
45 Accessible.onPressAction: clicked({ button: Qt.LeftButton })
46
47 text: action?.text ?? ""
48 enabled: action?.enabled ?? true
49
50 onClicked: action?.trigger()
51
52 font.bold: activeFocus
53 font.underline: enabled
54 color: enabled ? Kirigami.Theme.linkColor : Kirigami.Theme.textColor
55 horizontalAlignment: Text.AlignHCenter
56 verticalAlignment: Text.AlignVCenter
57 elide: Text.ElideRight
58
59 signal pressed(var mouse)
60 signal clicked(var mouse)
61
62 Keys.onPressed: event => {
63 switch (event.key) {
64 case Qt.Key_Space:
65 case Qt.Key_Enter:
66 case Qt.Key_Return:
67 case Qt.Key_Select:
68 control.clicked({ button: Qt.LeftButton });
69 event.accepted = true;
70 break;
71 case Qt.Key_Menu:
72 control.pressed({ button: Qt.RightButton });
73 event.accepted = true;
74 break;
75 }
76 }
77
78 MouseArea {
79 id: area
80 anchors.fill: parent
81 hoverEnabled: true
82 cursorShape: Qt.PointingHandCursor
83
84 onClicked: mouse => control.clicked(mouse)
85 onPressed: mouse => control.pressed(mouse)
86 }
87}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:09:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.