Warning, /frameworks/kirigami/src/controls/UrlButton.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 2.2
0008 import org.kde.kirigami 2.20 as Kirigami
0009 import org.kde.kirigami.private 2.6 as KirigamiPrivate
0010 import QtQuick.Controls 2.1 as QQC2
0011 
0012 /**
0013  * @brief A link button that contains a URL.
0014  *
0015  * It will open the URL by default, allowing to copy it if triggered with the
0016  * secondary mouse button.
0017  *
0018  * @since KDE Frameworks 5.63
0019  * @since org.kde.kirigami 2.6
0020  * @inherit QtQuick.LinkButton
0021  */
0022 Kirigami.LinkButton {
0023     id: button
0024 
0025     /**
0026      * @brief This property holds the URL the button links to.
0027      */
0028     property string url
0029 
0030     text: url
0031     enabled: !!url
0032     visible: text.length > 0
0033     acceptedButtons: Qt.LeftButton | Qt.RightButton
0034 
0035     Accessible.name: button.text !== button.url ? button.text : button.url
0036     Accessible.description: i18nc("@info:whatsthis", "Open link %1", button.text !== button.url ? button.url : "")
0037 
0038     onPressed: if (mouse.button === Qt.RightButton) {
0039         menu.popup()
0040     }
0041     onClicked: if (mouse.button !== Qt.RightButton) {
0042         Qt.openUrlExternally(url)
0043     }
0044 
0045     QQC2.ToolTip {
0046         // If button's text has been overridden, show a tooltip to expose the raw URL
0047         visible: button.text !== button.url && button.mouseArea.containsMouse
0048         text: url
0049     }
0050 
0051     QQC2.Menu {
0052         id: menu
0053         QQC2.MenuItem {
0054             text: qsTr("Copy Link to Clipboard")
0055             icon.name: "edit-copy"
0056             onClicked: KirigamiPrivate.CopyHelperPrivate.copyTextToClipboard(button.url)
0057         }
0058     }
0059 }