Kirigami2

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

KDE's Doxygen guidelines are available online.