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