Kirigami2

UrlButton.qml
1/*
2 * SPDX-FileCopyrightText: 2018 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import org.kde.kirigami as Kirigami
9import org.kde.kirigami.private as KirigamiPrivate
10import QtQuick.Controls 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 */
22Kirigami.LinkButton {
23 id: button
24
25 property string url
26
27 text: url
28 enabled: url.length > 0
29 visible: text.length > 0
30 acceptedButtons: Qt.LeftButton | Qt.RightButton
31
32 Accessible.name: text
33 Accessible.description: text !== url
34 ? qsTr("Open link %1", "@info:whatsthis").arg(url)
35 : qsTr("Open link", "@info:whatsthis")
36
37 onPressed: mouse => {
38 if (mouse.button === Qt.RightButton) {
39 menu.popup();
40 }
41 }
42
43 onClicked: mouse => {
44 if (mouse.button !== Qt.RightButton) {
45 Qt.openUrlExternally(url);
46 }
47 }
48
49 QQC2.ToolTip {
50 // If button's text has been overridden, show a tooltip to expose the raw URL
51 visible: button.text !== button.url && button.mouseArea.containsMouse
52 text: button.url
53 }
54
55 QQC2.Menu {
56 id: menu
57 QQC2.MenuItem {
58 text: qsTr("Copy Link to Clipboard")
59 icon.name: "edit-copy"
60 onClicked: KirigamiPrivate.CopyHelperPrivate.copyTextToClipboard(button.url)
61 }
62 }
63}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:09:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.