Kirigami2

UrlButton.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 org.kde.kirigami 2.20 as Kirigami
9 import org.kde.kirigami.private 2.6 as KirigamiPrivate
10 import QtQuick.Controls 2.1 as QQC2
11 
12 /**
13  * @brief A link button that contains a URL.
14  *
15  * It will open the url by default, allow to copy it if triggered with the
16  * secondary mouse button.
17  *
18  * @since 5.63
19  * @since org.kde.kirigami 2.6
20  * @inherit QtQuick.LinkButton
21  */
22 Kirigami.LinkButton {
23  id: button
24 
25  property string url
26 
27  text: url
28  enabled: !!url
29  visible: text.length > 0
30  acceptedButtons: Qt.LeftButton | Qt.RightButton
31 
32  Accessible.name: button.text !== button.url ? button.text : button.url
33  Accessible.description: i18nc("@info:whatsthis", "Open link %1", button.text !== button.url ? button.url : "")
34 
35  onPressed: if (mouse.button === Qt.RightButton) {
36  menu.popup()
37  }
38  onClicked: if (mouse.button !== Qt.RightButton) {
39  Qt.openUrlExternally(url)
40  }
41 
42  QQC2.ToolTip {
43  // If button's text has been overridden, show a tooltip to expose the raw URL
44  visible: button.text !== button.url && button.mouseArea.containsMouse
45  text: url
46  }
47 
48  QQC2.Menu {
49  id: menu
50  QQC2.MenuItem {
51  text: qsTr("Copy Link to Clipboard")
52  icon.name: "edit-copy"
53  onClicked: KirigamiPrivate.CopyHelperPrivate.copyTextToClipboard(button.url)
54  }
55  }
56 }
QString i18nc(const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.