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, allowing to copy it if triggered with the
16  * secondary mouse button.
17  *
18  * @since KDE Frameworks 5.63
19  * @since org.kde.kirigami 2.6
20  * @inherit QtQuick.LinkButton
21  */
22 Kirigami.LinkButton {
23  id: button
24 
25  /**
26  * @brief This property holds the URL the button links to.
27  */
28  property string url
29 
30  text: url
31  enabled: !!url
32  visible: text.length > 0
33  acceptedButtons: Qt.LeftButton | Qt.RightButton
34 
35  Accessible.name: button.text !== button.url ? button.text : button.url
36  Accessible.description: i18nc("@info:whatsthis", "Open link %1", button.text !== button.url ? button.url : "")
37 
38  onPressed: if (mouse.button === Qt.RightButton) {
39  menu.popup()
40  }
41  onClicked: if (mouse.button !== Qt.RightButton) {
42  Qt.openUrlExternally(url)
43  }
44 
45  QQC2.ToolTip {
46  // If button's text has been overridden, show a tooltip to expose the raw URL
47  visible: button.text !== button.url && button.mouseArea.containsMouse
48  text: url
49  }
50 
51  QQC2.Menu {
52  id: menu
53  QQC2.MenuItem {
54  text: qsTr("Copy Link to Clipboard")
55  icon.name: "edit-copy"
56  onClicked: KirigamiPrivate.CopyHelperPrivate.copyTextToClipboard(button.url)
57  }
58  }
59 }
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 Oct 1 2023 03:58:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.