|
9 | 9 | #include "BrowserWindow.h" |
10 | 10 | #include "History.h" |
11 | 11 | #include "Settings.h" |
12 | | -#include <QCoreApplication> |
| 12 | +#include <QClipboard> |
13 | 13 | #include <QFont> |
14 | 14 | #include <QFontMetrics> |
| 15 | +#include <QGuiApplication> |
15 | 16 | #include <QPoint> |
16 | 17 | #include <QResizeEvent> |
| 18 | +#include <QUrl> |
17 | 19 |
|
18 | 20 | extern String s_serenity_resource_root; |
19 | 21 | extern Browser::Settings* s_settings; |
@@ -76,6 +78,27 @@ Tab::Tab(QMainWindow* window) |
76 | 78 | m_back_action->setEnabled(m_history.can_go_back()); |
77 | 79 | m_forward_action->setEnabled(m_history.can_go_forward()); |
78 | 80 | }); |
| 81 | + |
| 82 | + QObject::connect(m_view, &WebView::link_content_menu, [this] (QPoint &local_position, const QUrl& url, unsigned ){ |
| 83 | + auto global_position = this->mapToGlobal(local_position); |
| 84 | + auto menu = QMenu(); |
| 85 | + |
| 86 | + auto copy_link_action = new QAction(tr("Copy Link")); |
| 87 | + auto open_link_in_tab_action = new QAction(tr("Open link in a new tab")); |
| 88 | + |
| 89 | + menu.addAction(open_link_in_tab_action); |
| 90 | + menu.addAction(copy_link_action); |
| 91 | + auto res = menu.exec(global_position); |
| 92 | + |
| 93 | + if (res == copy_link_action) { |
| 94 | + QClipboard *clipboard = QGuiApplication::clipboard(); |
| 95 | + clipboard->setText(url.toString()); |
| 96 | + qDebug() << "Copied to clipboard text:" << url.toString(); |
| 97 | + } else if (res == open_link_in_tab_action){ |
| 98 | + auto browser_window = static_cast<BrowserWindow*>(m_window); |
| 99 | + return browser_window->new_tab_with_url(url); |
| 100 | + } |
| 101 | + }); |
79 | 102 | QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed); |
80 | 103 | QObject::connect(m_view, &WebView::title_changed, this, &Tab::page_title_changed); |
81 | 104 | QObject::connect(m_view, &WebView::favicon_changed, this, &Tab::page_favicon_changed); |
|
0 commit comments