| 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 "kbookmarkaction_p.h" |
| 11 | #include "kbookmarkowner.h" |
| 12 | |
| 13 | #include <QDesktopServices> |
| 14 | #include <QGuiApplication> |
| 15 | |
| 16 | KBookmarkAction::KBookmarkAction(const KBookmark &bk, KBookmarkOwner *owner, QObject *parent) |
| 17 | : QAction(bk.text().replace(c: QLatin1Char('&'), after: QLatin1String("&&" )), parent) |
| 18 | , KBookmarkActionInterface(bk) |
| 19 | , d(new KBookmarkActionPrivate(this, owner)) |
| 20 | { |
| 21 | setIcon(QIcon::fromTheme(name: bookmark().icon())); |
| 22 | setIconText(text()); |
| 23 | setToolTip(bookmark().url().toDisplayString(options: QUrl::PreferLocalFile)); |
| 24 | setStatusTip(toolTip()); |
| 25 | setWhatsThis(toolTip()); |
| 26 | const QString description = bk.description(); |
| 27 | if (!description.isEmpty()) { |
| 28 | setToolTip(description); |
| 29 | } |
| 30 | connect(sender: this, signal: &QAction::triggered, context: this, slot: &KBookmarkAction::slotTriggered); |
| 31 | } |
| 32 | |
| 33 | KBookmarkAction::~KBookmarkAction() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | void KBookmarkAction::slotTriggered() |
| 38 | { |
| 39 | slotSelected(mb: d->buttons, km: QGuiApplication::keyboardModifiers()); |
| 40 | } |
| 41 | |
| 42 | void KBookmarkAction::slotSelected(Qt::MouseButtons mb, Qt::KeyboardModifiers km) |
| 43 | { |
| 44 | if (!d->owner) { |
| 45 | QDesktopServices::openUrl(url: bookmark().url()); |
| 46 | } else { |
| 47 | d->owner->openBookmark(bm: bookmark(), mb, km); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | #include "moc_kbookmarkaction.cpp" |
| 52 | |