1 | /* |
2 | This file is part of the KDE project |
3 | SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org> |
4 | SPDX-FileCopyrightText: 2006 Daniel Teske <teske@squorn.de> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #include "kbookmarkaction.h" |
10 | #include "kbookmarkowner.h" |
11 | |
12 | #include <QDesktopServices> |
13 | #include <QGuiApplication> |
14 | |
15 | KBookmarkAction::KBookmarkAction(const KBookmark &bk, KBookmarkOwner *owner, QObject *parent) |
16 | : QAction(bk.text().replace(c: QLatin1Char('&'), after: QLatin1String("&&" )), parent) |
17 | , KBookmarkActionInterface(bk) |
18 | , m_pOwner(owner) |
19 | { |
20 | setIcon(QIcon::fromTheme(name: bookmark().icon())); |
21 | setIconText(text()); |
22 | setToolTip(bookmark().url().toDisplayString(options: QUrl::PreferLocalFile)); |
23 | setStatusTip(toolTip()); |
24 | setWhatsThis(toolTip()); |
25 | const QString description = bk.description(); |
26 | if (!description.isEmpty()) { |
27 | setToolTip(description); |
28 | } |
29 | connect(sender: this, signal: &QAction::triggered, context: this, slot: &KBookmarkAction::slotTriggered); |
30 | } |
31 | |
32 | KBookmarkAction::~KBookmarkAction() |
33 | { |
34 | } |
35 | |
36 | void KBookmarkAction::slotTriggered() |
37 | { |
38 | slotSelected(mb: QGuiApplication::mouseButtons(), km: QGuiApplication::keyboardModifiers()); |
39 | } |
40 | |
41 | void KBookmarkAction::slotSelected(Qt::MouseButtons mb, Qt::KeyboardModifiers km) |
42 | { |
43 | if (!m_pOwner) { |
44 | QDesktopServices::openUrl(url: bookmark().url()); |
45 | } else { |
46 | m_pOwner->openBookmark(bm: bookmark(), mb, km); |
47 | } |
48 | } |
49 | |
50 | #include "moc_kbookmarkaction.cpp" |
51 | |