Warning, /frameworks/kirigami/src/controls/LinkButton.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import QtQuick.Templates as T
0010 import org.kde.kirigami as Kirigami
0011 
0012 /**
0013  * @brief A button that looks like a link.
0014  *
0015  * It uses the link color settings and triggers an action when clicked.
0016  *
0017  * Maps to the Command Link in the HIG:
0018  * https://develop.kde.org/hig/components/navigation/commandlink/
0019  *
0020  * @since 5.52
0021  * @since org.kde.kirigami 2.6
0022  * @inherit QtQuick.Controls.Label
0023  */
0024 QQC2.Label {
0025     id: control
0026 
0027     property T.Action action
0028 
0029     /**
0030      * @brief This property holds the mouse buttons that the mouse area reacts to.
0031      * @see QtQuick.MouseArea::acceptedButtons
0032      * @property Qt::MouseButtons acceptedButtons
0033      */
0034     property alias acceptedButtons: area.acceptedButtons
0035 
0036     /**
0037      * @brief This property holds the mouse area element covering the button.
0038      * @property MouseArea area
0039      */
0040     property alias mouseArea: area
0041 
0042     activeFocusOnTab: true
0043     Accessible.role: Accessible.Button
0044     Accessible.name: text
0045     Accessible.onPressAction: clicked({ button: Qt.LeftButton })
0046 
0047     text: action?.text ?? ""
0048     enabled: action?.enabled ?? true
0049 
0050     onClicked: action?.trigger()
0051 
0052     font.bold: activeFocus
0053     font.underline: enabled
0054     color: enabled ? Kirigami.Theme.linkColor : Kirigami.Theme.textColor
0055     horizontalAlignment: Text.AlignHCenter
0056     verticalAlignment: Text.AlignVCenter
0057     elide: Text.ElideRight
0058 
0059     signal pressed(var mouse)
0060     signal clicked(var mouse)
0061 
0062     Keys.onPressed: event => {
0063         switch (event.key) {
0064         case Qt.Key_Space:
0065         case Qt.Key_Enter:
0066         case Qt.Key_Return:
0067         case Qt.Key_Select:
0068             control.clicked({ button: Qt.LeftButton });
0069             event.accepted = true;
0070             break;
0071         case Qt.Key_Menu:
0072             control.pressed({ button: Qt.RightButton });
0073             event.accepted = true;
0074             break;
0075         }
0076     }
0077 
0078     MouseArea {
0079         id: area
0080         anchors.fill: parent
0081         hoverEnabled: true
0082         cursorShape: Qt.PointingHandCursor
0083 
0084         onClicked: mouse => control.clicked(mouse)
0085         onPressed: mouse => control.pressed(mouse)
0086     }
0087 }