diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/bookmarkswidget.cpp | 47 | ||||
-rw-r--r-- | src/bookmarks/bookmarkswidget.h | 1 | ||||
-rw-r--r-- | src/browser.cpp | 28 |
3 files changed, 45 insertions, 31 deletions
diff --git a/src/bookmarks/bookmarkswidget.cpp b/src/bookmarks/bookmarkswidget.cpp index 21739e7..e05f291 100644 --- a/src/bookmarks/bookmarkswidget.cpp +++ b/src/bookmarks/bookmarkswidget.cpp @@ -9,8 +9,13 @@ #include "bookmarkswidget.h" #include "bookmarkmodel.h" #include "editbookmarkdialog.h" +#include "mainwindow/mainwindow.h" +#include "subwindow/subwindow.h" #include "ui_bookmarksform.h" +#include "webengine/webprofilemanager.h" +#include "webengine/webview.h" #include <QFileDialog> +#include <QMenu> #include <QTreeView> #include <QUrl> @@ -90,9 +95,47 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) const QModelIndex idx = ui->treeView->indexAt(pos); if(idx.isValid()) { const QUrl url = m_model->data(idx, 1, Qt::DisplayRole).toUrl(); - const QPoint _pos = ui->treeView->viewport()->mapToGlobal(pos); - emit showContextMenu(url, _pos); + // get parent main window + MainWindow *window = nullptr; + for(QWidget *w = this; w != nullptr && window == nullptr; w = w->parentWidget()) { + window = qobject_cast<MainWindow *>(w); + } + if(window == nullptr) + return; + + auto *subwindow = window->currentSubWindow(); + if(subwindow == nullptr) + return; + + auto *menu = new QMenu(this); + + menu->addAction(tr("Open link in current tab"), subwindow, [url, subwindow]() { + subwindow->currentView()->load(url); + }); + + auto *openInCurrentTabWithProfile = menu->addMenu(tr("Open link in current tab with profile")); + profileMenu(openInCurrentTabWithProfile, [url, subwindow](WebProfile *profile) { + subwindow->currentView()->setProfile(profile); + subwindow->currentView()->load(url); + }); + + menu->addAction(tr("Open link in new tab"), subwindow, [url, subwindow]() { + subwindow->addTab(url); + }); + + auto *openInNewTabWithProfile = menu->addMenu(tr("Open link in new tab with profile")); + profileMenu(openInNewTabWithProfile, [url, subwindow](WebProfile *profile) { + subwindow->addTab(url, profile); + }); + + menu->addSeparator(); + menu->addAction(tr("Clear selection"), this, [this]() { + ui->treeView->setCurrentIndex(QModelIndex()); + ui->treeView->clearSelection(); + }); + + menu->exec(ui->treeView->viewport()->mapToGlobal(pos)); } }); diff --git a/src/bookmarks/bookmarkswidget.h b/src/bookmarks/bookmarkswidget.h index 432d936..5ba8080 100644 --- a/src/bookmarks/bookmarkswidget.h +++ b/src/bookmarks/bookmarkswidget.h @@ -34,7 +34,6 @@ protected: void editBookmark(const QModelIndex &index); signals: - void showContextMenu(const QUrl &url, const QPoint &pos); void openUrl(const QUrl &url); public slots: diff --git a/src/browser.cpp b/src/browser.cpp index 20367aa..3b47048 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -206,34 +206,6 @@ void Browser::setup() // bookmarks m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value())); - connect(m_bookmarks.get(), &BookmarksWidget::showContextMenu, this, [this](const QUrl &url, const QPoint &pos) { - auto *subwindow = m_windows.last()->currentSubWindow(); - if(subwindow == nullptr) - return; - - auto *menu = new QMenu(m_bookmarks.get()); - - menu->addAction(tr("Open link in current tab"), subwindow, [url, subwindow]() { - subwindow->currentView()->load(url); - }); - - auto *openInCurrentTabWithProfile = menu->addMenu(tr("Open link in current tab with profile")); - profileMenu(openInCurrentTabWithProfile, [url, subwindow](WebProfile *profile) { - subwindow->currentView()->setProfile(profile); - subwindow->currentView()->load(url); - }); - - menu->addAction(tr("Open link in new tab"), subwindow, [url, subwindow]() { - subwindow->addTab(url); - }); - - auto *openInNewTabWithProfile = menu->addMenu(tr("Open link in new tab with profile")); - profileMenu(openInNewTabWithProfile, [url, subwindow](WebProfile *profile) { - subwindow->addTab(url, profile); - }); - - menu->exec(pos); - }); connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { m_windows.last()->createTab(url); |